Xenova HF Staff commited on
Commit
4203db8
·
verified ·
1 Parent(s): 0dcee9d

sync 91d990483a17

Browse files
README.md CHANGED
@@ -18,15 +18,15 @@ See the [ONNX `Shape` spec](https://onnx.ai/onnx/operators/onnx__Shape.html) for
18
 
19
  ## Inputs
20
 
21
- | Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
22
- | --- | --- | --- | --- | --- | --- | --- |
23
- | `data` | `data` | `T` | — | — | The input tensor whose shape is computed. | required |
24
 
25
  ## Outputs
26
 
27
- | Name | Bind key | Logical dtype | WebGPU storage | Rank | Shape | Description | Presence |
28
- | --- | --- | --- | --- | --- | --- | --- | --- |
29
- | `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 |
30
 
31
  ## Attributes
32
 
@@ -34,8 +34,8 @@ Attributes and default values (overridable per request):
34
 
35
  | Attribute | Default | Description |
36
  | --- | --- | --- |
37
- | `start` | `0` | First axis (inclusive) of the shape slice; negative values count from the back, default is 0. |
38
  | `end` | — | Last axis (exclusive) of the shape slice; negative values count from the back; if omitted, all axes through the last are included. |
 
39
 
40
  ## Type constraints
41
 
@@ -46,7 +46,7 @@ Attributes and default values (overridable per request):
46
 
47
  ## Files
48
 
49
- - [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, provenance)
50
  - [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)
51
  - [`test.json`](build/webgpu/test.json) — correctness cases
52
  - [`bench.json`](build/webgpu/bench.json) — benchmark + tuning cases
@@ -54,10 +54,14 @@ Attributes and default values (overridable per request):
54
 
55
  ## Use with `@huggingface/kernels`
56
 
57
- The loader derives every required output's shape and logical dtype from the manifest contract and this call.
58
- It then allocates the result tensors automatically.
 
 
 
59
 
60
  The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.
 
61
 
62
  Replace each `*Data` placeholder with a typed array containing the corresponding input data.
63
 
 
18
 
19
  ## Inputs
20
 
21
+ | Name | Logical dtype | Rank | Shape | Description | Presence |
22
+ | --- | --- | --- | --- | --- | --- |
23
+ | `data` | `T` | — | — | The input tensor whose shape is computed. | required |
24
 
25
  ## Outputs
26
 
27
+ | Name | Logical dtype | WebGPU storage | Rank | Shape | Description | Presence |
28
+ | --- | --- | --- | --- | --- | --- | --- |
29
+ | `shape` | `S` | `uint32` | `1` | derived | Logical int64 1-D tensor of dimension sizes for the selected axes of the input; WebGPU emits bounded uint32 values. | required |
30
 
31
  ## Attributes
32
 
 
34
 
35
  | Attribute | Default | Description |
36
  | --- | --- | --- |
 
37
  | `end` | — | Last axis (exclusive) of the shape slice; negative values count from the back; if omitted, all axes through the last are included. |
38
+ | `start` | `0` | First axis (inclusive) of the shape slice; negative values count from the back, default is 0. |
39
 
40
  ## Type constraints
41
 
 
46
 
47
  ## Files
48
 
49
+ - [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, per-variant templates, provenance)
50
  - [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)
51
  - [`test.json`](build/webgpu/test.json) — correctness cases
52
  - [`bench.json`](build/webgpu/bench.json) — benchmark + tuning cases
 
54
 
55
  ## Use with `@huggingface/kernels`
56
 
57
+ ```sh
58
+ npm install --save-exact @huggingface/kernels@0.0.1-preview.2
59
+ ```
60
+
61
+ Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.
62
 
63
  The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.
64
+ It follows the `v1` branch as fixes land. To pin exact artifact bytes, pass a 40-character commit `revision` instead of `version`.
65
 
66
  Replace each `*Data` placeholder with a typed array containing the corresponding input data.
67
 
build/webgpu/bench.json CHANGED
@@ -1,5 +1,4 @@
1
  {
2
- "op": "ai.onnx.Shape",
3
  "cases": [
4
  {
5
  "name": "rank4",
 
1
  {
 
2
  "cases": [
3
  {
4
  "name": "rank4",
build/webgpu/manifest.json CHANGED
@@ -2,30 +2,13 @@
2
  "domain": "ai.onnx",
3
  "name": "Shape",
4
  "sinceVersion": 15,
5
- "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]`.",
6
- "inputs": [{ "role": "data", "dtype": "T", "description": "The input tensor whose shape is computed." }],
7
- "outputs": [
8
- {
9
- "role": "shape",
10
- "dtype": "S",
11
- "rank": 1,
12
- "description": "Logical int64 1-D tensor of dimension sizes for the selected axes of the input; WebGPU emits bounded uint32 values.",
13
- "shape": ["max(0, endAxis - startAxis)"]
14
- }
15
- ],
16
- "attributes": { "start": 0 },
17
- "attributeDescriptions": {
18
- "start": "First axis (inclusive) of the shape slice; negative values count from the back, default is 0.",
19
- "end": "Last axis (exclusive) of the shape slice; negative values count from the back; if omitted, all axes through the last are included."
20
- },
21
  "typeConstraints": {
22
  "T": ["float32", "float16", "int32", "int16", "uint32", "int8", "uint8", "bool"],
23
  "S": ["int64"]
24
  },
25
- "args": {
26
- "data": { "kind": "tensor", "semantic": "data", "role": "input" },
27
- "shape": { "kind": "tensor", "semantic": "shape", "role": "output", "dtype": "uint32" }
28
- },
29
  "derive": {
30
  "startAxis": "max(0, min(ranks.data, attrs.start + (ranks.data if attrs.start < 0 else 0)))",
31
  "endParam": "attrs.end if has(attrs, \"end\") else ranks.data",
@@ -39,24 +22,9 @@
39
  {
40
  "id": "main",
41
  "name": "Shape",
42
- "source": {
43
- "shader": "shape.wgsl.jinja",
44
- "inputs": {
45
- "inputShape": "shapes.data",
46
- "rank": "ranks.data",
47
- "start": "startAxis",
48
- "outputRank": "dim(shapes.shape, 0)"
49
- }
50
- },
51
- "bindings": [
52
- {
53
- "name": "shape",
54
- "arg": "shape",
55
- "semantic": "shape",
56
- "buffer": { "type": "storage" },
57
- "elementType": "u32"
58
- }
59
- ],
60
  "dispatch": { "x": 1 }
61
  }
62
  ]
 
2
  "domain": "ai.onnx",
3
  "name": "Shape",
4
  "sinceVersion": 15,
5
+ "inputs": { "data": { "dtype": "T" } },
6
+ "outputs": { "shape": { "dtype": "S", "rank": 1, "shape": ["max(0, endAxis - startAxis)"], "storage": "uint32" } },
7
+ "attributes": { "start": { "default": 0 }, "end": {} },
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  "typeConstraints": {
9
  "T": ["float32", "float16", "int32", "int16", "uint32", "int8", "uint8", "bool"],
10
  "S": ["int64"]
11
  },
 
 
 
 
12
  "derive": {
13
  "startAxis": "max(0, min(ranks.data, attrs.start + (ranks.data if attrs.start < 0 else 0)))",
14
  "endParam": "attrs.end if has(attrs, \"end\") else ranks.data",
 
22
  {
23
  "id": "main",
24
  "name": "Shape",
25
+ "shader": "shape.wgsl.jinja",
26
+ "derive": { "inputShape": "shapes.data", "start": "startAxis", "outputRank": "dim(shapes.shape, 0)" },
27
+ "bindings": ["shape"],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  "dispatch": { "x": 1 }
29
  }
30
  ]
build/webgpu/metadata.json CHANGED
@@ -1,18 +1,18 @@
1
  {
2
  "name": "ai.onnx.Shape",
3
- "id": "_ai_onnx_shape_webgpu_353de3d",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "backend": { "type": "webgpu" },
7
  "digest": {
8
  "algorithm": "sha256",
9
  "files": {
10
- "bench.json": "kiw8iMiBPBGaaz6TKqd9RaaOn38QOi/xilG0TXGnttQ=",
11
- "manifest.json": "Y8kEIxBXPtwm8XOQcctfW9bFg8RGzmi1r7HwvpwrEPY=",
12
- "shape.wgsl.jinja": "J1oIMamgxFx04z+NWiHv6zFj8vclOHR99dd4R/GsPzY=",
13
- "test.json": "U5HvTdgN4iqjYIRxu51OW8NZCuqqj/oRlYrEEruggIM="
14
  }
15
  },
16
- "provenance": { "kernel": { "sha": "2e7068faf55e7f43df740015f6d1ee49391a41c5", "dirty": false } },
17
- "webgpu": { "manifestSpec": "1.0", "specialized": true, "opPath": "ops/ai.onnx.Shape" }
18
  }
 
1
  {
2
  "name": "ai.onnx.Shape",
3
+ "id": "_ai_onnx_shape_webgpu_5a9b5b0",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "backend": { "type": "webgpu" },
7
  "digest": {
8
  "algorithm": "sha256",
9
  "files": {
10
+ "bench.json": "R7qQRulG0ZYBXID+7lefm4MMiRSotddmA7zkoCnxAsQ=",
11
+ "manifest.json": "1disq05Dn+ENQNGqLwxbl1S5KHhAizkNtqMKAXDaEC0=",
12
+ "shape.wgsl.jinja": "6VyYYEl2JqmSVGNpab59uvRysZnhLgkw4QlAZHhLPuM=",
13
+ "test.json": "CY1CD4C9jPFMmdxqKd9PY4TbKI0vUgRvBY79x5eekt4="
14
  }
15
  },
16
+ "provenance": { "kernel": { "sha": "91d990483a174128daf7673f3f37a7c890493ae1", "dirty": false } },
17
+ "webgpu": { "manifestSpec": "2.0", "variants": { "full_shape": ["shape.wgsl.jinja"] } }
18
  }
build/webgpu/shape.wgsl.jinja CHANGED
@@ -5,9 +5,9 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
5
  if (gid.x != 0u) {
6
  return;
7
  }
8
- {% for dim in source.inputShape %}
9
- {% if loop.index0 >= source.start and loop.index0 < source.start + source.outputRank %}
10
- shape[{{ loop.index0 - source.start }}u] = {{ dim }}u;
11
  {% endif %}
12
  {% endfor %}
13
  }
 
5
  if (gid.x != 0u) {
6
  return;
7
  }
8
+ {% for dim in inputShape %}
9
+ {% if loop.index0 >= start and loop.index0 < start + outputRank %}
10
+ shape[{{ loop.index0 - start }}u] = {{ dim }}u;
11
  {% endif %}
12
  {% endfor %}
13
  }
build/webgpu/test.json CHANGED
@@ -1,5 +1,4 @@
1
  {
2
- "op": "ai.onnx.Shape",
3
  "cases": [
4
  {
5
  "name": "rank3_f32",
@@ -241,7 +240,7 @@
241
  "name": "onnx_backend_shape",
242
  "provenance": {
243
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape",
244
- "notes": "ONNX shape/size outputs are int64; this framework uses uint32 shape/index storage."
245
  },
246
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
247
  "outputs": { "shape": { "dtype": "uint32", "shape": [3], "tolerance": 0 } }
@@ -250,7 +249,7 @@
250
  "name": "onnx_backend_shape_clip_end",
251
  "provenance": {
252
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_clip_end",
253
- "notes": "ONNX shape/size outputs are int64; this framework uses uint32 shape/index storage."
254
  },
255
  "attrs": { "end": 10 },
256
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
@@ -260,7 +259,7 @@
260
  "name": "onnx_backend_shape_clip_start",
261
  "provenance": {
262
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_clip_start",
263
- "notes": "ONNX shape/size outputs are int64; this framework uses uint32 shape/index storage."
264
  },
265
  "attrs": { "start": -10 },
266
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
@@ -270,7 +269,7 @@
270
  "name": "onnx_backend_shape_end_1",
271
  "provenance": {
272
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_end_1",
273
- "notes": "ONNX shape/size outputs are int64; this framework uses uint32 shape/index storage."
274
  },
275
  "attrs": { "end": 1 },
276
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
@@ -280,7 +279,7 @@
280
  "name": "onnx_backend_shape_end_negative_1",
281
  "provenance": {
282
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_end_negative_1",
283
- "notes": "ONNX shape/size outputs are int64; this framework uses uint32 shape/index storage."
284
  },
285
  "attrs": { "end": -1 },
286
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
@@ -290,7 +289,7 @@
290
  "name": "onnx_backend_shape_example",
291
  "provenance": {
292
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_example",
293
- "notes": "ONNX shape/size outputs are int64; this framework uses uint32 shape/index storage."
294
  },
295
  "inputs": { "data": { "dtype": "float32", "shape": [2, 3] } },
296
  "outputs": { "shape": { "dtype": "uint32", "shape": [2], "tolerance": 0 } }
@@ -299,7 +298,7 @@
299
  "name": "onnx_backend_shape_start_1",
300
  "provenance": {
301
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_start_1",
302
- "notes": "ONNX shape/size outputs are int64; this framework uses uint32 shape/index storage."
303
  },
304
  "attrs": { "start": 1 },
305
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
@@ -309,7 +308,7 @@
309
  "name": "onnx_backend_shape_start_1_end_2",
310
  "provenance": {
311
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_start_1_end_2",
312
- "notes": "ONNX shape/size outputs are int64; this framework uses uint32 shape/index storage."
313
  },
314
  "attrs": { "end": 2, "start": 1 },
315
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
@@ -319,7 +318,7 @@
319
  "name": "onnx_backend_shape_start_1_end_negative_1",
320
  "provenance": {
321
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_start_1_end_negative_1",
322
- "notes": "ONNX shape/size outputs are int64; this framework uses uint32 shape/index storage."
323
  },
324
  "attrs": { "end": -1, "start": 1 },
325
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
@@ -329,7 +328,7 @@
329
  "name": "onnx_backend_shape_start_greater_than_end",
330
  "provenance": {
331
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_start_greater_than_end",
332
- "notes": "ONNX shape/size outputs are int64; this framework uses uint32 shape/index storage."
333
  },
334
  "attrs": { "end": 1, "start": 2 },
335
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
@@ -339,7 +338,7 @@
339
  "name": "onnx_backend_shape_start_negative_1",
340
  "provenance": {
341
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_start_negative_1",
342
- "notes": "ONNX shape/size outputs are int64; this framework uses uint32 shape/index storage."
343
  },
344
  "attrs": { "start": -1 },
345
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
@@ -382,7 +381,7 @@
382
  "name": "rank7_full_shape",
383
  "provenance": {
384
  "source": "onnx spec: Shape returns the input tensor dimensions",
385
- "notes": "Small rank-7 sentinel. ORT CPU returns [1,2,1,3,1,4,1]; full_shape is rank-agnostic, and rank8_full_shape covers the band above it."
386
  },
387
  "inputs": { "data": { "dtype": "float32", "shape": [1, 2, 1, 3, 1, 4, 1] } },
388
  "outputs": {
 
1
  {
 
2
  "cases": [
3
  {
4
  "name": "rank3_f32",
 
240
  "name": "onnx_backend_shape",
241
  "provenance": {
242
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape",
243
+ "notes": "ONNX Shape and Size return int64 values; this package stores representable shape values in uint32 slots."
244
  },
245
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
246
  "outputs": { "shape": { "dtype": "uint32", "shape": [3], "tolerance": 0 } }
 
249
  "name": "onnx_backend_shape_clip_end",
250
  "provenance": {
251
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_clip_end",
252
+ "notes": "ONNX Shape and Size return int64 values; this package stores representable shape values in uint32 slots."
253
  },
254
  "attrs": { "end": 10 },
255
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
 
259
  "name": "onnx_backend_shape_clip_start",
260
  "provenance": {
261
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_clip_start",
262
+ "notes": "ONNX Shape and Size return int64 values; this package stores representable shape values in uint32 slots."
263
  },
264
  "attrs": { "start": -10 },
265
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
 
269
  "name": "onnx_backend_shape_end_1",
270
  "provenance": {
271
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_end_1",
272
+ "notes": "ONNX Shape and Size return int64 values; this package stores representable shape values in uint32 slots."
273
  },
274
  "attrs": { "end": 1 },
275
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
 
279
  "name": "onnx_backend_shape_end_negative_1",
280
  "provenance": {
281
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_end_negative_1",
282
+ "notes": "ONNX Shape and Size return int64 values; this package stores representable shape values in uint32 slots."
283
  },
284
  "attrs": { "end": -1 },
285
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
 
289
  "name": "onnx_backend_shape_example",
290
  "provenance": {
291
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_example",
292
+ "notes": "ONNX Shape and Size return int64 values; this package stores representable shape values in uint32 slots."
293
  },
294
  "inputs": { "data": { "dtype": "float32", "shape": [2, 3] } },
295
  "outputs": { "shape": { "dtype": "uint32", "shape": [2], "tolerance": 0 } }
 
298
  "name": "onnx_backend_shape_start_1",
299
  "provenance": {
300
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_start_1",
301
+ "notes": "ONNX Shape and Size return int64 values; this package stores representable shape values in uint32 slots."
302
  },
303
  "attrs": { "start": 1 },
304
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
 
308
  "name": "onnx_backend_shape_start_1_end_2",
309
  "provenance": {
310
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_start_1_end_2",
311
+ "notes": "ONNX Shape and Size return int64 values; this package stores representable shape values in uint32 slots."
312
  },
313
  "attrs": { "end": 2, "start": 1 },
314
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
 
318
  "name": "onnx_backend_shape_start_1_end_negative_1",
319
  "provenance": {
320
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_start_1_end_negative_1",
321
+ "notes": "ONNX Shape and Size return int64 values; this package stores representable shape values in uint32 slots."
322
  },
323
  "attrs": { "end": -1, "start": 1 },
324
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
 
328
  "name": "onnx_backend_shape_start_greater_than_end",
329
  "provenance": {
330
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_start_greater_than_end",
331
+ "notes": "ONNX Shape and Size return int64 values; this package stores representable shape values in uint32 slots."
332
  },
333
  "attrs": { "end": 1, "start": 2 },
334
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
 
338
  "name": "onnx_backend_shape_start_negative_1",
339
  "provenance": {
340
  "source": "cmake/external/onnx/onnx/backend/test/data/node/test_shape_start_negative_1",
341
+ "notes": "ONNX Shape and Size return int64 values; this package stores representable shape values in uint32 slots."
342
  },
343
  "attrs": { "start": -1 },
344
  "inputs": { "data": { "dtype": "float32", "shape": [3, 4, 5] } },
 
381
  "name": "rank7_full_shape",
382
  "provenance": {
383
  "source": "onnx spec: Shape returns the input tensor dimensions",
384
+ "notes": "A rank-7 tensor returns [1,2,1,3,1,4,1], exercising rank-agnostic full-shape emission."
385
  },
386
  "inputs": { "data": { "dtype": "float32", "shape": [1, 2, 1, 3, 1, 4, 1] } },
387
  "outputs": {