A ComfyUI custom node implementation of TwinFlow: Realizing One-step Generation on Large Models with Self-adversarial Flows.
This project allows you to accelerate DiT (Diffusion Transformer) models (like Qwen-Image, Z-Image, etc.) to 1-step or few-step generation using TwinFlow patch weights.
Based on the paper: TwinFlow: Realizing One-step Generation on Large Models with Self-adversarial Flows
Github: https://github.com/inclusionAI/TwinFlow
- TwinFlow Model Patcher: Loads specific TwinFlow patch weights (SafeTensors or GGUF) and injects them into the diffusion model.
- TwinFlow Sampler/Scheduler: Custom sampling logic (Euler/Heun) and scheduling (Kumaraswamy transform) specifically designed for TwinFlow's rectified flow.
- TwinFlow KSampler: An all-in-one node for ease of use.
- Clone this repository into your ComfyUI
custom_nodesdirectory:cd ComfyUI/custom_nodes git clone https://github.com/mengqin/ComfyUI-TwinFlow.git - Install dependencies:
pip install -r requirements.txt
Place your TwinFlow patch files (e.g., TwinFlow_Z_Image_Turbo_bf16.safetensors) in your ComfyUI/models/unet/ directory (gguf files can be this same directory).
Use the TwinFlow Model Patcher node:
- model: Connect your TwinFlow tunned DiT model (e.g., Qwen, Z-image).
- patch_file: Select the same model TwinFlow modle file (This is a necessary step. Twinflow uses an additional time embedder tensor for inference, which is removed by the standard ComfyUI UNet load node. Our patcher node must be used to restore it.).
You can use the TwinFlow KSampler for a simplified workflow, or use the individual TwinFlow Sampler and TwinFlow Scheduler nodes with the standard SamplerCustom node.
Alternatively, you can use Twinflow's Sampler and Scheduler to customize your own sampling process.
Key Parameters:
sampling_style:few: For extremely low steps (e.g., 2-4 steps).any: For flexible step counts.mul: For multi-step generation.
sampling_method:euler(1st order) orheun(2nd order).dist_ctrl_a/b/c: Controls the Kumaraswamy time distribution (default 1.0 is usually linear).gap_start/gap_end: Defines the time boundaries for the flow.
GGUF model supports:
Simply switch the unet loader node to the Comfyui-GGUF unet loader.
The Twinflow z-image-turbo gguf model has finally been released:
https://huggingface.co/wbruna/TwinFlow-Z-Image-Turbo-sdcpp-GGUF
However, this model has issues and cannot be loaded using Comfyui-GGUF. The following fix is required:
After the fix, these models can be easily integrated into our workflow.
Additionally, some models on Hugging Face, such as:
https://huggingface.co/smthem/TwinFlow-Qwen-Image-v1.0-diffusers-gguf/tree/main
have an incorrect architecture field; it uses "qwen" instead of the standard "qwen_image". This can be easily corrected by writing a script.
Alternatively, you can directly download the correct GGUF model:
https://huggingface.co/Arunk25/TwinFlow-Qwen-Image-v1.0-GGUF
ComfyUI has another Twinflow implementation as follows:
https://github.com/smthemex/ComfyUI_TwinFlow
This implementation directly integrates the Twinflow source code, but it doesn't quite conform to ComfyUI's implementation specifications. It uses a completely self-contained model loader and Ksampler internally, making it incompatible with other ComfyUI nodes. It also lacks some options found in the original Twinflow. Our implementation is based on the Twinflow source code, but we have completely reimplemented the sampling process to fully comply with ComfyUI standards. The nodes use standard inputs and outputs, allowing you to freely combine them with other ComfyUI nodes and experiment with any LoRA models you want.
@article{cheng2025twinflow,
title={TwinFlow: Realizing One-step Generation on Large Models with Self-adversarial Flows},
author={Cheng, Zhenglin and Sun, Peng and Li, Jianguo and Lin, Tao},
journal={arXiv preprint arXiv:2512.05150},
year={2025}
}Original implementation by inclusionAI/TwinFlow.
MIT License
Copyright (c) 2025 ComfyUI-TwinFlow Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

