patrickvonplaten commited on
Commit
eef717c
1 Parent(s): 54e78ff

Update code examples

Browse files
Files changed (1) hide show
  1. README.md +12 -14
README.md CHANGED
@@ -75,36 +75,34 @@ Running the pipeline with the default PNDM scheduler:
75
 
76
  ```python
77
  import torch
78
- from torch import autocast
79
  from diffusers import StableDiffusionPipeline
80
 
81
  model_id = "CompVis/stable-diffusion-v1-4"
82
  device = "cuda"
83
 
84
 
85
- pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True)
86
  pipe = pipe.to(device)
87
 
88
  prompt = "a photo of an astronaut riding a horse on mars"
89
- with autocast("cuda"):
90
- image = pipe(prompt, guidance_scale=7.5).images[0]
91
 
92
  image.save("astronaut_rides_horse.png")
93
  ```
94
 
95
  **Note**:
96
- 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:
97
 
98
 
99
  ```py
100
  import torch
101
 
102
- pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16", use_auth_token=True)
103
  pipe = pipe.to(device)
 
104
 
105
  prompt = "a photo of an astronaut riding a horse on mars"
106
- with autocast("cuda"):
107
- image = pipe(prompt, guidance_scale=7.5).images[0]
108
 
109
  image.save("astronaut_rides_horse.png")
110
  ```
@@ -112,17 +110,17 @@ image.save("astronaut_rides_horse.png")
112
  To swap out the noise scheduler, pass it to `from_pretrained`:
113
 
114
  ```python
115
- from diffusers import StableDiffusionPipeline, LMSDiscreteScheduler
116
 
117
  model_id = "CompVis/stable-diffusion-v1-4"
118
- # Use the K-LMS scheduler here instead
119
- scheduler = LMSDiscreteScheduler(beta_start=0.00085, beta_end=0.012, beta_schedule="scaled_linear", num_train_timesteps=1000)
120
- pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, use_auth_token=True)
 
121
  pipe = pipe.to("cuda")
122
 
123
  prompt = "a photo of an astronaut riding a horse on mars"
124
- with autocast("cuda"):
125
- image = pipe(prompt, guidance_scale=7.5).images[0]
126
 
127
  image.save("astronaut_rides_horse.png")
128
  ```
 
75
 
76
  ```python
77
  import torch
 
78
  from diffusers import StableDiffusionPipeline
79
 
80
  model_id = "CompVis/stable-diffusion-v1-4"
81
  device = "cuda"
82
 
83
 
84
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16")
85
  pipe = pipe.to(device)
86
 
87
  prompt = "a photo of an astronaut riding a horse on mars"
88
+ image = pipe(prompt).images[0]
 
89
 
90
  image.save("astronaut_rides_horse.png")
91
  ```
92
 
93
  **Note**:
94
+ 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:
95
 
96
 
97
  ```py
98
  import torch
99
 
100
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16")
101
  pipe = pipe.to(device)
102
+ pipe.enable_attention_slicing()
103
 
104
  prompt = "a photo of an astronaut riding a horse on mars"
105
+ image = pipe(prompt).images[0]
 
106
 
107
  image.save("astronaut_rides_horse.png")
108
  ```
 
110
  To swap out the noise scheduler, pass it to `from_pretrained`:
111
 
112
  ```python
113
+ from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
114
 
115
  model_id = "CompVis/stable-diffusion-v1-4"
116
+
117
+ # Use the Euler scheduler here instead
118
+ scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
119
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, torch_dtype=torch.float16, revision="fp16")
120
  pipe = pipe.to("cuda")
121
 
122
  prompt = "a photo of an astronaut riding a horse on mars"
123
+ image = pipe(prompt).images[0]
 
124
 
125
  image.save("astronaut_rides_horse.png")
126
  ```