sync 4385228f788d
Browse files- README.md +15 -17
- build/webgpu/manifest.json +1 -68
- build/webgpu/metadata.json +1 -22
- build/webgpu/test.json +4 -4
README.md
CHANGED
|
@@ -27,7 +27,7 @@ See the [ONNX `Unsqueeze` spec](https://onnx.ai/onnx/operators/onnx__Unsqueeze.h
|
|
| 27 |
|
| 28 |
| Name | Logical dtype | Rank | Shape | Description | Presence |
|
| 29 |
| --- | --- | --- | --- | --- | --- |
|
| 30 |
-
| `expanded` | `T` | derived |
|
| 31 |
|
| 32 |
## Type constraints
|
| 33 |
|
|
@@ -38,39 +38,37 @@ See the [ONNX `Unsqueeze` spec](https://onnx.ai/onnx/operators/onnx__Unsqueeze.h
|
|
| 38 |
|
| 39 |
## Files
|
| 40 |
|
| 41 |
-
- [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests,
|
| 42 |
-
- [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)
|
| 43 |
-
- [`test.json`](build/webgpu/test.json) — correctness cases
|
| 44 |
-
- [`bench.json`](build/webgpu/bench.json) — benchmark cases
|
| 45 |
-
- [`datamove-elementwise-copy.wgsl.jinja`](build/webgpu/datamove-elementwise-copy.wgsl.jinja)
|
| 46 |
-
- [`datamove-flat-copy.wgsl.jinja`](build/webgpu/datamove-flat-copy.wgsl.jinja)
|
| 47 |
|
| 48 |
## Use with `@huggingface/kernels`
|
| 49 |
|
| 50 |
```sh
|
| 51 |
-
npm install --save-exact @huggingface/kernels@0.0.1-preview.
|
| 52 |
```
|
| 53 |
|
| 54 |
-
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
- `expanded`
|
| 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 |
It follows the `v1` branch as fixes land. To pin exact artifact bytes, pass a 40-character commit `revision` instead of `version`.
|
| 62 |
|
| 63 |
-
Replace each `*Data` placeholder with a typed array containing the corresponding input data.
|
| 64 |
-
|
| 65 |
```js
|
| 66 |
import { getKernel } from "@huggingface/kernels";
|
| 67 |
|
| 68 |
const kernel = await getKernel("webgpu-kernels/ai.onnx.Unsqueeze", { version: 1 });
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
| 70 |
const { expanded } = await kernel({
|
| 71 |
data: { data: dataData, shape: [] },
|
| 72 |
axes: { data: axesData, shape: [1] },
|
| 73 |
-
}, {
|
| 74 |
-
outputs: { expanded: { shape: [1], dtype: "float32" } },
|
| 75 |
});
|
|
|
|
| 76 |
```
|
|
|
|
| 27 |
|
| 28 |
| Name | Logical dtype | Rank | Shape | Description | Presence |
|
| 29 |
| --- | --- | --- | --- | --- | --- |
|
| 30 |
+
| `expanded` | `T` | derived | derived | Reshaped tensor with the same data as the input and size-1 dimensions inserted at the specified axes. | required |
|
| 31 |
|
| 32 |
## Type constraints
|
| 33 |
|
|
|
|
| 38 |
|
| 39 |
## Files
|
| 40 |
|
| 41 |
+
- [`metadata.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.Unsqueeze/blob/v1/build/webgpu/metadata.json) — kernel metadata (id, file digests, manifest spec, provenance)
|
| 42 |
+
- [`manifest.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.Unsqueeze/blob/v1/build/webgpu/manifest.json) — the op contract (source of truth)
|
| 43 |
+
- [`test.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.Unsqueeze/blob/v1/build/webgpu/test.json) — correctness cases
|
| 44 |
+
- [`bench.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.Unsqueeze/blob/v1/build/webgpu/bench.json) — benchmark cases
|
| 45 |
+
- [`datamove-elementwise-copy.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.Unsqueeze/blob/v1/build/webgpu/datamove-elementwise-copy.wgsl.jinja)
|
| 46 |
+
- [`datamove-flat-copy.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.Unsqueeze/blob/v1/build/webgpu/datamove-flat-copy.wgsl.jinja)
|
| 47 |
|
| 48 |
## Use with `@huggingface/kernels`
|
| 49 |
|
| 50 |
```sh
|
| 51 |
+
npm install --save-exact @huggingface/kernels@0.0.1-preview.4
|
| 52 |
```
|
| 53 |
|
| 54 |
+
Paste the example into a browser app that resolves npm imports. Serve the app over HTTPS or localhost with WebGPU available.
|
| 55 |
|
| 56 |
+
Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.
|
|
|
|
|
|
|
| 57 |
|
| 58 |
The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.
|
| 59 |
It follows the `v1` branch as fixes land. To pin exact artifact bytes, pass a 40-character commit `revision` instead of `version`.
|
| 60 |
|
|
|
|
|
|
|
| 61 |
```js
|
| 62 |
import { getKernel } from "@huggingface/kernels";
|
| 63 |
|
| 64 |
const kernel = await getKernel("webgpu-kernels/ai.onnx.Unsqueeze", { version: 1 });
|
| 65 |
+
|
| 66 |
+
const dataData = Float32Array.of(1);
|
| 67 |
+
const axesData = Int32Array.of(-1);
|
| 68 |
+
|
| 69 |
const { expanded } = await kernel({
|
| 70 |
data: { data: dataData, shape: [] },
|
| 71 |
axes: { data: axesData, shape: [1] },
|
|
|
|
|
|
|
| 72 |
});
|
| 73 |
+
console.log({ expanded });
|
| 74 |
```
|
build/webgpu/manifest.json
CHANGED
|
@@ -1,68 +1 @@
|
|
| 1 |
-
{
|
| 2 |
-
"domain": "ai.onnx",
|
| 3 |
-
"name": "Unsqueeze",
|
| 4 |
-
"sinceVersion": 13,
|
| 5 |
-
"inputs": {
|
| 6 |
-
"data": { "dtype": "T" },
|
| 7 |
-
"axes": { "dtype": "S", "rank": 1, "storage": "int32", "narrowing": "checked" }
|
| 8 |
-
},
|
| 9 |
-
"outputs": { "expanded": { "dtype": "T", "rank": "ranks.data + dim(shapes.axes, 0)" } },
|
| 10 |
-
"typeConstraints": {
|
| 11 |
-
"T": ["float32", "float16", "int32", "uint32", "int16", "uint8", "int8", "bool", "int64"],
|
| 12 |
-
"S": ["int64"]
|
| 13 |
-
},
|
| 14 |
-
"tunables": { "WORKGROUP_SIZE": { "default": 256 } },
|
| 15 |
-
"derive": { "axesContract": "present.axes and ranks.axes == 1" },
|
| 16 |
-
"when": ["axesContract", "numel(shapes.data) == numel(shapes.expanded)", "f16Ok(dtypes.T)"],
|
| 17 |
-
"bindings": {
|
| 18 |
-
"src": { "arg": "data", "elementType": "$vectorScalar" },
|
| 19 |
-
"dst": { "arg": "expanded", "elementType": "$vectorScalar" },
|
| 20 |
-
"x": { "arg": "data", "elementType": "$scalar" },
|
| 21 |
-
"y": { "arg": "expanded", "elementType": "$scalar" }
|
| 22 |
-
},
|
| 23 |
-
"variants": [
|
| 24 |
-
{
|
| 25 |
-
"id": "copy_vec4",
|
| 26 |
-
"priority": 20,
|
| 27 |
-
"when": ["dtypes.T != \"vec2<u32>\"", "numel(shapes.data) > 0", "numel(shapes.data) % 4 == 0"],
|
| 28 |
-
"derive": { "vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"" },
|
| 29 |
-
"passes": [
|
| 30 |
-
{
|
| 31 |
-
"id": "main",
|
| 32 |
-
"name": "Unsqueeze.CopyVec4",
|
| 33 |
-
"shader": "datamove-flat-copy.wgsl.jinja",
|
| 34 |
-
"derive": { "count": "numel(shapes.expanded) / 4" },
|
| 35 |
-
"bindings": ["src", "dst"],
|
| 36 |
-
"dispatch": {
|
| 37 |
-
"x": "min(ceilDiv((numel(shapes.expanded) / 4), (tunables.WORKGROUP_SIZE)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))",
|
| 38 |
-
"y": 1,
|
| 39 |
-
"z": 1
|
| 40 |
-
},
|
| 41 |
-
"viewAlias": [{ "input": "src", "output": "dst" }]
|
| 42 |
-
}
|
| 43 |
-
]
|
| 44 |
-
},
|
| 45 |
-
{
|
| 46 |
-
"id": "copy",
|
| 47 |
-
"derive": { "scalar": "dtypes.T" },
|
| 48 |
-
"passes": [
|
| 49 |
-
{
|
| 50 |
-
"id": "main",
|
| 51 |
-
"name": "Unsqueeze",
|
| 52 |
-
"shader": "datamove-elementwise-copy.wgsl.jinja",
|
| 53 |
-
"bindings": [
|
| 54 |
-
"x",
|
| 55 |
-
"y",
|
| 56 |
-
{ "name": "params", "struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.expanded)" }] }
|
| 57 |
-
],
|
| 58 |
-
"dispatch": {
|
| 59 |
-
"x": "min(ceilDiv((numel(shapes.expanded)), (tunables.WORKGROUP_SIZE)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))",
|
| 60 |
-
"y": 1,
|
| 61 |
-
"z": 1
|
| 62 |
-
},
|
| 63 |
-
"viewAlias": [{ "input": "x", "output": "y" }]
|
| 64 |
-
}
|
| 65 |
-
]
|
| 66 |
-
}
|
| 67 |
-
]
|
| 68 |
-
}
|
|
|
|
| 1 |
+
{"domain":"ai.onnx","name":"Unsqueeze","sinceVersion":13,"inputs":{"data":{"dtype":"T"},"axes":{"dtype":"S","rank":1,"storage":"int32","narrowing":"checked"}},"outputs":{"expanded":{"dtype":"T","rank":"ranks.data + dim(shapes.axes, 0)","shape":"moveAxis(moveAxis(moveAxis(moveAxis(moveAxis(moveAxis(moveAxis(moveAxis(shapes.data + fill(1, shapes.axes[0]), -1, 0 if expandedRank > 0 and hasAxis(values.axes, 0, expandedRank) else -1), -1, 1 if expandedRank > 1 and hasAxis(values.axes, 1, expandedRank) else -1), -1, 2 if expandedRank > 2 and hasAxis(values.axes, 2, expandedRank) else -1), -1, 3 if expandedRank > 3 and hasAxis(values.axes, 3, expandedRank) else -1), -1, 4 if expandedRank > 4 and hasAxis(values.axes, 4, expandedRank) else -1), -1, 5 if expandedRank > 5 and hasAxis(values.axes, 5, expandedRank) else -1), -1, 6 if expandedRank > 6 and hasAxis(values.axes, 6, expandedRank) else -1), -1, 7 if expandedRank > 7 and hasAxis(values.axes, 7, expandedRank) else -1) if expandedRank <= 8 and expandedRank > 0 and isUniqueIntList(values.axes, -expandedRank, expandedRank, expandedRank) else shapes.expanded"}},"typeConstraints":{"T":["float32","float16","int32","uint32","int16","uint8","int8","bool","int64"],"S":["int64"]},"tunables":{"WORKGROUP_SIZE":{"default":256}},"derive":{"axesContract":"present.axes and ranks.axes == 1","expandedRank":"ranks.data + dim(shapes.axes, 0) if axesContract else 0"},"when":["axesContract","numel(shapes.data) == numel(shapes.expanded)","f16Ok(dtypes.T)"],"bindings":{"src":{"arg":"data","elementType":"$vectorScalar"},"dst":{"arg":"expanded","elementType":"$vectorScalar"},"x":{"arg":"data","elementType":"$scalar"},"y":{"arg":"expanded","elementType":"$scalar"}},"variants":[{"id":"copy_vec4","priority":20,"when":["dtypes.T != \"vec2<u32>\"","numel(shapes.data) > 0","numel(shapes.data) % 4 == 0"],"derive":{"vectorScalar":"\"vec4<\" ~ dtypes.T ~ \">\""},"passes":[{"id":"main","name":"Unsqueeze.CopyVec4","shader":"datamove-flat-copy.wgsl.jinja","derive":{"count":"numel(shapes.expanded) / 4"},"bindings":["src","dst"],"dispatch":{"x":"min(ceilDiv((numel(shapes.expanded) / 4), (tunables.WORKGROUP_SIZE)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1},"viewAlias":[{"input":"src","output":"dst"}]}]},{"id":"copy","derive":{"scalar":"dtypes.T"},"passes":[{"id":"main","name":"Unsqueeze","shader":"datamove-elementwise-copy.wgsl.jinja","bindings":["x","y",{"name":"params","struct":[{"name":"count","type":"u32","value":"numel(shapes.expanded)"}]}],"dispatch":{"x":"min(ceilDiv((numel(shapes.expanded)), (tunables.WORKGROUP_SIZE)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1},"viewAlias":[{"input":"x","output":"y"}]}]}]}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/webgpu/metadata.json
CHANGED
|
@@ -1,22 +1 @@
|
|
| 1 |
-
{
|
| 2 |
-
"name": "ai.onnx.Unsqueeze",
|
| 3 |
-
"id": "_ai_onnx_unsqueeze_webgpu_fa4aa23",
|
| 4 |
-
"version": 1,
|
| 5 |
-
"license": "Apache-2.0",
|
| 6 |
-
"backend": { "type": "webgpu" },
|
| 7 |
-
"digest": {
|
| 8 |
-
"algorithm": "sha256",
|
| 9 |
-
"files": {
|
| 10 |
-
"bench.json": "70cGk/A0yhfuRCQX6XqqX02QupHfOPOQGtMPW0uXhX0=",
|
| 11 |
-
"datamove-elementwise-copy.wgsl.jinja": "Q1WuZCqcDf9b6cbT4rLilpeWj6327t/bSFmKr6IVBoQ=",
|
| 12 |
-
"datamove-flat-copy.wgsl.jinja": "g9d62mer2bmHfbScqX5CIT5Zq/Pdinac0W2dH0CD+5s=",
|
| 13 |
-
"manifest.json": "+Usru7gIdbn3QHB+vilQ+g0jcJ8vXzf96tvLyxEt2Dc=",
|
| 14 |
-
"test.json": "cqLDgFIMIi7+k/IB4GxldotjPttDxEfK7yBwVBFJbSk="
|
| 15 |
-
}
|
| 16 |
-
},
|
| 17 |
-
"provenance": { "kernel": { "sha": "6fdf6301e2bbcc2f03bf1eaf493b7ad55ef33afc", "dirty": false } },
|
| 18 |
-
"webgpu": {
|
| 19 |
-
"manifestSpec": "2.1",
|
| 20 |
-
"variants": { "copy_vec4": ["datamove-flat-copy.wgsl.jinja"], "copy": ["datamove-elementwise-copy.wgsl.jinja"] }
|
| 21 |
-
}
|
| 22 |
-
}
|
|
|
|
| 1 |
+
{"name":"ai.onnx.Unsqueeze","id":"_ai_onnx_unsqueeze_webgpu_3ce5bd3","version":1,"license":"Apache-2.0","backend":{"type":"webgpu"},"digest":{"algorithm":"sha256","files":{"bench.json":"70cGk/A0yhfuRCQX6XqqX02QupHfOPOQGtMPW0uXhX0=","datamove-elementwise-copy.wgsl.jinja":"Q1WuZCqcDf9b6cbT4rLilpeWj6327t/bSFmKr6IVBoQ=","datamove-flat-copy.wgsl.jinja":"g9d62mer2bmHfbScqX5CIT5Zq/Pdinac0W2dH0CD+5s=","manifest.json":"/eQnu3y8bbVbF2tlsQhuMi7dYy1Qbe/g0ApP10lp5Ok=","test.json":"ZWKjGs2raYX8oQVb4RN7VMp27NQO6vl93TGk+4XWGCE="}},"provenance":{"kernel":{"sha":"4385228f788ddaa1bd7aec6a80a20f3ddffd8011","dirty":false}},"webgpu":{"manifestSpec":"2.2"}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/webgpu/test.json
CHANGED
|
@@ -33,7 +33,9 @@
|
|
| 33 |
},
|
| 34 |
{
|
| 35 |
"name": "f32_copy_vec4_4096",
|
| 36 |
-
"provenance": {
|
|
|
|
|
|
|
| 37 |
"inputs": {
|
| 38 |
"data": {
|
| 39 |
"dtype": "float32",
|
|
@@ -473,9 +475,7 @@
|
|
| 473 |
},
|
| 474 |
{
|
| 475 |
"name": "f32_vec4_copy_1024",
|
| 476 |
-
"provenance": {
|
| 477 |
-
"notes": "A small aligned float32 payload exercises vectorized copying while inserting outer and trailing unit axes."
|
| 478 |
-
},
|
| 479 |
"inputs": {
|
| 480 |
"data": {
|
| 481 |
"dtype": "float32",
|
|
|
|
| 33 |
},
|
| 34 |
{
|
| 35 |
"name": "f32_copy_vec4_4096",
|
| 36 |
+
"provenance": {
|
| 37 |
+
"notes": "A float32 [4096] input unsqueezed at axes [0,2] to [1,4096,1]; 4096 is a multiple of four."
|
| 38 |
+
},
|
| 39 |
"inputs": {
|
| 40 |
"data": {
|
| 41 |
"dtype": "float32",
|
|
|
|
| 475 |
},
|
| 476 |
{
|
| 477 |
"name": "f32_vec4_copy_1024",
|
| 478 |
+
"provenance": { "notes": "A float32 [1024] input unsqueezed at axes [0,2] to [1,1024,1]." },
|
|
|
|
|
|
|
| 479 |
"inputs": {
|
| 480 |
"data": {
|
| 481 |
"dtype": "float32",
|