ai.onnx.ArgMax
ai.onnx · standard ONNX operator · ONNX opset ≥ 13
Description
Returns the index of the maximum value along an axis, choosing the first equal value unless select_last_index is enabled.
See the ONNX ArgMax spec for the reference semantics.
Inputs
| Name | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|
data |
T |
— | — | Values whose maximum index is selected along axis. |
required |
Outputs
| Name | Logical dtype | WebGPU storage | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|---|
reduced |
I |
uint32 |
derived | derived | Logical int64 indices of the maximum values along the reduced axis; WebGPU stores these bounded indices as uint32. | required |
Attributes
Default values (overridable per request):
| Attribute | Default | Description |
|---|---|---|
axis |
0 |
Axis to reduce; negative values count from the back. |
keepdims |
1 |
Retain the reduced dimension with length one when non-zero. |
select_last_index |
0 |
Choose the last equal maximum instead of the first when non-zero. |
Type constraints
| Variable | Allowed dtypes |
|---|---|
T |
float32, float16, int32, uint32, int16, int8, uint8 |
I |
int64 |
Implementation variants
One implementation is selected per call from the device capabilities, the request shapes and the dtypes; these notes say what each one covers.
last_axis_atomic— Reduces long contiguous rows using one packed score/index atomic maximum per subgroup (ArgMin complements scores) and one eight-byte winner per row. The final pass decodes the first or last winning index; integer comparisons remain exact and signed zeros tie. Split-row variants that run on any device are used when packed atomics or subgroups are unavailable.axis_atomic— Scans a split non-final axis and atomically combines exact score/index winners into one eight-byte entry per output. Fully populated inner-column workgroups retain scalar or float32 vec4 loads; narrow tiled schedules and devices without packed atomics use other variants. A final pass decodes the requested first or last winning index.axis_split_packed— Scans four adjacent float32 inner-axis columns per invocation while preserving each column’s axis order and the scalar partial/combine layout. Small output grids keep the scalar variant.
Device requirements
Some implementation variants require atomic-vec2u-min-max and subgroups. Other variants run without them; which variant runs also depends on the request's shapes and dtypes.
Files
metadata.json— kernel metadata (id, file digests, manifest spec, provenance)manifest.json— the op contract (source of truth)test.json— correctness casesbench.json— benchmark casesreduce-arg-atomic-decode.wgsl.jinjareduce-arg-atomic-row.wgsl.jinjareduce-arg-axis-split-combine.wgsl.jinjareduce-arg-axis-split-reduce.wgsl.jinjareduce-arg-axis-split-tiled.wgsl.jinjareduce-arg-axis-tiled.wgsl.jinjareduce-arg-axis.wgsl.jinjareduce-arg-row-split.wgsl.jinjareduce-arg-row-subgroup.wgsl.jinja
Use with @huggingface/kernels
npm install --save-exact @huggingface/kernels@0.0.1-preview.4
Paste the example into a browser app that resolves npm imports. Serve the app over HTTPS or localhost with WebGPU available.
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.
import { getKernel } from "@huggingface/kernels";
const kernel = await getKernel("webgpu-kernels/ai.onnx.ArgMax", { version: 1 });
const dataData = Float32Array.of(2, 2, 3, 10);
const { reduced } = await kernel({ data: { data: dataData, shape: [2, 2] } });
console.log({ reduced });
- Downloads last month
- -
Requires WebGPU support. See the compatibility table.