damian0815 / compel

A prompting enhancement library for transformers-type text embedding systems
MIT License
526 stars 47 forks source link

when I try the code in compel-demo-sdxl.ipynb, a OverflowError returns #76

Open phoenixGRS opened 11 months ago

phoenixGRS commented 11 months ago

hello,when I try this code

compel = Compel(tokenizer=[pipeline.tokenizer, pipeline.tokenizer_2] , 
                text_encoder=[pipeline.text_encoder, pipeline.text_encoder_2], 
                returned_embeddings_type=ReturnedEmbeddingsType.PENULTIMATE_HIDDEN_STATES_NON_NORMALIZED, 
                requires_pooled=[False, True],
               truncate_long_prompts=False)

prompt_converted = "a cat playing with a ball++ in the forest"
negative_prompt_converted = "a long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long negative prompt"
conditioning, pooled = compel([prompt_converted, negative_prompt_converted])
print(conditioning.shape, pooled.shape)

image = pipeline(prompt_embeds=conditioning[0:1], pooled_prompt_embeds=pooled[0:1], 
                 negative_prompt_embeds=conditioning[1:2], negative_pooled_prompt_embeds=pooled[1:2],
                 num_inference_steps=24, width=768, height=768).images[0]
image

then it return

Traceback (most recent call last):
  File "20231011_ylj.py", line 259, in <module>
    conditioning, pooled = compel([prompt_converted, negative_prompt_converted])
  File "/root/miniconda3/envs/Diffusion/lib/python3.8/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/root/miniconda3/envs/Diffusion/lib/python3.8/site-packages/compel/compel.py", line 135, in __call__
    output = self.build_conditioning_tensor(text_input)
  File "/root/miniconda3/envs/Diffusion/lib/python3.8/site-packages/compel/compel.py", line 112, in build_conditioning_tensor
    conditioning, _ = self.build_conditioning_tensor_for_conjunction(conjunction)
  File "/root/miniconda3/envs/Diffusion/lib/python3.8/site-packages/compel/compel.py", line 186, in build_conditioning_tensor_for_conjunction
    this_conditioning, this_options = self.build_conditioning_tensor_for_prompt_object(p)
  File "/root/miniconda3/envs/Diffusion/lib/python3.8/site-packages/compel/compel.py", line 218, in build_conditioning_tensor_for_prompt_object
    return self._get_conditioning_for_flattened_prompt(prompt), {}
  File "/root/miniconda3/envs/Diffusion/lib/python3.8/site-packages/compel/compel.py", line 282, in _get_conditioning_for_flattened_prompt
    return self.conditioning_provider.get_embeddings_for_weighted_prompt_fragments(
  File "/root/miniconda3/envs/Diffusion/lib/python3.8/site-packages/compel/embeddings_provider.py", line 524, in get_embeddings_for_weighted_prompt_fragments
    outputs = [provider.get_embeddings_for_weighted_prompt_fragments(text_batch, fragment_weights_batch, should_return_tokens=should_return_tokens, device=device) for provider in self.embedding_providers]
  File "/root/miniconda3/envs/Diffusion/lib/python3.8/site-packages/compel/embeddings_provider.py", line 524, in <listcomp>
    outputs = [provider.get_embeddings_for_weighted_prompt_fragments(text_batch, fragment_weights_batch, should_return_tokens=should_return_tokens, device=device) for provider in self.embedding_providers]
  File "/root/miniconda3/envs/Diffusion/lib/python3.8/site-packages/compel/embeddings_provider.py", line 119, in get_embeddings_for_weighted_prompt_fragments
    tokens, per_token_weights, mask = self.get_token_ids_and_expand_weights(fragments, weights, device=device)
  File "/root/miniconda3/envs/Diffusion/lib/python3.8/site-packages/compel/embeddings_provider.py", line 280, in get_token_ids_and_expand_weights
    return self._chunk_and_pad_token_ids(all_token_ids, all_token_weights, device=device)
  File "/root/miniconda3/envs/Diffusion/lib/python3.8/site-packages/compel/embeddings_provider.py", line 307, in _chunk_and_pad_token_ids
    chunk_token_ids += [self.tokenizer.pad_token_id] * pad_length
OverflowError: cannot fit 'int' into an index-sized integer

I don't know how to fix it