Skip to content

Commit c697f52

Browse files
authored
[Docs] Update and make improvements (huggingface#5819)
Update and make improvements
1 parent a042909 commit c697f52

File tree

7 files changed

+18
-20
lines changed

7 files changed

+18
-20
lines changed

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ limitations under the License.
4747

4848
## Installation
4949

50-
We recommend installing 🤗 Diffusers in a virtual environment from PyPi or Conda. For more details about installing [PyTorch](https://pytorch.org/get-started/locally/) and [Flax](https://flax.readthedocs.io/en/latest/#installation), please refer to their official documentation.
50+
We recommend installing 🤗 Diffusers in a virtual environment from PyPI or Conda. For more details about installing [PyTorch](https://pytorch.org/get-started/locally/) and [Flax](https://flax.readthedocs.io/en/latest/#installation), please refer to their official documentation.
5151

5252
### PyTorch
5353

@@ -77,7 +77,7 @@ Please refer to the [How to use Stable Diffusion in Apple Silicon](https://huggi
7777

7878
## Quickstart
7979

80-
Generating outputs is super easy with 🤗 Diffusers. To generate an image from text, use the `from_pretrained` method to load any pretrained diffusion model (browse the [Hub](https://huggingface.co/models?library=diffusers&sort=downloads) for 14000+ checkpoints):
80+
Generating outputs is super easy with 🤗 Diffusers. To generate an image from text, use the `from_pretrained` method to load any pretrained diffusion model (browse the [Hub](https://huggingface.co/models?library=diffusers&sort=downloads) for 15000+ checkpoints):
8181

8282
```python
8383
from diffusers import DiffusionPipeline
@@ -94,14 +94,13 @@ You can also dig into the models and schedulers toolbox to build your own diffus
9494
from diffusers import DDPMScheduler, UNet2DModel
9595
from PIL import Image
9696
import torch
97-
import numpy as np
9897

9998
scheduler = DDPMScheduler.from_pretrained("google/ddpm-cat-256")
10099
model = UNet2DModel.from_pretrained("google/ddpm-cat-256").to("cuda")
101100
scheduler.set_timesteps(50)
102101

103102
sample_size = model.config.sample_size
104-
noise = torch.randn((1, 3, sample_size, sample_size)).to("cuda")
103+
noise = torch.randn((1, 3, sample_size, sample_size), device="cuda")
105104
input = noise
106105

107106
for t in scheduler.timesteps:
@@ -136,8 +135,7 @@ You can look out for [issues](https://github.com/huggingface/diffusers/issues) y
136135
- See [New model/pipeline](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22New+pipeline%2Fmodel%22) to contribute exciting new diffusion models / diffusion pipelines
137136
- See [New scheduler](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22New+scheduler%22)
138137

139-
Also, say 👋 in our public Discord channel <a href="https://discord.gg/G7tWnz98XR"><img alt="Join us on Discord" src="https://img.shields.io/discord/823813159592001537?color=5865F2&logo=discord&logoColor=white"></a>. We discuss the hottest trends about diffusion models, help each other with contributions, personal projects or
140-
just hang out ☕.
138+
Also, say 👋 in our public Discord channel <a href="https://discord.gg/G7tWnz98XR"><img alt="Join us on Discord" src="https://img.shields.io/discord/823813159592001537?color=5865F2&logo=discord&logoColor=white"></a>. We discuss the hottest trends about diffusion models, help each other with contributions, personal projects or just hang out ☕.
141139

142140

143141
## Popular Tasks & Pipelines

docs/source/en/optimization/memory.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ unet_runs_per_experiment = 50
194194

195195
# load inputs
196196
def generate_inputs():
197-
sample = torch.randn(2, 4, 64, 64).half().cuda()
198-
timestep = torch.rand(1).half().cuda() * 999
199-
encoder_hidden_states = torch.randn(2, 77, 768).half().cuda()
197+
sample = torch.randn((2, 4, 64, 64), device="cuda", dtype=torch.float16)
198+
timestep = torch.rand(1, device="cuda", dtype=torch.float16) * 999
199+
encoder_hidden_states = torch.randn((2, 77, 768), device="cuda", dtype=torch.float16)
200200
return sample, timestep, encoder_hidden_states
201201

202202

docs/source/en/tutorials/basic_training.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,13 @@ Now you can wrap all these components together in a training loop with 🤗 Acce
321321
... for step, batch in enumerate(train_dataloader):
322322
... clean_images = batch["images"]
323323
... # Sample noise to add to the images
324-
... noise = torch.randn(clean_images.shape).to(clean_images.device)
324+
... noise = torch.randn(clean_images.shape, device=clean_images.device)
325325
... bs = clean_images.shape[0]
326326

327327
... # Sample a random timestep for each image
328328
... timesteps = torch.randint(
329329
... 0, noise_scheduler.config.num_train_timesteps, (bs,), device=clean_images.device
330-
... ).long()
330+
... )
331331

332332
... # Add noise to the clean images according to the noise magnitude at each timestep
333333
... # (this is the forward diffusion process)

docs/source/en/using-diffusers/write_own_pipeline.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ tensor([980, 960, 940, 920, 900, 880, 860, 840, 820, 800, 780, 760, 740, 720,
7171
>>> import torch
7272

7373
>>> sample_size = model.config.sample_size
74-
>>> noise = torch.randn((1, 3, sample_size, sample_size)).to("cuda")
74+
>>> noise = torch.randn((1, 3, sample_size, sample_size), device="cuda")
7575
```
7676

7777
5. Now write a loop to iterate over the timesteps. At each timestep, the model does a [`UNet2DModel.forward`] pass and returns the noisy residual. The scheduler's [`~DDPMScheduler.step`] method takes the noisy residual, timestep, and input and it predicts the image at the previous timestep. This output becomes the next input to the model in the denoising loop, and it'll repeat until it reaches the end of the `timesteps` array.
@@ -216,8 +216,8 @@ Next, generate some initial random noise as a starting point for the diffusion p
216216
>>> latents = torch.randn(
217217
... (batch_size, unet.config.in_channels, height // 8, width // 8),
218218
... generator=generator,
219+
... device=torch_device,
219220
... )
220-
>>> latents = latents.to(torch_device)
221221
```
222222

223223
### Denoise the image

docs/source/ko/optimization/fp16.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ unet_runs_per_experiment = 50
273273

274274
# 입력 불러오기
275275
def generate_inputs():
276-
sample = torch.randn(2, 4, 64, 64).half().cuda()
277-
timestep = torch.rand(1).half().cuda() * 999
278-
encoder_hidden_states = torch.randn(2, 77, 768).half().cuda()
276+
sample = torch.randn((2, 4, 64, 64), device="cuda", dtype=torch.float16)
277+
timestep = torch.rand(1, device="cuda", dtype=torch.float16) * 999
278+
encoder_hidden_states = torch.randn((2, 77, 768), device="cuda", dtype=torch.float16)
279279
return sample, timestep, encoder_hidden_states
280280

281281

docs/source/ko/tutorials/basic_training.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,13 @@ TensorBoard에 로깅, 그래디언트 누적 및 혼합 정밀도 학습을 쉽
322322
... for step, batch in enumerate(train_dataloader):
323323
... clean_images = batch["images"]
324324
... # 이미지에 더할 노이즈를 샘플링합니다.
325-
... noise = torch.randn(clean_images.shape).to(clean_images.device)
325+
... noise = torch.randn(clean_images.shape, device=clean_images.device)
326326
... bs = clean_images.shape[0]
327327

328328
... # 각 이미지를 위한 랜덤한 타임스텝(timestep)을 샘플링합니다.
329329
... timesteps = torch.randint(
330330
... 0, noise_scheduler.config.num_train_timesteps, (bs,), device=clean_images.device
331-
... ).long()
331+
... )
332332

333333
... # 각 타임스텝의 노이즈 크기에 따라 깨끗한 이미지에 노이즈를 추가합니다.
334334
... # (이는 foward diffusion 과정입니다.)

docs/source/ko/using-diffusers/write_own_pipeline.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ specific language governing permissions and limitations under the License.
7171
>>> import torch
7272

7373
>>> sample_size = model.config.sample_size
74-
>>> noise = torch.randn((1, 3, sample_size, sample_size)).to("cuda")
74+
>>> noise = torch.randn((1, 3, sample_size, sample_size), device="cuda")
7575
```
7676

7777
5. 이제 timestep을 반복하는 루프를 작성합니다. 각 timestep에서 모델은 [`UNet2DModel.forward`]를 통해 noisy residual을 반환합니다. 스케줄러의 [`~DDPMScheduler.step`] 메서드는 noisy residual, timestep, 그리고 입력을 받아 이전 timestep에서 이미지를 예측합니다. 이 출력은 노이즈 제거 루프의 모델에 대한 다음 입력이 되며, `timesteps` 배열의 끝에 도달할 때까지 반복됩니다.
@@ -212,8 +212,8 @@ Stable Diffusion 은 text-to-image *latent diffusion* 모델입니다. latent di
212212
>>> latents = torch.randn(
213213
... (batch_size, unet.in_channels, height // 8, width // 8),
214214
... generator=generator,
215+
... device=torch_device,
215216
... )
216-
>>> latents = latents.to(torch_device)
217217
```
218218

219219
### 이미지 노이즈 제거

0 commit comments

Comments
 (0)