Skip to content

Align _choose_qparams_affine with _choose_scale_float8 behavior#3447

Merged
jerryzh168 merged 3 commits intopytorch:mainfrom
AryanBagade:fix-issue-3324-align-choose-qparams
Jan 10, 2026
Merged

Align _choose_qparams_affine with _choose_scale_float8 behavior#3447
jerryzh168 merged 3 commits intopytorch:mainfrom
AryanBagade:fix-issue-3324-align-choose-qparams

Conversation

@AryanBagade
Copy link
Copy Markdown
Contributor

@AryanBagade AryanBagade commented Dec 5, 2025

Changes keepdim default from False to True in _choose_qparams_affine to match _choose_scale_float8 behavior. This ensures scale/zero_point maintain the same rank as input tensor, making downstream handling more consistent.

Part 1 of fixing #3324

Changes

Core Changes (torchao/quantization/quant_primitives.py)

  • Changed keepdim: bool = Falsekeepdim: bool = True in both choose_qparams_affine (line 1220) and _choose_qparams_affine (line 1526)
  • Added reshape logic (lines 1600-1608) to match _choose_scale_float8 behavior
  • Saved original_input_size before reshaping to compute correct output shape
  • Added documentation explaining the alignment with _choose_scale_float8

Workflow Simplification (torchao/quantization/quantize_/workflows/intx/intx_unpacked_to_int8_tensor.py)

  • Removed manual reshape logic (lines 247-254) that is no longer needed

Test Updates(test/quantization/test_quant_primitives.py)

  • Updated 3 test cases to squeeze scale/zero_point before comparison with reference values
  • All 7 test_choose_qparams tests now pass

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Dec 5, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/3447

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 8a7b789 with merge base aa25287 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 5, 2025
@jerryzh168
Copy link
Copy Markdown
Contributor

Thanks, I think it's a good start, we can remove keepdim arg in next PR after this PR is merged

@AryanBagade
Copy link
Copy Markdown
Contributor Author

I see 25 integration tests failed due to backward compatibility issues with the keepdim=True default change

@jerryzh168
Copy link
Copy Markdown
Contributor

it's expected, I think maybe just don't change the default for now, but turn the keepdim to True in these tests one by one to make sure these tests are fixed, and alls the callsites are fixed before making the switch would be better

@AryanBagade
Copy link
Copy Markdown
Contributor Author

Really sorry, had a super busy schedule

@AryanBagade
Copy link
Copy Markdown
Contributor Author

@jerryzh168 could you please run the CI, made the required changes!

@meta-codesync
Copy link
Copy Markdown

meta-codesync bot commented Dec 19, 2025

@jerryzh168 has imported this pull request. If you are a Meta employee, you can view this in D89579365.

@AryanBagade
Copy link
Copy Markdown
Contributor Author

@jerryzh168 could you please let me know what further steps to take!

@jerryzh168
Copy link
Copy Markdown
Contributor

jerryzh168 commented Jan 5, 2026

@AryanBagade https://github.com/pytorch/ao/actions/runs/20121850704/job/57745005031?pr=3447 is failing but likely is fixed in main already, can you rebase on main branch? I have imported and confirmed that this change doesn't break any of the internal test, so we should be able to merge after you rebase

and `zero_point_domain`

Note:
keepdim defaults to True to align with _choose_scale_float8 behavior. This ensures
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right now it's defaults to False, so should change the comment here

Changes keepdim default from False to True in _choose_qparams_affine to match
_choose_scale_float8 behavior. This ensures scale/zero_point maintain the same rank as input tensor, making downstream handling more consistent.

Fixes pytorch#3324
Signed-off-by: Aryan Bagade <aryan@aryanbagade.com>
@AryanBagade AryanBagade force-pushed the fix-issue-3324-align-choose-qparams branch from a56f742 to 8a7b789 Compare January 5, 2026 19:59
@AryanBagade
Copy link
Copy Markdown
Contributor Author

@jerryzh168 Rebased on main and fixed the docstring comment as requested. Ready for re-import and merge!

@AryanBagade AryanBagade requested a review from jerryzh168 January 5, 2026 20:01
@jerryzh168 jerryzh168 added the module: not user facing Use this tag if you don't want this PR to show up in release notes label Jan 5, 2026
and `zero_point_domain`

Note:
Set keepdim=True to align with _choose_scale_float8 behavior. This ensures
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change this to False, thanks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh sorry, seems OK, it's not talking about default

@jerryzh168 jerryzh168 merged commit fbb3aef into pytorch:main Jan 10, 2026
23 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: not user facing Use this tag if you don't want this PR to show up in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants