Xenova HF Staff commited on
Commit
12f8f33
·
verified ·
1 Parent(s): 88a09b2

sync 91d990483a17

Browse files
README.md CHANGED
@@ -18,15 +18,15 @@ See the [ONNX `Identity` spec](https://onnx.ai/onnx/operators/onnx__Identity.htm
18
 
19
  ## Inputs
20
 
21
- | Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
22
  | --- | --- | --- | --- | --- | --- | --- |
23
- | `input` | `x` | `T` | — | — | Input tensor to be copied. | required |
24
 
25
  ## Outputs
26
 
27
- | Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
28
  | --- | --- | --- | --- | --- | --- | --- |
29
- | `output` | `y` | `T` | same as `input` | same as `input` | Output tensor; an exact copy of the input. | required |
30
 
31
  ## Type constraints
32
 
@@ -36,7 +36,7 @@ See the [ONNX `Identity` spec](https://onnx.ai/onnx/operators/onnx__Identity.htm
36
 
37
  ## Files
38
 
39
- - [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, provenance)
40
  - [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)
41
  - [`test.json`](build/webgpu/test.json) — correctness cases
42
  - [`bench.json`](build/webgpu/bench.json) — benchmark + tuning cases
@@ -45,10 +45,14 @@ See the [ONNX `Identity` spec](https://onnx.ai/onnx/operators/onnx__Identity.htm
45
 
46
  ## Use with `@huggingface/kernels`
47
 
48
- The loader derives every required output's shape and logical dtype from the manifest contract and this call.
49
- It then allocates the result tensors automatically.
 
 
 
50
 
51
  The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.
 
52
 
53
  Replace each `*Data` placeholder with a typed array containing the corresponding input data.
54
 
 
18
 
19
  ## Inputs
20
 
21
+ | Name | Upstream name | Logical dtype | Rank | Shape | Description | Presence |
22
  | --- | --- | --- | --- | --- | --- | --- |
23
+ | `x` | `input` | `T` | — | — | Input tensor to be copied. | required |
24
 
25
  ## Outputs
26
 
27
+ | Name | Upstream name | Logical dtype | Rank | Shape | Description | Presence |
28
  | --- | --- | --- | --- | --- | --- | --- |
29
+ | `y` | `output` | `T` | same as `x` | same as `x` | Output tensor; an exact copy of the input. | required |
30
 
31
  ## Type constraints
32
 
 
36
 
37
  ## Files
38
 
39
+ - [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, per-variant templates, provenance)
40
  - [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)
41
  - [`test.json`](build/webgpu/test.json) — correctness cases
42
  - [`bench.json`](build/webgpu/bench.json) — benchmark + tuning cases
 
45
 
46
  ## Use with `@huggingface/kernels`
47
 
48
+ ```sh
49
+ npm install --save-exact @huggingface/kernels@0.0.1-preview.2
50
+ ```
51
+
52
+ Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.
53
 
54
  The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.
55
+ It follows the `v1` branch as fixes land. To pin exact artifact bytes, pass a 40-character commit `revision` instead of `version`.
56
 
57
  Replace each `*Data` placeholder with a typed array containing the corresponding input data.
58
 
build/webgpu/bench.json CHANGED
@@ -1,5 +1,4 @@
1
  {
2
- "op": "ai.onnx.Identity",
3
  "tunableSpace": { "WORKGROUP_SIZE": [64, 128, 256] },
4
  "cases": [
5
  {
 
1
  {
 
2
  "tunableSpace": { "WORKGROUP_SIZE": [64, 128, 256] },
3
  "cases": [
4
  {
build/webgpu/datamove-elementwise-copy.wgsl.jinja CHANGED
@@ -1,6 +1,3 @@
1
- {% if usesF16 %}
2
- enable f16;
3
- {% endif %}
4
  {{ env.wgsl.resourceDeclarations }}
5
 
6
  const WG: u32 = {{ tunables.WORKGROUP_SIZE }}u;
 
 
 
 
1
  {{ env.wgsl.resourceDeclarations }}
2
 
3
  const WG: u32 = {{ tunables.WORKGROUP_SIZE }}u;
build/webgpu/datamove-flat-copy.wgsl.jinja CHANGED
@@ -1,9 +1,6 @@
1
- {% if usesF16 %}
2
- enable f16;
3
- {% endif %}
4
  {{ env.wgsl.resourceDeclarations }}
5
 
6
- const COUNT: u32 = {{ source.count }}u;
7
  const WG: u32 = {{ tunables.WORKGROUP_SIZE }}u;
8
 
9
  @compute @workgroup_size({{ tunables.WORKGROUP_SIZE }})
 
 
 
 
1
  {{ env.wgsl.resourceDeclarations }}
2
 
3
+ const COUNT: u32 = {{ count }}u;
4
  const WG: u32 = {{ tunables.WORKGROUP_SIZE }}u;
5
 
6
  @compute @workgroup_size({{ tunables.WORKGROUP_SIZE }})
build/webgpu/manifest.json CHANGED
@@ -2,87 +2,54 @@
2
  "domain": "ai.onnx",
3
  "name": "Identity",
4
  "sinceVersion": 16,
5
- "description": "Copies the input tensor to the output unchanged. The output has the same shape, dtype, and values as the input.",
6
- "inputs": [{ "role": "input", "dtype": "T", "description": "Input tensor to be copied." }],
7
- "outputs": [
8
- {
9
- "role": "output",
10
- "dtype": "T",
11
- "rank": "ranks.input",
12
- "description": "Output tensor; an exact copy of the input.",
13
- "shape": "shapes.input"
14
- }
15
- ],
16
  "typeConstraints": { "T": ["float32", "float16", "uint32", "int32", "int16", "uint8", "int8", "bool"] },
17
- "args": {
18
- "x": { "kind": "tensor", "semantic": "input", "role": "input" },
19
- "y": { "kind": "tensor", "semantic": "output", "role": "output" }
20
- },
21
- "tunables": { "WORKGROUP_SIZE": 256 },
22
- "constants": { "usesF16": "dtypes.T == \"f16\"" },
23
  "variants": [
24
  {
25
  "id": "copy_vec4",
26
  "priority": 20,
27
- "when": ["numel(shapes.input) > 0", "numel(shapes.input) % 4 == 0", "numel(shapes.input) == numel(shapes.output)", "f16Ok(dtypes.T)"],
28
- "constants": { "vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"", "COPY_VEC4_LEN": "numel(shapes.output) / 4" },
29
  "passes": [
30
  {
31
  "id": "main",
32
  "name": "Identity.copyVec4",
33
- "source": { "shader": "datamove-flat-copy.wgsl.jinja", "inputs": { "count": "numel(shapes.output) / 4" } },
 
34
  "bindings": [
35
- {
36
- "name": "src",
37
- "arg": "x",
38
- "semantic": "input",
39
- "buffer": { "type": "read-only-storage" },
40
- "elementType": "$vectorScalar",
41
- "length": "$COPY_VEC4_LEN"
42
- },
43
- {
44
- "name": "dst",
45
- "arg": "y",
46
- "semantic": "output",
47
- "buffer": { "type": "storage" },
48
- "elementType": "$vectorScalar",
49
- "length": "$COPY_VEC4_LEN"
50
- }
51
  ],
52
- "dispatch": { "gridStride": "numel(shapes.output) / 4", "workgroupSize": "tunables.WORKGROUP_SIZE" },
 
 
 
 
53
  "viewAlias": [{ "input": "src", "output": "dst" }]
54
  }
55
  ]
56
  },
57
  {
58
  "id": "copy",
59
- "when": "numel(shapes.input) == numel(shapes.output) and (f16Ok(dtypes.T))",
60
- "constants": { "scalar": "dtypes.T" },
61
  "passes": [
62
  {
63
  "id": "main",
64
  "name": "Identity",
65
  "shader": "datamove-elementwise-copy.wgsl.jinja",
66
  "bindings": [
67
- {
68
- "name": "x",
69
- "arg": "x",
70
- "semantic": "input",
71
- "buffer": { "type": "read-only-storage" },
72
- "elementType": "$scalar"
73
- },
74
- { "name": "y", "arg": "y", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "$scalar" },
75
- {
76
- "name": "params",
77
- "semantic": "kernel.params",
78
- "buffer": { "type": "uniform" },
79
- "struct": {
80
- "name": "Params",
81
- "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.output)" }]
82
- }
83
- }
84
  ],
85
- "dispatch": { "gridStride": "numel(shapes.output)", "workgroupSize": "tunables.WORKGROUP_SIZE" },
 
 
 
 
86
  "viewAlias": [{ "input": "x", "output": "y" }]
87
  }
88
  ]
 
2
  "domain": "ai.onnx",
3
  "name": "Identity",
4
  "sinceVersion": 16,
5
+ "inputs": { "x": { "onnx": "input", "dtype": "T" } },
6
+ "outputs": { "y": { "onnx": "output", "dtype": "T", "rank": "ranks.x", "shape": "shapes.x" } },
 
 
 
 
 
 
 
 
 
7
  "typeConstraints": { "T": ["float32", "float16", "uint32", "int32", "int16", "uint8", "int8", "bool"] },
8
+ "tunables": { "WORKGROUP_SIZE": { "default": 256 } },
 
 
 
 
 
9
  "variants": [
10
  {
11
  "id": "copy_vec4",
12
  "priority": 20,
13
+ "when": ["numel(shapes.x) > 0", "numel(shapes.x) % 4 == 0", "numel(shapes.x) == numel(shapes.y)", "f16Ok(dtypes.T)"],
14
+ "derive": { "vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"", "COPY_VEC4_LEN": "numel(shapes.y) / 4" },
15
  "passes": [
16
  {
17
  "id": "main",
18
  "name": "Identity.copyVec4",
19
+ "shader": "datamove-flat-copy.wgsl.jinja",
20
+ "derive": { "count": "numel(shapes.y) / 4" },
21
  "bindings": [
22
+ { "arg": "x", "name": "src", "elementType": "$vectorScalar", "length": "$COPY_VEC4_LEN" },
23
+ { "arg": "y", "name": "dst", "elementType": "$vectorScalar", "length": "$COPY_VEC4_LEN" }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  ],
25
+ "dispatch": {
26
+ "x": "min(ceilDiv((numel(shapes.y) / 4), (tunables.WORKGROUP_SIZE)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))",
27
+ "y": 1,
28
+ "z": 1
29
+ },
30
  "viewAlias": [{ "input": "src", "output": "dst" }]
31
  }
32
  ]
33
  },
34
  {
35
  "id": "copy",
36
+ "when": ["numel(shapes.x) == numel(shapes.y) and (f16Ok(dtypes.T))"],
37
+ "derive": { "scalar": "dtypes.T" },
38
  "passes": [
39
  {
40
  "id": "main",
41
  "name": "Identity",
42
  "shader": "datamove-elementwise-copy.wgsl.jinja",
43
  "bindings": [
44
+ { "arg": "x", "elementType": "$scalar" },
45
+ { "arg": "y", "elementType": "$scalar" },
46
+ { "name": "params", "struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.y)" }] }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  ],
48
+ "dispatch": {
49
+ "x": "min(ceilDiv((numel(shapes.y)), (tunables.WORKGROUP_SIZE)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))",
50
+ "y": 1,
51
+ "z": 1
52
+ },
53
  "viewAlias": [{ "input": "x", "output": "y" }]
54
  }
55
  ]
build/webgpu/metadata.json CHANGED
@@ -1,19 +1,22 @@
1
  {
2
  "name": "ai.onnx.Identity",
3
- "id": "_ai_onnx_identity_webgpu_ead6cd9",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "backend": { "type": "webgpu" },
7
  "digest": {
8
  "algorithm": "sha256",
9
  "files": {
10
- "bench.json": "iqLD60NoNy/WX0qdR5TO8/AK4j21dKyPOFD317acAH4=",
11
- "datamove-elementwise-copy.wgsl.jinja": "J5yC2bAddPiP+odXLgVGS3TJ9jeNsfRTvedKrj/fhZg=",
12
- "datamove-flat-copy.wgsl.jinja": "rEpeYMvIZQuQnB2f3lt51jrrklKICsqUTzCJPRTknNk=",
13
- "manifest.json": "reU3MC1V59I8kks+xwBlyge3ffTsAigWVsSR94J5+cY=",
14
- "test.json": "OFNAvELh9Hoap8iYTP7wEbReNVAlq3vq5wb82eROxcw="
15
  }
16
  },
17
- "provenance": { "kernel": { "sha": "2e7068faf55e7f43df740015f6d1ee49391a41c5", "dirty": false } },
18
- "webgpu": { "manifestSpec": "1.0", "specialized": true, "opPath": "ops/ai.onnx.Identity" }
 
 
 
19
  }
 
1
  {
2
  "name": "ai.onnx.Identity",
3
+ "id": "_ai_onnx_identity_webgpu_f578b50",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "backend": { "type": "webgpu" },
7
  "digest": {
8
  "algorithm": "sha256",
9
  "files": {
10
+ "bench.json": "EVWfSP81aiFZ0xNYpLvVUq3/kK1LLSxDhF0Ffh5Fz+A=",
11
+ "datamove-elementwise-copy.wgsl.jinja": "Q1WuZCqcDf9b6cbT4rLilpeWj6327t/bSFmKr6IVBoQ=",
12
+ "datamove-flat-copy.wgsl.jinja": "g9d62mer2bmHfbScqX5CIT5Zq/Pdinac0W2dH0CD+5s=",
13
+ "manifest.json": "Vg1Au59nMKZWSPXZvjRJsIALZRD1XRK9J2807gUTPqc=",
14
+ "test.json": "E/LdbK/rDuOL94nr1xgWIiyQDZd73hX1JGqJI5Xoyfc="
15
  }
16
  },
17
+ "provenance": { "kernel": { "sha": "91d990483a174128daf7673f3f37a7c890493ae1", "dirty": false } },
18
+ "webgpu": {
19
+ "manifestSpec": "2.0",
20
+ "variants": { "copy_vec4": ["datamove-flat-copy.wgsl.jinja"], "copy": ["datamove-elementwise-copy.wgsl.jinja"] }
21
+ }
22
  }
build/webgpu/test.json CHANGED
@@ -1,5 +1,4 @@
1
  {
2
- "op": "ai.onnx.Identity",
3
  "cases": [
4
  {
5
  "name": "int16_copy_boundaries",
 
1
  {
 
2
  "cases": [
3
  {
4
  "name": "int16_copy_boundaries",