Download examples/stable_diffusion/model_inference_low_vram/stable-diffusion-v1-5.py from ymyy307/diffsynth: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/ymyy307/diffsynth/resolve/main/examples/stable_diffusion/model_inference_low_vram/stable-diffusion-v1-5.py
- Command line
-
hf download hf://ymyy307/diffsynth/examples/stable_diffusion/model_inference_low_vram/stable-diffusion-v1-5.py
-
curl -L -o stable-diffusion-v1-5.py https://huggingface.co/ymyy307/diffsynth/resolve/main/examples/stable_diffusion/model_inference_low_vram/stable-diffusion-v1-5.py
1.44 kB
| import torch | |
| from diffsynth.core import ModelConfig | |
| from diffsynth.pipelines.stable_diffusion import StableDiffusionPipeline | |
| vram_config = { | |
| "offload_dtype": torch.float32, | |
| "offload_device": "cpu", | |
| "onload_dtype": torch.float32, | |
| "onload_device": "cpu", | |
| "preparing_dtype": torch.float32, | |
| "preparing_device": "cuda", | |
| "computation_dtype": torch.float32, | |
| "computation_device": "cuda", | |
| } | |
| pipe = StableDiffusionPipeline.from_pretrained( | |
| torch_dtype=torch.float32, | |
| model_configs=[ | |
| ModelConfig(model_id="AI-ModelScope/stable-diffusion-v1-5", origin_file_pattern="text_encoder/model.safetensors", **vram_config), | |
| ModelConfig(model_id="AI-ModelScope/stable-diffusion-v1-5", origin_file_pattern="unet/diffusion_pytorch_model.safetensors", **vram_config), | |
| ModelConfig(model_id="AI-ModelScope/stable-diffusion-v1-5", origin_file_pattern="vae/diffusion_pytorch_model.safetensors", **vram_config), | |
| ], | |
| tokenizer_config=ModelConfig(model_id="AI-ModelScope/stable-diffusion-v1-5", origin_file_pattern="tokenizer/"), | |
| vram_limit=torch.cuda.mem_get_info("cuda")[1] / (1024 ** 3) - 0.5, | |
| ) | |
| image = pipe( | |
| prompt="a photo of an astronaut riding a horse on mars, high quality, detailed", | |
| negative_prompt="blurry, low quality, deformed", | |
| cfg_scale=7.5, | |
| height=512, | |
| width=512, | |
| seed=42, | |
| rand_device="cuda", | |
| num_inference_steps=50, | |
| ) | |
| image.save("image.jpg") | |