ai.onnx.If
ai.onnx · tensor-only contract (non-standard) · reviewed against ONNX opset 25
Description
Selects elementwise between two pre-evaluated, equal-sized tensors from a scalar condition. This tensor-only package does not implement standard ONNX If control flow: it cannot carry or execute then_branch and else_branch graphs.
See the standard ONNX If spec for the graph semantics this tensor-only package does not implement.
Inputs
| Name | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|
cond |
B |
— | — | Scalar boolean condition that selects which value tensor to output. | required |
then_value |
T |
— | — | Values to output when cond is true. |
required |
else_value |
T |
— | — | Values to output when cond is false. |
required |
Outputs
| Name | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|
y |
T |
derived | derived | Output tensor with the same number of elements as then_value and else_value. |
required |
Type constraints
| Variable | Allowed dtypes |
|---|---|
T |
float32 |
B |
uint32, bool |
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 casesif-select.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.If", { version: 1 });
const condData = Uint32Array.of(1);
const then_valueData = Float32Array.of(2);
const else_valueData = Float32Array.of(11);
const { y } = await kernel({
cond: { data: condData, shape: [1] },
then_value: { data: then_valueData, shape: [1] },
else_value: { data: else_valueData, shape: [1] },
});
console.log({ y });
- Downloads last month
- -
Requires WebGPU support. See the compatibility table.