Removed `torch.ao.quantization.quantizer` imports in coremltools/optimize/torch break on torch 2.11 — request for decision on removal/deprecation of CoreMLQuantizer
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 850
- Avg merge
- 4d 5h
- Merged PRs (30d)
- 10
Description
## Summary
Three files under `coremltools/optimize/torch/quantization/` import from
`torch.ao.quantization.quantizer`, removed in torch 2.11 (PT2E quantization
migrated to [torchao](https://github.com/pytorch/ao)):
| 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
```bash
pip install torch==2.11.0 # or newer; 2.9.x does not reproduce
pip install coremltools
```
```python
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](https://github.com/pytorch/pytorch/pull/169151)
removed PT2E quantization from torch, and jerryzh168 (pytorch/ao maintainer)
opened [apple/coremltools#2634](https://github.com/apple/coremltools/pull/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](https://github.com/pytorch/executorch/pull/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 #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:
```python
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
- [apple/coremltools#2634](https://github.com/apple/coremltools/pull/2634) — "Update callsite for pt2e quant" (closed, migration abandoned)
- [pytorch/executorch#16473](https://github.com/pytorch/executorch/pull/16473) — CoreMLQuantizer moved to ExecuTorch
- PyTorch migration plan: [Torch.ao.quantization Migration Plan](https://dev-discuss.pytorch.org/t/torch-ao-quantization-migration-plan/2810) — PT2E quantization has been migrated to torchao
- Deprecation notice in pytorch/pytorch#153892 ("torch.ao.quantization is deprecated")
- torchao Quantizer API: `torchao.quantization.pt2e.quantizer.quantizer.QuantizationSpec`
Contributor guide
Research direction
Start with the three affected modules: coremltools/optimize/torch/quantization/_annotation_config.py, _coreml_quantizer.py, and _coreml_quantizer_utils.py, then read PR #2634 and the linked ExecuTorch PR. Verify the torch 2.11 import failure and review the related quantization tests. Done means an explicit support decision is implemented, the modules no longer crash on supported versions, and tests reflect removal or deprecation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100