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

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
-
kernel
webgpu
wgsl
apache-2.0
WebGPU

Requires WebGPU support. See the compatibility table.