ai.onnx.Einsum
ai.onnx · standard ONNX operator · ONNX opset ≥ 12
Description
Evaluates algebraic tensor operations using the Einstein summation convention, specified by an equation string of the form term1,term2,...->output-term. Output elements are computed as the product of the input operands summed over any indices that appear in the input terms but not in the output term; if no -> is given, output indices are the alphabetically sorted set of indices that appear exactly once across all terms.
See the ONNX Einsum spec for the reference semantics.
Inputs
| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|---|
A |
a |
T |
— | — | First operand tensor. | required |
B |
b |
T |
— | — | Second operand tensor (optional). | optional |
C |
c |
T |
— | — | Third operand tensor (optional). | optional |
D |
d |
T |
— | — | Fourth operand tensor (optional); ONNX Einsum takes a variadic operand list. | optional |
Outputs
| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|---|
Output |
y |
T |
— | — | Output tensor produced by the einsum contraction. | required |
Attributes
Attributes and default values (overridable per request):
| Attribute | Default | Description |
|---|---|---|
equation |
— | Required einsum expression string defining the subscript labels for each input operand and the output, in the form inputs->output (e.g. ij,jk->ik for matrix multiplication). |
Type constraints
| Variable | Allowed dtypes |
|---|---|
T |
float32, float16 |
Device requirements
Some implementation variants require subgroup-matrix and subgroups. These are route-specific capabilities, not package-wide requirements; availability also depends on the request shape and dtype.
Files
metadata.json— kernel metadata (id, digests, provenance)manifest.json— the op contract (source of truth)test.json— correctness casesbench.json— benchmark + tuning casesdatamove-elementwise-copy.wgsl.jinjadot-splitk-partial.wgsl.jinjaeinsum-4d-contract.wgsl.jinjaeinsum-ab-ba-ab.wgsl.jinjaeinsum-abc-contract.wgsl.jinjaeinsum-batch-diagonal-iij-j.wgsl.jinjaeinsum-batch-diagonal.wgsl.jinjaeinsum-batch-matmul.wgsl.jinjaeinsum-batch-reduce-all-split-scalar.wgsl.jinjaeinsum-batch-reduce-all-split.wgsl.jinjaeinsum-batch-reduce-all.wgsl.jinjaeinsum-batch-reduce-last.wgsl.jinjaeinsum-bilinear-split.wgsl.jinjaeinsum-diag-matmul-iij-jk.wgsl.jinjaeinsum-diagonal-extract.wgsl.jinjaeinsum-diagonal-iji-reduce.wgsl.jinjaeinsum-indexed-2d-output.wgsl.jinjaeinsum-matmul.wgsl.jinjaeinsum-mul.wgsl.jinjaeinsum-nd-generic.wgsl.jinjaeinsum-reduce-cols-splitk-cooperative.wgsl.jinjaeinsum-reduce-middle-transpose.wgsl.jinjaeinsum-reduce-rows.wgsl.jinjaeinsum-serial-scalar.wgsl.jinjaeinsum-transpose.wgsl.jinjamatmul-subgroup-matrix-ext.wgsl.jinjamatmul-tiled-general-reg.wgsl.jinjamatmul-tiled-general.wgsl.jinjamatmul-vector-matrix-vec4.wgsl.jinjareduce-axis0-splitk-combine.wgsl.jinjareduce-axis0-splitk-reduce.wgsl.jinjareduce-flat-partial.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:
y
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.Einsum", { version: 1 });
// Explicit destinations request optional results or supply metadata that cannot be inferred.
const { y } = await kernel({ a: { data: aData, shape: [2, 3] }, b: { data: bData, shape: [3, 2] } }, {
attrs: { equation: "ij,jk->ik" },
outputs: { y: { shape: [2, 2], dtype: "float32" } },
});
- Downloads last month
- -
Requires WebGPU support. See the compatibility table.