Skip to content

Chroma fails to mask attention in the transformer #11724

Description

Describe the bug

Chroma has attention masks on both the transformer and T5. Right now only T5 computes with the proper mask. The attention masks from T5 should carry forward into the transformer and mask padding tokens except for the last padding token. See the reference implementation.

https://github.com/lodestone-rock/flow/blob/master/src/models/chroma/model.py#L222-L257

Reproduction

importtorchfromdiffusersimportChromaTransformer2DModelfromtransformersimportT5EncoderModel, T5Tokenizerfromoptimum.quantoimportfreeze, qint8, qfloat8, quantizefromchroma_pipelineimportChromaPipelinebfl_repo="black-forest-labs/FLUX.1-schnell"dtype=torch.bfloat16transformer=ChromaTransformer2DModel.from_single_file(
"chroma-unlocked-v37-detail-calibrated.safetensors",
torch_dtype=dtype,
).to('cuda')
quantize(transformer, weights=qint8, exclude=["proj_out", "x_embedder", "norm_out",
"context_embedder", "distilled_guidance_layer"])
freeze(transformer)
text_encoder=T5EncoderModel.from_pretrained(bfl_repo, subfolder="text_encoder_2", torch_dtype=dtype).to('cuda')
quantize(text_encoder, weights=qint8)
freeze(text_encoder)
tokenizer=T5Tokenizer.from_pretrained(bfl_repo, subfolder="tokenizer_2", torch_dtype=dtype)
pipe=ChromaPipeline.from_pretrained(bfl_repo, transformer=transformer, text_encoder=text_encoder,
tokenizer=tokenizer, torch_dtype=dtype).to('cuda')
generator=torch.Generator().manual_seed(0)
image=pipe(
prompt='pikachu playing a violin on mars, sign in the background says, "welcome to mars!!',
negative_prompt="",
width=1024,
height=1024,
num_inference_steps=35, generator=generator,
guidance_scale=5,
).images[0]
image.save('chroma/test_chroma0.png')

Image

Logs

System Info

linux 24.04, 3090, diffusers main

Who can help?

@DN6@Ednaordinary

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions