Xenova HF Staff commited on
Commit
0fc11f4
·
verified ·
1 Parent(s): 8929c9c

sync 4385228f788d

Browse files
README.md CHANGED
@@ -60,30 +60,46 @@ One implementation is selected per call from the device capabilities, the reques
60
 
61
  ## Files
62
 
63
- - [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, per-variant templates, provenance)
64
- - [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)
65
- - [`test.json`](build/webgpu/test.json) — correctness cases
66
- - [`bench.json`](build/webgpu/bench.json) — benchmark cases
67
- - [`mrotary-embedding-vector.wgsl.jinja`](build/webgpu/mrotary-embedding-vector.wgsl.jinja)
68
- - [`mrotary-embedding.wgsl.jinja`](build/webgpu/mrotary-embedding.wgsl.jinja)
69
 
70
  ## Use with `@huggingface/kernels`
71
 
72
  ```sh
73
- npm install --save-exact @huggingface/kernels@0.0.1-preview.3
74
  ```
75
 
 
 
76
  Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.
77
 
78
  The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.
79
  It follows the `v1` branch as fixes land. To pin exact artifact bytes, pass a 40-character commit `revision` instead of `version`.
80
 
81
- Replace each `*Data` placeholder with a typed array containing the corresponding input data.
82
-
83
  ```js
84
  import { getKernel } from "@huggingface/kernels";
85
 
86
  const kernel = await getKernel("webgpu-kernels/com.microsoft.MRotaryEmbedding", { version: 1 });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  const { y } = await kernel({
88
  x: { data: xData, shape: [2, 2, 16] },
89
  positionIds: { data: positionIdsData, shape: [3, 2, 2] },
@@ -92,4 +108,5 @@ const { y } = await kernel({
92
  }, {
93
  attrs: { num_heads: 2, mrope_section: [2, 1, 1] },
94
  });
 
95
  ```
 
60
 
61
  ## Files
62
 
63
+ - [`metadata.json`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.MRotaryEmbedding/blob/v1/build/webgpu/metadata.json) — kernel metadata (id, file digests, manifest spec, provenance)
64
+ - [`manifest.json`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.MRotaryEmbedding/blob/v1/build/webgpu/manifest.json) — the op contract (source of truth)
65
+ - [`test.json`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.MRotaryEmbedding/blob/v1/build/webgpu/test.json) — correctness cases
66
+ - [`bench.json`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.MRotaryEmbedding/blob/v1/build/webgpu/bench.json) — benchmark cases
67
+ - [`mrotary-embedding-vector.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.MRotaryEmbedding/blob/v1/build/webgpu/mrotary-embedding-vector.wgsl.jinja)
68
+ - [`mrotary-embedding.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.MRotaryEmbedding/blob/v1/build/webgpu/mrotary-embedding.wgsl.jinja)
69
 
70
  ## Use with `@huggingface/kernels`
71
 
72
  ```sh
73
+ npm install --save-exact @huggingface/kernels@0.0.1-preview.4
74
  ```
75
 
76
+ Paste the example into a browser app that resolves npm imports. Serve the app over HTTPS or localhost with WebGPU available.
77
+
78
  Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.
79
 
80
  The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.
81
  It follows the `v1` branch as fixes land. To pin exact artifact bytes, pass a 40-character commit `revision` instead of `version`.
82
 
 
 
83
  ```js
84
  import { getKernel } from "@huggingface/kernels";
85
 
86
  const kernel = await getKernel("webgpu-kernels/com.microsoft.MRotaryEmbedding", { version: 1 });
87
+
88
+ const xData = Float32Array.of(
89
+ -2, -1.9365079, -1.8730159, -1.8095238, -1.7460318, -1.6825397, -1.6190476, -1.5555556,
90
+ -1.4920635, -1.4285715, -1.3650794, -1.3015873, -1.2380953, -1.1746032, -1.1111112,
91
+ -1.0476191, -0.984127, -0.9206349, -0.85714287, -0.7936508, -0.73015875, -0.6666667,
92
+ -0.6031746, -0.53968257, -0.47619048, -0.41269842, -0.34920636, -0.2857143,
93
+ -0.22222222, -0.15873016, -0.0952381, -0.031746034, 0.031746034, 0.0952381, 0.15873016,
94
+ 0.22222222, 0.2857143, 0.34920636, 0.41269842, 0.47619048, 0.53968257, 0.6031746,
95
+ 0.6666667, 0.73015875, 0.7936508, 0.85714287, 0.9206349, 0.984127, 1.0476191,
96
+ 1.1111112, 1.1746032, 1.2380953, 1.3015873, 1.3650794, 1.4285715, 1.4920635, 1.5555556,
97
+ 1.6190476, 1.6825397, 1.7460318, 1.8095238, 1.8730159, 1.9365079, 2,
98
+ );
99
+ const positionIdsData = Int32Array.of(-1, 0, 1, 2, 0, -1, 2, 1, 2, 1, 0, -1);
100
+ const cosData = Float32Array.of(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8);
101
+ const sinData = Float32Array.of(-0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1);
102
+
103
  const { y } = await kernel({
104
  x: { data: xData, shape: [2, 2, 16] },
105
  positionIds: { data: positionIdsData, shape: [3, 2, 2] },
 
108
  }, {
109
  attrs: { num_heads: 2, mrope_section: [2, 1, 1] },
110
  });
111
+ console.log({ y });
112
  ```
build/webgpu/bench.json CHANGED
@@ -112,7 +112,7 @@
112
  "vars": { "elems": 1024, "rotPairs": 512 },
113
  "provenance": {
114
  "model": "Qwen/Qwen3-VL-2B-Instruct",
115
- "notes": "Same layer's key projection: 8 kv heads, so half the query work and the smallest dispatch M-RoPE sees in decode."
116
  },
117
  "inputs": {
118
  "x": { "shape": [1, 8, 1, 128], "dtype": "float32", "dist": "normal", "seed": 1000, "scale": 0.2 },
@@ -146,7 +146,7 @@
146
  "vars": { "elems": 1048576, "rotPairs": 524288 },
147
  "provenance": {
148
  "model": "Qwen/Qwen2.5-VL-3B-Instruct",
149
- "notes": "Qwen2.5-VL sectioned M-RoPE, mrope_section [16, 24, 24]. The sectioned branch reads three contiguous chunks where the interleaved branch strides by 3, so the two layouts have different cache access patterns at the same shape."
150
  },
151
  "inputs": {
152
  "x": { "shape": [1, 16, 512, 128], "dtype": "float32", "dist": "normal", "seed": 1000, "scale": 0.2 },
 
112
  "vars": { "elems": 1024, "rotPairs": 512 },
113
  "provenance": {
114
  "model": "Qwen/Qwen3-VL-2B-Instruct",
115
+ "notes": "Same layer's key projection: 8 kv heads (half the query's head count), one decoded token."
116
  },
117
  "inputs": {
118
  "x": { "shape": [1, 8, 1, 128], "dtype": "float32", "dist": "normal", "seed": 1000, "scale": 0.2 },
 
146
  "vars": { "elems": 1048576, "rotPairs": 524288 },
147
  "provenance": {
148
  "model": "Qwen/Qwen2.5-VL-3B-Instruct",
149
+ "notes": "Qwen2.5-VL sectioned M-RoPE, mrope_section [16, 24, 24], over 16 query heads of head_dim 128 for a 512-token prefill."
150
  },
151
  "inputs": {
152
  "x": { "shape": [1, 16, 512, 128], "dtype": "float32", "dist": "normal", "seed": 1000, "scale": 0.2 },
build/webgpu/manifest.json CHANGED
@@ -1,134 +1 @@
1
- {
2
- "domain": "com.microsoft",
3
- "name": "MRotaryEmbedding",
4
- "sinceVersion": 1,
5
- "inputs": {
6
- "x": { "onnx": "input", "dtype": "T" },
7
- "positionIds": { "onnx": "position_ids", "dtype": "M", "rank": 3, "storage": "int32", "narrowing": "saturating" },
8
- "cos": { "onnx": "cos_cache", "dtype": "T", "rank": 2 },
9
- "sin": { "onnx": "sin_cache", "dtype": "T", "rank": 2 }
10
- },
11
- "outputs": { "y": { "onnx": "output", "dtype": "T", "rank": "ranks.x", "shape": "shapes.x" } },
12
- "attributes": {
13
- "interleaved": { "default": 0 },
14
- "is_packed_batching": { "default": 0 },
15
- "mrope_layout": { "default": 0 },
16
- "num_heads": { "default": 0 },
17
- "rotary_embedding_dim": { "default": 0 },
18
- "scale": { "default": 1 },
19
- "mrope_section": {}
20
- },
21
- "attributeConstraints": {
22
- "interleaved": { "values": [0, 1] },
23
- "is_packed_batching": { "values": [0] },
24
- "mrope_layout": { "values": [0, 1] },
25
- "mrope_section": { "required": true }
26
- },
27
- "typeConstraints": { "T": ["float32", "float16"], "M": ["int64"] },
28
- "tunables": { "WORKGROUP_SIZE": { "default": 256 } },
29
- "derive": {
30
- "rank3HeadSize": "dim(shapes.x, 2) / attrs.num_heads if attrs.num_heads is defined and attrs.num_heads > 0 else 0",
31
- "headSize": "rank3HeadSize if ranks.x == 3 else dim(shapes.x, 3)",
32
- "effectiveRotaryDim": "attrs.rotary_embedding_dim if attrs.rotary_embedding_dim != 0 else headSize",
33
- "tasksPerHead": "ceilDiv(headSize, 2)",
34
- "pairCount": "(numel(shapes.x) / max(1, headSize)) * tasksPerHead",
35
- "pairDispatchOk": "ceilDiv(pairCount, tunables.WORKGROUP_SIZE) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) * min(device.limits.maxComputeWorkgroupsPerDimension, 65535)",
36
- "halfRotaryDim": "dim(shapes.cos, 1)",
37
- "sectionsDefined": "attrs.mrope_section is defined and (attrs.mrope_section | length) == 3",
38
- "sectionsValid": "sectionsDefined and attrs.mrope_section[0] >= 0 and attrs.mrope_section[1] >= 0 and attrs.mrope_section[2] >= 0 and attrs.mrope_section[0] + attrs.mrope_section[1] + attrs.mrope_section[2] == halfRotaryDim",
39
- "commonContract": "f16Ok(dtypes.T) and sameShape(shapes.x, shapes.y) and (attrs.interleaved == 0 or attrs.interleaved == 1) and (attrs.mrope_layout == 0 or attrs.mrope_layout == 1) and attrs.num_heads >= 0 and attrs.rotary_embedding_dim >= 0 and (attrs.rotary_embedding_dim == 0 or attrs.num_heads > 0) and sameShape(shapes.cos, shapes.sin) and ranks.cos == 2 and ranks.sin == 2 and sectionsValid and ranks.positionIds == 3 and dim(shapes.positionIds, 0) == 3 and dim(shapes.positionIds, 1) == dim(shapes.x, 0) and dim(shapes.positionIds, 2) == dim(shapes.x, 1 if ranks.x == 3 else 2)",
40
- "rank3Contract": "commonContract and ranks.x == 3 and ranks.y == 3 and attrs.num_heads is defined and attrs.num_heads >= 1 and dim(shapes.x, 2) % attrs.num_heads == 0 and (rank3HeadSize > 0 or numel(shapes.x) == 0) and effectiveRotaryDim % 2 == 0 and (attrs.rotary_embedding_dim == 0 or attrs.rotary_embedding_dim <= rank3HeadSize) and halfRotaryDim * 2 == effectiveRotaryDim",
41
- "rank4Contract": "commonContract and ranks.x == 4 and ranks.y == 4 and dim(shapes.x, 3) > 0 and effectiveRotaryDim % 2 == 0 and (attrs.rotary_embedding_dim == 0 or attrs.rotary_embedding_dim <= dim(shapes.x, 3)) and halfRotaryDim * 2 == effectiveRotaryDim"
42
- },
43
- "when": ["pairDispatchOk", "rank3Contract or rank4Contract"],
44
- "bindings": {
45
- "x": { "elementType": "$T" },
46
- "position_ids": { "arg": "positionIds", "elementType": "i32" },
47
- "cos_cache": { "arg": "cos", "elementType": "$T" },
48
- "sin_cache": { "arg": "sin", "elementType": "$T" },
49
- "y": { "elementType": "$T" },
50
- "params": {
51
- "struct": [
52
- { "name": "pairCount", "type": "u32", "value": "pairCount" },
53
- { "name": "batchSize", "type": "u32", "value": "dim(shapes.x, 0)" },
54
- { "name": "sequenceLength", "type": "u32", "value": "dim(shapes.x, 1 if ranks.x == 3 else 2)" },
55
- { "name": "numHeads", "type": "u32", "value": "attrs.num_heads if ranks.x == 3 else dim(shapes.x, 1)" },
56
- { "name": "headSize", "type": "u32", "value": "headSize" },
57
- { "name": "rotaryDim", "type": "u32", "value": "halfRotaryDim * 2" },
58
- { "name": "halfRotaryDim", "type": "u32", "value": "halfRotaryDim" },
59
- { "name": "section0", "type": "u32", "value": "attrs.mrope_section[0]" },
60
- { "name": "section1", "type": "u32", "value": "attrs.mrope_section[1]" },
61
- { "name": "section2", "type": "u32", "value": "attrs.mrope_section[2]" },
62
- { "name": "scale", "type": "f32", "value": "attrs.scale" },
63
- { "name": "maxSequenceLength", "type": "u32", "value": "dim(shapes.cos, 0)" }
64
- ]
65
- },
66
- "x_vector": { "arg": "x", "name": "x", "elementType": "$vectorScalar" },
67
- "y_vector": { "arg": "y", "name": "y", "elementType": "$vectorScalar" },
68
- "params_vector": {
69
- "struct": [
70
- { "name": "pairCount", "type": "u32", "value": "pairCount" },
71
- { "name": "batchSize", "type": "u32", "value": "dim(shapes.x, 0)" },
72
- { "name": "sequenceLength", "type": "u32", "value": "dim(shapes.x, 1 if ranks.x == 3 else 2)" },
73
- { "name": "numHeads", "type": "u32", "value": "attrs.num_heads if ranks.x == 3 else dim(shapes.x, 1)" },
74
- { "name": "headSize", "type": "u32", "value": "headSize" },
75
- { "name": "halfRotaryDim", "type": "u32", "value": "halfRotaryDim" },
76
- { "name": "section0", "type": "u32", "value": "attrs.mrope_section[0]" },
77
- { "name": "section1", "type": "u32", "value": "attrs.mrope_section[1]" },
78
- { "name": "section2", "type": "u32", "value": "attrs.mrope_section[2]" },
79
- { "name": "scale", "type": "f32", "value": "attrs.scale" },
80
- { "name": "maxSequenceLength", "type": "u32", "value": "dim(shapes.cos, 0)" }
81
- ],
82
- "name": "params"
83
- }
84
- },
85
- "variants": [
86
- {
87
- "id": "pairs4",
88
- "when": ["headSize % 8 == 0", "effectiveRotaryDim == headSize", "attrs.interleaved == 0"],
89
- "derive": {
90
- "mropeSectioned": "attrs.mrope_layout == 0",
91
- "pairWidth": "4",
92
- "vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"",
93
- "scalar": "dtypes.T"
94
- },
95
- "passes": [
96
- {
97
- "id": "main",
98
- "name": "MRotaryEmbedding.Vector",
99
- "shader": "mrotary-embedding-vector.wgsl.jinja",
100
- "derive": { "rank": "ranks.x" },
101
- "bindings": ["x_vector", "position_ids", "cos_cache", "sin_cache", "y_vector", "params_vector"],
102
- "dispatch": {
103
- "x": "min(ceilDiv((pairCount / 4), (tunables.WORKGROUP_SIZE)), 65535)",
104
- "y": "ceilDiv(ceilDiv((pairCount / 4), (tunables.WORKGROUP_SIZE)), 65535)",
105
- "z": 1
106
- }
107
- }
108
- ],
109
- "priority": 10
110
- },
111
- {
112
- "id": "pairs",
113
- "derive": {
114
- "interleaved": "attrs.interleaved != 0",
115
- "mropeSectioned": "attrs.mrope_layout == 0",
116
- "scalar": "dtypes.T"
117
- },
118
- "passes": [
119
- {
120
- "id": "main",
121
- "name": "MRotaryEmbedding",
122
- "shader": "mrotary-embedding.wgsl.jinja",
123
- "derive": { "rank": "ranks.x" },
124
- "bindings": ["x", "position_ids", "cos_cache", "sin_cache", "y", "params"],
125
- "dispatch": {
126
- "x": "min(ceilDiv((pairCount), (tunables.WORKGROUP_SIZE)), 65535)",
127
- "y": "ceilDiv(ceilDiv((pairCount), (tunables.WORKGROUP_SIZE)), 65535)",
128
- "z": 1
129
- }
130
- }
131
- ]
132
- }
133
- ]
134
- }
 
1
+ {"domain":"com.microsoft","name":"MRotaryEmbedding","sinceVersion":1,"inputs":{"x":{"onnx":"input","dtype":"T"},"positionIds":{"onnx":"position_ids","dtype":"M","rank":3,"storage":"int32","narrowing":"saturating"},"cos":{"onnx":"cos_cache","dtype":"T","rank":2},"sin":{"onnx":"sin_cache","dtype":"T","rank":2}},"outputs":{"y":{"onnx":"output","dtype":"T","rank":"ranks.x","shape":"shapes.x"}},"attributes":{"interleaved":{"default":0},"is_packed_batching":{"default":0},"mrope_layout":{"default":0},"num_heads":{"default":0},"rotary_embedding_dim":{"default":0},"scale":{"default":1},"mrope_section":{}},"attributeConstraints":{"interleaved":{"values":[0,1]},"is_packed_batching":{"values":[0]},"mrope_layout":{"values":[0,1]},"mrope_section":{"required":true}},"typeConstraints":{"T":["float32","float16"],"M":["int64"]},"tunables":{"WORKGROUP_SIZE":{"default":256}},"derive":{"rank3HeadSize":"dim(shapes.x, 2) / attrs.num_heads if attrs.num_heads is defined and attrs.num_heads > 0 else 0","headSize":"rank3HeadSize if ranks.x == 3 else dim(shapes.x, 3)","effectiveRotaryDim":"attrs.rotary_embedding_dim if attrs.rotary_embedding_dim != 0 else headSize","tasksPerHead":"ceilDiv(headSize, 2)","pairCount":"(numel(shapes.x) / max(1, headSize)) * tasksPerHead","pairDispatchOk":"ceilDiv(pairCount, tunables.WORKGROUP_SIZE) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) * min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","halfRotaryDim":"dim(shapes.cos, 1)","sectionsDefined":"attrs.mrope_section is defined and (attrs.mrope_section | length) == 3","sectionsValid":"sectionsDefined and attrs.mrope_section[0] >= 0 and attrs.mrope_section[1] >= 0 and attrs.mrope_section[2] >= 0 and attrs.mrope_section[0] + attrs.mrope_section[1] + attrs.mrope_section[2] == halfRotaryDim","commonContract":"f16Ok(dtypes.T) and sameShape(shapes.x, shapes.y) and (attrs.interleaved == 0 or attrs.interleaved == 1) and (attrs.mrope_layout == 0 or attrs.mrope_layout == 1) and attrs.num_heads >= 0 and attrs.rotary_embedding_dim >= 0 and (attrs.rotary_embedding_dim == 0 or attrs.num_heads > 0) and sameShape(shapes.cos, shapes.sin) and ranks.cos == 2 and ranks.sin == 2 and sectionsValid and ranks.positionIds == 3 and dim(shapes.positionIds, 0) == 3 and dim(shapes.positionIds, 1) == dim(shapes.x, 0) and dim(shapes.positionIds, 2) == dim(shapes.x, 1 if ranks.x == 3 else 2)","rank3Contract":"commonContract and ranks.x == 3 and ranks.y == 3 and attrs.num_heads is defined and attrs.num_heads >= 1 and dim(shapes.x, 2) % attrs.num_heads == 0 and (rank3HeadSize > 0 or numel(shapes.x) == 0) and effectiveRotaryDim % 2 == 0 and (attrs.rotary_embedding_dim == 0 or attrs.rotary_embedding_dim <= rank3HeadSize) and halfRotaryDim * 2 == effectiveRotaryDim","rank4Contract":"commonContract and ranks.x == 4 and ranks.y == 4 and dim(shapes.x, 3) > 0 and effectiveRotaryDim % 2 == 0 and (attrs.rotary_embedding_dim == 0 or attrs.rotary_embedding_dim <= dim(shapes.x, 3)) and halfRotaryDim * 2 == effectiveRotaryDim"},"when":["pairDispatchOk","rank3Contract or rank4Contract"],"bindings":{"x":{"elementType":"$T"},"position_ids":{"arg":"positionIds","elementType":"i32"},"cos_cache":{"arg":"cos","elementType":"$T"},"sin_cache":{"arg":"sin","elementType":"$T"},"y":{"elementType":"$T"},"params":{"struct":[{"name":"pairCount","type":"u32","value":"pairCount"},{"name":"batchSize","type":"u32","value":"dim(shapes.x, 0)"},{"name":"sequenceLength","type":"u32","value":"dim(shapes.x, 1 if ranks.x == 3 else 2)"},{"name":"numHeads","type":"u32","value":"attrs.num_heads if ranks.x == 3 else dim(shapes.x, 1)"},{"name":"headSize","type":"u32","value":"headSize"},{"name":"rotaryDim","type":"u32","value":"halfRotaryDim * 2"},{"name":"halfRotaryDim","type":"u32","value":"halfRotaryDim"},{"name":"section0","type":"u32","value":"attrs.mrope_section[0]"},{"name":"section1","type":"u32","value":"attrs.mrope_section[1]"},{"name":"section2","type":"u32","value":"attrs.mrope_section[2]"},{"name":"scale","type":"f32","value":"attrs.scale"},{"name":"maxSequenceLength","type":"u32","value":"dim(shapes.cos, 0)"}]},"x_vector":{"arg":"x","name":"x","elementType":"$vectorScalar"},"y_vector":{"arg":"y","name":"y","elementType":"$vectorScalar"},"params_vector":{"struct":[{"name":"pairCount","type":"u32","value":"pairCount"},{"name":"batchSize","type":"u32","value":"dim(shapes.x, 0)"},{"name":"sequenceLength","type":"u32","value":"dim(shapes.x, 1 if ranks.x == 3 else 2)"},{"name":"numHeads","type":"u32","value":"attrs.num_heads if ranks.x == 3 else dim(shapes.x, 1)"},{"name":"headSize","type":"u32","value":"headSize"},{"name":"halfRotaryDim","type":"u32","value":"halfRotaryDim"},{"name":"section0","type":"u32","value":"attrs.mrope_section[0]"},{"name":"section1","type":"u32","value":"attrs.mrope_section[1]"},{"name":"section2","type":"u32","value":"attrs.mrope_section[2]"},{"name":"scale","type":"f32","value":"attrs.scale"},{"name":"maxSequenceLength","type":"u32","value":"dim(shapes.cos, 0)"}],"name":"params"}},"variants":[{"id":"pairs4","when":["headSize % 8 == 0","effectiveRotaryDim == headSize","attrs.interleaved == 0"],"derive":{"mropeSectioned":"attrs.mrope_layout == 0","pairWidth":"4","vectorScalar":"\"vec4<\" ~ dtypes.T ~ \">\"","scalar":"dtypes.T"},"passes":[{"id":"main","name":"MRotaryEmbedding.Vector","shader":"mrotary-embedding-vector.wgsl.jinja","derive":{"rank":"ranks.x"},"bindings":["x_vector","position_ids","cos_cache","sin_cache","y_vector","params_vector"],"dispatch":{"x":"min(ceilDiv((pairCount / 4), (tunables.WORKGROUP_SIZE)), 65535)","y":"ceilDiv(ceilDiv((pairCount / 4), (tunables.WORKGROUP_SIZE)), 65535)","z":1}}],"priority":10},{"id":"pairs","derive":{"interleaved":"attrs.interleaved != 0","mropeSectioned":"attrs.mrope_layout == 0","scalar":"dtypes.T"},"passes":[{"id":"main","name":"MRotaryEmbedding","shader":"mrotary-embedding.wgsl.jinja","derive":{"rank":"ranks.x"},"bindings":["x","position_ids","cos_cache","sin_cache","y","params"],"dispatch":{"x":"min(ceilDiv((pairCount), (tunables.WORKGROUP_SIZE)), 65535)","y":"ceilDiv(ceilDiv((pairCount), (tunables.WORKGROUP_SIZE)), 65535)","z":1}}]}]}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
build/webgpu/metadata.json CHANGED
@@ -1,22 +1 @@
1
- {
2
- "name": "com.microsoft.MRotaryEmbedding",
3
- "id": "_com_microsoft_mrotaryembedding_webgpu_9f14b3e",
4
- "version": 1,
5
- "license": "Apache-2.0",
6
- "backend": { "type": "webgpu" },
7
- "digest": {
8
- "algorithm": "sha256",
9
- "files": {
10
- "bench.json": "O2zNl+WongpRuCa+0uG2J/53uKtH0dOeHjs0V/SP5NQ=",
11
- "manifest.json": "m6PieJLI+fSwIhyAV5llQg4PcQyE9OtvRC0w/Z3jOy0=",
12
- "mrotary-embedding-vector.wgsl.jinja": "MZwbSQREHhZKFMGn1YC7CJATkbgtimGoPwdnzafMOn8=",
13
- "mrotary-embedding.wgsl.jinja": "bMGNQWBiANeYtK1oQO0dRJjn/JwkB8ZTu/Zw/uKW2M4=",
14
- "test.json": "TLcimbROUuwC6I8+3L/QcPyKX9brKS3g2eH68BRDfqI="
15
- }
16
- },
17
- "provenance": { "kernel": { "sha": "6fdf6301e2bbcc2f03bf1eaf493b7ad55ef33afc", "dirty": false } },
18
- "webgpu": {
19
- "manifestSpec": "2.1",
20
- "variants": { "pairs4": ["mrotary-embedding-vector.wgsl.jinja"], "pairs": ["mrotary-embedding.wgsl.jinja"] }
21
- }
22
- }
 
1
+ {"name":"com.microsoft.MRotaryEmbedding","id":"_com_microsoft_mrotaryembedding_webgpu_11d3b42","version":1,"license":"Apache-2.0","backend":{"type":"webgpu"},"digest":{"algorithm":"sha256","files":{"bench.json":"Fl1tCB9l2RJwgn5DkO/D6WvYuJ3c3NZIxzLFuSgxcjA=","manifest.json":"C9FEdinonRogSSd8PhC1eEVnGwHEsVx+HRrUkALDuX8=","mrotary-embedding-vector.wgsl.jinja":"ANe3C9wcatYdgHH9lL2/gRWNGPaLHWfk9Mnf28OAQgQ=","mrotary-embedding.wgsl.jinja":"brYdsOS/RdiB9eYAE3H/PwVbFDW1cVHgdcigIsj1l04=","test.json":"HrO6JM/91yOQNz9rnXt1QCB3bF6I75tdr1tpxb1DdzI="}},"provenance":{"kernel":{"sha":"4385228f788ddaa1bd7aec6a80a20f3ddffd8011","dirty":false}},"webgpu":{"manifestSpec":"2.2"}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
build/webgpu/mrotary-embedding-vector.wgsl.jinja CHANGED
@@ -23,18 +23,17 @@
23
  let valid{{ suffix }} = pos{{ suffix }} >= 0 && u32(pos{{ suffix }}) < params.maxSequenceLength;
24
  let cache{{ suffix }} = u32(pos{{ suffix }}) * params.halfRotaryDim + {{ pair }};
25
  {% endmacro %}
26
- {% macro flat_index_2d(workgroupSize, name="i", bound="params.count", guardInline=false) %}
27
  {% set wgTerm = workgroupSize ~ "u" if workgroupSize is number else workgroupSize %}
28
  // 2D-folded flat index: gid.y carries the high bits past the dispatch's
29
  // per-axis workgroup fold width.
30
- {% if bound == "" %}
31
- let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};{% elif guardInline %}
32
- let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};
33
- if ({{ name }} >= {{ bound }}) { return; }{% else %}
34
  let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};
 
35
  if ({{ name }} >= {{ bound }}) {
36
  return;
37
- }{% endif %}{% endmacro %}
 
 
38
  {{ env.wgsl.resourceDeclarations }}
39
  // A contiguous vector owns several split-half rotation pairs. Each component
40
  // gathers its own stream position, including vectors crossing section boundaries.
 
23
  let valid{{ suffix }} = pos{{ suffix }} >= 0 && u32(pos{{ suffix }}) < params.maxSequenceLength;
24
  let cache{{ suffix }} = u32(pos{{ suffix }}) * params.halfRotaryDim + {{ pair }};
25
  {% endmacro %}
26
+ {% macro flat_index_2d(workgroupSize, name="i", bound="params.count") %}
27
  {% set wgTerm = workgroupSize ~ "u" if workgroupSize is number else workgroupSize %}
28
  // 2D-folded flat index: gid.y carries the high bits past the dispatch's
29
  // per-axis workgroup fold width.
 
 
 
 
30
  let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};
31
+ {% if bound != "" %}
32
  if ({{ name }} >= {{ bound }}) {
33
  return;
34
+ }
35
+ {% endif %}
36
+ {% endmacro %}
37
  {{ env.wgsl.resourceDeclarations }}
38
  // A contiguous vector owns several split-half rotation pairs. Each component
39
  // gathers its own stream position, including vectors crossing section boundaries.
build/webgpu/mrotary-embedding.wgsl.jinja CHANGED
@@ -23,14 +23,15 @@
23
  let valid{{ suffix }} = pos{{ suffix }} >= 0 && u32(pos{{ suffix }}) < params.maxSequenceLength;
24
  let cache{{ suffix }} = u32(pos{{ suffix }}) * params.halfRotaryDim + {{ pair }};
25
  {% endmacro %}
26
- {% macro flat_index_2d(workgroupSize, name="i", bound="params.count", guardInline=false) %}
27
  {% set wgTerm = workgroupSize ~ "u" if workgroupSize is number else workgroupSize %}
28
  // 2D-folded flat index: gid.y carries the high bits past the dispatch's
29
  // per-axis workgroup fold width.
30
  let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};
31
  if ({{ name }} >= {{ bound }}) {
32
  return;
33
- }{% endmacro %}
 
34
  {{ env.wgsl.resourceDeclarations }}
35
  // M-RoPE: three position streams (temporal, height, width) index one cos/sin cache.
36
  // The half-rotary axis is partitioned among the streams, so each rotated pair picks
 
23
  let valid{{ suffix }} = pos{{ suffix }} >= 0 && u32(pos{{ suffix }}) < params.maxSequenceLength;
24
  let cache{{ suffix }} = u32(pos{{ suffix }}) * params.halfRotaryDim + {{ pair }};
25
  {% endmacro %}
26
+ {% macro flat_index_2d(workgroupSize, name="i", bound="params.count") %}
27
  {% set wgTerm = workgroupSize ~ "u" if workgroupSize is number else workgroupSize %}
28
  // 2D-folded flat index: gid.y carries the high bits past the dispatch's
29
  // per-axis workgroup fold width.
30
  let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};
31
  if ({{ name }} >= {{ bound }}) {
32
  return;
33
+ }
34
+ {% endmacro %}
35
  {{ env.wgsl.resourceDeclarations }}
36
  // M-RoPE: three position streams (temporal, height, width) index one cos/sin cache.
37
  // The half-rotary axis is partitioned among the streams, so each rotated pair picks
build/webgpu/test.json CHANGED
@@ -35,7 +35,7 @@
35
  "provenance": {
36
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
37
  "test": "ContribOpMRotaryEmbeddingTest.SectionedRank3",
38
- "notes": "Pinned from ORT. Sectioned layout over three one-column sections, so each cache column is fed by a different position stream (T=[0,1], H=[1,2], W=[2,3]) and a stream mix-up changes every output."
39
  },
40
  "attrs": {
41
  "num_heads": 2,
@@ -81,7 +81,7 @@
81
  "provenance": {
82
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
83
  "test": "ContribOpMRotaryEmbeddingTest.InterleavedRank4",
84
- "notes": "Pinned from ORT. Interleaved mrope_layout together with interleaved rotation pairing and a non-unit scale, so the two independent 'interleaved' knobs and the scale are exercised at once."
85
  },
86
  "attrs": {
87
  "num_heads": 2,
@@ -125,7 +125,7 @@
125
  {
126
  "name": "rank3_layout1_interleaved0",
127
  "provenance": {
128
- "notes": "Interleaved mrope_layout with the split (non-interleaved) rotation pairing — the layout/pairing knobs are independent, and this is the combination neither pinned case covers."
129
  },
130
  "attrs": {
131
  "num_heads": 4,
@@ -150,7 +150,7 @@
150
  {
151
  "name": "rank4_layout0_partial_rotary_tail",
152
  "provenance": {
153
- "notes": "Sectioned layout with rotary_embedding_dim < head_size, so the lanes past the rotary window copy their tail values unchanged."
154
  },
155
  "attrs": {
156
  "num_heads": 2,
@@ -180,11 +180,7 @@
180
  "attrs": { "num_heads": 2, "mrope_section": [2, 1, 1] },
181
  "inputs": {
182
  "x": { "dtype": "float32", "shape": [1, 4, 16], "data": { "kind": "linspace", "start": -2.0, "end": 2.0 } },
183
- "positionIds": {
184
- "dtype": "int32",
185
- "shape": [3, 1, 4],
186
- "data": { "kind": "values", "values": [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3] }
187
- },
188
  "cos": { "dtype": "float32", "shape": [8, 4], "data": { "kind": "linspace", "start": -1.0, "end": 1.0 } },
189
  "sin": { "dtype": "float32", "shape": [8, 4], "data": { "kind": "linspace", "start": 1.0, "end": -1.0 } }
190
  },
@@ -271,7 +267,7 @@
271
  },
272
  "outputs": { "y": { "dtype": "float32", "shape": [2, 5, 24], "tolerance": 0.00001, "relTolerance": 0.00001 } },
273
  "provenance": {
274
- "notes": "Aligned vector pairs with a partial final workgroup, section-crossing cache columns, multiple batches, non-unit scale and both tensor ranks. Zero temporal section is covered at the smallest head width."
275
  }
276
  },
277
  {
@@ -308,7 +304,7 @@
308
  },
309
  "outputs": { "y": { "dtype": "float32", "shape": [2, 5, 48], "tolerance": 0.00001, "relTolerance": 0.00001 } },
310
  "provenance": {
311
- "notes": "Aligned vector pairs with a partial final workgroup, section-crossing cache columns, multiple batches, non-unit scale and both tensor ranks. Zero temporal section is covered at the smallest head width."
312
  }
313
  },
314
  {
@@ -345,7 +341,7 @@
345
  },
346
  "outputs": { "y": { "dtype": "float32", "shape": [2, 5, 72], "tolerance": 0.00001, "relTolerance": 0.00001 } },
347
  "provenance": {
348
- "notes": "Aligned vector pairs with a partial final workgroup, section-crossing cache columns, multiple batches, non-unit scale and both tensor ranks. Zero temporal section is covered at the smallest head width."
349
  }
350
  },
351
  {
@@ -382,7 +378,7 @@
382
  },
383
  "outputs": { "y": { "dtype": "float32", "shape": [2, 3, 5, 8], "tolerance": 0.00001, "relTolerance": 0.00001 } },
384
  "provenance": {
385
- "notes": "Aligned vector pairs with a partial final workgroup, section-crossing cache columns, multiple batches, non-unit scale and both tensor ranks. Zero temporal section is covered at the smallest head width."
386
  }
387
  },
388
  {
@@ -419,7 +415,7 @@
419
  },
420
  "outputs": { "y": { "dtype": "float32", "shape": [2, 3, 5, 16], "tolerance": 0.00001, "relTolerance": 0.00001 } },
421
  "provenance": {
422
- "notes": "Aligned vector pairs with a partial final workgroup, section-crossing cache columns, multiple batches, non-unit scale and both tensor ranks. Zero temporal section is covered at the smallest head width."
423
  }
424
  },
425
  {
@@ -456,7 +452,7 @@
456
  },
457
  "outputs": { "y": { "dtype": "float32", "shape": [2, 3, 5, 24], "tolerance": 0.00001, "relTolerance": 0.00001 } },
458
  "provenance": {
459
- "notes": "Aligned vector pairs with a partial final workgroup, section-crossing cache columns, multiple batches, non-unit scale and both tensor ranks. Zero temporal section is covered at the smallest head width."
460
  }
461
  },
462
  {
@@ -493,7 +489,7 @@
493
  },
494
  "outputs": { "y": { "dtype": "float16", "shape": [2, 5, 24], "tolerance": 0.01, "relTolerance": 0.01 } },
495
  "provenance": {
496
- "notes": "Aligned vector pairs with a partial final workgroup, section-crossing cache columns, multiple batches, non-unit scale and both tensor ranks. Zero temporal section is covered at the smallest head width."
497
  }
498
  },
499
  {
@@ -530,7 +526,7 @@
530
  },
531
  "outputs": { "y": { "dtype": "float16", "shape": [2, 5, 48], "tolerance": 0.01, "relTolerance": 0.01 } },
532
  "provenance": {
533
- "notes": "Aligned vector pairs with a partial final workgroup, section-crossing cache columns, multiple batches, non-unit scale and both tensor ranks. Zero temporal section is covered at the smallest head width."
534
  }
535
  },
536
  {
@@ -567,7 +563,7 @@
567
  },
568
  "outputs": { "y": { "dtype": "float16", "shape": [2, 5, 72], "tolerance": 0.01, "relTolerance": 0.01 } },
569
  "provenance": {
570
- "notes": "Aligned vector pairs with a partial final workgroup, section-crossing cache columns, multiple batches, non-unit scale and both tensor ranks. Zero temporal section is covered at the smallest head width."
571
  }
572
  },
573
  {
@@ -604,7 +600,7 @@
604
  },
605
  "outputs": { "y": { "dtype": "float16", "shape": [2, 3, 5, 8], "tolerance": 0.01, "relTolerance": 0.01 } },
606
  "provenance": {
607
- "notes": "Aligned vector pairs with a partial final workgroup, section-crossing cache columns, multiple batches, non-unit scale and both tensor ranks. Zero temporal section is covered at the smallest head width."
608
  }
609
  },
610
  {
@@ -641,7 +637,7 @@
641
  },
642
  "outputs": { "y": { "dtype": "float16", "shape": [2, 3, 5, 16], "tolerance": 0.01, "relTolerance": 0.01 } },
643
  "provenance": {
644
- "notes": "Aligned vector pairs with a partial final workgroup, section-crossing cache columns, multiple batches, non-unit scale and both tensor ranks. Zero temporal section is covered at the smallest head width."
645
  }
646
  },
647
  {
@@ -678,7 +674,7 @@
678
  },
679
  "outputs": { "y": { "dtype": "float16", "shape": [2, 3, 5, 24], "tolerance": 0.01, "relTolerance": 0.01 } },
680
  "provenance": {
681
- "notes": "Aligned vector pairs with a partial final workgroup, section-crossing cache columns, multiple batches, non-unit scale and both tensor ranks. Zero temporal section is covered at the smallest head width."
682
  }
683
  },
684
  {
@@ -698,16 +694,8 @@
698
  "data": { "kind": "values", "values": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0] }
699
  },
700
  "positionIds": { "dtype": "int32", "shape": [3, 1, 1], "data": { "kind": "values", "values": [0, 0, 0] } },
701
- "cos": {
702
- "dtype": "float32",
703
- "shape": [4, 3],
704
- "data": { "kind": "values", "values": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] }
705
- },
706
- "sin": {
707
- "dtype": "float32",
708
- "shape": [4, 3],
709
- "data": { "kind": "values", "values": [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] }
710
- }
711
  },
712
  "outputs": { "y": { "dtype": "float32", "shape": [1, 1, 8], "tolerance": 0.000001, "relTolerance": 0.000001 } }
713
  },
@@ -828,7 +816,7 @@
828
  "provenance": {
829
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
830
  "test": "PositionIdsOOBPassthroughAllStreams",
831
- "notes": "Each invalid stream copies only its own rotation pair. Values outside int32 are saturated by the host projection."
832
  },
833
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
834
  "inputs": {
@@ -854,7 +842,7 @@
854
  "provenance": {
855
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
856
  "test": "PositionIdsOOBPassthroughAllStreams",
857
- "notes": "Each invalid stream copies only its own rotation pair. Values outside int32 are saturated by the host projection."
858
  },
859
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
860
  "inputs": {
@@ -880,7 +868,7 @@
880
  "provenance": {
881
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
882
  "test": "PositionIdsOOBPassthroughAllStreams",
883
- "notes": "Each invalid stream copies only its own rotation pair. Values outside int32 are saturated by the host projection."
884
  },
885
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
886
  "inputs": {
@@ -910,7 +898,7 @@
910
  "provenance": {
911
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
912
  "test": "PositionIdsOOBPassthroughAllStreams",
913
- "notes": "Each invalid stream copies only its own rotation pair. Values outside int32 are saturated by the host projection."
914
  },
915
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
916
  "inputs": {
@@ -940,7 +928,7 @@
940
  "provenance": {
941
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
942
  "test": "PositionIdsOOBPassthroughAllStreams",
943
- "notes": "Each invalid stream copies only its own rotation pair. Values outside int32 are saturated by the host projection."
944
  },
945
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
946
  "inputs": {
@@ -966,7 +954,7 @@
966
  "provenance": {
967
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
968
  "test": "PositionIdsOOBPassthroughAllStreams",
969
- "notes": "Each invalid stream copies only its own rotation pair. Values outside int32 are saturated by the host projection."
970
  },
971
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
972
  "inputs": {
@@ -992,7 +980,7 @@
992
  "provenance": {
993
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
994
  "test": "PositionIdsOOBPassthroughAllStreams",
995
- "notes": "Each invalid stream copies only its own rotation pair. Values outside int32 are saturated by the host projection."
996
  },
997
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
998
  "inputs": {
@@ -1022,7 +1010,7 @@
1022
  "provenance": {
1023
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
1024
  "test": "PositionIdsOOBPassthroughAllStreams",
1025
- "notes": "Each invalid stream copies only its own rotation pair. Values outside int32 are saturated by the host projection."
1026
  },
1027
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
1028
  "inputs": {
@@ -1052,7 +1040,7 @@
1052
  "provenance": {
1053
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
1054
  "test": "PositionIdsOOBPassthroughAllStreams",
1055
- "notes": "Each invalid stream copies only its own rotation pair. Values outside int32 are saturated by the host projection."
1056
  },
1057
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
1058
  "inputs": {
@@ -1078,7 +1066,7 @@
1078
  "provenance": {
1079
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
1080
  "test": "PositionIdsOOBPassthroughAllStreams",
1081
- "notes": "Each invalid stream copies only its own rotation pair. Values outside int32 are saturated by the host projection."
1082
  },
1083
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
1084
  "inputs": {
@@ -1104,7 +1092,7 @@
1104
  "provenance": {
1105
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
1106
  "test": "PositionIdsOOBPassthroughAllStreams",
1107
- "notes": "Each invalid stream copies only its own rotation pair. Values outside int32 are saturated by the host projection."
1108
  },
1109
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
1110
  "inputs": {
@@ -1134,7 +1122,7 @@
1134
  "provenance": {
1135
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
1136
  "test": "PositionIdsOOBPassthroughAllStreams",
1137
- "notes": "Each invalid stream copies only its own rotation pair. Values outside int32 are saturated by the host projection."
1138
  },
1139
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
1140
  "inputs": {
 
35
  "provenance": {
36
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
37
  "test": "ContribOpMRotaryEmbeddingTest.SectionedRank3",
38
+ "notes": "Expected values from ORT. Sectioned layout over three one-column sections, so each cache column is fed by a different position stream (T=[0,1], H=[1,2], W=[2,3]) and a stream mix-up changes every output."
39
  },
40
  "attrs": {
41
  "num_heads": 2,
 
81
  "provenance": {
82
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
83
  "test": "ContribOpMRotaryEmbeddingTest.InterleavedRank4",
84
+ "notes": "Expected values from ORT. Interleaved mrope_layout together with interleaved rotation pairing and a non-unit scale, so the two independent 'interleaved' settings and the scale are exercised at once."
85
  },
86
  "attrs": {
87
  "num_heads": 2,
 
125
  {
126
  "name": "rank3_layout1_interleaved0",
127
  "provenance": {
128
+ "notes": "Interleaved mrope_layout with the split (non-interleaved) rotation pairing — the layout and pairing settings are independent, and this is the combination neither ORT-derived case covers."
129
  },
130
  "attrs": {
131
  "num_heads": 4,
 
150
  {
151
  "name": "rank4_layout0_partial_rotary_tail",
152
  "provenance": {
153
+ "notes": "Sectioned layout with rotary_embedding_dim < head_size, so the four elements past the rotary window are copied unchanged."
154
  },
155
  "attrs": {
156
  "num_heads": 2,
 
180
  "attrs": { "num_heads": 2, "mrope_section": [2, 1, 1] },
181
  "inputs": {
182
  "x": { "dtype": "float32", "shape": [1, 4, 16], "data": { "kind": "linspace", "start": -2.0, "end": 2.0 } },
183
+ "positionIds": { "dtype": "int32", "shape": [3, 1, 4], "data": { "kind": "cycle", "values": [0, 1, 2, 3] } },
 
 
 
 
184
  "cos": { "dtype": "float32", "shape": [8, 4], "data": { "kind": "linspace", "start": -1.0, "end": 1.0 } },
185
  "sin": { "dtype": "float32", "shape": [8, 4], "data": { "kind": "linspace", "start": 1.0, "end": -1.0 } }
186
  },
 
267
  },
268
  "outputs": { "y": { "dtype": "float32", "shape": [2, 5, 24], "tolerance": 0.00001, "relTolerance": 0.00001 } },
269
  "provenance": {
270
+ "notes": "Rotary dimension 8 over 3 heads (the whole head rotates), batch 2 and 5 positions, float32 rank-3 [batch, tokens, hidden] input, sectioned layout, mrope_section [0, 3, 1] over 4 cache columns, scale 0.3. The temporal section is empty."
271
  }
272
  },
273
  {
 
304
  },
305
  "outputs": { "y": { "dtype": "float32", "shape": [2, 5, 48], "tolerance": 0.00001, "relTolerance": 0.00001 } },
306
  "provenance": {
307
+ "notes": "Rotary dimension 16 over 3 heads (the whole head rotates), batch 2 and 5 positions, float32 rank-3 [batch, tokens, hidden] input, sectioned layout, mrope_section [1, 2, 5] over 8 cache columns, scale 0.3."
308
  }
309
  },
310
  {
 
341
  },
342
  "outputs": { "y": { "dtype": "float32", "shape": [2, 5, 72], "tolerance": 0.00001, "relTolerance": 0.00001 } },
343
  "provenance": {
344
+ "notes": "Rotary dimension 24 over 3 heads (the whole head rotates), batch 2 and 5 positions, float32 rank-3 [batch, tokens, hidden] input, sectioned layout, mrope_section [1, 2, 9] over 12 cache columns, scale 0.3."
345
  }
346
  },
347
  {
 
378
  },
379
  "outputs": { "y": { "dtype": "float32", "shape": [2, 3, 5, 8], "tolerance": 0.00001, "relTolerance": 0.00001 } },
380
  "provenance": {
381
+ "notes": "Rotary dimension 8 over 3 heads (the whole head rotates), batch 2 and 5 positions, float32 rank-4 [batch, heads, tokens, head] input, interleaved layout, mrope_section [0, 3, 1] over 4 cache columns, scale 0.3. The temporal section is empty."
382
  }
383
  },
384
  {
 
415
  },
416
  "outputs": { "y": { "dtype": "float32", "shape": [2, 3, 5, 16], "tolerance": 0.00001, "relTolerance": 0.00001 } },
417
  "provenance": {
418
+ "notes": "Rotary dimension 16 over 3 heads (the whole head rotates), batch 2 and 5 positions, float32 rank-4 [batch, heads, tokens, head] input, interleaved layout, mrope_section [1, 2, 5] over 8 cache columns, scale 0.3."
419
  }
420
  },
421
  {
 
452
  },
453
  "outputs": { "y": { "dtype": "float32", "shape": [2, 3, 5, 24], "tolerance": 0.00001, "relTolerance": 0.00001 } },
454
  "provenance": {
455
+ "notes": "Rotary dimension 24 over 3 heads (the whole head rotates), batch 2 and 5 positions, float32 rank-4 [batch, heads, tokens, head] input, interleaved layout, mrope_section [1, 2, 9] over 12 cache columns, scale 0.3."
456
  }
457
  },
458
  {
 
489
  },
490
  "outputs": { "y": { "dtype": "float16", "shape": [2, 5, 24], "tolerance": 0.01, "relTolerance": 0.01 } },
491
  "provenance": {
492
+ "notes": "Rotary dimension 8 over 3 heads (the whole head rotates), batch 2 and 5 positions, float16 rank-3 [batch, tokens, hidden] input, sectioned layout, mrope_section [0, 3, 1] over 4 cache columns, scale 0.3. The temporal section is empty."
493
  }
494
  },
495
  {
 
526
  },
527
  "outputs": { "y": { "dtype": "float16", "shape": [2, 5, 48], "tolerance": 0.01, "relTolerance": 0.01 } },
528
  "provenance": {
529
+ "notes": "Rotary dimension 16 over 3 heads (the whole head rotates), batch 2 and 5 positions, float16 rank-3 [batch, tokens, hidden] input, sectioned layout, mrope_section [1, 2, 5] over 8 cache columns, scale 0.3."
530
  }
531
  },
532
  {
 
563
  },
564
  "outputs": { "y": { "dtype": "float16", "shape": [2, 5, 72], "tolerance": 0.01, "relTolerance": 0.01 } },
565
  "provenance": {
566
+ "notes": "Rotary dimension 24 over 3 heads (the whole head rotates), batch 2 and 5 positions, float16 rank-3 [batch, tokens, hidden] input, sectioned layout, mrope_section [1, 2, 9] over 12 cache columns, scale 0.3."
567
  }
568
  },
569
  {
 
600
  },
601
  "outputs": { "y": { "dtype": "float16", "shape": [2, 3, 5, 8], "tolerance": 0.01, "relTolerance": 0.01 } },
602
  "provenance": {
603
+ "notes": "Rotary dimension 8 over 3 heads (the whole head rotates), batch 2 and 5 positions, float16 rank-4 [batch, heads, tokens, head] input, interleaved layout, mrope_section [0, 3, 1] over 4 cache columns, scale 0.3. The temporal section is empty."
604
  }
605
  },
606
  {
 
637
  },
638
  "outputs": { "y": { "dtype": "float16", "shape": [2, 3, 5, 16], "tolerance": 0.01, "relTolerance": 0.01 } },
639
  "provenance": {
640
+ "notes": "Rotary dimension 16 over 3 heads (the whole head rotates), batch 2 and 5 positions, float16 rank-4 [batch, heads, tokens, head] input, interleaved layout, mrope_section [1, 2, 5] over 8 cache columns, scale 0.3."
641
  }
642
  },
643
  {
 
674
  },
675
  "outputs": { "y": { "dtype": "float16", "shape": [2, 3, 5, 24], "tolerance": 0.01, "relTolerance": 0.01 } },
676
  "provenance": {
677
+ "notes": "Rotary dimension 24 over 3 heads (the whole head rotates), batch 2 and 5 positions, float16 rank-4 [batch, heads, tokens, head] input, interleaved layout, mrope_section [1, 2, 9] over 12 cache columns, scale 0.3."
678
  }
679
  },
680
  {
 
694
  "data": { "kind": "values", "values": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0] }
695
  },
696
  "positionIds": { "dtype": "int32", "shape": [3, 1, 1], "data": { "kind": "values", "values": [0, 0, 0] } },
697
+ "cos": { "dtype": "float32", "shape": [4, 3], "data": { "kind": "constant", "value": 0.0 } },
698
+ "sin": { "dtype": "float32", "shape": [4, 3], "data": { "kind": "constant", "value": 1.0 } }
 
 
 
 
 
 
 
 
699
  },
700
  "outputs": { "y": { "dtype": "float32", "shape": [1, 1, 8], "tolerance": 0.000001, "relTolerance": 0.000001 } }
701
  },
 
816
  "provenance": {
817
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
818
  "test": "PositionIdsOOBPassthroughAllStreams",
819
+ "notes": "The temporal position id -1 is negative, with the other two streams at 0. The invalid stream copies only its own rotation pair."
820
  },
821
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
822
  "inputs": {
 
842
  "provenance": {
843
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
844
  "test": "PositionIdsOOBPassthroughAllStreams",
845
+ "notes": "The temporal position id 2 equals the cache length of 2, with the other two streams at 0. The invalid stream copies only its own rotation pair."
846
  },
847
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
848
  "inputs": {
 
868
  "provenance": {
869
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
870
  "test": "PositionIdsOOBPassthroughAllStreams",
871
+ "notes": "The temporal position id 2147483647 is the int32 maximum, with the other two streams at 0. The invalid stream copies only its own rotation pair. The saturated values stand in for ids outside the int32 range."
872
  },
873
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
874
  "inputs": {
 
898
  "provenance": {
899
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
900
  "test": "PositionIdsOOBPassthroughAllStreams",
901
+ "notes": "The temporal position id -2147483648 is the int32 minimum, with the other two streams at 0. The invalid stream copies only its own rotation pair. The saturated values stand in for ids outside the int32 range."
902
  },
903
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
904
  "inputs": {
 
928
  "provenance": {
929
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
930
  "test": "PositionIdsOOBPassthroughAllStreams",
931
+ "notes": "The height position id -1 is negative, with the other two streams at 0. The invalid stream copies only its own rotation pair."
932
  },
933
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
934
  "inputs": {
 
954
  "provenance": {
955
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
956
  "test": "PositionIdsOOBPassthroughAllStreams",
957
+ "notes": "The height position id 2 equals the cache length of 2, with the other two streams at 0. The invalid stream copies only its own rotation pair."
958
  },
959
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
960
  "inputs": {
 
980
  "provenance": {
981
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
982
  "test": "PositionIdsOOBPassthroughAllStreams",
983
+ "notes": "The height position id 2147483647 is the int32 maximum, with the other two streams at 0. The invalid stream copies only its own rotation pair. The saturated values stand in for ids outside the int32 range."
984
  },
985
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
986
  "inputs": {
 
1010
  "provenance": {
1011
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
1012
  "test": "PositionIdsOOBPassthroughAllStreams",
1013
+ "notes": "The height position id -2147483648 is the int32 minimum, with the other two streams at 0. The invalid stream copies only its own rotation pair. The saturated values stand in for ids outside the int32 range."
1014
  },
1015
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
1016
  "inputs": {
 
1040
  "provenance": {
1041
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
1042
  "test": "PositionIdsOOBPassthroughAllStreams",
1043
+ "notes": "The width position id -1 is negative, with the other two streams at 0. The invalid stream copies only its own rotation pair."
1044
  },
1045
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
1046
  "inputs": {
 
1066
  "provenance": {
1067
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
1068
  "test": "PositionIdsOOBPassthroughAllStreams",
1069
+ "notes": "The width position id 2 equals the cache length of 2, with the other two streams at 0. The invalid stream copies only its own rotation pair."
1070
  },
1071
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
1072
  "inputs": {
 
1092
  "provenance": {
1093
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
1094
  "test": "PositionIdsOOBPassthroughAllStreams",
1095
+ "notes": "The width position id 2147483647 is the int32 maximum, with the other two streams at 0. The invalid stream copies only its own rotation pair. The saturated values stand in for ids outside the int32 range."
1096
  },
1097
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
1098
  "inputs": {
 
1122
  "provenance": {
1123
  "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
1124
  "test": "PositionIdsOOBPassthroughAllStreams",
1125
+ "notes": "The width position id -2147483648 is the int32 minimum, with the other two streams at 0. The invalid stream copies only its own rotation pair. The saturated values stand in for ids outside the int32 range."
1126
  },
1127
  "attrs": { "num_heads": 1, "rotary_embedding_dim": 6, "mrope_section": [1, 1, 1] },
1128
  "inputs": {