|
| 1 | +<!--Copyright 2025 The HuggingFace Team. All rights reserved. |
| 2 | +
|
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 4 | +the License. You may obtain a copy of the License at |
| 5 | +
|
| 6 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +
|
| 8 | +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 9 | +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 10 | +specific language governing permissions and limitations under the License. |
| 11 | +--> |
| 12 | + |
| 13 | +# Chroma |
| 14 | + |
| 15 | +<div class="flex flex-wrap space-x-1"> |
| 16 | + <img alt="LoRA" src="https://img.shields.io/badge/LoRA-d8b4fe?style=flat"/> |
| 17 | + <img alt="MPS" src="https://img.shields.io/badge/MPS-000000?style=flat&logo=apple&logoColor=white%22"> |
| 18 | +</div> |
| 19 | + |
| 20 | +Chroma is a text to image generation model based on Flux. |
| 21 | + |
| 22 | +Original model checkpoints for Chroma can be found [here](https://huggingface.co/lodestones/Chroma). |
| 23 | + |
| 24 | +<Tip> |
| 25 | + |
| 26 | +Chroma can use all the same optimizations as Flux. |
| 27 | + |
| 28 | +</Tip> |
| 29 | + |
| 30 | +## Inference (Single File) |
| 31 | + |
| 32 | +The `ChromaTransformer2DModel` supports loading checkpoints in the original format. This is also useful when trying to load finetunes or quantized versions of the models that have been published by the community. |
| 33 | + |
| 34 | +The following example demonstrates how to run Chroma from a single file. |
| 35 | + |
| 36 | +Then run the following example |
| 37 | + |
| 38 | +```python |
| 39 | +import torch |
| 40 | +from diffusers import ChromaTransformer2DModel, ChromaPipeline |
| 41 | +from transformers import T5EncoderModel |
| 42 | + |
| 43 | +bfl_repo = "black-forest-labs/FLUX.1-dev" |
| 44 | +dtype = torch.bfloat16 |
| 45 | + |
| 46 | +transformer = ChromaTransformer2DModel.from_single_file("https://huggingface.co/lodestones/Chroma/blob/main/chroma-unlocked-v35.safetensors", torch_dtype=dtype) |
| 47 | + |
| 48 | +text_encoder = T5EncoderModel.from_pretrained(bfl_repo, subfolder="text_encoder_2", torch_dtype=dtype) |
| 49 | +tokenizer = T5Tokenizer.from_pretrained(bfl_repo, subfolder="tokenizer_2", torch_dtype=dtype) |
| 50 | + |
| 51 | +pipe = ChromaPipeline.from_pretrained(bfl_repo, transformer=transformer, text_encoder=text_encoder, tokenizer=tokenizer, torch_dtype=dtype) |
| 52 | + |
| 53 | +pipe.enable_model_cpu_offload() |
| 54 | + |
| 55 | +prompt = "A cat holding a sign that says hello world" |
| 56 | +image = pipe( |
| 57 | + prompt, |
| 58 | + guidance_scale=4.0, |
| 59 | + output_type="pil", |
| 60 | + num_inference_steps=26, |
| 61 | + generator=torch.Generator("cpu").manual_seed(0) |
| 62 | +).images[0] |
| 63 | + |
| 64 | +image.save("image.png") |
| 65 | +``` |
| 66 | + |
| 67 | +## ChromaPipeline |
| 68 | + |
| 69 | +[[autodoc]] ChromaPipeline |
| 70 | + - all |
| 71 | + - __call__ |
0 commit comments