切換節點
關於切換節點如何工作的指南:簡單的文字切換和LoRA切換
關於
此教學工作流程示範如何使用 ComfyUI 的 ComfySwitchNode,透過簡單的布林切換在兩個輸入之間進行路由。它包含兩個聚焦範例:範例 1-字串選擇,示範如何用 PrimitiveString 與 PrimitiveStringMultiline 在兩段提示詞字串間切換,並用 PreviewAny 預覽目前啟用的選項。範例 2-LoRA 切換,示範如何在基礎模型前後將 LoRA 開關:UNETLoader 載入 Z-Image-Turbo,LoraLoaderModelOnly 套用所選的 LoRA,再由 ComfySwitchNode 選擇純 UNet(on_false)或套用 LoRA 後的 UNet(on_true)送入生成節點。
在節點層面,ComfySwitchNode 提供四個針腳:on_false、on_true、switch(布林)、output。當 switch 為 OFF(false)時,output 會轉送連到 on_false 的內容;當為 ON(true)時則轉送 on_true。此工作流程把這個切換用在實際任務上:文字切換會選出下游使用的一段提示詞字串;LoRA 切換則控制在出圖前是否把 LoRA 權重套用到 Z-Image-Turbo 的 UNet。SaveImage 節點會保存結果以便進行 A/B 對照,並用 MarkdownNote 區塊在流程中直接說明路由邏輯。生成路徑透過 UNETLoader 使用 Z-Image-Turbo,並使用生成節點(ID 0f79b7f9-d214-4587-b475-bc429519b976),消耗所選模型與提示詞來渲染圖片。
您提供的內容
- 正在讀取工作流程
在 ComfyUI 中執行。 此工作流程無法在此頁面上執行。請在已載入所有內容的 Comfy Cloud 中開啟,或下載到您自己的 ComfyUI。
在 Cloud 中試用工作流程內部
節點圖的唯讀預覽。請在 Comfy Cloud 中開啟,或下載後編輯節點。
Loading the graph
Open full-size workflow preview需要自訂節點
- 正在讀取工作流程
從程式碼使用此工作流程
可行時會根據工作流程圖和輸入內容產生;否則會顯示儲存的範例。執行可能產生費用的程式碼前,請檢查認證資訊和端點。
What you need
- Runs on
- Comfy Cloud
- 金鑰
- COMFY_API_KEY
需要付費 Cloud 方案與點數。
# Python 3.10+: pip install comfy-sdk==0.4.0
import os
from comfy_sdk import Comfy
api_key = os.environ.get("COMFY_API_KEY", "").strip()
if not api_key: raise RuntimeError("Set COMFY_API_KEY")
os.environ.setdefault("COMFY_BASE_URL", "https://cloud.comfy.org")
client = Comfy(api_key=api_key)
workflow = client.workflows.from_json({
"1": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"3",
0
],
"on_true": [
"2",
0
],
"switch": False
},
"_meta": {
"title": "If/Else Switch"
}
},
"2": {
"class_type": "PrimitiveString",
"inputs": {
"value": "true"
},
"_meta": {
"title": "Text"
}
},
"3": {
"class_type": "PrimitiveString",
"inputs": {
"value": "false"
},
"_meta": {
"title": "Text"
}
},
"4": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"1",
0
]
},
"_meta": {
"title": "Preview as Text"
}
},
"5": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"7",
0
],
"on_true": [
"6",
0
],
"switch": True
},
"_meta": {
"title": "If/Else Switch"
}
},
"6": {
"class_type": "PrimitiveString",
"inputs": {
"value": "true"
},
"_meta": {
"title": "Text"
}
},
"7": {
"class_type": "PrimitiveString",
"inputs": {
"value": "false"
},
"_meta": {
"title": "Text"
}
},
"8": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"5",
0
]
},
"_meta": {
"title": "Preview as Text"
}
},
"60": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "z_image_turbo_bf16.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"61": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"60",
0
],
"on_true": [
"62",
0
],
"switch": [
"66",
0
]
},
"_meta": {
"title": "Model Switch (MODEL)"
}
},
"62": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "zimage-90_s_anime_melancholy.safetensors",
"model": [
"60",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"63": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"64:55",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"65": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"67",
0
],
"on_true": [
"68",
0
],
"switch": [
"66",
0
]
},
"_meta": {
"title": "Prompt Switch (CLIP)"
}
},
"66": {
"class_type": "PrimitiveBoolean",
"inputs": {
"value": True
},
"_meta": {
"title": "LoRA Switch"
}
},
"67": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "a 27 year old man wearing a baseball uniform, smiling at the camera and holding a bat"
},
"_meta": {
"title": "Prompt - No LoRA"
}
},
"68": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "90s_melancholy, retro, a 27 year old man wearing a baseball uniform, smiling at the camera and holding a bat"
},
"_meta": {
"title": "Prompt - With LoRA Trigger"
}
},
"64:52": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_3_4b.safetensors",
"device": "default",
"type": "lumina2"
},
"_meta": {
"title": "Load CLIP"
}
},
"64:53": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"64:54": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"64:56",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"64:55": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"64:58",
0
],
"vae": [
"64:53",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"64:56": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"64:52",
0
],
"text": [
"65",
0
]
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"64:57": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 1024,
"width": 1024
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"64:58": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"64:57",
0
],
"model": [
"61",
0
],
"negative": [
"64:54",
0
],
"positive": [
"64:56",
0
],
"sampler_name": "res_multistep",
"scheduler": "simple",
"seed": 12673005598788,
"steps": 4
},
"_meta": {
"title": "KSampler"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)問答
由布林 switch 針腳控制路由:OFF(false)轉送 on_false;ON(true)轉送 on_true。兩個輸入必須是相容的類型(例如都為字串,或都為 UNet 模型)。
不會。UNETLoader 會保留基礎 Z-Image-Turbo 模型。當該路徑啟用時,LoraLoaderModelOnly 才會套用 LoRA。切換後重新排程即可用/不用 LoRA 重新計算。
可以。串接多個 ComfySwitchNode(例如第一個選 A vs B,第二個再把該結果 vs C)。請保持所有分支的資料類型一致。
使用相同提示詞與固定 seed,一次只改動一個變因(提示詞或 LoRA),並用 SaveImage 保存輸出以便並排檢視。
相關工作流程
- ZZ-Image-Turbo
1.1 入門-文字轉圖像
- ZZ-Image-Turbo
2.1 Creator-擴散基礎
- ZZ-Image-Turbo
2.2 Creator - 擴散引導
- ZZ-Image-Turbo
2.3 Creator:影像放大與分析
- Wan2.2, Z-Image-Turbo
AIrt MAchIne
- Google Gemini, Kling 3.0, Z-Image-Turbo
AIrt MAchIne(API 版本)
- ZZ-Image-Turbo
Z-Image-Turbo 控制生圖
- ZZ-Image-Turbo
Z-Image-Turbo: 文生圖
- ZZ-Image-Turbo
Z-Image-Turbo_Oldschool-Hud-Graphics
- ZZ-Image-Turbo
圖像放大:Z-Image-Turbo 2K
- Kling 2.6, Nano Banana Pro, Z-Image-Turbo
圖生影片
- ZZ-Image-Turbo
從列表批次處理文字提示