From 54339629927bffafe810b312c2f3526c67a52324 Mon Sep 17 00:00:00 2001 From: Steven Liu <59462357+stevhliu@users.noreply.github.com> Date: Tue, 19 Dec 2023 16:50:18 -0800 Subject: [PATCH] [docs] Batched seeds (#6237) batched seed --- docs/source/en/using-diffusers/reusing_seeds.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/source/en/using-diffusers/reusing_seeds.md b/docs/source/en/using-diffusers/reusing_seeds.md index d2638b469e30..6d0f6ac9837f 100644 --- a/docs/source/en/using-diffusers/reusing_seeds.md +++ b/docs/source/en/using-diffusers/reusing_seeds.md @@ -41,6 +41,20 @@ Now, define four different `Generator`s and assign each `Generator` a seed (`0` generator = [torch.Generator(device="cuda").manual_seed(i) for i in range(4)] ``` + + +To create a batched seed, you should use a list comprehension that iterates over the length specified in `range()`. This creates a unique `Generator` object for each image in the batch. If you only multiply the `Generator` by the batch size, this only creates one `Generator` object that is used sequentially for each image in the batch. + +For example, if you want to use the same seed to create 4 identical images: + +```py +❌ [torch.Generator().manual_seed(seed)] * 4 + +✅ [torch.Generator().manual_seed(seed) for _ in range(4)] +``` + + + Generate the images and have a look: ```python