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 Upstream name 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 Upstream name 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 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 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.
ceil_mode 0 When non-zero, use ceiling instead of floor when computing output spatial dimensions.
dilations Dilation along each spatial axis. When omitted, every dilation is 1.
kernel_shape Required kernel shape, with one positive value per spatial axis.
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.
storage_order 0 Storage order of the Indices output tensor: 0 for row-major, 1 for column-major.
strides Stride along each spatial axis. When omitted, every stride is 1.

Type constraints

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

Files

Use with @huggingface/kernels

npm install --save-exact @huggingface/kernels@0.0.1-preview.2

Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.

The version: 1 option selects the published kernel contract; it is independent of any operator opset, contrib since_version, or model version. It follows the v1 branch as fixes land. To pin exact artifact bytes, pass a 40-character commit revision instead of 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.