Repository navigation
Description
Bug Description
FoldAndAnnotateQParamsPass folds the boundary dequantize_per_tensor at an Ethos-U partition exit into the preceding passthrough op (view_copy, permute_copy). Vela then compiles the partition INT8-only and writes 1 byte per output element, but the parent graph's executorch_call_delegate node retains the original FP32 dtype on meta["val"], so ExecuTorch allocates a 4× larger buffer. At runtime copy_with_layout_adjustment() sees expand_factor=4 elem_size=1 ScalarType::Float, which is not a handled case, and returns Error::InvalidProgram — hard-fault on the first delegate-call boundary in any attention model.
Error
EthosUBackend.cpp::copy_with_layout_adjustment()
expand_factor=4 elem_size=1 ScalarType::Float → Error::InvalidProgram
If a raw-memcpy fallback is applied (v1.0.1-style, skipping the reject), inference completes but produces wrong outputs: Vela's INT8 bytes land in the first 25% of the FP32 buffer and downstream FP32 consumers (softmax, scale, mask) reinterpret them as floats.
Steps to Reproduce
- Lower any quantized attention model (e.g.
mobilevit_sINT8) viaEthosUQuantizer→EthosUPartitionertargetingethos-u85-256. - Build the runner and run on
FVP_Corstone_SSE-320withtorch.ones(1, 3, 256, 256)(mobilevit_sdefault input is 256×256 in timm). - Without fallback: hard-fault at the first
CALL_DELEGATEinstruction. - With v1.0.1-style raw-memcpy fallback: inference completes with wrong outputs — on
mobilevit_sINT8 we observed CPU top-1 = 916, FVP top-1 = 482, max |diff| = 14.73.
Root Cause
Two AOT-side legs interact:
-
FoldAndAnnotateQParamsPass.is_foldable()returnsTruefor passthrough ops (view_copy,permute_copy) annotated withArmAnnotationInfo(quantized=True)byEthosUQuantizer. For a chainmatmul (INT8) → DQ → view_copy → partition output, the DQ is erased andview_copyis rewired to the pre-DQ INT8 node. The trailing retrace updatesview_copy.meta["val"]to INT8 inside the deep-copied partition graph. -
_insert_lowered_submodule()inexir/backend/backend_api.pycapturescall_delegate.meta["val"]fromsubmodule_output_node.args[0]— the pre-deepcopy FX nodes in the parent graph, which were never refreshed. The stale FP32 dtype is serialized into the PTE, causing ExecuTorch to allocate a 4×-sized buffer for a 1-byte-per-element Vela output.
On mobilevit_s INT8: 36 out of 58 partition outputs have this stale FP32 dtype, matching 36 runtime expand_factor=4 rejects exactly.
Why Narrower Fixes Don't Work
- Skip the boundary DQ fold: keeping the DQ inside the partition leaves its FP32-typed
scale/zero_pointplaceholders in the TOSA graph;TOSA-1.0+INTrejects every FP32 placeholder regardless of role. - Set
meta["val"]inside the pass: only updates the deep-copied partition graph, not the parent graph'ssubmodule_output_node.args[0]. - Vela output flag: Vela has no FP32 output mode (
--output-formatonly exposestflite/raw).
Proposed Fix
Propagate the actual Vela output dtype back to the parent graph through PreprocessResult:
- Return
output_elem_sizesfromvela_compile()(already in the Vela NPZ asoutput_elem_size). - Add
output_dtypes: Optional[List[torch.dtype]] = Noneandoutput_qparams: Optional[List[Optional[Tuple[float, int]]]] = NonetoPreprocessResult(both defaultNone→ no impact on other backends). - In
_insert_lowered_submodule(), whenoutput_dtypesis present: rewritecall_delegate.meta["val"]to the correct dtype and pre-setmeta["spec"](theif "spec" not in node.meta:guard inSpecPropPassfrom Fix double-tracing in SpecPropPass #15485 prevents subsequent retrace from overwriting it). Insert a CPUdequantize_per_tensorafter eachgetitemto restore the FP32 view expected by downstream consumers.
We have a working implementation against v1.1.0 and will open an upstream PR once the design direction is acknowledged.
Verification
AOT (PTE flatbuffer inspection, 6 INT8 models):
| Model | NPU partitions | FP32 DQ inputs (baseline) | FP32 DQ inputs (fixed) |
|---|---|---|---|
mobilevit_s |
37 | 36 | 0 |
swin_t ¹ |
48 | — | 0 |
swin_b |
24 | — | 0 |
vit_b_16 |
25 | — | 0 |
deit_base |
13 | — | 0 |
convnext_small |
2 | — | 0 |
| Total | 149 | — | 0 (289 DQ inputs all INT8) |
Baseline FP32 DQ inputs were measured only for mobilevit_s; the other models hard-fault before PTE inspection is possible on unpatched code. The "fixed" column was verified by PTE flatbuffer inspection after applying the fix.
¹ swin_t also requires a one-line fix in op_slice.py::define_node to handle the 5th step argument (inputs[:4]); without it lowering aborts with ValueError: too many values to unpack (expected 4). Orthogonal to this bug.
FVP (mobilevit_s INT8, ones(1,3,256,256)):
| Metric | Baseline (raw-memcpy fallback) | Fixed |
|---|---|---|
| factor4 fires | 36 | 0 |
| FVP top-1 | 482 | 916 |
| Max abs diff | 14.73 | 0.896 |
Environment
- ExecuTorch: v1.1.0
- Target:
ethos-u85-256 - Simulator:
FVP_Corstone_SSE-320 - Quantizer:
EthosUQuantizer(PT2E flow)
Related (not duplicates)
- [ARM/TOSA] Dependency cycle after Q/DQ de-tagging in TOSAPartitioner breaks models with attention blocks #18190 / Arm backend: fix(arm): validate partitions for dependency cycles after Q/DQ de-tagging #18191 (cycle after Q/DQ de-tagging in
TOSAPartitioner): different mechanism; cycle path does not fire onmobilevit_s(0 cycle warnings). - Arm backend bug:
FoldAndAnnotateQParamsPassfolds qdomain changes throughaten.cat#18999 / Arm backend: Fix quantized constant-folding for aten.cat lists (#18971) #19064 (FoldAndAnnotateQParamsPassqdomain change viaaten.cat): same pass, different case (within-INT qdomain change, not INT/FP partition boundary). - Arm backend: Fix meta propagation in some call passes #19154 (
Arm backend: Fix meta propagation in some call passes): targetsRewriteUpsamplePass-class node creation; does not address cross-graph dtype propagation between preprocess and parent graph. - Arm backend: Partition boundary Q/DQ nodes for INT+FP #16312 (
Arm backend: Partition boundary Q/DQ nodes for INT+FP): for INT+FP profile where Vela has FP32 ops; Ethos-U INT-only is a different scenario. - Fix double-tracing in SpecPropPass #15485 (
Fix double-tracing in SpecPropPass): documents theif "spec" not in node.meta:guard forexecutorch_call_delegatethat this fix relies on.
Asks
- Does this analysis match maintainers' understanding of the Ethos-U INT-only partition boundary contract?
- Is
PreprocessResultschema additions (output_dtypes/output_qparams) the right mechanism, or is a dedicated callback onBackendDetailspreferred? - Are there additional models we should validate before opening the upstream PR?
cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell
Activity
Erik-Lundell commentedon May 11, 2026
Hi! A couple of comments:
_detag_boundary_nodesfunction in the partitioner. Looking at the function, it would not do this if an operator has one user that is partitioned and one that is not, which could explain the bug. I would have to look more into this to be sure though.Would it be possible to provide a minimal reproducer?
Erik-Lundell commentedon May 12, 2026
Hi again! I tested
For Ethos-U85 on v1.1. Both models lowered to one delegate and did not replicate the issue. To continue investigation, I would need a more detailed reproducer.
chanil222 commentedon May 12, 2026
Hi, thanks for testing and following up!
After further investigation, we traced the root cause to a custom modification we made for experimentation rather than the standard EthosUQuantizer flow — which is why you couldn't reproduce it.
When loading an externally-quantized PT2, our modified flow calls annotate_qdq_nodes() to inject ArmAnnotationInfo metadata. This function marks any node whose input comes from a DQ op as quantized=True — including
view_copy nodes that merely reshape the FP32 output of DQ. This creates a partition boundary pattern that EthosUQuantizer does not produce:
Because view_copy is inside the partition, is_boundary_dq_node returns False for the DQ node so it is not detagged. FoldAndAnnotateQParamsPass then folds the DQ into the partition, Vela emits INT8 bytes — but
call_delegate.meta["val"].dtype remains torch.float32, causing a 4× buffer misallocation at runtime.
With standard EthosUQuantizer, view_copy is never annotated as quantized so it stays outside the partition and the boundary check works correctly.
We've also confirmed that the approach you suggested — checking all partitioned descendants of a DQ node rather than only its direct users — does prevent this issue as well, as long as annotations are preserved
correctly.
We've resolved it on our end. Thanks again for the quick response!
chanil222 commentedon May 12, 2026
Leaving the patch inline below for reference in case it's useful to anyone hitting the same issue later — feel free to use, adapt, or ignore as you see fit.
Thank you again for your time and attention on this.
digantdesai commentedon May 18, 2026
@Erik-Lundell - did we apply this?