ai.onnx.MaxPool

ai.onnx · standard ONNX operator · ONNX opset ≥ 12

Description

Applies max pooling over a sliding kernel window on input tensor X, computing the maximum value within each window and writing it to output Y. Output spatial dimensions are determined by kernel size, strides, padding, and dilations; ceil_mode controls whether output size is rounded up or down.

See the ONNX MaxPool spec for the reference semantics.

Inputs

Name Bind key Logical dtype Rank Shape Description Presence
X x T Input tensor of shape (N x C x D1 x ... x Dn); batch size N, channels C, followed by spatial dimensions. required

Outputs

Name Bind key Logical dtype WebGPU storage Rank Shape Description Presence
Y y T runtime-selected; narrow integers and bool use 32-bit slots same as X derived; see description Pooled output tensor with the same batch and channel dimensions as X but reduced spatial dimensions. required
Indices indices I uint32 same as X derived; see description Optional logical int64 flat indices of the maximum values selected during pooling, with the same shape as Y; indices do not account for padding and use uint32 WebGPU storage. optional

Attributes

Attributes and default values (overridable per request):

Attribute Default Description
auto_pad "NOTSET" Deprecated auto-padding mode: NOTSET (use explicit pads), SAME_UPPER, SAME_LOWER (pad so output size is ceil(input / stride)), or VALID (no padding). It cannot be used together with pads.
storage_order 0 Storage order of the Indices output tensor: 0 for row-major, 1 for column-major.
ceil_mode 0 When non-zero, use ceiling instead of floor when computing output spatial dimensions.
kernel_shape Required kernel shape, with one positive value per spatial axis.
strides Stride along each spatial axis. When omitted, every stride is 1.
pads Padding at the beginning and end of each spatial axis, ordered as [begin_0, ..., begin_n, end_0, ..., end_n]. When omitted, every pad is 0.
dilations Dilation along each spatial axis. When omitted, every dilation is 1.

Type constraints

Variable Allowed dtypes
T float32, float16, int8, uint8
I int64

Files

Use with @huggingface/kernels

The loader derives every required output's shape and logical dtype from the manifest contract and this call. It then allocates the result tensors automatically.

The version: 1 option selects the published kernel contract; it is independent of any operator opset, contrib since_version, or model version.

Replace each *Data placeholder with a typed array containing the corresponding input data.

import { getKernel } from "@huggingface/kernels";

const kernel = await getKernel("webgpu-kernels/ai.onnx.MaxPool", { version: 1 });
const { y } = await kernel({ x: { data: xData, shape: [1, 1, 3] } }, {
  attrs: { kernel_shape: [2] },
});
Downloads last month
-
kernel
webgpu
wgsl
apache-2.0
WebGPU

Requires WebGPU support. See the compatibility table.