Preserve Python scalar semantics in Vulkan and XNNPACK quantizers - #22804
Open
JakeStevens wants to merge 1 commit into
Open
JakeStevens wants to merge 1 commit into
JakeStevens wants to merge 1 commit into
Conversation
Converting Python scalars to the output tensor dtype can round or overflow them before arithmetic. For example, multiplying an FP16 tensor containing 1e-4 by 100000.0 should produce approximately 10, but materializing the scalar as FP16 produces infinity instead. Limit scalar lifting to FP32 add and multiply operations, preserving the original scalar operands for other dtypes. Cover scalar promotion and rounding across low-precision floats, doubles, integers, bools, and complex values, with and without quantization configuration. Authored with OpenAI Codex.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22804
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 1 PendingAs of commit 0a26d9e with merge base 89fcfe7 ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
JakeStevens
marked this pull request as ready for review
September 14, 2026 16:14
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.
Summary
Preparing a model with the Vulkan or XNNPACK quantizer can change its results when a Python scalar is materialized using the operation's output dtype. For example,
torch.tensor([1e-4], dtype=torch.float16) * 100000.0produces approximately 10 in PyTorch, but casting the scalar to FP16 first makes the result infinite. Smaller scalars can underflow, and other dtypes have their own promotion and rounding rules.Keep the original Python scalar operands for add and multiply operations whose output is not FP32. FP32 operations retain scalar lifting for quantization. Integer index arithmetic covered by #22372 and #22065 continues to work.
Test plan
All 10 focused tests and 208 scalar-promotion subtests pass across dtypes, add/multiply, scalar/vector inputs, and configured/unconfigured quantizers:
OMP_NUM_THREADS=1 MKL_NUM_THREADS=1 PYTHONPATH=src python -m pytest -o addopts= -q \ backends/vulkan/test/quantizer/test_vulkan_quantizer.py \ backends/xnnpack/test/quantizer/test_xnnpack_quantizer.py \ -k 'scalar or int64 or add_mul_long or mul_float32_max or add_and_inplace_add or mul_and_inplace_mul'Existing FP32 scalar quantization, tensor add/multiply, large-scalar handling, and integer-index regressions are included.
lintrunner --revision mainandgit diff --checkpass.Authored with OpenAI Codex.
cc @SS-JIA @manuelcandales @digantdesai @cbilgin