Skip to content

[Web] WebGPU EP: DETR-family model creates a session but first run() throws "Invalid dimension of 4294967295 for SizeToDimension" #32438

Description

@houtvongsak

Describe the issue

A D-FINE object-detection model (DETR-family) creates successfully on the WebGPU EP, then throws on the first session.run():

failed to call OrtRun(). ERROR_CODE: 1, ERROR_MESSAGE:
onnxruntime/core/framework/tensor_shape.cc:67
int64_t onnxruntime::TensorShape::SizeToDimension(size_t) const
dimension <= num_dims was false.
Invalid dimension of 4294967295 for SizeToDimension. Tensor has 1 dimensions.

4294967295 is (size_t)(-1), so an axis computed as -1 appears to reach SizeToDimension unsigned, against a rank-1 tensor.

The same model runs correctly on the WASM EP at every input size, and on the Python CPU EP, so the graph itself is executable — this looks specific to the WebGPU EP.

Worth distinguishing from the usual "operator not supported" reports: the failure is at inference, not session creation. The EP accepts the whole graph.

Stack:

Error: failed to call OrtRun(). ERROR_CODE: 1, ERROR_MESSAGE:
  onnxruntime/core/framework/tensor_shape.cc:67 ... Invalid dimension of 4294967295 ...
    at V  (onnxruntime-web_webgpu.js:3563)
    at er (onnxruntime-web_webgpu.js:4614)
    at async mr.run (onnxruntime-web_webgpu.js:4978)

Model graph. Exported by pytorch 2.6.0, single opset ai.onnx 16. Inputs pixel_values [batch_size, 3, height, width]; outputs logits [batch_size, 300, 80], pred_boxes [batch_size, 300, 4]. Operator counts:

Add 244   And 1     Cast 12     Clip 9      Concat 54   ConstantOfShape 2
Conv 79   Cos 2     Div 27      Equal 8     Erf 1       Expand 46
Gather 53 GatherElements 2      Greater 2   GridSample 6            Less 1
Log 2     MatMul 72 MaxPool 1   Mul 155     Not 2       Pad 2
Pow 12    Range 22  ReduceMax 1 ReduceMean 25           ReduceSum 4
Relu 47   Reshape 97            Resize 1    ScatterND 8 Shape 39
Sigmoid 29          Sin 2       Slice 18    Softmax 11  Split 8
Sqrt 12   Squeeze 12            Sub 29      Tile 2      TopK 2
Transpose 34        Unsqueeze 85            Where 9

Attempts to narrow it down. Fourteen single-node probes, each run alone on WebGPU, all pass: Softmax, ReduceMax, Concat, Gather, Split, TopK with negative axes on rank-1 and rank-3 tensors, plus Range, GridSample, Expand, GatherElements, ScatterND, Tile. So it appears to need the full graph — a shape combination or a fused subgraph — rather than one operator.

Verbose logging (logSeverityLevel: 0, logVerbosityLevel: 2) emits the WGSL shader sources but does not identify the throwing node, so I could not name it from the client side.

Possibly related (none reports this error, so I don't think this is a duplicate):

GPU adapter reports amd / rdna-2. Note that ort.env.webgpu.adapter reads undefined before session creation.

To reproduce

Model: https://huggingface.co/onnx-community/dfine_n_coco-ONNX (onnx/model.onnx)

const ort = await import('onnxruntime-web/webgpu')

const session = await ort.InferenceSession.create(modelUrl, {
  executionProviders: ['webgpu'],
})
// -> succeeds

const feeds = {
  pixel_values: new ort.Tensor('float32', new Float32Array(3 * 640 * 640), [1, 3, 640, 640]),
}
await session.run(feeds)
// -> throws

Run each case on a fresh page. A failed WebGPU session create leaves the single-session lock held, and every later create on that page then fails with another WebGPU EP inference session is being created, which is easy to mistake for additional distinct failures.

variation result
input 256 / 416 / 640 identical error at all three
model.onnx (fp32) and model_fp16.onnx identical error for both
graphOptimizationLevel: 'all' (default) fails
graphOptimizationLevel: 'disabled' fails
freeDimensionOverrides pinning batch_size/height/width fails
WASM EP, same model, same sizes works
Python CPU EP, same model works
onnxruntime-web 1.27.0 same error
onnxruntime-web 1.29.0 same error

Urgency

Not blocking — the WASM EP runs the same model correctly, so there is a workaround. Filing because a crash on a public model looked worth recording.

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.29.0 (also reproduced on 1.27.0)

Execution Provider

'webgpu' (WebGPU)

Activity

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

    ep: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