Spaces:
Running
on
T4
Running
on
T4
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,11 +36,32 @@ def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed):
|
|
| 36 |
return image
|
| 37 |
|
| 38 |
if Model == "SD3.5 Turbo":
|
| 39 |
-
|
| 40 |
torch.cuda.empty_cache()
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
pipe.enable_model_cpu_offload()
|
| 45 |
pipe.vae.enable_slicing()
|
| 46 |
pipe.vae.enable_tiling()
|
|
|
|
| 36 |
return image
|
| 37 |
|
| 38 |
if Model == "SD3.5 Turbo":
|
| 39 |
+
torch.cuda.max_memory_allocated(device=device)
|
| 40 |
torch.cuda.empty_cache()
|
| 41 |
+
progress=gr.Progress(track_tqdm=True)
|
| 42 |
+
from diffusers import BitsAndBytesConfig, SD3Transformer2DModel
|
| 43 |
+
from diffusers import StableDiffusion3Pipeline
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
model_id = "stabilityai/stable-diffusion-3.5-large-turbo"
|
| 47 |
+
|
| 48 |
+
nf4_config = BitsAndBytesConfig(
|
| 49 |
+
load_in_4bit=True,
|
| 50 |
+
bnb_4bit_quant_type="nf4",
|
| 51 |
+
bnb_4bit_compute_dtype=torch.bfloat16)
|
| 52 |
+
model_nf4 = SD3Transformer2DModel.from_pretrained(
|
| 53 |
+
model_id,
|
| 54 |
+
subfolder="transformer",
|
| 55 |
+
quantization_config=nf4_config,
|
| 56 |
+
torch_dtype=torch.bfloat16)
|
| 57 |
+
|
| 58 |
+
t5_nf4 = T5EncoderModel.from_pretrained("diffusers/t5-nf4", torch_dtype=torch.bfloat16)
|
| 59 |
+
|
| 60 |
+
pipe = StableDiffusion3Pipeline.from_pretrained(
|
| 61 |
+
model_id,
|
| 62 |
+
transformer=model_nf4,
|
| 63 |
+
text_encoder_3=t5_nf4,
|
| 64 |
+
torch_dtype=torch.bfloat16)
|
| 65 |
pipe.enable_model_cpu_offload()
|
| 66 |
pipe.vae.enable_slicing()
|
| 67 |
pipe.vae.enable_tiling()
|