模型合并丨分片
Stitch model-00001-of-00005.safetensors shards back into one file
- 结果信息
- 输出路径
- 张量数量
You downloaded a checkpoint and got a folder full of model-00001-of-00005.safetensors shards instead of a single file. ComfyUI wants one file; you have five. MergeShardedModel is the QING pack's one-click answer: point it at the directory, give the merged file a name, and it concatenates the shards into a single .safetensors ComfyUI can load straight from its models folder.
How it works
The node looks in input_dir for shard files two ways, in order:
- Index file - if a
*.index.jsonexists (the standard companion for diffusers-style sharded safetensors), it reads theweight_mapand collects exactly the files named there, in the right order. - Filename pattern - otherwise it grabs every
.safetensorswhose name contains-of-or-0000, which is how HuggingFace-style shards are named.
It loads each shard on CPU with safetensors.load_file, merges the state dicts, and writes the result with safetensors.save_file. strict_check (default true) is the safety net: if the same tensor key shows up in more than one shard - which shouldn't happen, but sometimes does with half-downloaded or re-packaged models - it aborts rather than silently overwrite. Outputs are a result message, the output path (the file is written inside input_dir), and the tensor count.
The output_name gets normalized: it's always forced to a .safetensors extension, so don't bother typing anything else.
Where you'd reach for it
Any time a download lands as shards and you need a single file. Some HuggingFace conversions, some Community checkpoints, and a lot of the "fp8 / split" exports from other tools ship this way, and not every loader handles a directory. This is a merge in the concatenation sense, not the model-blending sense - it does not average, mix, or interpolate weights, and it won't merge two different checkpoints into a Franken-model. Single-purpose tool, single job.
The QING pack is a broad all-in-one (79 nodes: AI APIs, image, mask, SVG, data flow), so this lives alongside unrelated stuff; you're not installing anything heavy just for this node. Core dependency is the safetensors library, which ComfyUI itself ships with, so this usually just works.
Installing it
cd ComfyUI/custom_nodes
git clone https://github.com/GAO-SHIQING/ComfyUI-QING
cd ComfyUI-QING
python install_dependencies.py # or: pip install -r requirements.txt
Restart ComfyUI. The install script pulls Pillow, opencv-python, scipy, scikit-image, cairosvg, and the openai client for the pack's other nodes - again, safetensors is not in there because ComfyUI provides it. Note the README's clone URL has a GAOSHI-QING typo; the real repo is GAO-SHIQING/ComfyUI-QING (also searchable as "ComfyUI-QING" in Manager).
Things to know
The merged file lands in the same directory as the shards - so if you point input_dir at your models/checkpoints folder, the result is immediately loadable. The node skips any single file already named like your output, so re-running doesn't try to merge the output into itself. Where people get burned: strict_check with a genuinely duplicated key aborts with a clear Chinese-language message ("检测到重复张量键"), so read the result string if the output file doesn't appear. And it works on shards only - point it at a folder with unrelated safetensors files and it'll ignore them unless they look like shards, which is exactly the behavior you want.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| input_dir | STRING | models/xxx | — |
| output_name | STRING | merged_models.safetensors | — |
| strict_check | BOOLEAN | true | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| 结果信息 | STRING | — |
| 输出路径 | STRING | — |
| 张量数量 | INT | — |