microsoft / microsoft/onnxruntime
[Web] WebGPU EP: DETR-family model creates a session but first run() throws "Invalid dimension of 4294967295 for SizeToDimension"
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 21.9k
- Forks
- 4.2k
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 184
Description
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):
- #32275 — WebGPU GridSample produces incorrect output in deformable-attention decoders (RT-DETR family), closed as not planned. This model has 6 GridSample nodes.
- #29070, #21206 — RT-DETR blocked on WebGPU by
ceil()in shape computation. - #26618 — CumSum type mismatch crashes DETR on WebGPU. A single-node CumSum probe still fails for me on 1.29.0.
- #22425, #18584 — Deformable-DETR / DETR WebGPU performance.
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure with onnx/model.onnx using InferenceSession.create and session.run on a fresh page, then compare the WebGPU and WASM results. Use the listed single-node probes, verbose WGSL logging, and the graph's Shape/Reshape-related operators to narrow the failing node or fused subgraph; done means the D-FINE model runs successfully on WebGPU at the reported input sizes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, javascript
- Domain
- backend, machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100