Spaces:
Running on Zero
Running on Zero
Force free diffusion model to float32 on CPU
Browse files
app.py
CHANGED
|
@@ -1033,8 +1033,12 @@ def free_diffusion_png(spec: AssetSpec, index: int, run_id: int) -> tuple[bytes
|
|
| 1033 |
from diffusers import DiffusionPipeline
|
| 1034 |
|
| 1035 |
if FREE_DIFFUSION_PIPE is None:
|
| 1036 |
-
FREE_DIFFUSION_PIPE = DiffusionPipeline.from_pretrained(FREE_IMAGE_MODEL)
|
| 1037 |
FREE_DIFFUSION_PIPE = FREE_DIFFUSION_PIPE.to("cpu")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1038 |
if hasattr(FREE_DIFFUSION_PIPE, "enable_attention_slicing"):
|
| 1039 |
FREE_DIFFUSION_PIPE.enable_attention_slicing()
|
| 1040 |
|
|
|
|
| 1033 |
from diffusers import DiffusionPipeline
|
| 1034 |
|
| 1035 |
if FREE_DIFFUSION_PIPE is None:
|
| 1036 |
+
FREE_DIFFUSION_PIPE = DiffusionPipeline.from_pretrained(FREE_IMAGE_MODEL, torch_dtype=torch.float32)
|
| 1037 |
FREE_DIFFUSION_PIPE = FREE_DIFFUSION_PIPE.to("cpu")
|
| 1038 |
+
for component_name in ("unet", "vae", "text_encoder"):
|
| 1039 |
+
component = getattr(FREE_DIFFUSION_PIPE, component_name, None)
|
| 1040 |
+
if component is not None and hasattr(component, "to"):
|
| 1041 |
+
component.to(device="cpu", dtype=torch.float32)
|
| 1042 |
if hasattr(FREE_DIFFUSION_PIPE, "enable_attention_slicing"):
|
| 1043 |
FREE_DIFFUSION_PIPE.enable_attention_slicing()
|
| 1044 |
|