Skip to content

fix(quant_api): prevent IndexError in _fqn_to_config_handler when multiple parameter FQNs are None (#4818) - #4901

Open
somuai wants to merge 1 commit into
pytorch:mainfrom
somuai:fix-fqn-to-config-index-error
Open

somuai wants to merge 1 commit into
pytorch:mainfrom
somuai:fix-fqn-to-config-index-error

Conversation

@somuai

@somuai somuai commented Sep 15, 2026

Copy link
Copy Markdown

Summary

Fixes #4818

In _fqn_to_config_handler (torchao/quantization/quant_api.py), when multiple parameter FQNs are set to None in FqnToConfig to exclude them from quantization, the previous implementation called top_level_params.pop(i):

if c is None:
    top_level_params.pop(i)  # BUG: i is the named_parameters index, not current list index

When two or more parameters were set to None, popping reduced the list size, and subsequent pop(i) calls either targeted the wrong element or failed with IndexError: pop index out of range.

Solution

Filter top_level_params via list comprehension to safely exclude parameters matching parameter_fqn without index mutation side-effects:

if c is None:
    top_level_params = [
        entry for entry in top_level_params if entry[3] != parameter_fqn
    ]

Test Plan

  • Added unit test test_fqn_to_config_multiple_none_parameters in test/quantization/test_quant_api.py under TestQuantFlow (CPU-compatible).
  • Verified test passes:
    pytest test/quantization/test_quant_api.py -k test_fqn_to_config_multiple_none_parameters -v
  • Checked linters: ruff check passes with zero errors.

…tiple parameter FQNs are None

When multiple parameter FQNs are set to None in FqnToConfig to exclude them from quantization, _fqn_to_config_handler previously called top_level_params.pop(i) using the named_parameters() index i rather than the current list position. When multiple parameters were excluded, popping changed the list size and subsequent pop(i) raised IndexError: pop index out of range.

Filter top_level_params using list comprehension to safely remove excluded parameter entries without index mutation bugs.

Fixes pytorch#4818

Signed-off-by: Soumyajit Ghosh <[email protected]>
@pytorch-bot

pytorch-bot Bot commented Sep 15, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

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 Sep 15, 2026
@somuai

somuai commented Sep 22, 2026

Copy link
Copy Markdown
Author

Gentle check-in on this PR — all CI checks have passed green and the Meta CLA is signed. This cleanly resolves the IndexError reported in #4818 when parameter FQNs are None. Friendly ping for the reviewers (@vkuzo, @andrewor14, @jerryzh168) whenever convenient to review. Thank you!

This branch has not been deployed

No deployments
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexError in _fqn_to_config_handler when multiple parameter FQNs are set to None

1 participant