Skip to content

Expanded Attention reference decomposition: SizeFromDimension SIZE_MAX underflow at Add node (surfaced by ONNX 1.22 integration) #28969

Description

Summary

The ONNX function-expanded reference decomposition of the Attention op fails at runtime with a TensorShape::SizeFromDimension underflow (a shape dimension computed as -1, surfaced as the unsigned value 18446744073709551615 = SIZE_MAX). It is currently masked by a skip added in PR #28754 and should be removed once the underlying bug is fixed.

This was unmasked by the ONNX 1.22 / opset-27 integration. Note: the ONNX-domain Attention op itself (opset 23/24) was not changed by the opset-27 bump — the bump simply enabled running the expanded reference for these node tests.

Failing tests

  • test_attention_4d_softcap_neginf_mask_expanded_cpu
  • test_attention_4d_softcap_neginf_mask_poison_expanded_cpu

Both are ONNX backend node-model tests run via onnx_backend_test_series.py on the CPU EP.

Observed error

Non-zero status code returned while running Add node. Name:''
onnxruntime/core/framework/tensor_shape.cc:77
  int64_t onnxruntime::TensorShape::SizeFromDimension(size_t) const
  dimension <= num_dims was false.
  Invalid dimension of 18446744073709551615 for SizeFromDimension. Tensor has 2 dimensions.

First seen on the webgpu / build-and-test (arm64, arm64, Release) leg (macOS-arm64 build, onnxruntime_USE_WEBGPU=ON), run 27243073719.

Root cause (current understanding)

  • The failure is in the EXPANDED (ONNX function-decomposed reference) Attention graph, not the native fused Attention kernel.
  • A shape dimension is computed as -1 somewhere downstream of the bias Add in the expanded decomposition and then passed into SizeFromDimension, where the unsigned underflow trips the dimension <= num_dims enforce in core/framework/tensor_shape.cc:73.
  • The _poison variant (identical graph, -inf mask values swapped in) fails identically, so the -inf/softcap mask values are not the trigger — it is the shape flow of the expanded decomposition. Prime suspect: the bias-Add → softmax shape handling path.
  • Only surfaced after the ONNX 1.22 / opset-27 bump (PR Integrate ONNX 1.22.0 (opset 27) — issue #28752 #28754) enabled the expanded Attention reference for these tests.

Why it is NOT user-facing today

  • The native fused Attention kernel passes on every architecture (test_attention_4d_softcap_neginf_mask and _poison, without _expanded).
  • The CPU EP passes these expanded tests on x64 and Linux-arm64, and the ONNX ReferenceEvaluator passes them — the failure only reproduces on the macOS-arm64-webgpu build.
  • Production inference uses the fused kernel; the expanded decomposition is a conformance-reference artifact. So there is no known user-facing regression — but the underflow is a genuine latent correctness/robustness bug worth root-causing.

Current mitigation (to be removed when fixed)

Skipped via the global current_failing_tests list in onnxruntime/test/testdata/onnx_backend_test_series_filters.jsonc (lines 43–44), added in commit 027820e7e6 on PR #28754:

"^test_attention_4d_softcap_neginf_mask_expanded*",
"^test_attention_4d_softcap_neginf_mask_poison_expanded*",

Action when fixed: remove these two skip entries and confirm the tests pass on macOS-arm64-webgpu.

Repro

  1. Build with --use_webgpu on macOS-arm64 Release (or reproduce the expanded reference graph on the affected build).
  2. Run onnx_backend_test_series.py filtering to test_attention_4d_softcap_neginf_mask_expanded_cpu.
  3. Observe the SizeFromDimension SIZE_MAX error at the Add node.

References

  • PR: Integrate ONNX 1.22.0 (opset 27) — issue #28752 #28754 (ONNX 1.22.0rc2 / opset-27 integration)
  • Skip commit: 027820e7e6
  • Enforce site: onnxruntime/core/framework/tensor_shape.cc:73 (SizeFromDimension)
  • CI: run 27243073719, job 80450998304 (webgpu / build-and-test (arm64, arm64, Release))

Activity

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

Metadata

Metadata

Labels

core runtimeissues related to core runtimeep:WebGPUort-web webgpu providerplatform:webissues related to ONNX Runtime web; typically submitted using template

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions