Skip to content

[ARM/Ethos-U] Partition boundary buffer dtype mismatch causes silent accuracy loss in attention models #19364

Closed

Description

@chanil222

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

  1. Lower any quantized attention model (e.g. mobilevit_s INT8) via EthosUQuantizer → EthosUPartitioner targeting ethos-u85-256.
  2. Build the runner and run on FVP_Corstone_SSE-320 with torch.ones(1, 3, 256, 256) (mobilevit_s default input is 256×256 in timm).
  3. Without fallback: hard-fault at the first CALL_DELEGATE instruction.
  4. With v1.0.1-style raw-memcpy fallback: inference completes with wrong outputs — on mobilevit_s INT8 we observed CPU top-1 = 916, FVP top-1 = 482, max |diff| = 14.73.

Root Cause

Two AOT-side legs interact:

  1. FoldAndAnnotateQParamsPass.is_foldable() returns True for passthrough ops (view_copy, permute_copy) annotated with ArmAnnotationInfo(quantized=True) by EthosUQuantizer. For a chain matmul (INT8) → DQ → view_copy → partition output, the DQ is erased and view_copy is rewired to the pre-DQ INT8 node. The trailing retrace updates view_copy.meta["val"] to INT8 inside the deep-copied partition graph.

  2. _insert_lowered_submodule() in exir/backend/backend_api.py captures call_delegate.meta["val"] from submodule_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_point placeholders in the TOSA graph; TOSA-1.0+INT rejects every FP32 placeholder regardless of role.
  • Set meta["val"] inside the pass: only updates the deep-copied partition graph, not the parent graph's submodule_output_node.args[0].
  • Vela output flag: Vela has no FP32 output mode (--output-format only exposes tflite/raw).

Proposed Fix

Propagate the actual Vela output dtype back to the parent graph through PreprocessResult:

  1. Return output_elem_sizes from vela_compile() (already in the Vela NPZ as output_elem_size).
  2. Add output_dtypes: Optional[List[torch.dtype]] = None and output_qparams: Optional[List[Optional[Tuple[float, int]]]] = None to PreprocessResult (both default None → no impact on other backends).
  3. In _insert_lowered_submodule(), when output_dtypes is present: rewrite call_delegate.meta["val"] to the correct dtype and pre-set meta["spec"] (the if "spec" not in node.meta: guard in SpecPropPass from Fix double-tracing in SpecPropPass #15485 prevents subsequent retrace from overwriting it). Insert a CPU dequantize_per_tensor after each getitem to 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)

Asks

  1. Does this analysis match maintainers' understanding of the Ethos-U INT-only partition boundary contract?
  2. Is PreprocessResult schema additions (output_dtypes / output_qparams) the right mechanism, or is a dedicated callback on BackendDetails preferred?
  3. Are there additional models we should validate before opening the upstream PR?

cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell

Activity

  1. added
    module: arm
    on May 7, 2026
  2. added theissue type on May 7, 2026
  3. added
    partner: arm
    on May 11, 2026
  4. Erik-Lundell commented on May 11, 2026

    @Erik-Lundell
    Collaborator

    Hi! A couple of comments:

    • op_slice was refactored to op_tosa_slice two months, so that issue is fixed on main (possibly also in 1.2).
    • The way I would view this is that the partitioner should produce a valid boundary where the the output of the delegate matches what the outside of the delegate expects. This is the delegate contract, and we should not introduce mechanisms for working around it. This means that for a for an op on the boundary of an integer only partition, the following DQ op should not be partitioned (and as such, not folded either). The mechanism that is supposed to handle this is the _detag_boundary_nodes function 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.
    • As a short-term fix, you could try looking into why nodes were rejected and try to fix that. Do this by setting the debug level to atleast info and look for a table in the lowering log that reports what nodes were rejected and why.

    Would it be possible to provide a minimal reproducer?

  5. Erik-Lundell commented on May 12, 2026

    @Erik-Lundell
    Collaborator

    Hi again! I tested

    • mobilevit_s: timm.create_model("mobilevit_s", pretrained=False).eval()
      • input shape (1, 3, 224, 224), quantized to int8
    • deit_base: timm.create_model("deit_base_patch16_224", pretrained=False).eval()
      • input shape (1, 3, 256, 256), quantized to int8

    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.

  6. chanil222 commented on May 12, 2026

    @chanil222
    Author

    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:

      ┌──────────────────────────────────────────────────────┐  ← partition
      │  Q → bmm_INT8                                        │
      │         │                                            │
      │        [DQ]  ← direct user = view_copy (partitioned) │
      │         │       → is_boundary_dq_node = False        │
      │        view_copy  ← annotated as quantized=True      │
      └──────────────────────────────────┬───────────────────┘
                                         │
                                     softmax (FP32, outside)
    

    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!

  7. chanil222 commented on May 12, 2026

    @chanil222
    Author

    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.

    # backends/arm/tosa/partitioner.py
    def _has_outside_exit(
        node: torch.fx.Node,
        tag: str,
        visited: Optional[set] = None,
    ) -> bool:
        """Return True if any node reachable from ``node`` (within the partition) exits to outside.
    
        Performs a DFS through partitioned descendants of ``node`` and returns True
        as soon as a user outside the partition is found. This detects the case where
        a DQ node's output eventually reaches a consumer outside the partition through
        intermediate passthrough ops (e.g. view_copy, permute_copy) that are themselves
        inside the partition.
        """
        if visited is None:
            visited = set()
        if node in visited:
            return False
        visited.add(node)
        for user in node.users:
            if not is_partitioned(user, tag):
                return True
            if _has_outside_exit(user, tag, visited):
                return True
        return False
    
    # In _detag_boundary_nodes, replace:
    #   is_boundary_dq_node = is_dq_node and any(
    #       not is_partitioned(user, tag) for user in node.users
    #   )
    # with:
    is_boundary_dq_node = is_dq_node and _has_outside_exit(node, tag)

    Thank you again for your time and attention on this.

  8. digantdesai commented on May 18, 2026

    @digantdesai
    Contributor

    @Erik-Lundell - did we apply this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: armpartner: arm

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions