Pooling Operators¶
Every op on this page is used the same way: construct it once, then call it. The
constructor takes what the kernel is compiled with; the call takes the tensors.
Both are documented under each op — __init__ and forward, where forward is
what runs when you call op(...).
Average pooling¶
tileops.pool.AvgPool1dFwdOp
¶
Average pooling over PyTorch-compatible NCL inputs.
__init__
¶
__init__(
kernel_size,
stride=None,
padding=0,
ceil_mode=False,
count_include_pad=True,
*,
target=None
)
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
kernel_size(int | tuple[int]) –Window extent, an int or a one-element tuple.
-
stride(int | tuple[int] | None, default:None) –Window step, an int or a one-element tuple;
Nonesteps bykernel_size. -
padding(int | tuple[int], default:0) –Implicit zero padding on both sides, an int or a one-element tuple.
-
ceil_mode(bool, default:False) –Round the output extent up instead of down.
-
count_include_pad(bool, default:True) –Count padded positions in a window's divisor.
-
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
forward
¶
Pool input.
Parameters:
-
input(Tensor) –Input, \([N \times C]\) followed by
ndimspatial axes.
Returns:
-
Tensor–A new tensor of the pooled averages, \([N \times C]\) followed by the
ndim -
Tensor–pooled extents, in the dtype of
input.
tileops.pool.AvgPool2dFwdOp
¶
Average pooling over PyTorch-compatible NCHW inputs.
__init__
¶
__init__(
kernel_size,
stride=None,
padding=0,
ceil_mode=False,
count_include_pad=True,
divisor_override=None,
*,
target=None
)
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
kernel_size(int | tuple[int, ...]) –Window extent, an int or one per spatial axis.
-
stride(int | tuple[int, ...] | None, default:None) –Window step, an int or one per spatial axis;
Nonesteps bykernel_size. -
padding(int | tuple[int, ...], default:0) –Implicit zero padding on both sides, an int or one per spatial axis.
-
ceil_mode(bool, default:False) –Round each output extent up instead of down.
-
count_include_pad(bool, default:True) –Count padded positions in a window's divisor.
-
divisor_override(int | None, default:None) –Divide every window sum by this instead;
Nonedivides by the window's element count. -
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
forward
¶
Pool input.
Parameters:
-
input(Tensor) –Input, \([N \times C]\) followed by
ndimspatial axes.
Returns:
-
Tensor–A new tensor of the pooled averages, \([N \times C]\) followed by the
ndim -
Tensor–pooled extents, in the dtype of
input.
tileops.pool.AvgPool3dFwdOp
¶
Average pooling over PyTorch-compatible NCDHW inputs.
__init__
¶
__init__(
kernel_size,
stride=None,
padding=0,
ceil_mode=False,
count_include_pad=True,
divisor_override=None,
*,
target=None
)
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
kernel_size(int | tuple[int, ...]) –Window extent, an int or one per spatial axis.
-
stride(int | tuple[int, ...] | None, default:None) –Window step, an int or one per spatial axis;
Nonesteps bykernel_size. -
padding(int | tuple[int, ...], default:0) –Implicit zero padding on both sides, an int or one per spatial axis.
-
ceil_mode(bool, default:False) –Round each output extent up instead of down.
-
count_include_pad(bool, default:True) –Count padded positions in a window's divisor.
-
divisor_override(int | None, default:None) –Divide every window sum by this instead;
Nonedivides by the window's element count. -
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
forward
¶
Pool input.
Parameters:
-
input(Tensor) –Input, \([N \times C]\) followed by
ndimspatial axes.
Returns:
-
Tensor–A new tensor of the pooled averages, \([N \times C]\) followed by the
ndim -
Tensor–pooled extents, in the dtype of
input.
Max pooling¶
tileops.pool.MaxPool1dFwdOp
¶
Max pooling over PyTorch-compatible NCL inputs (return_indices=False).
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
kernel_size(int | tuple[int, ...]) –Window extent, an int or one per spatial axis.
-
stride(int | tuple[int, ...] | None, default:None) –Window step, an int or one per spatial axis;
Nonesteps bykernel_size. -
padding(int | tuple[int, ...], default:0) –Implicit
-infpadding on both sides, an int or one per spatial axis, at most half the window. -
dilation(int | tuple[int, ...], default:1) –Spacing between window elements, an int or one per spatial axis.
-
ceil_mode(bool, default:False) –Round each output extent up instead of down.
-
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
forward
¶
Pool input.
Parameters:
-
input(Tensor) –Input, \([N \times C]\) followed by
ndimspatial axes.
Returns:
-
Tensor–A new tensor of the pooled maximums, \([N \times C]\) followed by the
ndim -
Tensor–pooled extents, in the dtype of
input.
tileops.pool.MaxPool1dIndicesFwdOp
¶
Max pooling over PyTorch-compatible NCL inputs (return_indices=True).
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
kernel_size(int | tuple[int, ...]) –Window extent, an int or one per spatial axis.
-
stride(int | tuple[int, ...] | None, default:None) –Window step, an int or one per spatial axis;
Nonesteps bykernel_size. -
padding(int | tuple[int, ...], default:0) –Implicit
-infpadding on both sides, an int or one per spatial axis, at most half the window. -
dilation(int | tuple[int, ...], default:1) –Spacing between window elements, an int or one per spatial axis.
-
ceil_mode(bool, default:False) –Round each output extent up instead of down.
-
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
forward
¶
Pool input and return where each maximum came from.
Parameters:
-
input(Tensor) –(N, C, L_in), float16, bfloat16 or float32.
Returns:
-
Tensor–output(N, C, L_out)in the input dtype andindices, int64 of the same -
shape(Tensor) –the flat position of each maximum within its
(n, c)plane.
tileops.pool.MaxPool2dFwdOp
¶
Max pooling over PyTorch-compatible NCHW inputs (return_indices=False).
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
kernel_size(int | tuple[int, ...]) –Window extent, an int or one per spatial axis.
-
stride(int | tuple[int, ...] | None, default:None) –Window step, an int or one per spatial axis;
Nonesteps bykernel_size. -
padding(int | tuple[int, ...], default:0) –Implicit
-infpadding on both sides, an int or one per spatial axis, at most half the window. -
dilation(int | tuple[int, ...], default:1) –Spacing between window elements, an int or one per spatial axis.
-
ceil_mode(bool, default:False) –Round each output extent up instead of down.
-
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
forward
¶
Pool input.
Parameters:
-
input(Tensor) –Input, \([N \times C]\) followed by
ndimspatial axes.
Returns:
-
Tensor–A new tensor of the pooled maximums, \([N \times C]\) followed by the
ndim -
Tensor–pooled extents, in the dtype of
input.
tileops.pool.MaxPool2dIndicesFwdOp
¶
Max pooling over PyTorch-compatible NCHW inputs (return_indices=True).
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
kernel_size(int | tuple[int, ...]) –Window extent, an int or one per spatial axis.
-
stride(int | tuple[int, ...] | None, default:None) –Window step, an int or one per spatial axis;
Nonesteps bykernel_size. -
padding(int | tuple[int, ...], default:0) –Implicit
-infpadding on both sides, an int or one per spatial axis, at most half the window. -
dilation(int | tuple[int, ...], default:1) –Spacing between window elements, an int or one per spatial axis.
-
ceil_mode(bool, default:False) –Round each output extent up instead of down.
-
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
forward
¶
Pool input and return where each maximum came from.
Parameters:
-
input(Tensor) –(N, C, H_in, W_in), float16, bfloat16 or float32.
Returns:
-
Tensor–output(N, C, H_out, W_out)in the input dtype andindices, int64 of the same -
shape(Tensor) –the flat position of each maximum within its
(n, c)plane.
tileops.pool.MaxPool3dFwdOp
¶
Max pooling over PyTorch-compatible NCDHW inputs (return_indices=False).
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
kernel_size(int | tuple[int, ...]) –Window extent, an int or one per spatial axis.
-
stride(int | tuple[int, ...] | None, default:None) –Window step, an int or one per spatial axis;
Nonesteps bykernel_size. -
padding(int | tuple[int, ...], default:0) –Implicit
-infpadding on both sides, an int or one per spatial axis, at most half the window. -
dilation(int | tuple[int, ...], default:1) –Spacing between window elements, an int or one per spatial axis.
-
ceil_mode(bool, default:False) –Round each output extent up instead of down.
-
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
forward
¶
Pool input.
Parameters:
-
input(Tensor) –Input, \([N \times C]\) followed by
ndimspatial axes.
Returns:
-
Tensor–A new tensor of the pooled maximums, \([N \times C]\) followed by the
ndim -
Tensor–pooled extents, in the dtype of
input.
tileops.pool.MaxPool3dIndicesFwdOp
¶
Max pooling over PyTorch-compatible NCDHW inputs (return_indices=True).
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
kernel_size(int | tuple[int, ...]) –Window extent, an int or one per spatial axis.
-
stride(int | tuple[int, ...] | None, default:None) –Window step, an int or one per spatial axis;
Nonesteps bykernel_size. -
padding(int | tuple[int, ...], default:0) –Implicit
-infpadding on both sides, an int or one per spatial axis, at most half the window. -
dilation(int | tuple[int, ...], default:1) –Spacing between window elements, an int or one per spatial axis.
-
ceil_mode(bool, default:False) –Round each output extent up instead of down.
-
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
forward
¶
Pool input and return where each maximum came from.
Parameters:
-
input(Tensor) –(N, C, D_in, H_in, W_in), float16, bfloat16 or float32.
Returns:
-
Tensor–output(N, C, D_out, H_out, W_out)in the input dtype andindices, int64 of the same -
shape(Tensor) –the flat position of each maximum within its
(n, c)plane.
Adaptive pooling¶
tileops.pool.AdaptiveAvgPool2dFwdOp
¶
Adaptive average pooling over PyTorch-compatible CHW/NCHW inputs.
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
output_size(int | None | tuple[int | None, int | None] | list[int | None]) –Output
(H_out, W_out), or one int for both; aNoneextent keeps the input's. -
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
forward
¶
Pool input.
Parameters:
-
input(Tensor) –Input, \([C \times H \times W]\) or \([N \times C \times H \times W]\).
Returns:
-
Tensor–A new tensor with the leading axes of
inputandoutput_sizeas its last -
Tensor–two extents, in the dtype of
input.
tileops.pool.AdaptiveMaxPool2dFwdOp
¶
Adaptive max pooling over CHW/NCHW inputs (return_indices=False).
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
output_size(int | None | tuple[int | None, int | None] | list[int | None]) –Output
(H_out, W_out), or one int for both; aNoneextent keeps the input's. -
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
forward
¶
Pool input.
Parameters:
-
input(Tensor) –Input, \([C \times H \times W]\) or \([N \times C \times H \times W]\).
Returns:
-
Tensor–A new tensor with the leading axes of
inputandoutput_sizeas its last -
Tensor–two extents, in the dtype of
input.
tileops.pool.AdaptiveMaxPool2dIndicesFwdOp
¶
Adaptive max pooling over CHW/NCHW inputs (return_indices=True).
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
output_size(int | None | tuple[int | None, int | None] | list[int | None]) –Output
(H_out, W_out), or one int for both; aNoneextent keeps the input's. -
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
forward
¶
Pool input and return where each maximum came from.
Parameters:
-
input(Tensor) –(C, H_in, W_in)or(N, C, H_in, W_in), float16 or bfloat16.
Returns:
-
Tensor–outputwith the leading axes ofinputandoutput_sizeas its last two -
Tensor–extents, in the input dtype, and
indices, int64 of the same shape: the flat -
tuple[Tensor, Tensor]–position of each maximum within its
(H_in, W_in)plane.
Chunked sequence mean¶
The one op on this page with no PyTorch counterpart. It averages the sequence axis of
a [batch, seq, heads, dim] tensor in fixed-size chunks, and can follow ragged
sequence boundaries rather than a uniform split.
tileops.pool.MeanPoolingFwdOp
¶
Chunked mean over the sequence axis of a [batch, seq, heads, dim] tensor.
Not a PyTorch pooling op, and torch has no counterpart. The sequence axis is cut into
chunks of chunk_size and each chunk is averaged, giving one output row per chunk.
Pass cu_seqlens and chunk_indices and the chunks follow the ragged sequence
boundaries cu_seqlens describes instead of a uniform split; chunk_indices then
names the (sequence, chunk-within-sequence) pair each output row belongs to, one row
per chunk.
A sequence's last chunk may be shorter than chunk_size. It is divided by the count
it actually holds, so no padding is averaged in. On a uniform split that makes the op
equal to torch.nn.functional.avg_pool1d(kernel_size=chunk_size, stride=chunk_size,
ceil_mode=True) over a view with the sequence axis last. Chunk sums accumulate in
accum_dtype and are cast back to the input dtype at the boundary, so a float16
input with accum_dtype=torch.float32 does not lose the sum to rounding.
By default the op does not check the contents of cu_seqlens and chunk_indices.
The kernel indexes cu_seqlens by chunk_indices and x by cu_seqlens
without bounds checks, so an inconsistent map can cause out-of-bounds accesses or
incorrect results. The caller guarantees a consistent map. validate_inputs=True
checks cu_seqlens on every call, at the cost of a device synchronization, and cannot
run inside CUDA Graph capture; it does not check chunk_indices.
Example
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
chunk_size(int) –Tokens per chunk, a positive multiple of 32.
-
accum_dtype(dtype) –The dtype a chunk sum accumulates in.
-
validate_inputs(bool, default:False) –Check
cu_seqlenssynchronously on each call. Disable during CUDA Graph capture; shapes and dtypes are always checked. -
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
forward
¶
Average each chunk of x's sequence axis.
Parameters:
-
x(Tensor) –Input tensor,
[batch, seq, heads, dim], dtypefloat16,bfloat16orfloat32.dimis at most 128 or a multiple of it, which is what the manifest declares rather than what the kernel needs. -
cu_seqlens(Tensor | None, default:None) –Sequence boundaries,
[seq_num + 1], dtypeint32. Passing it selects the ragged split, and it comes withchunk_indices. -
chunk_indices(Tensor | None, default:None) –One
(sequence, chunk-within-sequence)pair per output chunk,[chunks, 2], dtypeint32.
Returns:
-
Tensor–output,[batch, chunks, heads, dim], dtype asx.chunksis -
Tensor–ceil(seq / chunk_size)for a uniform split andchunk_indices.shape[0]for a -
Tensor–ragged one.
Raises:
-
ValueError–With
validate_inputs=True,cu_seqlensdoes not partition the sequence axis.