BleachNick's picture
upload required packages
87d40d2

A newer version of the Gradio SDK is available: 5.23.3

Upgrade

좔둠을 μœ„ν•΄ ONNX λŸ°νƒ€μž„μ„ μ‚¬μš©ν•˜λŠ” 방법

πŸ€— DiffusersλŠ” ONNX Runtimeκ³Ό ν˜Έν™˜λ˜λŠ” Stable Diffusion νŒŒμ΄ν”„λΌμΈμ„ μ œκ³΅ν•©λ‹ˆλ‹€. 이λ₯Ό 톡해 ONNX(CPU 포함)λ₯Ό μ§€μ›ν•˜κ³  PyTorch의 가속 버전을 μ‚¬μš©ν•  수 μ—†λŠ” λͺ¨λ“  ν•˜λ“œμ›¨μ–΄μ—μ„œ Stable Diffusion을 μ‹€ν–‰ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

μ„€μΉ˜

λ‹€μŒ λͺ…λ Ήμ–΄λ‘œ ONNX Runtimeλ₯Ό μ§€μ›ν•˜λŠ” πŸ€— Optimumλ₯Ό μ„€μΉ˜ν•©λ‹ˆλ‹€:

pip install optimum["onnxruntime"]

Stable Diffusion μΆ”λ‘ 

μ•„λž˜ μ½”λ“œλŠ” ONNX λŸ°νƒ€μž„μ„ μ‚¬μš©ν•˜λŠ” 방법을 λ³΄μ—¬μ€λ‹ˆλ‹€. StableDiffusionPipeline λŒ€μ‹  OnnxStableDiffusionPipeline을 μ‚¬μš©ν•΄μ•Ό ν•©λ‹ˆλ‹€. PyTorch λͺ¨λΈμ„ 뢈러였고 μ¦‰μ‹œ ONNX ν˜•μ‹μœΌλ‘œ λ³€ν™˜ν•˜λ €λŠ” 경우 export=True둜 μ„€μ •ν•©λ‹ˆλ‹€.

from optimum.onnxruntime import ORTStableDiffusionPipeline

model_id = "runwayml/stable-diffusion-v1-5"
pipe = ORTStableDiffusionPipeline.from_pretrained(model_id, export=True)
prompt = "a photo of an astronaut riding a horse on mars"
images = pipe(prompt).images[0]
pipe.save_pretrained("./onnx-stable-diffusion-v1-5")

νŒŒμ΄ν”„λΌμΈμ„ ONNX ν˜•μ‹μœΌλ‘œ μ˜€ν”„λΌμΈμœΌλ‘œ 내보내고 λ‚˜μ€‘μ— 좔둠에 μ‚¬μš©ν•˜λ €λŠ” 경우, optimum-cli export λͺ…λ Ήμ–΄λ₯Ό μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€:

optimum-cli export onnx --model runwayml/stable-diffusion-v1-5 sd_v15_onnx/

κ·Έ λ‹€μŒ 좔둠을 μˆ˜ν–‰ν•©λ‹ˆλ‹€:

from optimum.onnxruntime import ORTStableDiffusionPipeline

model_id = "sd_v15_onnx"
pipe = ORTStableDiffusionPipeline.from_pretrained(model_id)
prompt = "a photo of an astronaut riding a horse on mars"
images = pipe(prompt).images[0]

Notice that we didn't have to specify export=True above.

Optimum λ¬Έμ„œμ—μ„œ 더 λ§Žμ€ μ˜ˆμ‹œλ₯Ό 찾을 수 μžˆμŠ΅λ‹ˆλ‹€.

μ•Œλ €μ§„ μ΄μŠˆλ“€

  • μ—¬λŸ¬ ν”„λ‘¬ν”„νŠΈλ₯Ό 배치둜 μƒμ„±ν•˜λ©΄ λ„ˆλ¬΄ λ§Žμ€ λ©”λͺ¨λ¦¬κ°€ μ‚¬μš©λ˜λŠ” 것 κ°™μŠ΅λ‹ˆλ‹€. 이λ₯Ό μ‘°μ‚¬ν•˜λŠ” λ™μ•ˆ, 배치 λŒ€μ‹  반볡 방법이 ν•„μš”ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.