Support lazy-init Linear layers in Z-Image patching#817
Open
kj863257 wants to merge 2 commits into
Open
Conversation
Support lazy-init Linear layers in Z-Image patching
6 tasks
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
On recent ComfyUI Windows builds, some
Linearmodules can be lazily initialized and temporarily haveweight=Nonebefore model weights are fully loaded.
In the Z-Image loading path,
ComfyUI-nunchakupatches attention and feed-forward modules before weight loadingcompletes. The current implementation assumes
linear.weightis always available and directly accesseslinear.weight.dtypeandlinear.weight.device, which can raise:AttributeError: 'NoneType' object has no attribute 'dtype'This PR makes the Z-Image patching path compatible with lazy-initialized
Linearmodules while preserving theexisting behavior when real weights are already present.
This PR is paired with the corresponding
nunchakuPR:nunchaku:Support lazy-initialized Linear modules in SVDQW4A4Linear.from_linear<NUNCHAKU_PR_URL>Modifications
models/zimage.pyto resolvedtypeanddevicefrom a possibly lazy-initializedLinearmodule.linear.weightis available.torch_dtype, orweight_comfy_model_dtype, and finally CPU whenlinear.weight is None.fuse_to_svdquant_linear()so the Z-Image feed-forward patching path no longer depends onlinear.weight.dtypeorlinear.weight.devicebeing immediately available.pre-commitonmodels/zimage.py.No new workflow test case is added because this PR does not introduce a new workflow, model asset, custom node, or
output behavior. It only makes the existing Z-Image patching path tolerant to lazy-initialized
Linearmodules.Checklist
pre-commit run --all-files).tests/workflowsdirectory following the guidance inthe Contribution Guide.
test_cases.json.test_data/inputs.yaml.scripts/download_models.pyand
test_data/models.yaml..github/workflows/pr-test.yaml](../.github/workflows/pr-test.yaml).
remove yourself as a co-author when merging.
datasets/nunchaku-tech/cdn/blob/main/nunchaku/assets/wechat.jpg) to discuss your PR.