Skip to content

Fix TypeError bug in static quantization tutorial#4500

Open
Ashutosh0x wants to merge 1 commit into
pytorch:mainfrom
Ashutosh0x:fix/static-quant-tutorial-bug
Open

Fix TypeError bug in static quantization tutorial#4500
Ashutosh0x wants to merge 1 commit into
pytorch:mainfrom
Ashutosh0x:fix/static-quant-tutorial-bug

Conversation

@Ashutosh0x

Copy link
Copy Markdown

Summary

Fix a TypeError bug in the static quantization tutorial. QuantizedLinear.from_observed() passes target_dtype to __init__() which doesn't accept it:

# __init__ takes 6 positional args:
def __init__(self, in_features, out_features, act_obs, weight_obs, weight, bias):

# from_observed passes 7 args (extra target_dtype):
quantized_linear = cls(in_features, out_features, act_obs, weight_obs, weight, bias, target_dtype)
# TypeError: __init__() takes 7 positional arguments but 8 were given

Anyone copying this tutorial code would hit TypeError immediately. The target_dtype was unused since QuantizedLinear hardcodes int8 behavior via Int8Tensor.

Fix

  • Removed target_dtype from from_observed()
  • Removed target_dtype field from StaticQuantConfig (now empty dataclass)
  • Updated quantize_() call to match: StaticQuantConfig() instead of StaticQuantConfig(torch.uint8)

Partial fix for #3637

Test Plan

Documentation-only change. Verified argument counts match between __init__ (6 params) and from_observed's cls() call (6 args).

This change was authored with the assistance of an AI coding assistant.

QuantizedLinear.from_observed() passes target_dtype to __init__()
which doesn't accept it. Anyone copying this tutorial code would get:

  TypeError: __init__() takes 7 positional arguments but 8 were given

The target_dtype parameter was unused -- QuantizedLinear hardcodes
Int8Tensor behavior. Removed the dead parameter from from_observed,
StaticQuantConfig, and the quantize_ call site.

Partial fix for pytorch#3637

Test Plan:
Documentation-only change. Verified argument counts match between
__init__ (6 params) and from_observed's cls() call (6 args).

This change was authored with the assistance of an AI coding assistant.
@Ashutosh0x Ashutosh0x requested a review from vkuzo as a code owner June 15, 2026 16:16
@pytorch-bot

pytorch-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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 Jun 15, 2026
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.

1 participant