Text-to-Image
Diffusers
Safetensors
StableDiffusionPipeline
stable-diffusion
stable-diffusion-diffusers
Run this model with HF Jobs
Run CompVis/stable-diffusion-v1-4 on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/CompVis/stable-diffusion-v1-4. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/CompVis/stable-diffusion-v1-4 on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use CompVis/stable-diffusion-v1-4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use CompVis/stable-diffusion-v1-4 with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", dtype=torch.bfloat16, device_map="cuda") prompt = "A high tech solarpunk utopia in the Amazon rainforest" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
Update code examples
#148
by patrickvonplaten - opened
74 unmodified lines757677787980818283848586878889909192939495969798991001011021031041051061071081091101 unmodified line11211311411511611711811912012112212312412512612712874 unmodified lines```pythonimport torchfrom torch import autocastfrom diffusers import StableDiffusionPipelinemodel_id = "CompVis/stable-diffusion-v1-4"device = "cuda"pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True)pipe = pipe.to(device)prompt = "a photo of an astronaut riding a horse on mars"with autocast("cuda"):image = pipe(prompt, guidance_scale=7.5).images[0]image.save("astronaut_rides_horse.png")```**Note**:If you are limited by GPU memory and have less than 10GB of GPU RAM available, please make sure to load the StableDiffusionPipeline in float16 precision instead of the default float32 precision as done above. You can do so by telling diffusers to expect the weights to be in float16 precision:```pyimport torchpipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16", use_auth_token=True)pipe = pipe.to(device)prompt = "a photo of an astronaut riding a horse on mars"with autocast("cuda"):image = pipe(prompt, guidance_scale=7.5).images[0]image.save("astronaut_rides_horse.png")```1 unmodified lineTo swap out the noise scheduler, pass it to `from_pretrained`:```pythonfrom diffusers import StableDiffusionPipeline, LMSDiscreteSchedulermodel_id = "CompVis/stable-diffusion-v1-4"# Use the K-LMS scheduler here insteadscheduler = LMSDiscreteScheduler(beta_start=0.00085, beta_end=0.012, beta_schedule="scaled_linear", num_train_timesteps=1000)pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, use_auth_token=True)pipe = pipe.to("cuda")prompt = "a photo of an astronaut riding a horse on mars"with autocast("cuda"):image = pipe(prompt, guidance_scale=7.5).images[0]image.save("astronaut_rides_horse.png")```74 unmodified lines757677787980818283848586878889909192939495969798991001011021031041051061071081 unmodified line11011111211311411511611711811912012112212312412512674 unmodified lines```pythonimport torchfrom diffusers import StableDiffusionPipelinemodel_id = "CompVis/stable-diffusion-v1-4"device = "cuda"pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16")pipe = pipe.to(device)prompt = "a photo of an astronaut riding a horse on mars"image = pipe(prompt).images[0]image.save("astronaut_rides_horse.png")```**Note**:If you are limited by GPU memory and have less than 4GB of GPU RAM available, please make sure to load the StableDiffusionPipeline in float16 precision instead of the default float32 precision as done above. You can do so by telling diffusers to expect the weights to be in float16 precision:```pyimport torchpipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16")pipe = pipe.to(device)pipe.enable_attention_slicing()prompt = "a photo of an astronaut riding a horse on mars"image = pipe(prompt).images[0]image.save("astronaut_rides_horse.png")```1 unmodified lineTo swap out the noise scheduler, pass it to `from_pretrained`:```pythonfrom diffusers import StableDiffusionPipeline, EulerDiscreteSchedulermodel_id = "CompVis/stable-diffusion-v1-4"# Use the Euler scheduler here insteadscheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, torch_dtype=torch.float16, revision="fp16")pipe = pipe.to("cuda")prompt = "a photo of an astronaut riding a horse on mars"image = pipe(prompt).images[0]image.save("astronaut_rides_horse.png")```
README.md+12-14