model_patcher: skip synthetic quant keys in get_key_patches#14413
Open
liminfei-amd wants to merge 1 commit into
Open
model_patcher: skip synthetic quant keys in get_key_patches#14413liminfei-amd wants to merge 1 commit into
liminfei-amd wants to merge 1 commit into
Conversation
get_key_patches() iterates model_state_dict() and calls get_key_weight(), which does getattr(op, op_keys[1]). A quantized (fp8/QuantizedTensor) checkpoint flattens into synthetic state_dict keys (*.weight_scale, *.weight_scale_2, *.input_scale and a comfy_quant marker) that are components of the QuantizedTensor in *.weight, not module attributes, so getattr(linear, "weight_scale") raises AttributeError and every merge node (ModelMergeSimple, ModelMergeBlocks, CLIPMergeSimple, ...) crashes on a quantized model2. Skip the synthetic quant sub-keys, gathered from comfy.quant_ops.QUANT_ALGOS so new quant types are covered automatically. The real *.weight key keeps its convert_weight dequant path, so quantized merging still works. Only the known core-defined suffixes are skipped (not a blanket getattr swallow that would also hide a genuinely missing weight). Fixes Comfy-Org#14382 Signed-off-by: liminfei-amd <91481003+liminfei-amd@users.noreply.github.com>
06ddebf to
8d53b96
Compare
📝 WalkthroughWalkthroughThis PR extends 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
ModelMergeSimple— and everyget_key_patches-based merge/save node — crashes withAttributeError: 'Linear' object has no attribute 'weight_scale'when the model being merged is aquantized (fp8 /
QuantizedTensor) checkpoint. 100% reproducible, no sampling/GPU needed.Problem
A
QuantizedTensorflattens into syntheticstate_dictkeys —*.weightplus*.weight_scale/*.weight_scale_2/*.input_scaleand acomfy_quantmarker (per corecomfy/quant_ops.py QUANT_ALGOS).get_key_patches()iteratesmodel_state_dict()and callsget_key_weight(), which doesgetattr(op, op_keys[1]). For the synthetic sub-keys that isgetattr(linear, "weight_scale")— not amodule attribute (the scale lives inside the
QuantizedTensorin.weight), so it throws.Change
Skip the synthetic quant sub-keys in
get_key_patches(). The suffix set is gathered from corecomfy.quant_ops.QUANT_ALGOS(so new quant types are covered automatically), plus thecomfy_quantmarker. The real
*.weightkey keeps its existingconvert_weightdequant path, so quantized mergingstill works as designed.
This skips only the known, core-generated quant suffixes — not a blanket
getattr(op, key, None)swallow, which would also hide a genuinely missing weight (cf. the #11585 discussion about not masking
bugs).
Validation
A standalone harness models a quantized
state_dict(*.weight+*.weight_scale+*.input_scale+comfy_quant): the stock path raisesAttributeError: 'Linear' object has no attribute 'weight_scale',and with the fix
get_key_patchesreturns only the real*.weightkey (preserving the dequant path) withno crash.
python -m py_compile comfy/model_patcher.pyis clean. The fix is pure Python andhardware-independent.
Fixes #14382
AI usage disclosure: this change was prepared with AI assistance; a human reviewed and verified it and can explain every line. (Reviewed by AMD engineers before submission.)