# mit-han-lab/comfyui-nunchaku architecture

> Architecture diagram of the GitHub repository mit-han-lab/comfyui-nunchaku, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mit-han-lab/comfyui-nunchaku
- Repository: https://github.com/mit-han-lab/comfyui-nunchaku

## Overview

ComfyUI-nunchaku exposes custom workflow nodes for loading and adapting quantized image-generation models, with ancillary conditioning, preprocessing, and model-management tools. A typical user assembles nodes in ComfyUI to load a model and text encoder, optionally apply adapters or other conditioning, then run inference through ComfyUI. The graph preserves README-documented FLUX, Qwen-Image, and Z-Image support and optional capabilities. Connections are limited to relationships visible in excerpts or the source index, plus explicitly documented capabilities; unsampled implementations are not inferred.

Main entry points: [`__init__.py`](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/__init__.py) (Node registration), [`wrappers/flux.py`](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/wrappers/flux.py) (FLUX wrapper), [`nodes/models/zimage.py`](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/models/zimage.py) (Z-Image loader), [`models/qwenimage.py`](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/models/qwenimage.py) (Qwen transformer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_model_runtime["Model runtime"]
  node_flux_transformer["FLUX wrapper<br/>[flux.py]"]
  node_qwen_transformer["Qwen transformer<br/>[qwenimage.py]"]
  node_qwen_base["Qwen model base<br/>[qwenimage.py]"]
  node_zimage_config["Z-Image config<br/>[zimage.py]"]
  node_zimage_transformer["Z-Image transformer<br/>[zimage.py]"]
  node_zimage_patcher["Z-Image patcher<br/>[zimage.py]"]
  node_offload_mixin["Offload mixin<br/>[model.py]"]
end

subgraph group_workflow_nodes["Workflow nodes"]
  node_plugin_registry["Node registration<br/>[__init__.py]"]
  node_flux_loader["FLUX model loader<br/>[flux.py]"]
  node_qwen_loader["Qwen-Image loader<br/>[qwenimage.py]"]
  node_zimage_loader["Z-Image loader<br/>[zimage.py]"]
  node_text_encoder["Text encoder loader<br/>[text_encoder.py]"]
end

subgraph group_conditioning["Conditioning"]
  node_lora["FLUX LoRA nodes<br/>[flux.py]"]
  node_pulid["PuLID nodes<br/>[pulid.py]"]
  node_ipadapter["IPAdapter nodes<br/>[ipadapter.py]"]
  node_depth["Depth preprocessor<br/>[depth.py]"]
end

subgraph group_model_tools["Model tools"]
  node_installer["Wheel installer<br/>[installers.py]"]
  node_merger["Safetensors merger"]
end

node_user(("ComfyUI user"))
node_comfyui["ComfyUI runtime"]
node_nunchaku["Nunchaku engine"]
node_diffusion_result["Generated image"]

node_user -->|"builds workflow"| node_comfyui
node_comfyui -->|"loads plugin"| node_plugin_registry
node_plugin_registry -->|"registers"| node_flux_loader
node_plugin_registry -->|"registers"| node_qwen_loader
node_plugin_registry -->|"registers"| node_zimage_loader
node_plugin_registry -->|"registers"| node_text_encoder
node_plugin_registry -->|"registers"| node_lora
node_plugin_registry -->|"registers"| node_pulid
node_plugin_registry -->|"registers"| node_ipadapter
node_plugin_registry -->|"registers"| node_depth
node_plugin_registry -->|"registers"| node_installer
node_plugin_registry -->|"registers"| node_merger
node_flux_loader -->|"wraps model"| node_flux_transformer
node_lora -->|"adapts model"| node_flux_transformer
node_pulid -->|"conditions model"| node_flux_transformer
node_qwen_loader -->|"loads model"| node_qwen_base
node_qwen_base -->|"instantiates"| node_qwen_transformer
node_zimage_loader -->|"selects config"| node_zimage_config
node_zimage_config -->|"patches model"| node_zimage_transformer
node_zimage_loader -->|"uses patcher"| node_zimage_patcher
node_flux_transformer -.->|"runs inference"| node_nunchaku
node_qwen_transformer -.->|"runs inference"| node_nunchaku
node_zimage_transformer -.->|"runs inference"| node_nunchaku
node_comfyui -.->|"returns image"| node_diffusion_result

click node_plugin_registry "https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/__init__.py"
click node_flux_loader "https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/models/flux.py"
click node_qwen_loader "https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/models/qwenimage.py"
click node_zimage_loader "https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/models/zimage.py"
click node_flux_transformer "https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/wrappers/flux.py"
click node_qwen_transformer "https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/models/qwenimage.py"
click node_qwen_base "https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/model_base/qwenimage.py"
click node_zimage_config "https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/model_configs/zimage.py"
click node_zimage_transformer "https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/models/zimage.py"
click node_zimage_patcher "https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/model_patcher/zimage.py"
click node_offload_mixin "https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/mixins/model.py"
click node_text_encoder "https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/models/text_encoder.py"
click node_lora "https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/lora/flux.py"
click node_pulid "https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/models/pulid.py"
click node_ipadapter "https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/models/ipadapter.py"
click node_depth "https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/preprocessors/depth.py"
click node_installer "https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/tools/installers.py"
click node_merger "https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/tools/merge_safetensors.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_flux_transformer,node_qwen_transformer,node_qwen_base,node_zimage_config,node_zimage_transformer,node_zimage_patcher,node_offload_mixin,node_user,node_comfyui toneBlue
class node_plugin_registry,node_flux_loader,node_qwen_loader,node_zimage_loader,node_text_encoder toneAmber
class node_lora,node_pulid,node_ipadapter,node_depth toneMint
class node_installer,node_merger toneRose
class node_nunchaku,node_diffusion_result toneIndigo
```

## Components

### Model runtime

- [FLUX wrapper](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/wrappers/flux.py): `wrappers/flux.py`
- [Qwen transformer](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/models/qwenimage.py): `models/qwenimage.py`
- [Qwen model base](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/model_base/qwenimage.py): `model_base/qwenimage.py`
- [Z-Image config](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/model_configs/zimage.py): `model_configs/zimage.py`
- [Z-Image transformer](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/models/zimage.py): `models/zimage.py`
- [Z-Image patcher](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/model_patcher/zimage.py): `model_patcher/zimage.py`
- [Offload mixin](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/mixins/model.py): `mixins/model.py`

### Workflow nodes

- [Node registration](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/__init__.py): `__init__.py`
- [FLUX model loader](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/models/flux.py): `nodes/models/flux.py`
- [Qwen-Image loader](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/models/qwenimage.py): `nodes/models/qwenimage.py`
- [Z-Image loader](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/models/zimage.py): `nodes/models/zimage.py`
- [Text encoder loader](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/models/text_encoder.py): `nodes/models/text_encoder.py`

### Conditioning

- [FLUX LoRA nodes](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/lora/flux.py): `nodes/lora/flux.py`
- [PuLID nodes](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/models/pulid.py): `nodes/models/pulid.py`
- [IPAdapter nodes](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/models/ipadapter.py): `nodes/models/ipadapter.py`
- [Depth preprocessor](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/preprocessors/depth.py): `nodes/preprocessors/depth.py`

### Model tools

- [Wheel installer](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/tools/installers.py): `nodes/tools/installers.py`
- [Safetensors merger](https://github.com/mit-han-lab/comfyui-nunchaku/blob/main/nodes/tools/merge_safetensors.py): `nodes/tools/merge_safetensors.py`

### Other components

- **ComfyUI user**
- **ComfyUI runtime**
- **Nunchaku engine**
- **Generated image**

## Connections

- ComfyUI user → ComfyUI runtime: builds workflow (evidence: `README.md`)
- ComfyUI runtime → Node registration: loads plugin (evidence: `README.md`)
- Node registration → FLUX model loader: registers (evidence: `__init__.py`)
- Node registration → Qwen-Image loader: registers (evidence: `__init__.py`)
- Node registration → Z-Image loader: registers (evidence: `__init__.py`)
- Node registration → Text encoder loader: registers (evidence: `__init__.py`)
- Node registration → FLUX LoRA nodes: registers (evidence: `__init__.py`)
- Node registration → PuLID nodes: registers (evidence: `__init__.py`)
- Node registration → IPAdapter nodes: registers (evidence: `__init__.py`)
- Node registration → Depth preprocessor: registers (evidence: `__init__.py`)
- Node registration → Wheel installer: registers (evidence: `__init__.py`)
- Node registration → Safetensors merger: registers (evidence: `__init__.py`)
- FLUX model loader → FLUX wrapper: wraps model (evidence: `nodes/models/flux.py`)
- FLUX LoRA nodes → FLUX wrapper: adapts model (evidence: `nodes/lora/flux.py`)
- PuLID nodes → FLUX wrapper: conditions model (evidence: `nodes/models/pulid.py`)
- Qwen-Image loader → Qwen model base: loads model (evidence: `nodes/models/qwenimage.py`)
- Qwen model base → Qwen transformer: instantiates (evidence: `model_base/qwenimage.py`)
- Z-Image loader → Z-Image config: selects config (evidence: `nodes/models/zimage.py`)
- Z-Image config → Z-Image transformer: patches model (evidence: `model_configs/zimage.py`)
- Z-Image loader → Z-Image patcher: uses patcher (evidence: `nodes/models/zimage.py`)
- FLUX wrapper → Nunchaku engine: runs inference (evidence: `README.md`)
- Qwen transformer → Nunchaku engine: runs inference (evidence: `README.md`)
- Z-Image transformer → Nunchaku engine: runs inference (evidence: `README.md`)
- ComfyUI runtime → Generated image: returns image (evidence: `README.md`)
