Skip to content

Copy the weight before per-channel-scale normalization in palettize_weights - #2777

Open
LeSingh1 wants to merge 1 commit into
apple:mainfrom
LeSingh1:fix/palettize-per-channel-scale-inplace
Open

Copy the weight before per-channel-scale normalization in palettize_weights#2777
LeSingh1 wants to merge 1 commit into
apple:mainfrom
LeSingh1:fix/palettize-per-channel-scale-inplace

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Problem

weight_to_compress = op.outputs[0].val is the const's live numpy buffer, and weight_to_compress /= per_channel_scale mutates it in place. The two earlier skip points sit before that division, but the blockwise_compress skip 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=True on a 120-output-channel Linear. 120 isn't divisible by 16, so compression is declined:

op types: ['const', 'linear']        (correctly not palettized)
torch : [17.385, -8.286, -19.897, -2.406, -25.859]
coreml: [ 6.430, -3.609,  -7.175, -0.851,  -8.917]

Max absolute error 16.94.

Fix

Copy before normalizing.

Testing

New test fails on main with 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 both main and this branch (they need scikit-learn for k-means); no new ones.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant