Text-to-Image
Diffusers
Safetensors
StableDiffusionPipeline
stable-diffusion
stable-diffusion-diffusers
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
cam
#139
by CamRule - opened
Files changed (18)
- .gitattributes-1
- README.md+31-29
- model_index.json+1-1
- safety_checker/model.fp16.safetensorsDeleted-3
- safety_checker/model.safetensorsDeleted-3
- safety_checker/pytorch_model.fp16.binDeleted-3
- text_encoder/model.fp16.safetensorsDeleted-3
- text_encoder/model.safetensorsDeleted-3
- text_encoder/pytorch_model.fp16.binDeleted-3
- unet/diffusion_pytorch_model.fp16.binDeleted-3
- unet/diffusion_pytorch_model.fp16.safetensorsDeleted-3
- unet/diffusion_pytorch_model.non_ema.binDeleted-3
- unet/diffusion_pytorch_model.non_ema.safetensorsDeleted-3
- unet/diffusion_pytorch_model.safetensorsDeleted-3
- vae/config.json-1
- vae/diffusion_pytorch_model.fp16.binDeleted-3
- vae/diffusion_pytorch_model.fp16.safetensorsDeleted-3
- vae/diffusion_pytorch_model.safetensorsDeleted-3
28 unmodified lines2930313228 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -text3 unmodified lines45678910111213141516177891011121323141525262716171819202122232434 unmodified lines59606162636465666768697071727374757677787879808182838284858687888988909192939495949697969899100991011021031041 unmodified line10610710810710911011111011111211311211311411511611711811711912012112227 unmodified lines15015115215115315415515626 unmodified lines1831841851841861871881893 unmodified lines- stable-diffusion- stable-diffusion-diffusers- text-to-imagewidget:- text: "A high tech solarpunk utopia in the Amazon rainforest" example_title: Amazon rainforest- text: "A pikachu fine dining with a view to the Eiffel Tower" example_title: Pikachu in Paris- text: "A mecha robot in a favela in expressionist style" example_title: Expressionist robot- text: "an insect robot preparing a delicious meal" example_title: Insect robot- text: "A small cabin on top of a snowy mountain in the style of Disney, artstation" example_title: Snowy disney cabininference: falseextra_gated_prompt: |- One more step before getting this model. This model is open access and available to all, with a CreativeML OpenRAIL-M license further specifying rights and usage. The CreativeML OpenRAIL License specifies:
1. You can't use the model to deliberately produce nor share illegal or harmful outputs or content 2. The authors claim no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in the license 2. CompVis claims no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in the license 3. You may re-distribute the weights and use the model commercially and/or as a service. If you do, please be aware you have to include the same use restrictions as the ones in the license and share a copy of the CreativeML OpenRAIL-M to all your users (please read the license entirely and carefully) Please read the full license carefully here: https://huggingface.co/spaces/CompVis/stable-diffusion-license extra_gated_heading: Please read the LICENSE to access this model Please read the full license here: https://huggingface.co/spaces/CompVis/stable-diffusion-license By clicking on "Access repository" below, you accept that your *contact information* (email address and username) can be shared with the model authors as well. extra_gated_fields: I have read the License and agree with its terms: checkbox---
# Stable Diffusion v1-4 Model Card34 unmodified linespip install --upgrade diffusers transformers scipy```
Run this command to log in with your HF Hub token if you haven't before:
```bashhuggingface-cli login```
Running the pipeline with the default PNDM scheduler:
```pythonimport torchfrom torch import autocastfrom diffusers import StableDiffusionPipeline
model_id = "CompVis/stable-diffusion-v1-4"device = "cuda"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)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).images[0] 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 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: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 torch
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16", use_auth_token=True)pipe = pipe.to(device)pipe.enable_attention_slicing()
prompt = "a photo of an astronaut riding a horse on mars"with autocast("cuda"):image = pipe(prompt).images[0] 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, EulerDiscreteSchedulerfrom diffusers import StableDiffusionPipeline, LMSDiscreteScheduler
model_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)# 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).images[0] image = pipe(prompt, guidance_scale=7.5).images[0] image.save("astronaut_rides_horse.png")```27 unmodified lines
# shard inputs and rngparams = replicate(params)prng_seed = jax.random.split(prng_seed, num_samples)prng_seed = jax.random.split(prng_seed, 8)prompt_ids = shard(prompt_ids)
images = pipeline(prompt_ids, params, prng_seed, num_inference_steps, jit=True).images26 unmodified lines
# shard inputs and rngparams = replicate(params)prng_seed = jax.random.split(prng_seed, num_samples)prng_seed = jax.random.split(prng_seed, 8)prompt_ids = shard(prompt_ids)
images = pipeline(prompt_ids, params, prng_seed, num_inference_steps, jit=True).images2 unmodified lines345667892 unmodified lines "_diffusers_version": "0.2.2", "feature_extractor": [ "transformers", "CLIPImageProcessor" "CLIPFeatureExtractor" ], "safety_checker": [ "stable_diffusion",123version https://git-lfs.github.com/spec/v1oid sha256:08902f19b1cfebd7c989f152fc0507bef6898c706a91d666509383122324b511size 608018440123version https://git-lfs.github.com/spec/v1oid sha256:9d6a233ff6fd5ccb9f76fd99618d73369c52dd3d8222376384d0e601911089e8size 1215981830123version https://git-lfs.github.com/spec/v1oid sha256:22ba87205445ad5def13e54919b038dcfb7321ec1c3f4b12487d4fba6036125fsize 608103564123version https://git-lfs.github.com/spec/v1oid sha256:77795e2023adcf39bc29a884661950380bd093cf0750a966d473d1718dc9ef4esize 246144864123version https://git-lfs.github.com/spec/v1oid sha256:7b3a12df205cb3c74dd4eae4354d93f606ae6b3bc29d5d06fd97921cb9ad8a81size 492265879123version https://git-lfs.github.com/spec/v1oid sha256:05eee911f195625deeab86f0b22b115d7d8bc3adbfc1404f03557f7e4e6a8fd7size 246187076123version https://git-lfs.github.com/spec/v1oid sha256:3ac986370f51d806d2119577d5a66fbf6d3746e2356f45dc474e7561ce94bdbfsize 1719327893123version https://git-lfs.github.com/spec/v1oid sha256:a35404d03ec8f977715a4d2a080ddf72e2144f2ee49bb1ee213258bc64f9cc87size 1719125304123version https://git-lfs.github.com/spec/v1oid sha256:f5f12f7078f361f137f91edc270cb523208dc2322a597e07773eb3b1e5703850size 3438366373123version https://git-lfs.github.com/spec/v1oid sha256:ac3d1bff03f9e9a6f8671b5a7a3fd984f90185c84e407bc569f97c1cce7445fdsize 3438167536123version https://git-lfs.github.com/spec/v1oid sha256:145a07e0f05ec5bbe6e2e9faf608bdb311caf708895cac8c8ed713c59864e1e8size 343816753418 unmodified lines1920212222232418 unmodified lines "layers_per_block": 2, "out_channels": 3, "sample_size": 512, "scaling_factor": 0.18215, "up_block_types": [ "UpDecoderBlock2D", "UpDecoderBlock2D",123version https://git-lfs.github.com/spec/v1oid sha256:b7643b3e40b9f128eda5fe174fea73c3ef3903562651fb344a79439709c2e503size 167405651123version https://git-lfs.github.com/spec/v1oid sha256:4fbcf0ebe55a0984f5a5e00d8c4521d52359af7229bb4d81890039d2aa16dd7csize 167335342123version https://git-lfs.github.com/spec/v1oid sha256:a2b5134f4dbc140d9c11f11cba3233099e00af40f262f136c691fb7d38d2194csize 334643276.gitattributes-1
README.md+31-29
model_index.json+1-1
safety_checker/model.fp16.safetensorsDeleted-3
safety_checker/model.safetensorsDeleted-3
safety_checker/pytorch_model.fp16.binDeleted-3
text_encoder/model.fp16.safetensorsDeleted-3
text_encoder/model.safetensorsDeleted-3
text_encoder/pytorch_model.fp16.binDeleted-3
unet/diffusion_pytorch_model.fp16.binDeleted-3
unet/diffusion_pytorch_model.fp16.safetensorsDeleted-3
unet/diffusion_pytorch_model.non_ema.binDeleted-3
unet/diffusion_pytorch_model.non_ema.safetensorsDeleted-3
unet/diffusion_pytorch_model.safetensorsDeleted-3
vae/config.json-1
vae/diffusion_pytorch_model.fp16.binDeleted-3
vae/diffusion_pytorch_model.fp16.safetensorsDeleted-3
vae/diffusion_pytorch_model.safetensorsDeleted-3