File size: 3,341 Bytes
43b7e92 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
-->
# Deterministic(κ²°μ μ ) μμ±μ ν΅ν μ΄λ―Έμ§ νμ§ κ°μ
μμ±λ μ΄λ―Έμ§μ νμ§μ κ°μ νλ μΌλ°μ μΈ λ°©λ²μ *κ²°μ μ batch(λ°°μΉ) μμ±*μ μ¬μ©νλ κ²μ
λλ€. μ΄ λ°©λ²μ μ΄λ―Έμ§ batch(λ°°μΉ)λ₯Ό μμ±νκ³ λ λ²μ§Έ μΆλ‘ λΌμ΄λμμ λ μμΈν ν둬ννΈμ ν¨κ» κ°μ ν μ΄λ―Έμ§ νλλ₯Ό μ ννλ κ²μ
λλ€. ν΅μ¬μ μΌκ΄ μ΄λ―Έμ§ μμ±μ μν΄ νμ΄νλΌμΈμ [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html#generator) λͺ©λ‘μ μ λ¬νκ³ , κ° `Generator`λ₯Ό μλμ μ°κ²°νμ¬ μ΄λ―Έμ§μ μ¬μ¬μ©ν μ μλλ‘ νλ κ²μ
λλ€.
μλ₯Ό λ€μ΄ [`runwayml/stable-diffusion-v1-5`](runwayml/stable-diffusion-v1-5)λ₯Ό μ¬μ©νμ¬ λ€μ ν둬ννΈμ μ¬λ¬ λ²μ μ μμ±ν΄ λ΄
μλ€.
```py
prompt = "Labrador in the style of Vermeer"
```
(κ°λ₯νλ€λ©΄) νμ΄νλΌμΈμ [`DiffusionPipeline.from_pretrained`]λ‘ μΈμ€ν΄μ€ννμ¬ GPUμ λ°°μΉν©λλ€.
```python
>>> from diffusers import DiffusionPipeline
>>> pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
>>> pipe = pipe.to("cuda")
```
μ΄μ λ€ κ°μ μλ‘ λ€λ₯Έ `Generator`λ₯Ό μ μνκ³ κ° `Generator`μ μλ(`0` ~ `3`)λ₯Ό ν λΉνμ¬ λμ€μ νΉμ μ΄λ―Έμ§μ λν΄ `Generator`λ₯Ό μ¬μ¬μ©ν μ μλλ‘ ν©λλ€.
```python
>>> import torch
>>> generator = [torch.Generator(device="cuda").manual_seed(i) for i in range(4)]
```
μ΄λ―Έμ§λ₯Ό μμ±νκ³ μ΄ν΄λ΄
λλ€.
```python
>>> images = pipe(prompt, generator=generator, num_images_per_prompt=4).images
>>> images
```
![img](https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/reusabe_seeds.jpg)
μ΄ μμ μμλ 첫 λ²μ§Έ μ΄λ―Έμ§λ₯Ό κ°μ νμ§λ§ μ€μ λ‘λ μνλ λͺ¨λ μ΄λ―Έμ§λ₯Ό μ¬μ©ν μ μμ΅λλ€(μ¬μ§μ΄ λ κ°μ λμ΄ μλ μ΄λ―Έμ§λ!). 첫 λ²μ§Έ μ΄λ―Έμ§μμλ μλκ° '0'μΈ 'μμ±κΈ°'λ₯Ό μ¬μ©νκΈ° λλ¬Έμ λ λ²μ§Έ μΆλ‘ λΌμ΄λμμλ μ΄ 'μμ±κΈ°'λ₯Ό μ¬μ¬μ©ν κ²μ
λλ€. μ΄λ―Έμ§μ νμ§μ κ°μ νλ €λ©΄ ν둬ννΈμ λͺ κ°μ§ ν
μ€νΈλ₯Ό μΆκ°ν©λλ€:
```python
prompt = [prompt + t for t in [", highly realistic", ", artsy", ", trending", ", colorful"]]
generator = [torch.Generator(device="cuda").manual_seed(0) for i in range(4)]
```
μλκ° `0`μΈ μ λλ μ΄ν° 4κ°λ₯Ό μμ±νκ³ , μ΄μ λΌμ΄λμ 첫 λ²μ§Έ μ΄λ―Έμ§μ²λΌ 보μ΄λ λ€λ₯Έ μ΄λ―Έμ§ batch(λ°°μΉ)λ₯Ό μμ±ν©λλ€!
```python
>>> images = pipe(prompt, generator=generator).images
>>> images
```
![img](https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/reusabe_seeds_2.jpg)
|