Update README.md
Browse files
README.md
CHANGED
|
@@ -53,6 +53,73 @@ image = pipe(
|
|
| 53 |
).images[0]
|
| 54 |
image.save("chroma.png")
|
| 55 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
ComfyUI
|
| 57 |
For advanced users and customized workflows, you can use Chroma with ComfyUI.
|
| 58 |
|
|
|
|
| 53 |
).images[0]
|
| 54 |
image.save("chroma.png")
|
| 55 |
```
|
| 56 |
+
|
| 57 |
+
Quantized inference using gemlite
|
| 58 |
+
|
| 59 |
+
```py
|
| 60 |
+
import torch
|
| 61 |
+
from diffusers import ChromaPipeline
|
| 62 |
+
|
| 63 |
+
pipe = ChromaPipeline.from_pretrained("lodestones/Chroma1-HD", torch_dtype=torch.float16)
|
| 64 |
+
#pipe.enable_model_cpu_offload()
|
| 65 |
+
|
| 66 |
+
#######################################################
|
| 67 |
+
import gemlite
|
| 68 |
+
device = 'cuda:0'
|
| 69 |
+
processor = gemlite.helper.A8W8_int8_dynamic
|
| 70 |
+
#processor = gemlite.helper.A8W8_fp8_dynamic
|
| 71 |
+
#processor = gemlite.helper.A16W4_MXFP
|
| 72 |
+
|
| 73 |
+
for name, module in pipe.transformer.named_modules():
|
| 74 |
+
module.name = name
|
| 75 |
+
|
| 76 |
+
def patch_linearlayers(model, fct):
|
| 77 |
+
for name, layer in model.named_children():
|
| 78 |
+
if isinstance(layer, torch.nn.Linear):
|
| 79 |
+
setattr(model, name, fct(layer, name))
|
| 80 |
+
else:
|
| 81 |
+
patch_linearlayers(layer, fct)
|
| 82 |
+
|
| 83 |
+
def patch_linear_to_gemlite(layer, name):
|
| 84 |
+
layer = layer.to(device, non_blocking=True)
|
| 85 |
+
try:
|
| 86 |
+
return processor(device=device).from_linear(layer)
|
| 87 |
+
except Exception as exception:
|
| 88 |
+
print('Skipping gemlite conversion for: ' + str(layer.name), exception)
|
| 89 |
+
return layer
|
| 90 |
+
|
| 91 |
+
patch_linearlayers(pipe.transformer, patch_linear_to_gemlite)
|
| 92 |
+
torch.cuda.synchronize()
|
| 93 |
+
torch.cuda.empty_cache()
|
| 94 |
+
|
| 95 |
+
pipe.to(device)
|
| 96 |
+
pipe.transformer.forward = torch.compile(pipe.transformer.forward, fullgraph=True)
|
| 97 |
+
pipe.vae.forward = torch.compile(pipe.vae.forward, fullgraph=True)
|
| 98 |
+
#pipe.set_progress_bar_config(disable=True)
|
| 99 |
+
#######################################################
|
| 100 |
+
|
| 101 |
+
prompt = [
|
| 102 |
+
"A high-fashion close-up portrait of a blonde woman in clear sunglasses. The image uses a bold teal and red color split for dramatic lighting. The background is a simple teal-green. The photo is sharp and well-composed, and is designed for viewing with anaglyph 3D glasses for optimal effect. It looks professionally done."
|
| 103 |
+
]
|
| 104 |
+
negative_prompt = ["low quality, ugly, unfinished, out of focus, deformed, disfigure, blurry, smudged, restricted palette, flat colors"]
|
| 105 |
+
|
| 106 |
+
import time
|
| 107 |
+
for _ in range(3):
|
| 108 |
+
t_start = time.time()
|
| 109 |
+
image = pipe(
|
| 110 |
+
prompt=prompt,
|
| 111 |
+
negative_prompt=negative_prompt,
|
| 112 |
+
generator=torch.Generator("cpu").manual_seed(433),
|
| 113 |
+
num_inference_steps=40,
|
| 114 |
+
guidance_scale=3.0,
|
| 115 |
+
num_images_per_prompt=1,
|
| 116 |
+
).images[0]
|
| 117 |
+
t_end = time.time()
|
| 118 |
+
print(f"Took: {t_end - t_start} secs.") #66.1242527961731 -> 27.72 sec
|
| 119 |
+
|
| 120 |
+
image.save("chroma.png")
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
ComfyUI
|
| 124 |
For advanced users and customized workflows, you can use Chroma with ComfyUI.
|
| 125 |
|