ai.onnx.Shape / README.md
Xenova's picture
Xenova HF Staff
sync 2e7068faf55e
0dcee9d verified
|
Raw
History Blame
2.68 kB
metadata
library_name: kernels
license: apache-2.0
tags:
  - kernel
  - webgpu
  - wgsl

ai.onnx.Shape

ai.onnx · standard ONNX operator · ONNX opset ≥ 15

Description

Returns a 1-D tensor containing the shape of the input tensor. Optional start and end attributes select a slice of the shape axes; negative values count from the back, and axes are clamped to [0, rank].

See the ONNX Shape spec for the reference semantics.

Inputs

Name Bind key Logical dtype Rank Shape Description Presence
data data T The input tensor whose shape is computed. required

Outputs

Name Bind key Logical dtype WebGPU storage Rank Shape Description Presence
shape shape S uint32 1 derived; see description Logical int64 1-D tensor of dimension sizes for the selected axes of the input; WebGPU emits bounded uint32 values. required

Attributes

Attributes and default values (overridable per request):

Attribute Default Description
start 0 First axis (inclusive) of the shape slice; negative values count from the back, default is 0.
end Last axis (exclusive) of the shape slice; negative values count from the back; if omitted, all axes through the last are included.

Type constraints

Variable Allowed dtypes
T float32, float16, int32, int16, uint32, int8, uint8, bool
S int64

Files

Use with @huggingface/kernels

The loader derives every required output's shape and logical dtype from the manifest contract and this call. It then allocates the result tensors automatically.

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.Shape", { version: 1 });
const { shape } = await kernel({ data: { data: dataData, shape: [1, 2, 2] } });