mirror of
https://github.com/huggingface/diffusers.git
synced 2026-01-27 17:22:53 +03:00
* why mdx? * why mdx? * why mdx? * no x for kandinksy either --------- Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
64 lines
3.3 KiB
Markdown
64 lines
3.3 KiB
Markdown
<!--Copyright 2023 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
|
|
```
|
|
|
|

|
|
|
|
์ด ์์ ์์๋ ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ๊ฐ์ ํ์ง๋ง ์ค์ ๋ก๋ ์ํ๋ ๋ชจ๋ ์ด๋ฏธ์ง๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค(์ฌ์ง์ด ๋ ๊ฐ์ ๋์ด ์๋ ์ด๋ฏธ์ง๋!). ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์์๋ ์๋๊ฐ '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
|
|
```
|
|
|
|

|