一. 前言
这一篇主要是做一个开源工具的附属产品 ,之前提到过 Modal 这个平台 ,它时不时有活动可以薅羊毛 , 并且账号每个月有$30 的额度 ,是一个不错的体验平台。
然后由于赠送的额度一直没用 ,所以就简单写了一个工具 ,用来做一键部署。所以顺带把才发布的 Z-Image 体验了一把。
- Modal 使用 : juejin.cn/post/754425...
- Modal ComfyUI : juejin.cn/post/754679...
二. 关于用到的材料
需要用到的材料
Comfy-Org : Z-Image ComfyUI 版本 ,主要用于 ComfyUI 部署

- qwen_3_4b.safetensors : 文本编码器 ,自然语言推理与生成,视觉语义转化为符合逻辑的文本描述。
- z_image_turbo_bf16.safetensors : 扩散主模型 ,主要的模型
- ae.safetensors : VAE 解码器 , 负责底层视觉编码
三. 工作流

四. 效果展示

几张图片的效果 :


- 光影和质感都是非常不错的
- 最重要的是出图很快 ,没有具体的参数 ,但是明显比之前 Flux 用起来快一些
总结
简单体验了一下 ,生产力应该是足够了 ,出图很快 ,效果也很好。
开源的模型 ,你想生成什么都可以。
附录 : 如果你用到了 Modal
python
# =============================================================================
# Z-Image-Turbo ComfyUI 一键部署服务
# =============================================================================
# 启动命令: modal deploy z_image_turbo_deploy.py
# =============================================================================
import json
import os
import subprocess
from pathlib import Path
import modal
# =============================================================================
# S1: 环境准备 - 构建基础镜像
# =============================================================================
image = (
modal.Image.debian_slim(python_version="3.11")
.apt_install("git", "wget", "curl")
.pip_install(
"fastapi[standard]==0.115.4",
"comfy-cli==1.5.3",
"requests==2.32.3",
)
.run_commands("comfy --skip-prompt install --fast-deps --nvidia")
)
# HuggingFace Secret
try:
hf_secret = modal.Secret.from_name("huggingface-secret")
except modal.exception.NotFoundError:
hf_secret = None
# =============================================================================
# S2: 模型下载 - 从 Tongyi-MAI/Z-Image-Turbo 下载 3 个核心模型
# =============================================================================
def hf_download():
"""
下载 Z-Image-Turbo 模型:
- z_image_turbo_bf16.safetensors (主扩散模型)
- qwen_3_4b.safetensors (CLIP 文本编码器)
- ae.safetensors (VAE 解码器)
"""
from huggingface_hub import hf_hub_download
hf_token = os.getenv("HF_TOKEN")
repo_id = "Comfy-Org/z_image_turbo"
print(f"📦 从 {repo_id} 下载模型...")
# 模型配置列表 (文件路径包含 split_files/ 前缀)
models = [
{
"filename": "split_files/diffusion_models/z_image_turbo_bf16.safetensors",
"target_dir": "/root/comfy/ComfyUI/models/diffusion_models",
"target_name": "z_image_turbo_bf16.safetensors",
"desc": "主扩散模型"
},
{
"filename": "split_files/text_encoders/qwen_3_4b.safetensors",
"target_dir": "/root/comfy/ComfyUI/models/clip",
"target_name": "qwen_3_4b.safetensors",
"desc": "CLIP 文本编码器"
},
{
"filename": "split_files/vae/ae.safetensors",
"target_dir": "/root/comfy/ComfyUI/models/vae",
"target_name": "ae.safetensors",
"desc": "VAE 解码器"
}
]
for model in models:
print(f"📥 下载 {model['desc']}: {model['target_name']}...")
cached_path = hf_hub_download(
repo_id=repo_id,
filename=model["filename"],
cache_dir="/cache",
token=hf_token
)
Path(model["target_dir"]).mkdir(parents=True, exist_ok=True)
target_path = f"{model['target_dir']}/{model['target_name']}"
subprocess.run(f"ln -sf {cached_path} {target_path}", shell=True, check=True)
print(f" ✅ {model['desc']} 完成")
print("🎉 所有模型下载完成!")
def create_workflow_file():
"""创建工作流 JSON 文件"""
workflow = {
"1": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "z_image_turbo_bf16.safetensors",
"weight_dtype": "default"
}
},
"2": {
"class_type": "DualCLIPLoader",
"inputs": {
"clip_name1": "qwen_3_4b.safetensors",
"clip_name2": "qwen_3_4b.safetensors",
"type": "z_image"
}
},
"3": {
"class_type": "VAELoader",
"inputs": {"vae_name": "ae.safetensors"}
},
"4": {
"class_type": "CLIPTextEncode",
"inputs": {
"text": "一位美丽的亚洲女性,照片级真实,自然光线,高清细节",
"clip": ["2", 0]
}
},
"5": {
"class_type": "CLIPTextEncode",
"inputs": {
"text": "低质量,模糊,畸形,丑陋,文字,水印",
"clip": ["2", 0]
}
},
"6": {
"class_type": "EmptyLatentImage",
"inputs": {"width": 1024, "height": 1024, "batch_size": 1}
},
"7": {
"class_type": "KSampler",
"inputs": {
"model": ["1", 0],
"positive": ["4", 0],
"negative": ["5", 0],
"latent_image": ["6", 0],
"seed": 42,
"steps": 4,
"cfg": 1.0,
"sampler_name": "euler",
"scheduler": "simple",
"denoise": 1.0
}
},
"8": {
"class_type": "VAEDecode",
"inputs": {"samples": ["7", 0], "vae": ["3", 0]}
},
"9": {
"class_type": "SaveImage",
"inputs": {"filename_prefix": "z_image_turbo", "images": ["8", 0]}
}
}
Path("/root/workflow_api.json").write_text(json.dumps(workflow, ensure_ascii=False, indent=2))
print("📝 工作流文件已创建")
# =============================================================================
# S3: 服务配置
# =============================================================================
vol = modal.Volume.from_name("z-image-turbo-test-cache", create_if_missing=True)
image = (
image.pip_install("huggingface_hub[hf_transfer]==0.34.4")
.env({"HF_HUB_ENABLE_HF_TRANSFER": "1"})
.run_function(
hf_download,
volumes={"/cache": vol},
secrets=[hf_secret] if hf_secret else []
)
.run_function(create_workflow_file)
)
app = modal.App(name="z-image-turbo-test", image=image)
# =============================================================================
# S4: UI 服务
# =============================================================================
@app.function(
max_containers=1,
gpu="L40S",
volumes={"/cache": vol},
timeout=86400
)
@modal.concurrent(max_inputs=10)
@modal.web_server(8000, startup_timeout=60)
def ui():
"""ComfyUI Web 界面"""
print("🌐 启动 Z-Image-Turbo Web 界面...")
subprocess.Popen("comfy launch -- --listen 0.0.0.0 --port 8000", shell=True)
# =============================================================================
# S5: 本地入口点
# =============================================================================
@app.local_entrypoint()
def main():
print("=" * 60)
print("Z-Image-Turbo ComfyUI 一键部署")
print("=" * 60)
print("\n📦 模型来源: Comfy-Org/z_image_turbo")
print("\n📋 已下载模型:")
print(" - z_image_turbo_bf16.safetensors (主扩散模型)")
print(" - qwen_3_4b.safetensors (CLIP 文本编码器)")
print(" - ae.safetensors (VAE 解码器)")
print("\n📌 部署命令: modal deploy z_image_turbo_deploy.py")
print("=" * 60)
部署成功后 :
python
PS D:\code\Modal安装\modal-manager> modal deploy z_image_turbo_deploy.py
Building image im-RuODNKSpmlSj8WWyALvgT8
=> Step 0: running function 'hf_download'
📦 从 Comfy-Org/z_image_turbo 下载模型...
📥 下载 主扩散模型: z_image_turbo_bf16.safetensors...
✅ 主扩散模型 完成
📥 下载 CLIP 文本编码器: qwen_3_4b.safetensors...
✅ CLIP 文本编码器 完成
📥 下载 VAE 解码器: ae.safetensors...
✅ VAE 解码器 完成
🎉 所有模型下载完成!
Saving image...
Image saved, took 1.50s
Finished image build for im-RuODNKSpmlSj8WWyALvgT8
Building image im-KblbHI0Rx9z0J54HpxvUH3
=> Step 0: running function 'create_workflow_file'
📝 工作流文件已创建
Saving image...
Image saved, took 1.21s
Finished image build for im-KblbHI0Rx9z111HpxvUH3
✓ Created objects.
├── 🔨 Created mount D:\code\学习资料\Modal安装\modal-manager\z_image_turbo_deploy.py
├── 🔨 Created function hf_download.
├── 🔨 Created function create_workflow_file.
└── 🔨 Created web function ui => https://aubreyce5ju45p2le3t--z-image-turbo-test-ui.modal.run
✓ App deployed in 106.760s! 🎉
View Deployment: https://modal.com/apps/aubreyce5ju45p2le3t/main/deployed/z-image-turbo-test