Support lazy-initialized Linear modules in SVDQW4A4Linear.from_linear - #929
Open
kj863257 wants to merge 3 commits into
Open
Support lazy-initialized Linear modules in SVDQW4A4Linear.from_linear#929kj863257 wants to merge 3 commits into
kj863257 wants to merge 3 commits into
Conversation
Handle ComfyUI lazy-init Linear modules in SVDQW4A4Linear.from_linear
5 tasks
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.
Motivation
Some integration paths may construct
Linearmodules lazily, withweight=Noneuntil state dict loading completes.SVDQW4A4Linear.from_linear()currently assumeslinear.weightis always available and directly accesseslinear.weight.dtypeandlinear.weight.device. In lazy-initialization scenarios, this can raise:AttributeError: 'NoneType' object has no attribute 'dtype'This PR adds safe fallback behavior for lazy-initialized
Linearmodules while preserving the existing behavior forregular
nn.Linearmodules that already have materialized weights.This change is part of a paired fix with the corresponding
ComfyUI-nunchakuPR:ComfyUI-nunchaku:Support lazy-init Linear layers in Z-Image patching<COMFYUI_NUNCHAKU_PR_URL>Modifications
SVDQW4A4Linear.from_linear()innunchaku/models/linear.py.linear.weightis present.linear.weight is None, resolvetorch_dtypefrom the explicit argument if provided, otherwise fall back tolinear.weight_comfy_model_dtype, and finallytorch.bfloat16.devicefrom the explicit argument if provided, otherwise fall back toweight.device,bias.device, andfinally CPU.
linear.biasinstead of assuming a populated weight tensor.tests/test_linear_lazy_init.pycovering both lazy-initialized and regularLinearcases.
pre-commiton the touched files.Checklist
testsdirectory following the guidance inContribution Guide.examplesare updated if necessary.remove yourself as a co-author when merging.
NgZzWaTrEj~n2KEV3Hpl5Q), Discord or [WeChat](https://huggingface.co/datasets/
nunchaku-tech/cdn/blob/main/nunchaku/assets/wechat.jpg) to discuss your PR.
nunchaku-ai/ComfyUI-nunchaku#817