ai.onnx.Pad
ai.onnx · standard ONNX operator · ONNX opset ≥ 19
Description
Pads a tensor along each axis using one of four modes: constant (fill with a scalar value), reflect (mirror edge values), edge (replicate boundary values), or wrap (torus-like wrap-around). Supply the required ONNX pads tensor, and optional axes tensor when present, through the pads request attribute as a full-rank list. Negative counts crop the corresponding edge.
See the ONNX Pad spec for the reference semantics.
Inputs
| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|---|
data |
data |
T |
— | — | Input tensor to be padded. | required |
constant_value |
constant_value |
T |
0 |
— | Optional scalar value used as the fill constant when mode is constant; defaults to 0. |
optional |
Outputs
| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|---|
output |
output |
T |
same as data |
— | Tensor after padding, with each axis enlarged by the corresponding begin and end pad counts. | required |
Attributes
Attributes and default values (overridable per request):
| Attribute | Default | Description |
|---|---|---|
mode |
"constant" |
Padding mode: constant (default), reflect, edge, or wrap. |
pads |
— | Values of the required pads tensor, with an optional axes tensor expanded to full rank, supplied as [x1_begin, ..., xN_begin, x1_end, ..., xN_end]. |
Type constraints
| Variable | Allowed dtypes |
|---|---|
T |
float32, float16, uint32, int32, uint8, int8, bool |
Files
metadata.json— kernel metadata (id, digests, provenance)manifest.json— the op contract (source of truth)test.json— correctness casesbench.json— benchmark + tuning casespad-quad-vec4.wgsl.jinjapad.wgsl.jinja
Use with @huggingface/kernels
The loader automatically allocates outputs whose metadata it can derive from the manifest contract and this call.
The explicit outputs entries provide shape and logical dtype metadata for the results listed below:
output
Each entry either requests an optional result or supplies metadata that cannot be inferred from the inputs.
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.Pad", { version: 1 });
// Explicit destinations request optional results or supply metadata that cannot be inferred.
const { output } = await kernel({ data: { data: dataData, shape: [2] } }, {
attrs: { pads: [0, 0] },
outputs: { output: { shape: [2], dtype: "float32" } },
});
- Downloads last month
- -
Requires WebGPU support. See the compatibility table.