Skip to content

Removed torch.ao.quantization.quantizer imports in coremltools/optimize/torch break on torch 2.11 — request for decision on removal/deprecation of CoreMLQuantizer #2823

Description

@xyf5432

Summary

Three files under coremltools/optimize/torch/quantization/ import from
torch.ao.quantization.quantizer, removed in torch 2.11 (PT2E quantization
migrated to torchao):

File Lines
_annotation_config.py 11–13 from torch.ao.quantization.quantizer.quantizer import QuantizationSpec
_coreml_quantizer.py 12–13 from torch.ao.quantization.quantizer.quantizer import Quantizer / ...xnnpack_quantizer import _get_module_name_filter
_coreml_quantizer_utils.py 22–36 (8 lines: QuantizationSpec, xnnpack_quantizer, xnnpack_quantizer_utils imports)

Not wired into the public API, but still used by the test suite, and loading
any of them on torch 2.11+ fails immediately:
ModuleNotFoundError: No module named 'torch.ao.quantization.quantizer'.
Verified with torch 2.11.0 (crash) vs 2.9.1 (control, succeeds).

How to reproduce

pip install torch==2.11.0  # or newer; 2.9.x does not reproduce
pip install coremltools
from coremltools.optimize.torch.quantization._annotation_config import AnnotationConfig
# ModuleNotFoundError: No module named 'torch.ao.quantization.quantizer'

Related discussion: PR #2634

A migration attempt already exists: pytorch/pytorch#169151
removed PT2E quantization from torch, and jerryzh168 (pytorch/ao maintainer)
opened apple/coremltools#2634
"Update callsite for pt2e quant" migrating these files to torchao. It was
closed without merging (2026-01-24); the stated plan is to remove
CoreMLQuantizer from coremltools in favor of the ExecuTorch implementation
(executorch#16473).
See the PR for details.

Request

Please make a decision on the future of CoreMLQuantizer and act on it:

  1. Remove the three modules (and their tests) as planned in PR Update callsite for pt2e quant #2634, or
    formally deprecate them with a clear support statement (including a
    torch < 2.11 requirement or a torchao dependency for torch 2.11+); or
  2. At minimum, keep these files from crashing on torch 2.11+: delete the
    stale imports or gate them behind a version check with a clear error
    message pointing to the replacement.

We'd appreciate an explicit statement on the support status, since the
current release allows torch 2.11+ (unbounded torch requirement) and ships
files that crash on load.

Suggested fix

Given PR #2634, deletion is the preferred direction (migration is blocked by
the observer/fake_quant incompatibility noted in the PR discussion). If
keeping the modules, the minimal fix is a guarded import:

try:
    from torch.ao.quantization.quantizer.quantizer import (
        QuantizationSpec as _TorchQuantizationSpec,
    )
except ImportError:  # torch>=2.11: PT2E quantization moved to torchao
    from torchao.quantization.pt2e.quantizer.quantizer import (
        QuantizationSpec as _TorchQuantizationSpec,
    )

(torchao.quantization.pt2e.quantizer.quantizer.QuantizationSpec verified
present in torchao 0.16.0.)

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions