setup_windows.md 7.48 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Nunchaku Setup Guide (Windows)

# Environment Setup

## 1. Install Cuda

Download and install the latest CUDA Toolkit from the official [NVIDIA CUDA Downloads](https://developer.nvidia.com/cuda-downloads?target_os=Windows&target_arch=x86_64&target_version=Server2022&target_type=exe_local). After installation, verify the installation:

```bash
nvcc --version
```

## 2. Install Visual Studio C++ Build Tools

Download from the official [Visual Studio Build Tools page](https://visualstudio.microsoft.com/visual-cpp-build-tools/). During installation, select the following workloads:

- **Desktop development with C++**
- **C++ tools for Linux development**

### 3. Git

Download Git from [https://git-scm.com/downloads/win](https://git-scm.com/downloads/win) and follow the installation steps.

## 4. (Optional) Install Conda

Conda helps manage Python environments. You can install either Anaconda or Miniconda from the [official site](https://www.anaconda.com/download/success).

## 5. (Optional) Installing ComfyUI

You may have some various ways to install ComfyUI. For example, I used ComfyUI CLI. Once Python is installed, you can install ComfyUI via the CLI:

```shell
pip install comfy-cli
comfy-cli install
```

To launch ComfyUI:

```shell
comfy-cli launch
```

# Installing Nunchaku

## Step 1: Identify Your Python Environment

To ensure correct installation, you need to find the Python interpreter used by ComfyUI. Launch ComfyUI and look for this line in the log:

```bash
** Python executable: G:\ComfyuI\python\python.exe
```

Then verify the Python version and installed PyTorch version:

```bash
"G:\ComfyuI\python\python.exe" --version
"G:\ComfyuI\python\python.exe" -m pip show torch
```

## Step 2: Install PyTorch (≥2.5) if you haven’t

Install PyTorch appropriate for your setup

- **For most users**:
Muyang Li's avatar
Muyang Li committed
65

66
67
68
  ```bash
  "G:\ComfyuI\python\python.exe" -m pip install torch==2.6 torchvision==0.21 torchaudio==2.6
  ```
Muyang Li's avatar
Muyang Li committed
69

70
- **For RTX 50-series GPUs** (requires PyTorch ≥2.7 with CUDA 12.8):
Muyang Li's avatar
Muyang Li committed
71

72
73
74
  ```bash
  "G:\ComfyuI\python\python.exe" -m pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu128
  ```
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

## Step 3: Install Nunchaku

### Prebuilt Wheels

You can install Nunchaku wheels from one of the following:

- [Hugging Face](https://huggingface.co/mit-han-lab/nunchaku/tree/main)
- [ModelScope](https://modelscope.cn/models/Lmxyy1999/nunchaku)
- [GitHub Releases](https://github.com/mit-han-lab/nunchaku/releases)

Example (for Python 3.10 + PyTorch 2.6):

```bash
"G:\ComfyuI\python\python.exe" -m pip install https://huggingface.co/mit-han-lab/nunchaku/resolve/main/nunchaku-0.2.0+torch2.6-cp310-cp310-win_amd64.whl
```

To verify the installation:

```bash
"G:\ComfyuI\python\python.exe" -c "import nunchaku"
```

You can also run a test (requires a Hugging Face token for downloading the models):

```bash
"G:\ComfyuI\python\python.exe" -m huggingface-cli login
"G:\ComfyuI\python\python.exe" -m nunchaku.test
```

### (Alternative) Build Nunchaku from Source

Please use CMD instead of PowerShell for building.

- Step 1: Install Build Tools
Muyang Li's avatar
Muyang Li committed
110

111
112
113
114
  ```bash
  C:\Users\muyang\miniconda3\envs\comfyui\python.exe
  "G:\ComfyuI\python\python.exe" -m pip install ninja setuptools wheel build
  ```
Muyang Li's avatar
Muyang Li committed
115

116
- Step 2: Clone the Repository
Muyang Li's avatar
Muyang Li committed
117

118
119
120
121
122
123
  ```bash
  git clone https://github.com/mit-han-lab/nunchaku.git
  cd nunchaku
  git submodule init
  git submodule update
  ```
Muyang Li's avatar
Muyang Li committed
124

125
- Step 3: Set Up Visual Studio Environment
Muyang Li's avatar
Muyang Li committed
126

127
  Locate the `VsDevCmd.bat` script on your system. Example path:
Muyang Li's avatar
Muyang Li committed
128

129
130
131
  ```
  C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat
  ```
Muyang Li's avatar
Muyang Li committed
132

133
  Then run:
Muyang Li's avatar
Muyang Li committed
134

135
136
137
138
  ```bash
  "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64
  set DISTUTILS_USE_SDK=1
  ```
Muyang Li's avatar
Muyang Li committed
139

140
- Step 4: Build Nunchaku
Muyang Li's avatar
Muyang Li committed
141

142
143
144
  ```bash
  "G:\ComfyuI\python\python.exe" setup.py develop
  ```
Muyang Li's avatar
Muyang Li committed
145

146
  Verify with:
Muyang Li's avatar
Muyang Li committed
147

148
149
150
  ```bash
  "G:\ComfyuI\python\python.exe" -c "import nunchaku"
  ```
Muyang Li's avatar
Muyang Li committed
151

152
  You can also run a test (requires a Hugging Face token for downloading the models):
Muyang Li's avatar
Muyang Li committed
153

154
155
156
157
  ```bash
  "G:\ComfyuI\python\python.exe" -m huggingface-cli login
  "G:\ComfyuI\python\python.exe" -m nunchaku.test
  ```
Muyang Li's avatar
Muyang Li committed
158

muyangli's avatar
muyangli committed
159
160
- (Optional) Step 5: Building wheel for Portable Python

161
  If building directly with portable Python fails, you can first build the wheel in a working Conda environment, then install the `.whl` file using your portable Python:
muyangli's avatar
muyangli committed
162

163
164
165
166
  ```shell
  set NUNCHAKU_INSTALL_MODE=ALL
  "G:\ComfyuI\python\python.exe" python -m build --wheel --no-isolation
  ```
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183

# Use Nunchaku in ComfyUI

## 1. Install the Plugin

Clone the [ComfyUI-Nunchaku](https://github.com/mit-han-lab/ComfyUI-nunchaku) plugin into the `custom_nodes` folder:

```
cd ComfyUI/custom_nodes
git clone https://github.com/mit-han-lab/ComfyUI-nunchaku.git
```

Alternatively, install using [ComfyUI-Manager](https://github.com/Comfy-Org/ComfyUI-Manager) or `comfy-cli`.

## 2. Download Models

- **Standard FLUX.1-dev Models**
Muyang Li's avatar
Muyang Li committed
184

185
  Start by downloading the standard [FLUX.1-dev text encoders](https://huggingface.co/comfyanonymous/flux_text_encoders/tree/main) and [VAE](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/ae.safetensors). You can also optionally download the original [BF16 FLUX.1-dev](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/flux1-dev.safetensors) model. An example command:
Muyang Li's avatar
Muyang Li committed
186

187
188
189
190
191
192
  ```bash
  huggingface-cli download comfyanonymous/flux_text_encoders clip_l.safetensors --local-dir models/text_encoders
  huggingface-cli download comfyanonymous/flux_text_encoders t5xxl_fp16.safetensors --local-dir models/text_encoders
  huggingface-cli download black-forest-labs/FLUX.1-schnell ae.safetensors --local-dir models/vae
  huggingface-cli download black-forest-labs/FLUX.1-dev flux1-dev.safetensors --local-dir models/diffusion_models
  ```
Muyang Li's avatar
Muyang Li committed
193

194
- **SVDQuant 4-bit FLUX.1-dev Models**
Muyang Li's avatar
Muyang Li committed
195

196
  Next, download the SVDQuant 4-bit models:
Muyang Li's avatar
Muyang Li committed
197

198
199
  - For **50-series GPUs**, use the [FP4 model](https://huggingface.co/mit-han-lab/svdq-fp4-flux.1-dev).
  - For **other GPUs**, use the [INT4 model](https://huggingface.co/mit-han-lab/svdq-int4-flux.1-dev).
Muyang Li's avatar
Muyang Li committed
200

201
  Make sure to place the **entire downloaded folder** into `models/diffusion_models`. For example:
Muyang Li's avatar
Muyang Li committed
202

203
204
205
  ```bash
  huggingface-cli download mit-han-lab/svdq-int4-flux.1-dev --local-dir models/diffusion_models/svdq-int4-flux.1-dev
  ```
Muyang Li's avatar
Muyang Li committed
206

207
- **(Optional): Download Sample LoRAs**
Muyang Li's avatar
Muyang Li committed
208

209
  You can test with some sample LoRAs like [FLUX.1-Turbo](https://huggingface.co/alimama-creative/FLUX.1-Turbo-Alpha/blob/main/diffusion_pytorch_model.safetensors) and [Ghibsky](https://huggingface.co/aleksa-codes/flux-ghibsky-illustration/blob/main/lora.safetensors). Place these files in the `models/loras` directory:
Muyang Li's avatar
Muyang Li committed
210

211
212
213
214
  ```bash
  huggingface-cli download alimama-creative/FLUX.1-Turbo-Alpha diffusion_pytorch_model.safetensors --local-dir models/loras
  huggingface-cli download aleksa-codes/flux-ghibsky-illustration lora.safetensors --local-dir models/loras
  ```
215
216
217

## 3. Set Up Workflows

Muyang Li's avatar
Muyang Li committed
218
To use the official workflows, download them from the [ComfyUI-nunchaku](https://github.com/mit-han-lab/ComfyUI-nunchaku/tree/main/workflows) and place them in your `ComfyUI/user/default/workflows` directory. The command can be
219
220
221
222
223
224
225
226
227
228
229
230
231

```bash
# From the root of your ComfyUI folder
cp -r custom_nodes/ComfyUI-nunchaku/workflows user/default/workflows/nunchaku_examples
```

You can now launch ComfyUI and try running the example workflows.

# Troubleshooting

If you encounter issues, refer to our:

- [FAQs](https://github.com/mit-han-lab/nunchaku/discussions/262)
Muyang Li's avatar
Muyang Li committed
232
- [GitHub Issues](https://github.com/mit-han-lab/nunchaku/issues)