Transformers_stable_diffusion_example.ipynb Open in SWAN Download

Transformers - stable diffusion example

Transformers provides APIs and tools to easily download and train state-of-the-art pretrained models.
Credits: Huggingface documentation and examples
https://github.com/huggingface/notebooks/blob/main/diffusers/stable_diffusion.ipynb

In [ ]:
# install dependencies
!pip install diffusers==0.11.1
!pip install transformers scipy ftfy accelerate
In [2]:
import torch
from diffusers import StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
Downloading (…)ain/model_index.json:   0%|          | 0.00/541 [00:00<?, ?B/s]
Fetching 19 files:   0%|          | 0/19 [00:00<?, ?it/s]
Downloading pytorch_model.bin:   0%|          | 0.00/492M [00:00<?, ?B/s]
Downloading model.safetensors:   0%|          | 0.00/492M [00:00<?, ?B/s]
Downloading (…)_checker/config.json:   0%|          | 0.00/4.72k [00:00<?, ?B/s]
Downloading pytorch_model.bin:   0%|          | 0.00/1.22G [00:00<?, ?B/s]
Downloading model.safetensors:   0%|          | 0.00/1.22G [00:00<?, ?B/s]
Downloading (…)rocessor_config.json:   0%|          | 0.00/342 [00:00<?, ?B/s]
Downloading (…)_encoder/config.json:   0%|          | 0.00/617 [00:00<?, ?B/s]
Downloading (…)tokenizer/merges.txt:   0%|          | 0.00/525k [00:00<?, ?B/s]
Downloading (…)cheduler_config.json:   0%|          | 0.00/308 [00:00<?, ?B/s]
Downloading (…)tokenizer/vocab.json:   0%|          | 0.00/1.06M [00:00<?, ?B/s]
Downloading (…)e6a/unet/config.json:   0%|          | 0.00/743 [00:00<?, ?B/s]
Downloading (…)cial_tokens_map.json:   0%|          | 0.00/472 [00:00<?, ?B/s]
Downloading (…)okenizer_config.json:   0%|          | 0.00/806 [00:00<?, ?B/s]
Downloading (…)on_pytorch_model.bin:   0%|          | 0.00/3.44G [00:00<?, ?B/s]
Downloading (…)ch_model.safetensors:   0%|          | 0.00/3.44G [00:00<?, ?B/s]
Downloading (…)on_pytorch_model.bin:   0%|          | 0.00/335M [00:00<?, ?B/s]
Downloading (…)8e6a/vae/config.json:   0%|          | 0.00/547 [00:00<?, ?B/s]
Downloading (…)ch_model.safetensors:   0%|          | 0.00/335M [00:00<?, ?B/s]
`text_config_dict` is provided which will be used to initialize `CLIPTextConfig`. The value `text_config["id2label"]` will be overriden.
In [3]:
pipe = pipe.to("cuda")
In [4]:
prompt = "a photograph of an astronaut riding a horse"
image = pipe(prompt).images[0]  # image here is in [PIL format](https://pillow.readthedocs.io/en/stable/)
  0%|          | 0/50 [00:00<?, ?it/s]
In [6]:
# Display the image
image
Out[6]:
No description has been provided for this image
In [ ]: