Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/24153
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit c8655ab with merge base 7586c16 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Contributor
|
@pssrawat has exported this pull request. If you are a Meta employee, you can view the originating Diff in D127380012. |
expand_as through the existing shared-qparams expand pathexpand_as through the existing shared-qparams expand path (#24153)
pssrawat
force-pushed
the
export-D127380012
branch
from
October 28, 2026 21:28
4b45f5f to
f5c6eea
Compare
pssrawat
added a commit
to pssrawat/executorch
that referenced
this pull request
Oct 28, 2026
pytorch#24153) Summary: `SharedQspecQuantizer` already gives `expand` and `expand_copy` shared qparams when a neighbor is quantized, and the lowering then runs `expand_copy` on int8. `expand_as` is not in that list, and it only decomposes to `expand` at `to_edge`, after quantization, so every `expand_as` broadcast stayed in float behind a dequantize and a requantize. `ExpandAsToExpandPass` runs in `transform_for_annotation` and rewrites `expand_as(x, other)` into `expand(x, other.shape)`, emitting `sym_size` nodes for symbolic dims. `expand_as` then gets the same neighbor-driven treatment as `expand`: int8 when its neighbors are quantized, float otherwise. The shape-only `other` operand is no longer an input of the op, so it is never pulled into the shared-qparams cluster. No new pattern check or support-dict entry is added for `expand`, so an expand between float-only ops is not forced to int8. Differential Revision: D127380012
pssrawat
added a commit
to pssrawat/executorch
that referenced
this pull request
Oct 29, 2026
pytorch#24153) Summary: `SharedQspecQuantizer` already gives `expand` and `expand_copy` shared qparams when a neighbor is quantized, and the lowering then runs `expand_copy` on int8. `expand_as` is not in that list, and it only decomposes to `expand` at `to_edge`, after quantization, so every `expand_as` broadcast stayed in float behind a dequantize and a requantize. `ExpandAsToExpandPass` runs in `transform_for_annotation` and rewrites `expand_as(x, other)` into `expand(x, other.shape)`, emitting `sym_size` nodes for symbolic dims. `expand_as` then gets the same neighbor-driven treatment as `expand`: int8 when its neighbors are quantized, float otherwise. The shape-only `other` operand is no longer an input of the op, so it is never pulled into the shared-qparams cluster. No new pattern check or support-dict entry is added for `expand`, so an expand between float-only ops is not forced to int8. Differential Revision: D127380012
pssrawat
force-pushed
the
export-D127380012
branch
from
October 29, 2026 06:25
f5c6eea to
55155eb
Compare
pssrawat
added a commit
to pssrawat/executorch
that referenced
this pull request
Oct 29, 2026
pytorch#24153) Summary: `SharedQspecQuantizer` already gives `expand` and `expand_copy` shared qparams when a neighbor is quantized, and the lowering then runs `expand_copy` on int8. `expand_as` is not in that list, and it only decomposes to `expand` at `to_edge`, after quantization, so every `expand_as` broadcast stayed in float behind a dequantize and a requantize. `ExpandAsToExpandPass` runs in `transform_for_annotation` and rewrites `expand_as(x, other)` into `expand(x, other.shape)`, emitting `sym_size` nodes for symbolic dims. `expand_as` then gets the same neighbor-driven treatment as `expand`: int8 when its neighbors are quantized, float otherwise. The shape-only `other` operand is no longer an input of the op, so it is never pulled into the shared-qparams cluster. No new pattern check or support-dict entry is added for `expand`, so an expand between float-only ops is not forced to int8. Differential Revision: D127380012
pssrawat
added a commit
to pssrawat/executorch
that referenced
this pull request
Oct 29, 2026
pytorch#24153) Summary: `SharedQspecQuantizer` already gives `expand` and `expand_copy` shared qparams when a neighbor is quantized, and the lowering then runs `expand_copy` on int8. `expand_as` is not in that list, and it only decomposes to `expand` at `to_edge`, after quantization, so every `expand_as` broadcast stayed in float behind a dequantize and a requantize. `ExpandAsToExpandPass` runs in `transform_for_annotation` and rewrites `expand_as(x, other)` into `expand(x, other.shape)`, emitting `sym_size` nodes for symbolic dims. `expand_as` then gets the same neighbor-driven treatment as `expand`: int8 when its neighbors are quantized, float otherwise. The shape-only `other` operand is no longer an input of the op, so it is never pulled into the shared-qparams cluster. No new pattern check or support-dict entry is added for `expand`, so an expand between float-only ops is not forced to int8. Differential Revision: D127380012
pssrawat
force-pushed
the
export-D127380012
branch
from
October 29, 2026 20:26
55155eb to
76c0392
Compare
pssrawat
added a commit
to pssrawat/executorch
that referenced
this pull request
Oct 29, 2026
pytorch#24153) Summary: `SharedQspecQuantizer` already gives `expand` and `expand_copy` shared qparams when a neighbor is quantized, and the lowering then runs `expand_copy` on int8. `expand_as` is not in that list, and it only decomposes to `expand` at `to_edge`, after quantization, so every `expand_as` broadcast stayed in float behind a dequantize and a requantize. `ExpandAsToExpandPass` runs in `transform_for_annotation` and rewrites `expand_as(x, other)` into `expand(x, other.shape)`, emitting `sym_size` nodes for symbolic dims. `expand_as` then gets the same neighbor-driven treatment as `expand`: int8 when its neighbors are quantized, float otherwise. The shape-only `other` operand is no longer an input of the op, so it is never pulled into the shared-qparams cluster. No new pattern check or support-dict entry is added for `expand`, so an expand between float-only ops is not forced to int8. Differential Revision: D127380012
expand_as through the existing shared-qparams expand path (#24153)
pssrawat
added a commit
to pssrawat/executorch
that referenced
this pull request
Oct 30, 2026
…pytorch#24153) Summary: `SharedQspecQuantizer` gives each shared-qparams cluster one set of qparams for every float input and output of its ops. `view_as(x, other)` is in that list, and the cluster was built from all of its inputs, so `other` was pulled in even though it contributes only its shape. `x` and `other` were then quantized with one scale, set by whichever has the wider range: the data loses precision, or the shape operand is clipped. For example, in `(x * y).view_as(other) + other` with `other = z + z`, `x * y` spans about ±2.5 and `other` about ±51. `x * y` was quantized at `other`'s scale of 0.349, about 18x coarser than the 0.0195 it gets when the same reshape is written `reshape(4, 8)`, and the output error against float rose from 0.258 to 0.307. `expand_as` has the same shape-only second operand but was not in the shared-qparams list at all, so every `expand_as` broadcast stayed in float behind a dequantize and a requantize. Shape-as ops (`view_as`, `expand_as`) now share qparams only through their data operand, `args[0]`. The cluster walk does not cross the edge to the shape operand in either direction, and that operand gets no shared input qspec, so it keeps the qparams of its own producer. `expand_as` joins the shared-qparams ops, so like `expand` it is quantized to int8 when its neighbours are, and lowers on Cortex-M to an int8 `expand_copy`. Authored with Claude Code. Differential Revision: D127380012
pssrawat
force-pushed
the
export-D127380012
branch
from
October 30, 2026 05:48
76c0392 to
eb2f222
Compare
pssrawat
added a commit
to pssrawat/executorch
that referenced
this pull request
Oct 30, 2026
…pytorch#24153) Summary: `SharedQspecQuantizer` gives each shared-qparams cluster one set of qparams for every float input and output of its ops. `view_as(x, other)` is in that list, and the cluster was built from all of its inputs, so `other` was pulled in even though it contributes only its shape. `x` and `other` were then quantized with one scale, set by whichever has the wider range: the data loses precision, or the shape operand is clipped. For example, in `(x * y).view_as(other) + other` with `other = z + z`, `x * y` spans about ±2.5 and `other` about ±51. `x * y` was quantized at `other`'s scale of 0.349, about 18x coarser than the 0.0195 it gets when the same reshape is written `reshape(4, 8)`, and the output error against float rose from 0.258 to 0.307. `expand_as` has the same shape-only second operand but was not in the shared-qparams list at all, so every `expand_as` broadcast stayed in float behind a dequantize and a requantize. Shape-as ops (`view_as`, `expand_as`) now share qparams only through their data operand, `args[0]`. The cluster walk does not cross the edge to the shape operand in either direction, and that operand gets no shared input qspec, so it keeps the qparams of its own producer. `expand_as` joins the shared-qparams ops, so like `expand` it is quantized to int8 when its neighbours are, and lowers on Cortex-M to an int8 `expand_copy`. Authored with Claude Code. Differential Revision: D127380012
Summary: Q/DQ folding (`FoldAndAnnotateQParamsPass`) always folds the quantize/dequantize pair around a constant-producing op (`full`, `full_like`, `arange`, `eye`, `linspace`, `scalar_tensor`) into the op: it removes the Q node and records the output qparams, but the op itself keeps producing float. The Arm backend follows folding with `ComputeConstantOpsAOTPass`, which evaluates such ops in float and quantizes the result. Cortex-M did not, so in `x + torch.full(shape, 0.5)` the int8 `quantized_add` kernel read a float32 constant, and the output was silently wrong. Add `ComputeQuantizedConstantOpsPass` and run it after folding on both Cortex-M pass lists. - a. It only touches nodes with output qparams, so unquantized constant ops are unchanged. A quantized `full` stays a runtime fill, with its fill value quantized and its dtype set to the qparams' dtype, so a large fill does not turn into a large constant; - b.`full_like` is first converted to `full` with the Arm backend's `ConvertFullLikeToFullPass`. This also fixes a test that was already failing. `surrounded_quantized_op_constant` in `misc/test_quantization.py` was marked as an expected failure. Its `torch.ones(2, 2)` constant is lowered to a `full` op, so the int8 add read float data, and every output element was off by about 0.49. With this change the case matches the quantized reference exactly, so its `xfail` is removed. The other constants in that file are stored tensors, which folding already quantized correctly. Differential Revision: D128002647
…pytorch#24153) Summary: `SharedQspecQuantizer` gives each shared-qparams cluster one set of qparams for every float input and output of its ops. `view_as(x, other)` is in that list, and the cluster was built from all of its inputs, so `other` was pulled in even though it contributes only its shape. `x` and `other` were then quantized with one scale, set by whichever has the wider range: the data loses precision, or the shape operand is clipped. For example, in `(x * y).view_as(other) + other` with `other = z + z`, `x * y` spans about ±2.5 and `other` about ±51. `x * y` was quantized at `other`'s scale of 0.349, about 18x coarser than the 0.0195 it gets when the same reshape is written `reshape(4, 8)`, and the output error against float rose from 0.258 to 0.307. `expand_as` has the same shape-only second operand but was not in the shared-qparams list at all, so every `expand_as` broadcast stayed in float behind a dequantize and a requantize. Shape-as ops (`view_as`, `expand_as`) now share qparams only through their data operand, `args[0]`. The cluster walk does not cross the edge to the shape operand in either direction, and that operand gets no shared input qspec, so it keeps the qparams of its own producer. `expand_as` joins the shared-qparams ops, so like `expand` it is quantized to int8 when its neighbours are, and lowers on Cortex-M to an int8 `expand_copy`. Authored with Claude Code. Differential Revision: D127380012
pssrawat
force-pushed
the
export-D127380012
branch
from
October 30, 2026 07:25
eb2f222 to
c8655ab
Compare
pssrawat
added a commit
to pssrawat/executorch
that referenced
this pull request
Oct 30, 2026
…pytorch#24153) Summary: `SharedQspecQuantizer` gives each shared-qparams cluster one set of qparams for every float input and output of its ops. `view_as(x, other)` is in that list, and the cluster was built from all of its inputs, so `other` was pulled in even though it contributes only its shape. `x` and `other` were then quantized with one scale, set by whichever has the wider range: the data loses precision, or the shape operand is clipped. For example, in `(x * y).view_as(other) + other` with `other = z + z`, `x * y` spans about ±2.5 and `other` about ±51. `x * y` was quantized at `other`'s scale of 0.349, about 18x coarser than the 0.0195 it gets when the same reshape is written `reshape(4, 8)`, and the output error against float rose from 0.258 to 0.307. `expand_as` has the same shape-only second operand but was not in the shared-qparams list at all, so every `expand_as` broadcast stayed in float behind a dequantize and a requantize. Shape-as ops (`view_as`, `expand_as`) now share qparams only through their data operand, `args[0]`. The cluster walk does not cross the edge to the shape operand in either direction, and that operand gets no shared input qspec, so it keeps the qparams of its own producer. `expand_as` joins the shared-qparams ops, so like `expand` it is quantized to int8 when its neighbours are, and lowers on Cortex-M to an int8 `expand_copy`. Authored with Claude Code. Differential Revision: D127380012
This branch has not been deployed
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:
SharedQspecQuantizergives each shared-qparams cluster one set of qparams for every float input and output of its ops.view_as(x, other)is in that list, and the cluster was built from all of its inputs, sootherwas pulled in even though it contributes only its shape.xandotherwere then quantized with one scale, set by whichever has the wider range: the data loses precision, or the shape operand is clipped.For example, in
(x * y).view_as(other) + otherwithother = z + z,x * yspans about ±2.5 andotherabout ±51.x * ywas quantized atother's scale of 0.349, about 18x coarser than the 0.0195 it gets when the same reshape is writtenreshape(4, 8), and the output error against float rose from 0.258 to 0.307.expand_ashas the same shape-only second operand but was not in the shared-qparams list at all, so everyexpand_asbroadcast stayed in float behind a dequantize and a requantize.Shape-as ops (
view_as,expand_as) now share qparams only through their data operand,args[0]. The cluster walk does not cross the edge to the shape operand in either direction, and that operand gets no shared input qspec, so it keeps the qparams of its own producer.expand_asjoins the shared-qparams ops, so likeexpandit is quantized to int8 when its neighbours are, and lowers on Cortex-M to an int8expand_copy.Authored with Claude Code.
Differential Revision: D127380012