Skip to content

[TorchOnnxToTorch] Add block_size support for onnx.DequantizeLinear#4505

Open
jtuyls wants to merge 1 commit intollvm:mainfrom
jtuyls:block-dequantize-linear
Open

[TorchOnnxToTorch] Add block_size support for onnx.DequantizeLinear#4505
jtuyls wants to merge 1 commit intollvm:mainfrom
jtuyls:block-dequantize-linear

Conversation

@jtuyls
Copy link
Copy Markdown
Contributor

@jtuyls jtuyls commented Mar 18, 2026

Lower block-quantized DequantizeLinear (opset 21+) to reshape → cast → sub(zero_point) → mul(scale) → reshape.

@jtuyls jtuyls requested review from rsuderman, sahas3 and zjgarvey and removed request for sahas3 March 18, 2026 08:37
Copy link
Copy Markdown
Member

@sahas3 sahas3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change @jtuyls. The changes look good to me, just some suggestions. I am not much familiar with ONNX code-path, so I'll defer approval to other reviewers.

Comment thread lib/Conversion/TorchOnnxToTorch/DefaultDomainAtoF.cpp Outdated
Comment thread lib/Conversion/TorchOnnxToTorch/DefaultDomainAtoF.cpp
Comment thread lib/Conversion/TorchOnnxToTorch/DefaultDomainAtoF.cpp Outdated

// Block quantization: signed int8 input (si8→f32)
// CHECK-LABEL: @test_dequantizelinear_blocked_si8
func.func @test_dequantizelinear_blocked_si8(%arg0: !torch.vtensor<[8,256],si8>, %arg1: !torch.vtensor<[8,4],f32>, %arg2: !torch.vtensor<[8,4],si8>) -> !torch.vtensor<[8,256],f32> attributes {torch.onnx_meta.ir_version = 10 : si64, torch.onnx_meta.opset_version = 21 : si64} {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can some e2e tests be added as well for numerical equivalence?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find good infrastructure to test onnx ops e2e. The existing infra seems to rely on torch onnx export but that doesn't create onnx dequantize layers with block size. Adding infra for this would be out-of-scope for this PR imo and I think the current lit tests verify the conversion well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification. Is the dequantize layers with block size produced when an ONNX model is quantized in ONNX directly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for example, or it could come from rewrites or other export paths.

Lower block-quantized DequantizeLinear (opset 21+) to
reshape → cast → sub(zero_point) → mul(scale) → reshape.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants