Model Patch Torch Settings
FP16 accumulation is a ComfyUI flag you have to restart for. This node kills the restart
- model
- model
Ever launched ComfyUI with --fast (which enables CUDA FP16 accumulation for matmuls) and then loaded a model that quietly produces garbage or NaNs because it doesn't get along with full FP16 accumulation? The standard fix is editing your startup flag and restarting ComfyUI. Every. Time. You switch models. It's the kind of friction that makes people write angry reddit posts - and someone did, asking if a node could toggle this setting at runtime.
This node is that runtime toggle, dependency-light. It wraps a MODEl in callbacks that flip torch.backends.cuda.matmul.allow_fp16_accumulation on (or off) just while that model runs, then restore the setting during cleanup. So the model that needs it gets it, the model that breaks on it doesn't, and you never touch the command line again.
Note: the idea isn't unique to this pack - KJNodes has a "Model Patch Torch Settings" too, and that's what people usually point to first. Enviral's version exists so you get the behavior without pulling in the whole KJNodes bundle. Same job, fewer dependencies.
How it works
The node clones your model with ComfyUI's patcher (model.clone()), then registers callbacks via comfy.patcher_extension.CallbacksMP:
enable_fp16_accumulationon →ON_PRE_RUNsets the flag true,ON_CLEANUPsets it back to false.enable_fp16_accumulationoff →ON_PRE_RUNforces the flag false for that model.
So the setting is scoped to the patched model's execution, not left toggled globally afterward.
Inputs and output
model- the MODEL to clone and patch. Wire it between your model loader and the sampler.enable_fp16_accumulation- boolean, default false. This is the whole node.
Output is the patched model. That's it. Two inputs, one output, one decision.
Install
Same pack as the rest of these: ComfyUI Manager (search "Enviral Design Node Pack") or
cd ComfyUI/custom_nodes
git clone https://github.com/EnviralDesign/comfyUI-enviral-design-node-pack
then restart. No extra dependencies - it uses PyTorch and ComfyUI's patcher API.
Common issues & honest caveats
It's flagged EXPERIMENTAL in the source, so treat it as such. Three things to know:
- It needs a PyTorch build that exposes
torch.backends.cuda.matmul.allow_fp16_accumulation. If your build lacks it, the node raises immediately with a clear message. That attribute has been around for a while, so most current installs are fine. - It needs a ComfyUI patcher with
clone()andadd_callback(). That's the modern patcher_extension API; if you're on a very old ComfyUI, update before expecting this to work. - BF16 is unaffected. As someone pointed out on that thread: the flag only changes behavior for FP16 matmuls, so non-FP16 models won't be "made worse" by leaving it on - which means if you're not hitting a genuine FP16 problem, you might not need this node at all.
Where it shines: you run --fast for speed on most models, but a specific one (some Qwen-based builds are the classic offender) corrupts output under FP16 accumulation. Drop this node on that branch with the flag off, leave everything else alone, and stop restarting.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| enable_fp16_accumulation | BOOLEAN | false | Toggles torch.backends.cuda.matmul.allow_fp16_accumulation while the patched model runs. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| model | MODEL | — |