Fix import for torch>=2.12: quantize_pt2e removed#289
Open
beausifutmez wants to merge 1 commit into
Open
Conversation
torch.ao.quantization.quantize_pt2e was removed in torch 2.12 (PT2E quant migrated to torchao), so `import torch_migraphx` fails for all users on recent torch, not only those using pt2e quantization. The import's purpose is its side effect: populating torch.ops.quantized_decomposed (used by the converter decorators below). In torch>=2.12 those ops are registered by torch.ao.quantization.fx._decomposed instead. Guard the import to use the new module when the old one is absent, keeping back-compat with torch<2.12. Verified on torch 2.12.1+rocm7.2 / gfx1100: import succeeds, the migraphx dynamo backend loads, torch.ops.quantized_decomposed is populated, and torch.compile(backend="migraphx") matches eager to fp32 epsilon. Fixes ROCm#279 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
import torch_migraphxon torch >= 2.12 (quantize_pt2eremoved)Problem
import torch_migraphxfails for all users on recent PyTorch, not only those doing quantization:The module was deleted in pytorch/pytorch#169151
("Delete pt2e flow… migrated to torchao", merged
0e38e02), which ships in the torch 2.9+ line —matching the report in #279 (torch 2.9.1) and reproduced here on torch 2.12.1.
Note the import exists purely for a side effect: registering the
torch.ops.quantized_decomposedops used by the converter decorators just below it. Guarding the import alone is not enough — the
module then fails at decorator time with
'_OpNamespace' 'quantized_decomposed' object has no attribute 'quantize_per_tensor'.Fix
The two layers PyTorch split apart matter here:
prepare_pt2e/convert_pt2e) moved to torchao — that's what #169151 deleted.quantized_decomposedops remain in torch core, registered bytorch.ao.quantization.fx._decomposed.This import only needs the latter, so pointing it at
fx._decomposedis the canonical, in-core,zero-dependency registrar (not a workaround). Guarded for back-compat with torch < 2.12:
One file changed; no behavioral change on older torch (it takes the
trypath unchanged).Verification
Verified on torch 2.12.1+rocm7.2 (HIP 7.2), ROCm 7.2.4, Radeon RX 7900 XTX (gfx1100), Linux:
import torch_migraphxsucceeds; themigraphxdynamo backend loads.torch.ops.quantized_decomposedis populated (quantize_per_tensoretc. present).torch.compile(model, backend="migraphx")runs a conv+linear model and ResNet-50, output matchingeager to fp32 epsilon (max |Δ| ≈ 1.2e-7).
fx._decomposedhas existed across the affected range, so the same guard covers the torch 2.9.1case reported in #279 (Windows / gfx1151) as well as torch 2.12 here.
Scope
This restores import + the existing
quantized_decomposedconverters only. Fully migratingtorch_migraphx's pt2e quantization flow to torchao is a separate, larger change and out of scope here.
Fixes #279