Nodes/ComfyUI-mem-safe-wrapper/Reset model patcher (middlek)
ComfyUI Node

Reset model patcher (middlek)

When calculate_weight() breaks your sampler, this undoes it

By MiddleKD·Created 2 years ago·Updated 2 years ago· 4
Reset model patcher (middlek)
  • model
  • MODEL

Ever had KSampler suddenly die with something like calculate_weight() got an unexpected keyword argument 'intermediate_dtype'? If you have, you've already met the problem this node fixes: a custom node injected its own calculate_weight function into ComfyUI's ModelPatcher, and now every model in your session is broken until you restart.

The background

ModelPatcher.calculate_weight is the hook that applies LoRAs, controlnet weights, and other patching during sampling. Some custom nodes monkey-patch it globally - swap the method on ModelPatcher itself - because it's the easiest way to hook into every weight lookup. The README explicitly names comfyui-inpaint-nodes (Acly) as an offender, but i-c-light and friends do it too. The problem: the patched version often doesn't accept the arguments ComfyUI's newer samplers pass, and once it's patched, it stays patched for the whole session - affecting models that have nothing to do with the node that did it. Hence errors in nodes you never touched.

Reset model patcher (middlek) is the undo button. It restores ModelPatcher.calculate_weight back to ComfyUI's original implementation.

How it works

It's almost embarrassingly simple, and that's the appeal. You feed it a MODEL, and it checks whether that patcher carries an original_calculate_weight attribute (ComfyUI saves the pre-patch method there). If it does, it copies the original back onto both the model instance and the ModelPatcher class, clearing the injected version. Then it hands your MODEL right back unchanged.

Drop it into the model's path before the node that's erroring, and the sampler gets a clean, unpatched patcher to work with. If there's nothing to reset, it's a harmless no-op - wire it in and forget it.

  • Input: model (MODEL) - the model whose patcher you want restored.
  • Output: MODEL - the same model, with the original calculate_weight back in place.

Install

Same as the rest of the pack - no extra dependencies, no model downloads:

cd {your_comfyui_path}/custom_nodes
git clone https://github.com/MiddleKD/ComfyUI-mem-safe-wrapper

Then restart ComfyUI. Or search "ComfyUI-mem-safe-wrapper" in ComfyUI Manager.

When to reach for it

This is a surgical fix for a specific failure class, not a daily-driver node. The error above - or any "unexpected keyword argument" coming out of calculate_weight - is your cue. A few things worth knowing:

  • It only helps if the patch is actually the problem. If you're getting that error, this is the right call. If your issue is something else entirely, resetting the patcher won't fix it.
  • Updating ComfyUI sometimes fixes it too. These injected calculate_weight signatures rot when ComfyUI's sampler changes its calls - the error usually appears right after a ComfyUI update. Resetting the patcher is a faster, less disruptive workaround than rolling back.
  • It's a band-aid, not a cure. The offending node will re-patch calculate_weight on its next run. You're clearing the deck for the current workflow; the underlying incompatibility lives in that other node's repo.

It's a niche tool from a small pack with basically zero community chatter, but if you've hit this specific error - and plenty of people have - it's the cleanest fix going. Consider it the "have you tried turning it off and on again" of the ModelPatcher world, minus the downtime.

Categorysafewrapper

Inputs (1)

NameTypeDefaultDescription
modelMODEL

Outputs (1)

NameTypeDescription
MODELMODEL