
목표: gpu가 달린 가상머신을 생성후 ssh로 접속하기





리소스그룹 → ML → Launch Studio







자동종료: 지정하면 필요할 때만 사용하고 사용하지 않을 때 VM 중지SSH: SSH 접속에서 사용

키가 다운로드되며 실행중으로 바뀌면 성공


ssh -i .\[프라이빗키파일이름] azureuser@[IP주소] -p 50000
# Create a new Conda environment
conda create -n sd python=3.10
# Activate environment
conda activate sd
# Clone SD Forge
git clone https://github.com/lllyasviel/stable-diffusion-webui-forge.git
# Go to Stable Diffusion folder
cd stable-diffusion-webui-forge
# Go to the models folder
cd ~/stable-diffusion-webui-forge/models/Stable-diffusion

# 환경 목록 확인
conda env list
# 환경 on
conda activate [환경이름]
# 환경 off
conda deactivate
루트에서 .bashrc의 conda initialize 부분의 하단에 시작 환경을 설정할 수 있다.




civitAI - 생성형 AI 이미지 및 모델 관련된 것들이 올라옴

프로필아이콘 → Settings → 최하단 부분의 API Keys

# To download models from Civit.ai
pip install civitdl
# Review library (설치하지 않아도 문제 없음)
sudo apt-get install lynx w3m links
https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5
# Download base models 1.5 and XL(base and refiner) Model
curl -H "Authorization: Bearer <Your Hugging Face Token>" https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/resolve/main/v1-5-pruned.safetensors --location --output sd-v1-5.safetensors

--location: 리다이렉션 허용--output: 로컬에서의 이름 설정# apt get update
sudo apt-get update
# Install alloc 메모리 관리에 탁월
sudo apt-get install libgoogle-perftools-dev
# Run the WebUI script # chmod +x webui.sh
# --always-cpu --skip-torch-cuda-test
./webui.sh --share



저장해야할 위치로 이동한 후 다운로드 명령어 사용
Base model / Checkpoint 저장 위치 : ~/stable-diffusion-webui-forge/models/Stable-diffusionLora 저장 위치 : ~/stable-diffusion-webui-forge/models/LoraControlNet 저장 위치: ~/stable-diffusion-webui-forge/extensions/sd-webui-controlnet# Download base models Flux1 Model
curl -H "Authorization: Bearer <Your Hugging Face Token>”
https://huggingface.co/lllyasviel/flux1_dev/resolve/main/flux1-dev-fp8.safetensors --location --output flux1-dev-fp8.safetensors
# VAE
curl -H "Authorization: Bearer <Your Hugging Face Token>" https://huggingface.co/black-forest-labs/FLUX.1-dev/resolve/main/ae.safetensors --location --output ae.safetensors
# Text Encoder
curl -H "Authorization: Bearer <Your Hugging Face Token>"
https://huggingface.co/comfyanonymous/flux_text_encoders/resolve/main/clip_l.safetensors --location --output clip_l.safetensors
1. Huggingface에서 있는 모델
curl -H "Authorization: Bearer <Your Hugging Face Token>" https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.ckpt --location --output v1-5-pruned-emaonly.ckpt
2. Civit.AI에 있는 모델
# To download models from Civit.ai
pip install civitdl
# Download models from Civit.ai
civitdl [값] [저장위치] -k [키값]

zip -r output.zip .
윈도우 명령 프롬프트에서 다음 명령 입력
scp: secure copyscp -i [프라이빗키주소] -P 50000 azureuser@[ip주소]:/home/azureuser/stable-diffusion-webui-forge/outputs/output.zip .
예)scp -i .\3dt016-vm-gpu_key.pem -P 50000 azureuser@0.000.00.00:/home/azureuser/stable-diffusion-webui-forge/outputs/output.zip .

pip install --upgrade pip
pip install watchdog



sudo apt-get update && sudo apt-get install azure-cli
# Image 가 생성되는 폴더로 이동.
cd ~/stable-diffusion-webui-forge/outputs/
# vi로 sh 파일 생성 및 편집
vi upload_to_azure.sh
https://learn.microsoft.com/ko-kr/azure/storage/common/storage-use-azcopy-v10
#!/bin/bash
STORAGE_ACCOUNT_NAME="dt016mlstorage"
CONTAINER_NAME="stable-diffusion-images"
LOCAL_PATH="/home/azureuser/stable-diffusion-webui-forge/outputs/"
SAS_TOKEN="<토큰>"
BLOB_URL="https://${STORAGE_ACCOUNT_NAME}.blob.core.windows.net/${CONTAINER_NAME}?${SAS_TOKEN}"
azcopy sync "${LOCAL_PATH}" "${BLOB_URL}" --recursive --include-pattern="*.png"
sh upload_to_azure.sh
# 실행 권한 추가
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