Skip to content

v2.6.7 - Nunchaku ZImageModelPatcher fast_disk clone compatibility (ComfyUI >= 0.38)

Latest

Choose a tag to compare

@ussoewwin ussoewwin released this 05 Oct 22:54
· 1 commit to main since this release
EN 中文

1. What changed, and why

1.1 Background: ComfyUI v0.38 introduced fast_disk

From ComfyUI v0.38 on, fast-disk (aimdo virtual VRAM) is enabled by default for every model loader. ModelPatcher.clone() now unconditionally passes a new keyword when re-instantiating the patcher class:

# comfy/model_patcher.py (v0.38.x, clone())
n = class_(model_override[0], self.load_device, self.offload_device, self.model_size(),
           weight_inplace_update=self.weight_inplace_update, fast_disk=self.fast_disk)

The base ModelPatcher.__init__ declares fast_disk=False, but the subclass ZImageModelPatcher never followed its signature.

1.2 The symptom

ComfyUI-nunchaku (upstream development has stopped) defines, in model_patcher/zimage.py:

class ZImageModelPatcher(ModelPatcher):
    def __init__(self, model, load_device, offload_device, size=0, weight_inplace_update=False):
        super().__init__(model, load_device, offload_device, size, weight_inplace_update=False)
        self.svdq_backup = {}

Every node that calls model.clone() on a nunchaku Z-Image model (e.g. the EasyCache node inside the sampling chain) dies with:

TypeError: ZImageModelPatcher.__init__() got an unexpected keyword argument 'fast_disk'

The failed clone also triggers a follow-up AttributeError: 'ZImageModelPatcher' object has no attribute 'pinned' when the half-constructed object is garbage-collected (__del__ -> unpin_all_weights).

2. The fix: an in-memory runtime wrapper (nunchaku files untouched)

patches/nunchaku_patch.py gains apply_nunchaku_zimage_fast_disk_patch():

  • Wraps ZImageModelPatcher.__init__ with a shim that accepts and stores the fast_disk keyword (self.fast_disk = ...) and forwards everything else to the original __init__.
  • Idempotent: the wrapper carries a _qwen_lora_loader_zimage_fast_disk_patch tag; repeated calls short-circuit.
  • Future-proof: if a later nunchaku build already declares fast_disk in its signature, the patch no-ops automatically.
  • sys.modules scan only, never re-importing: ComfyUI loads packs under names like custom_nodes.ComfyUI-nunchaku.model_patcher.zimage; importing the module again would create a second module instance and patch a class nobody uses.
  • Load-order safe: this package often loads before ComfyUI-nunchaku (folder name order). The patch shares the existing retry timer (0.25 s x 24 attempts) already used for the fuse-patch and applies as soon as the nunchaku module shows up.
  • No new entry point: it runs inside apply_nunchaku_patch() (called from this package's __init__.py), next to the rotary shim, lazy-Linear and copy_params patches.

3. Repository state after this release

Path Change Note
patches/nunchaku_patch.py +79 / -3 new apply_nunchaku_zimage_fast_disk_patch(), wired into apply_nunchaku_patch() and the retry timer
ComfyUI-nunchaku package files unchanged the fix lives entirely in this package's runtime patch
pyproject.toml / __init__.py version 2.6.6 -> 2.6.7

4. What was verified

  • Standalone construction test: before the patch the fast_disk parameter is absent; after the patch, v0.38-style clone() calls (positional args + weight_inplace_update= + fast_disk=True) succeed, fast_disk is stored, and svdq_backup / pinned remain intact.
  • Legacy calls (no fast_disk keyword) are unaffected and default to False.
  • Idempotency: a second call returns success without double-wrapping.
  • Real end-to-end: the full mixed workflow on ComfyUI v0.38.1 - HSWQ ConvRot NVFP4 UNet + INT8 ConvRot ControlNet (180 runtime patches) + EasyCache - completed (7/7 and 5/5 sampling passes, zero exceptions).

5. Action required

  • Update this package to v2.6.7 (ComfyUI Manager / git pull) and restart ComfyUI.
  • No workflow edits and no nunchaku changes are needed.

6. Notes

  • This issue surfaced while validating a ComfyUI v0.38.1 upgrade. The other problems from the same investigation (fast-disk native read serialization, the quantized-weight requantize crash, and migrating the DiT quant-lock guard from comfy/ops.py into the node side) were fixed in the ComfyUI-HSWQ-Loader-and-Tools repository and are not part of this package.

7. Links