microsoft / microsoft/onnxruntime

[Web] Using ceil() in shape computation is not yet supported for MaxPool

Open
#20,938 3 comments 2 reactions 0 assignees View on GitHub
ep:WebGPU feature request platform:web
Dominant language
C++
Stars
21.9k
Forks
4.2k
Avg merge
4d 11h
Merged PRs (30d)
184

Description

### Describe the issue

I want to run a simple CNN using `onnxruntime-web` with WebGPU (or WebGL) to get some runtime acceleration and I cannot do this due to the following error:
```
ERROR Error: using ceil() in shape computation is not yet supported for MaxPool
at Array.Jh (ort.all.min.mjs:3702:627)
at jo.computeKernel (ort.all.min.mjs:4204:10470)
at Object.Xb (ort.all.min.mjs:4204:17298)
at 851205 (ort-wasm-simd-threaded.jsep.mjs:45:422)
at mc (ort-wasm-simd-threaded.jsep.mjs:92:259)
at ort-wasm-simd-threaded.jsep.wasm:0x1224637
at ort-wasm-simd-threaded.jsep.wasm:0x122535a
at ort-wasm-simd-threaded.jsep.wasm:0x10de910
at ort-wasm-simd-threaded.jsep.wasm:0x23b86c
at ort-wasm-simd-threaded.jsep.wasm:0x7155da
```

It's a pretty standard operation and I'm surprised that it's not supported. When do you plan to add the support for it?

### To reproduce

1. Create and export neural network to ONNX:

Example code

```python
import torch
from torch import nn

class Net(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(in_channels=3, out_channels=64, kernel_size=3)
self.maxpool = nn.MaxPool2d(kernel_size=2, stride=2, ceil_mode=True)

def forward(self, x):
x = self.conv1(x)
x = self.maxpool(x)
return x

def convert_to_onnx(model, example_input, opset_version=12):
# Prepare the model for export
model.eval()
# Set the name of the ONNX file
onnx_file_name = "net.onnx"
# Export the model to an ONNX file
torch.onnx.export(model,
example_input,
onnx_file_name,
export_params=True,
opset_version=opset_version,
do_constant_folding=True,
input_names = ['input'],
output_names = ['output'],
dynamic_axes={'input' : {0 : 'batch_size'}, # variable length axes
'output' : {0 : 'batch_size'}})

```


2. Load the network in JS/TS and use `webgpu` or `webgl` (both fail):
```typescript
import * as ort from 'onnxruntime-web/all';
ort.env.wasm.wasmPaths = 'https://cdn.jsdelivr.net/npm/onnxruntime-web@dev/dist/';

let model = await ort.InferenceSession
.create('./net.onnx'
,{executionProviders: ['webgpu'] }
);

function createRandomTensor() {
const size = [1, 3, 320, 320];
const values = new Float32Array(size.reduce((a, b) => a * b));

for (let i = 0; i < values.length; i++) {
values[i] = Math.random();
}

const tensor = new Tensor("float32", values, size);
console.log(tensor);
return tensor;
}

const feeds: Record = {};
feeds[model.inputNames[0]] = createRandomTensor();

const outputData = await model.run(feeds);
```

3. When the runtime is initialized **without webgpu**, like this:
```typescript
let model = await ort.InferenceSession
.create('./net.onnx')
);
// ... rest of the code
```
**it works fine.**

### Urgency

Not urgent, but utilizing WebGPU / WebGL would be beneficial for pretty standard CNNs.

### ONNX Runtime Installation

Other / Unknown

### ONNX Runtime Version or Commit ID

onnxruntime-web 1.19.0-dev.20240601-217b66fd85

### Execution Provider

'webgl' (WebGL), 'webgpu' (WebGPU)

Contributor guide

Open the contributing guide

Research direction

Start with the WebGPU and WebGL execution paths for the MaxPool operator and the reported ceil() shape-computation error in ort.all.min.mjs. Reproduce the model with PyTorch and ONNX Runtime Web 1.19.0-dev, comparing webgpu or webgl against the working default runtime. Done means the same ceil_mode MaxPool model initializes and runs successfully on the affected web execution providers.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch, typescript
Domain
machine-learning, performance, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.