Skip to content

Conversation

@petrex
Copy link
Collaborator

@petrex petrex commented Nov 21, 2025

TLDR: Fix mutable default argument in autoquant.py

Fix Summary

  • AutoQuantizableLinearWeight and the various _autoquant_test implementations used ["relu", None] as a default parameter list. Because lists are mutable and default parameters are evaluated once at function definition time, every call shared the exact same list object. Any in-place mutation would accidentally leak between callers.
  • Added _DEFAULT_MODE_SENTINEL and _resolve_autoquant_mode() so the public API still behaves as though the default is ["relu", None], but a fresh list is created whenever a caller doesn’t supply mode.
  • Constructors and _autoquant_test overrides now default to the sentinel and immediately call _resolve_autoquant_mode(mode), ensuring explicit None stays None while the implicit default gets rebuilt per call.

Expected Outcome

  • Each use of autoquant mode receives its own list instance, eliminating shared state. Any code that mutates mode (e.g., mode[0] = "interpolate") affects only that invocation, preventing subtle cross-layer or cross-run contamination.
  • Users should see consistent behavior across runs even if some part of the pipeline tweaks mode in-place; no more erratic quantization choices caused by reused mutable defaults.
  • Since the API stays identical—still defaulting to ["relu", None]—existing call sites require no changes, just safer semantics.

@pytorch-bot
Copy link

pytorch-bot bot commented Nov 21, 2025

🔗 Helpful Links

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

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

✅ No Failures

As of commit bbf915a with merge base 53b5efd (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 Nov 21, 2025
@petrex petrex added the topic: not user facing Use this tag if you don't want this PR to show up in release notes label Nov 21, 2025
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. topic: 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.

1 participant