SDNQ: use v0.2.2 and compat-checked patch for smart checkpointing - #2895
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request updates the SDNQ dependency floor and introduces a runtime compatibility patch (sdnq_compat.py) that monkeypatches SDNQ checkpointed-backward paths to support “smart checkpointing” behavior across multiple SDNQ integration points.
Changes:
- Bump
sdnqminimum version from>=0.1.2to>=0.2.2. - Add
simpletuner.helpers.training.sdnq_compat.apply_sdnq_checkpointed_backward_fix()implementing the checkpointed-backward compatibility patch. - Invoke the compatibility patch during SDNQ initialization/loading in the quantisation helper and in Krea2 / Z-Image SDNQ symbol loaders.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| simpletuner/helpers/training/sdnq_compat.py | Adds SDNQ checkpointed-backward compatibility patch via monkeypatching multiple SDNQ linear ckpt modules. |
| simpletuner/helpers/training/quantisation/init.py | Applies the SDNQ compatibility patch during SDNQ initialization in _sdnq_model. |
| simpletuner/helpers/models/z_image/quantized_loading.py | Applies the SDNQ compatibility patch before importing SDNQ training symbols. |
| simpletuner/helpers/models/krea2/quantized_loading.py | Applies the SDNQ compatibility patch before importing SDNQ training symbols. |
| setup.py | Updates the sdnq dependency requirement to >=0.2.2. |
Comments suppressed due to low confidence (5)
simpletuner/helpers/training/sdnq_compat.py:247
ctx.save_for_backward(...)is passed optional/non-tensor values (new_input/input_scalemay beNone,biasis optional, andsvd_up/svd_downareNonewhenweightis not anSDNQTensor). This will raise at runtime. Store these as attributes onctx(or otherwise ensure only tensors are saved) and updatebackwardaccordingly.
weight,
hadamard,
do_grad_weight=ctx.needs_input_grad[1],
)
ctx.save_for_backward(new_input, new_weight, input_scale, weight_scale, bias, svd_up, svd_down)
simpletuner/helpers/training/sdnq_compat.py:359
- Same issue as above:
ctx.save_for_backward(...)is passedNonevalues (new_input/input_scalecan beNone, andbiasis optional), which will raise at runtime. Store these onctxand read fromctxinbackwardinstead of unpackingctx.saved_tensors.
matmul_dtype=matmul_dtype,
)
else:
new_input = input_scale = None
ctx.save_for_backward(new_input, weight, input_scale, bias)
simpletuner/helpers/training/sdnq_compat.py:495
ctx.save_for_backward(...)is passed optional/non-tensor values (new_input/input_scalemay beNone,biasis optional, andsvd_up/svd_downmay beNone). This will raise at runtime. Store these onctxand unpack fromctxinbackward.
weight,
hadamard,
do_grad_weight=ctx.needs_input_grad[1],
)
ctx.save_for_backward(new_input, new_weight, input_scale, weight_scale, bias, svd_up, svd_down)
simpletuner/helpers/training/sdnq_compat.py:608
ctx.save_for_backward(...)is passedNonevalues (new_input/input_scale/input_zero_pointcan beNone, andbiasis optional). This will raise at runtime. Store these onctxand read fromctxinbackwardrather than unpackingctx.saved_tensors.
if ctx.needs_input_grad[1]:
new_input, input_scale, input_zero_point = module.get_uint8_matmul_backward_inputs(input, hadamard)
else:
new_input = input_scale = input_zero_point = None
ctx.save_for_backward(new_input, weight, input_scale, input_zero_point, bias)
simpletuner/helpers/training/sdnq_compat.py:745
ctx.save_for_backward(...)is passed optional/non-tensor values (new_input/input_scale/input_zero_pointmay beNone,biasis optional, andsvd_up/svd_downmay beNone). This will raise at runtime. Store these values onctxand read them fromctxinbackwardinstead of unpackingctx.saved_tensors.
ctx.save_for_backward(
new_input,
new_weight,
input_scale,
weight_scale,
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
This pull request updates the
sdnqdependency and introduces a compatibility fix for SDNQ checkpointed backward support across several SDNQ integration points. The fix is applied during SDNQ initialization to ensure correct behavior when using checkpointed backward passes.Dependency update:
sdnqpackage requirement insetup.pyfrom version>=0.1.2to>=0.2.2to ensure compatibility with the latest features and fixes.SDNQ compatibility fix integration:
apply_sdnq_checkpointed_backward_fixfromsimpletuner.helpers.training.sdnq_compatin the SDNQ loading routines for Krea2 and Z-Image models, ensuring the compatibility fix is applied before SDNQ symbols are loaded. [1] [2]