Z-Image Turbo를 로컬에 설치하는 방법
발행: (2025년 12월 10일 오전 10:30 GMT+9)
3 min read
원문: Dev.to
Source: Dev.to
개요
이 가이드는 Z-Image Turbo를 로컬 머신에 설정하는 방법을 설명합니다. 이 모델은 6B 파라미터 아키텍처를 사용하여 뛰어난 텍스트 렌더링 능력을 갖춘 고품질 이미지를 생성합니다.
온라인 대안
GPU가 없거나 로컬에 설치하고 싶지 않은 경우 온라인 버전을 사용할 수 있습니다:
- Z‑Image Online – 20개 이상의 언어에서 완벽한 텍스트 렌더링을 제공하는 무료 AI 생성기, 4K 포토리얼리스틱 출력, GPU 필요 없음.
시스템 요구 사항
| 구성 요소 | 권장 |
|---|---|
| GPU | 16 GB VRAM (예: RTX 3090/4090 또는 유사한 데이터센터 카드). 메모리가 적은 GPU도 오프로드를 사용하면 작동하지만 속도가 느려집니다. |
| Python | 3.9 이상 |
| CUDA | GPU 드라이버와 호환되는 버전 (예시에서는 CUDA 12.4 사용) |
가상 환경 만들기
# Create the environment
python -m venv zimage-env
# Activate the environment
# Linux / macOS
source zimage-env/bin/activate
# Windows
zimage-env\Scripts\activate
종속성 설치
# Install PyTorch for CUDA 12.4 (adjust the index URL for other CUDA versions)
pip install torch --index-url https://download.pytorch.org/whl/cu124
# Install diffusers directly from source
pip install git+https://github.com/huggingface/diffusers
# Additional libraries
pip install transformers accelerate safetensors
파이썬 스크립트 만들기
다음 코드를 generate.py(또는 원하는 이름)로 저장하세요.
import torch
from diffusers import ZImagePipeline
# Load the model from Hugging Face
pipe = ZImagePipeline.from_pretrained(
"Tongyi-MAI/Z-Image-Turbo",
torch_dtype=torch.bfloat16,
low_cpu_mem_usage=False,
)
# Move pipeline to GPU
pipe.to("cuda")
이미지 생성
스크립트에 아래 코드를 추가하여 이미지를 생성합니다:
prompt = (
"City street at night with clear bilingual store signs, warm lighting, "
"and detailed reflections on wet pavement."
)
image = pipe(
prompt=prompt,
height=1024,
width=1024,
num_inference_steps=9,
guidance_scale=0.0,
generator=torch.Generator("cuda").manual_seed(123),
).images[0]
image.save("z_image_turbo_city.png")
print("Image saved successfully!")
선택적 최적화
Flash Attention 2
# Switch attention backend to Flash Attention 2
pipe.transformer.set_attention_backend("flash")
Compile the Transformer (requires PyTorch 2.0+)
# Optional: compile for faster inference
# pipe.transformer.compile()
CPU 오프로드 (저 VRAM 시스템)
GPU의 VRAM이 16 GB 미만인 경우, 모델 일부를 시스템 RAM으로 이동시키는 CPU 오프로드를 활성화하세요:
pipe.enable_model_cpu_offload()
Note: 오프로드를 사용하면 작은 GPU에서도 모델을 실행할 수 있지만, 생성 속도가 느려집니다.