Fix intermittent "addmm_cuda not implemented for 'Char'" on partial unload (#76)#77
Open
Dawgmastah wants to merge 1 commit into
Open
Conversation
…nload The addmm_cuda/'Char' crash (BobJohnson24#76) persisted after the load()-only cleanup in c0cc280 because ComfyUI core re-installs a stock LowVramPatch on offloaded INT8 layers inside partially_unload() (comfy/model_patcher.py), which does NOT route through INT8ModelPatcher.load(). That stock patch runs calculate_weight(..., intermediate_dtype=weight.dtype); for an INT8 weight the intermediate dtype is torch.int8, so the LoRA matmul fails. Because partially_unload only fires under memory pressure and only touches a memory-dependent subset of layers, the failure was random and "fixed itself" on reload. Extract the LowVramPatch -> INT8LowVramPatch swap from load() into _reinstall_int8_lowvram_patches() and also call it from a new partially_unload() override so the scale-aware patch is restored after every core path that can install the stock one. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the intermittent
"addmm_cuda" not implemented for 'Char'crash reported in #76, which persisted even after theload()-only cleanup in c0cc280.Root cause
c0cc280 strips ComfyUI's stock
LowVramPatchand swaps in the scale-awareINT8LowVramPatch, but only insideINT8ModelPatcher.load().ComfyUI core also installs a stock
LowVramPatchon offloaded INT8 layers insidepartially_unload()(comfy/model_patcher.py), and that path does not route throughload(). The stock patch's__call__runs:For an INT8 weight the intermediate dtype is
torch.int8, so the LoRA matmul hitsaddmm_cuda not implemented for 'Char'.Because
partially_unload()only fires under memory pressure — and only touches a memory-dependent subset of layers — the failure looked random and appeared to "fix itself" on reload. That matches the reports of the same LoRA working on some runs and failing on others.Fix
LowVramPatch→INT8LowVramPatchswap out ofload()into a shared_reinstall_int8_lowvram_patches()helper (behavior unchanged — all three branches preserved).partially_unload()override that callssuper()then re-runs the helper, so the scale-aware patch is restored after every core path that can install the stock one.Net change: +30/-1, contained entirely within
INT8ModelPatcher.Notes
I intentionally did not take the alternative "force
intermediate_dtypeto float32 for non-float weights" monkey-patch suggested in the issue. It would stop the traceback, but the stockLowVramPatchwould then return a float weight with no re-quantization against the per-row scale — silently corrupting those layers instead of crashing.🤖 Generated with Claude Code