
๋ณธ ์ค์ต์์๋ Azure Machine Learning Compute Instance๋ฅผ ์ฌ์ฉํ์ฌ GPU ํ๊ฒฝ์ ๋น ๋ฅด๊ฒ ๊ตฌ์ถํ๊ณ , WebUI Forge๋ฅผ ์ค์นํ์ฌ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ฉฐ, ๊ฒฐ๊ณผ๋ฌผ์ Azure Blob Storage๋ก ์๋ ๋๊ธฐํํ๋ ๊ณผ์ ์ ๋ค๋ฃน๋๋ค.

์ถ์ฒ: https://lambda.ai/blog/inference-benchmark-stable-diffusion
1. ๋ฆฌ์์ค ๊ทธ๋ฃน (Resource Group) ์์ฑ
student01_sdlab_rg)2. Azure Machine Learning Workspace ์์ฑ
dt005storage)

3. Compute Instance (VM) ์์ฑ
Standard_NC4as_T4_v3).dt005-vmgpu-key) ํ ํ๋ผ์ด๋น ํค(.pem) ๋ค์ด๋ก๋ (ํ์).





Azure ML Compute Instance๋ ์ผ๋ฐ VM๊ณผ ๋ฌ๋ฆฌ ํฌํธ ๋ฒํธ๊ฐ 22๋ฒ์ด ์๋ 50000๋ฒ ๋์ ์์ ํฌํธ๊ฐ ํ ๋น๋ฉ๋๋ค.
์ ์ ์ ๋ณด ํ์ธ: ML Studio โ ์ปดํจํ โ ์ธ์คํด์ค ํด๋ฆญ โ '์ฐ๊ฒฐ' ํญ.
ํฐ๋ฏธ๋ ์ ์ (๋ก์ปฌ PC):
icacls ๋ช
๋ น์ด๋ฅผ ์คํํ๋ ๊ฒ์ด ์ข์ต๋๋ค.:: Windows ๊ถํ ์ค์ (ํค ํ์ผ ์๋ ํด๋์์)
icacls ํคํ์ผ๋ช
.pem /reset
icacls ํคํ์ผ๋ช
.pem /grant:r %username%:(R)
icacls ํคํ์ผ๋ช
.pem /inheritance:r
# ์ ์ ๋ช
๋ น์ด (๋ฐ๋์ -p ์ต์
์ผ๋ก ํฌํธ ์ง์ )
ssh -i "๊ฒฝ๋ก/ํคํ์ผ.pem" azureuser@IP์ฃผ์ -p 50000
#์
ssh -i C:\\Key\\geondongkim-vm-gpu_key.pem azureuser@4.230.xx.xx -p 50000

์ ์ ํ, Git์ ํตํด ์์ค ์ฝ๋๋ฅผ ๋ฐ๊ณ Conda๋ฅผ ์ด์ฉํด ๋ ๋ฆฝ์ ์ธ ์คํ ํ๊ฒฝ์ ๊ตฌ์ถํฉ๋๋ค.
# 1. ์์ค ์ฝ๋ ๋ณต์ (Forge ๋ฒ์ )
git clone <https://github.com/lllyasviel/stable-diffusion-webui-forge.git>
# 2. ํด๋ ์ด๋
cd stable-diffusion-webui-forge
# 3. Conda ๊ฐ์ํ๊ฒฝ ์์ฑ (Python 3.10 ๊ถ์ฅ)
conda create -n sd python=3.10
# 4. ๊ฐ์ํ๊ฒฝ ํ์ฑํ (ํ์)
conda activate sd
# 5. ํ์ ์์คํ
๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์น
sudo apt-get update
sudo apt-get install libgoogle-perftools-dev -y
๐ก Tip: ๋ก๊ทธ์ธ ์ ์๋์ผ๋ก sd ํ๊ฒฝ์ด ํ์ฑํ๋๊ฒ ํ๋ ค๋ฉด:
vi .bashrc ์ ๋ ฅ ํ ํ์ผ ๋์ conda activate sd ์ถ๊ฐ.



์ด๋ฏธ์ง ์์ฑ์ ์ํด์๋ ์ฒดํฌํฌ์ธํธ(Checkpoint) ๋ชจ๋ธ ํ์ผ์ด ํ์ํฉ๋๋ค.
Hugging Face์์ ๋ชจ๋ธ์ ๋ฐ์ผ๋ ค๋ฉด Access Token์ด ํ์ํ๋ฉฐ, ์ผ๋ถ ๋ชจ๋ธ(Flux ๋ฑ)์ ์ฌ์ดํธ์์ ์ฝ๊ด ๋์๊ฐ ์ ํ๋์ด์ผ ํฉ๋๋ค.


# ๋ชจ๋ธ ์ ์ฅ ๊ฒฝ๋ก๋ก ์ด๋
cd ~/stable-diffusion-webui-forge/models/Stable-diffusion
# cURL๋ก ๋ค์ด๋ก๋ (-L ์ต์
: ๋ฆฌ๋ค์ด๋ ํธ ์ถ์ )
# [YOUR_HF_TOKEN]์ ๋ณธ์ธ์ ํ ํฐ ์
๋ ฅ
curl -H "Authorization: Bearer [YOUR_HF_TOKEN]" \\
<https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/resolve/main/v1-5-pruned.safetensors> \\
--location --output sd-v1-5.safetensors
Civitai๋ civitdl ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉํ๋ฐ์ดํฐ์ ํจ๊ป ํธ๋ฆฌํ๊ฒ ๋ค์ด๋ก๋ํ ์ ์์ต๋๋ค.
# 1. ๋๊ตฌ ์ค์น
pip install civitdl
# 2. ๋ชจ๋ธ ๋ค์ด๋ก๋ ์์ (๋ชจ๋ธ ID ์ฌ์ฉ)
# ์ฒดํฌํฌ์ธํธ ๋ค์ด๋ก๋
civitdl 24350 ~/stable-diffusion-webui-forge/models/Stable-diffusion -k
# key ๊ฐ ์
๋ ฅ
key : [YOUR_CIVITAI_API_KEY]
# LoRA ๋ค์ด๋ก๋
civitdl 151576 ~/stable-diffusion-webui-forge/models/Lora -k
# key ๊ฐ ์
๋ ฅ
key : [YOUR_CIVITAI_API_KEY]
์ค์น๊ฐ ์๋ฃ๋๋ฉด ์คํฌ๋ฆฝํธ๋ฅผ ์คํํฉ๋๋ค. ์ธ๋ถ ์ ์์ ์ํด --share ์ต์
์ ์ฌ์ฉํฉ๋๋ค.
# Forge ํด๋๋ก ์ด๋
cd ~/stable-diffusion-webui-forge
# ์คํ (๊ณ์ /๋น๋ฒ ์ค์ ๊ถ์ฅ)
./webui.sh --share --gradio-auth <์์ด๋:๋น๋ฐ๋ฒํธ>
# ์คํ (๊ณ์ /๋น๋ฒ ์์ด)
./webui.sh --share
https://xxxxxxxx.gradio.live ์ฃผ์๋ก ์ ์ํฉ๋๋ค.
์์ฑ๋ ์ด๋ฏธ์ง๋ฅผ ๋ก์ปฌ๋ก ๊ฐ์ ธ์ค๊ฑฐ๋ Azure Blob Storage๋ก ์ค์๊ฐ ๋ฐฑ์ ํ๋ ํ์ดํ๋ผ์ธ์ ๊ตฌ์ถํฉ๋๋ค.
๋ก์ปฌ PC์ ํฐ๋ฏธ๋์์ ์คํํฉ๋๋ค.
# 1. (VM ๋ด๋ถ) ๊ฒฐ๊ณผ๋ฌผ ํด๋ ์์ถ
cd ~/stable-diffusion-webui-forge/outputs
zip -r output.zip .
# 2. (๋ก์ปฌ PC) ํ์ผ ์ ์ก (๋๋ฌธ์ -P ์ต์
์ฃผ์)
scp -i [ํค๊ฒฝ๋ก] -P 50000 azureuser@[IP]:/home/azureuser/stable-diffusion-webui-forge/outputs/output.zip .
๋จ๊ณ 1: Azure Storage ์ค๋น (SAS ํ ํฐ ๋ฐ๊ธ)
stable-diffusion-images).




๋จ๊ณ 2: VM ๋ด๋ถ ํ๊ฒฝ ์ค์
# 1. ๋๊ตฌ ์ค์น (Azure CLI, Watchdog)
pip install --upgrade pip
pip install watchdog
sudo apt-get update && sudo apt-get install azure-cli
๋จ๊ณ 3: ๋๊ธฐํ ์คํฌ๋ฆฝํธ ์์ฑ (upload_to_azure.sh)vi upload_to_azure.sh ๋ก ํ์ผ์ ์์ฑํ๊ณ ์๋ ๋ด์ฉ์ ์
๋ ฅํฉ๋๋ค. (URL ๋ถ๋ถ์ ๋ณธ์ธ์ SAS URL๋ก ๊ต์ฒด)
# ๋๊ธฐํ ์คํฌ๋ฆฝํธ ์์ฑํ ๊ฒฝ๋ก๋ก ์ด๋
cd ~/stable-diffusion-webui-forge/outputs
# vim ํธ์ง๊ธฐ๋ก vi upload_to_azure.sh ํ์ผ ์์ฑ
vi upload_to_azure.sh
#!/bin/bash
# ์คํ ๋ฆฌ์ง ๊ณ์ ๋ฐ ์ปจํ
์ด๋ ์ ๋ณด
STORAGE_ACCOUNT_NAME="gdkim1023storage"
CONTAINER_NAME="stable-diffusion-images"
LOCAL_PATH="/home/azureuser/stable-diffusion-webui-forge/outputs/"
# SAS ํ ํฐ (๋ฌผ์ํ ? ๋ค์ ๊ฐ๋ถํฐ ์์)
SAS_TOKEN="sv=2024-11-~~~"
# ์ ์ฒด URL ์กฐํฉ
BLOB_URL="<https://$>{STORAGE_ACCOUNT_NAME}.blob.core.windows.net/${CONTAINER_NAME}?${SAS_TOKEN}"
# ๋๊ธฐํ ์คํ (์ฌ๊ท์ )
echo "Syncing to Azure Blob Storage..."
azcopy sync "${LOCAL_PATH}" "${BLOB_URL}" --recursive
๋จ๊ณ 4: ๊ถํ ๋ถ์ฌ ๋ฐ ๊ฐ์ ์คํ
# ์คํ ๊ถํ ๋ถ์ฌ
chmod 775 upload_to_azure.sh
# Watchdog ์คํ (ํ์ผ ๋ณํ ๊ฐ์ง ์ ์
๋ก๋ ์คํฌ๋ฆฝํธ ์คํ)
# ๋ณ๋์ ํฐ๋ฏธ๋ ์ฐฝ์ ์ด์ด์ ์คํํ๊ฑฐ๋ ๋ฐฑ๊ทธ๋ผ์ด๋(&)๋ก ์คํ ๊ถ์ฅ
watchmedo shell-command \\
--patterns="*.png" \\
--recursive \\
--command="sh /home/azureuser/stable-diffusion-webui-forge/outputs/upload_to_azure.sh" \\
/home/azureuser/stable-diffusion-webui-forge/outputs