Manjushri commited on
Commit
5baa1fb
·
verified ·
1 Parent(s): b36176f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -4
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
- progress=gr.Progress(track_tqdm=True)
40
  torch.cuda.empty_cache()
41
- model_repo_id = "stabilityai/stable-diffusion-3.5-large-turbo"
42
- pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype = torch.float32)
43
- pipe = pipe.to(device)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()