Skip to content

SDXL with non-truncated prompts results in error #45

@bghira

Description

@bghira

This works:

from compel import Compel, ReturnedEmbeddingsType
from diffusers import DiffusionPipeline
import torch

pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-0.9", use_safetensors=True, torch_dtype=torch.float16).to("cuda")
compel = Compel(truncate_long_prompts=False, 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])
prompt = "('a psychedelic style', 'cat playing in the forest').and()"
negative_prompt = "a test negative prompt that would be very short" 
prompt = [prompt] * 4
conditioning, pooled = compel(prompt)
negative_embed, negative_pooled = compel([negative_prompt] * 4)
[conditioning, negative_embed] = compel.pad_conditioning_tensors_to_same_length([conditioning, negative_embed])
# generate image
images = pipeline(prompt_embeds=conditioning, pooled_prompt_embeds=pooled, negative_prompt_embeds=negative_embed, negative_pooled_prompt_embeds=negative_pooled, num_inference_steps=30, num_images_per_prompt=1).images
images[0].save('/notebooks/test0.png')
images[1].save('/notebooks/test1.png')
images[2].save('/notebooks/test2.png')
images[3].save('/notebooks/test3.png')

This does not work:

from compel import Compel, ReturnedEmbeddingsType
from diffusers import DiffusionPipeline
import torch

pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-0.9", use_safetensors=True, torch_dtype=torch.float16).to("cuda")
compel = Compel(truncate_long_prompts=False, 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])
prompt = "('a psychedelic style', 'cat playing in the forest').and()"
negative_prompt = "a test negative prompt that would be very long indeed and maybe we can blow past the seventy seven token limit and like, then we will see the error maybe? it is hard to say because the thing is hard to reproduce here in the standalone script, with the washed out and other studf that usuallyug esosouhfsldfh sldkf aldksfj glasdkjfg lasdkjfg laskdjfgh alsdkfg laskdhfjg alsdfg "
prompt = [prompt] * 4
conditioning, pooled = compel(prompt)
negative_embed, negative_pooled = compel([negative_prompt] * 4)
[conditioning, negative_embed] = compel.pad_conditioning_tensors_to_same_length([conditioning, negative_embed])
# generate image
images = pipeline(prompt_embeds=conditioning, pooled_prompt_embeds=pooled, negative_prompt_embeds=negative_embed, negative_pooled_prompt_embeds=negative_pooled, num_inference_steps=30, num_images_per_prompt=1).images
images[0].save('/notebooks/test0.png')
images[1].save('/notebooks/test1.png')
images[2].save('/notebooks/test2.png')
images[3].save('/notebooks/test3.png')

I'm not sure if there's something I'm doing wrong in this example, so, it's possible that the documentation simply needs an update.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions