Copy the weight before per-channel-scale normalization in palettize_weights - #2777
Open
LeSingh1 wants to merge 1 commit into
Open
Copy the weight before per-channel-scale normalization in palettize_weights#2777LeSingh1 wants to merge 1 commit into
LeSingh1 wants to merge 1 commit into
Conversation
…eights weight_to_compress aliases the const's own array, so the in-place division by per_channel_scale is visible outside the pass. When blockwise_compress then declines the op, the const is left permanently scaled down and the model returns wrong values with only a 'Skipped this op' warning.
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.
Problem
weight_to_compress = op.outputs[0].valis the const's live numpy buffer, andweight_to_compress /= per_channel_scalemutates it in place. The two earlier skip points sit before that division, but theblockwise_compressskip sits after it — so when compression declines, the const survives un-palettized and divided by its per-channel max.The only signal is a
logger.warning("... Skipped this op."), which says the opposite of what happened to the weight.Triggered by an ordinary config —
granularity="per_grouped_channel",group_size=16,enable_per_channel_scale=Trueon a 120-output-channelLinear. 120 isn't divisible by 16, so compression is declined:Max absolute error 16.94.
Fix
Copy before normalizing.
Testing
New test fails on
mainwith 15360/15360 elements mismatched, passes with the fix. The success path is bit-identical before and after, verified by checksum. Full PTQ suite has 3 pre-existing failures on bothmainand this branch (they need scikit-learn for k-means); no new ones.