File size: 10,348 Bytes
5ce7237
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
{
  "op": "com.microsoft.MRotaryEmbedding",
  "fixtureArrays": {
    "ort_sectioned_rank3_input_x": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
  },
  "cases": [
    {
      "name": "rank4_odd_head_even_partial_rotation",
      "provenance": {
        "source": "onnxruntime/contrib_ops/cuda/bert/mrotary_embedding_impl.cu",
        "notes": "The provider requires the effective rotary dimension, not the full head size, to be even. The singleton tail element is copied unchanged."
      },
      "attrs": {
        "num_heads": 1,
        "rotary_embedding_dim": 4,
        "mrope_layout": 0,
        "interleaved": 0,
        "mrope_section": [1, 1, 0]
      },
      "inputs": {
        "x": { "dtype": "float32", "shape": [1, 1, 2, 5], "data": { "kind": "linspace", "start": -1.25, "end": 1.5 } },
        "positionIds": {
          "dtype": "uint32",
          "shape": [3, 1, 2],
          "data": { "kind": "values", "values": [0, 1, 1, 2, 2, 0] }
        },
        "cos": { "dtype": "float32", "shape": [3, 2], "data": { "kind": "linspace", "start": 0.25, "end": 1.0 } },
        "sin": { "dtype": "float32", "shape": [3, 2], "data": { "kind": "linspace", "start": -0.5, "end": 0.5 } }
      },
      "outputs": { "y": { "dtype": "float32", "shape": [1, 1, 2, 5], "tolerance": 0.00001 } }
    },
    {
      "name": "ort_sectioned_rank3",
      "provenance": {
        "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
        "test": "ContribOpMRotaryEmbeddingTest.SectionedRank3",
        "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."
      },
      "attrs": {
        "num_heads": 2,
        "rotary_embedding_dim": 6,
        "mrope_layout": 0,
        "interleaved": 0,
        "scale": 1,
        "mrope_section": [1, 1, 1]
      },
      "inputs": {
        "x": {
          "dtype": "float32",
          "shape": [1, 2, 12],
          "data": { "kind": "values", "values": { "$ref": "#/fixtureArrays/ort_sectioned_rank3_input_x" } }
        },
        "positionIds": {
          "dtype": "uint32",
          "shape": [3, 1, 2],
          "data": { "kind": "values", "values": [0, 1, 1, 2, 2, 3] }
        },
        "cos": {
          "dtype": "float32",
          "shape": [4, 3],
          "data": { "kind": "values", "values": [1.0, 1.01, 1.02, 1.1, 1.11, 1.12, 1.2, 1.21, 1.22, 1.3, 1.31, 1.32] }
        },
        "sin": {
          "dtype": "float32",
          "shape": [4, 3],
          "data": { "kind": "values", "values": [0.1, 0.11, 0.12, 0.15, 0.16, 0.17, 0.2, 0.21, 0.22, 0.25, 0.26, 0.27] }
        }
      },
      "outputs": {
        "y": {
          "dtype": "float32",
          "shape": [1, 2, 12],
          "tolerance": 0.00001,
          "data": {
            "kind": "values",
            "values": [0.6, 1.42, 2.34, 4.1, 5.87, 7.98, 6.0, 7.12, 8.34, 10.7, 13.49, 16.62, 11.9, 13.37, 14.94, 19.55, 23.51, 27.81, 17.6, 19.37, 21.24, 27.05, 32.03, 37.35]
          }
        }
      }
    },
    {
      "name": "ort_interleaved_rank4",
      "provenance": {
        "source": "onnxruntime/test/contrib_ops/mrotary_embedding_op_test.cc",
        "test": "ContribOpMRotaryEmbeddingTest.InterleavedRank4",
        "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."
      },
      "attrs": {
        "num_heads": 2,
        "rotary_embedding_dim": 6,
        "mrope_layout": 1,
        "interleaved": 1,
        "scale": 0.5,
        "mrope_section": [1, 1, 1]
      },
      "inputs": {
        "x": {
          "dtype": "float32",
          "shape": [1, 2, 2, 6],
          "data": { "kind": "values", "values": { "$ref": "#/fixtureArrays/ort_sectioned_rank3_input_x" } }
        },
        "positionIds": {
          "dtype": "uint32",
          "shape": [3, 1, 2],
          "data": { "kind": "values", "values": [0, 1, 1, 2, 2, 3] }
        },
        "cos": {
          "dtype": "float32",
          "shape": [4, 3],
          "data": { "kind": "values", "values": [1.0, 1.01, 1.02, 1.1, 1.11, 1.12, 1.2, 1.21, 1.22, 1.3, 1.31, 1.32] }
        },
        "sin": {
          "dtype": "float32",
          "shape": [4, 3],
          "data": { "kind": "values", "values": [0.1, 0.11, 0.12, 0.15, 0.16, 0.17, 0.2, 0.21, 0.22, 0.25, 0.26, 0.27] }
        }
      },
      "outputs": {
        "y": {
          "dtype": "float32",
          "shape": [1, 2, 2, 6],
          "tolerance": 0.00001,
          "data": {
            "kind": "values",
            "values": [0.4, 1.05, 1.345, 2.46, 2.39, 4.21, 3.25, 4.925, 4.395, 6.995, 5.64, 9.405, 5.8, 7.65, 7.045, 10.08, 8.39, 12.85, 8.95, 12.425, 10.395, 15.515, 11.94, 18.945]
          }
        }
      }
    },
    {
      "name": "rank3_layout1_interleaved0",
      "provenance": {
        "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."
      },
      "attrs": {
        "num_heads": 4,
        "rotary_embedding_dim": 0,
        "mrope_layout": 1,
        "interleaved": 0,
        "scale": 1,
        "mrope_section": [2, 1, 1]
      },
      "inputs": {
        "x": { "dtype": "float32", "shape": [2, 3, 32], "data": { "kind": "linspace", "start": -2.0, "end": 2.0 } },
        "positionIds": {
          "dtype": "uint32",
          "shape": [3, 2, 3],
          "data": { "kind": "values", "values": [0, 1, 2, 1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7] }
        },
        "cos": { "dtype": "float32", "shape": [8, 4], "data": { "kind": "linspace", "start": -1.0, "end": 1.0 } },
        "sin": { "dtype": "float32", "shape": [8, 4], "data": { "kind": "linspace", "start": 1.0, "end": -1.0 } }
      },
      "outputs": { "y": { "dtype": "float32", "shape": [2, 3, 32], "tolerance": 0.00001, "relTolerance": 0.00001 } }
    },
    {
      "name": "rank4_layout0_partial_rotary_tail",
      "provenance": {
        "notes": "Sectioned layout with rotary_embedding_dim < head_size, so the lanes past the rotary window copy their tail values unchanged."
      },
      "attrs": {
        "num_heads": 2,
        "rotary_embedding_dim": 8,
        "mrope_layout": 0,
        "interleaved": 0,
        "scale": 1,
        "mrope_section": [1, 2, 1]
      },
      "inputs": {
        "x": { "dtype": "float32", "shape": [1, 2, 4, 12], "data": { "kind": "linspace", "start": -2.0, "end": 2.0 } },
        "positionIds": {
          "dtype": "uint32",
          "shape": [3, 1, 4],
          "data": { "kind": "values", "values": [0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5] }
        },
        "cos": { "dtype": "float32", "shape": [6, 4], "data": { "kind": "linspace", "start": -1.0, "end": 1.0 } },
        "sin": { "dtype": "float32", "shape": [6, 4], "data": { "kind": "linspace", "start": 1.0, "end": -1.0 } }
      },
      "outputs": { "y": { "dtype": "float32", "shape": [1, 2, 4, 12], "tolerance": 0.00001, "relTolerance": 0.00001 } }
    },
    {
      "name": "rank3_text_only_streams_collapse",
      "provenance": {
        "notes": "Text-only tokens set T == H == W, which ORT documents as reducing M-RoPE to standard RoPE; the section split must then become unobservable."
      },
      "attrs": { "num_heads": 2, "mrope_section": [2, 1, 1] },
      "inputs": {
        "x": { "dtype": "float32", "shape": [1, 4, 16], "data": { "kind": "linspace", "start": -2.0, "end": 2.0 } },
        "positionIds": {
          "dtype": "uint32",
          "shape": [3, 1, 4],
          "data": { "kind": "values", "values": [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3] }
        },
        "cos": { "dtype": "float32", "shape": [8, 4], "data": { "kind": "linspace", "start": -1.0, "end": 1.0 } },
        "sin": { "dtype": "float32", "shape": [8, 4], "data": { "kind": "linspace", "start": 1.0, "end": -1.0 } }
      },
      "outputs": { "y": { "dtype": "float32", "shape": [1, 4, 16], "tolerance": 0.00001, "relTolerance": 0.00001 } }
    },
    {
      "name": "f16_rank4_layout1_interleaved",
      "provenance": {
        "notes": "f16 storage, including the provider's T-rounded scaled-cache intermediate, on the interleaved layout and pairing."
      },
      "attrs": {
        "rotary_embedding_dim": 0,
        "mrope_layout": 1,
        "interleaved": 1,
        "scale": 0.3,
        "mrope_section": [2, 2, 2]
      },
      "inputs": {
        "x": { "dtype": "float16", "shape": [1, 2, 3, 12], "data": { "kind": "linspace", "start": -2.0, "end": 2.0 } },
        "positionIds": {
          "dtype": "uint32",
          "shape": [3, 1, 3],
          "data": { "kind": "values", "values": [0, 1, 2, 1, 2, 3, 2, 3, 4] }
        },
        "cos": { "dtype": "float16", "shape": [6, 6], "data": { "kind": "linspace", "start": -1.0, "end": 1.0 } },
        "sin": { "dtype": "float16", "shape": [6, 6], "data": { "kind": "linspace", "start": 1.0, "end": -1.0 } }
      },
      "outputs": { "y": { "dtype": "float16", "shape": [1, 2, 3, 12], "tolerance": 0.01, "relTolerance": 0.01 } }
    },
    {
      "name": "rank3_scale_half_sectioned",
      "provenance": { "notes": "Non-unit scale on the sectioned layout; scale multiplies both gathered cos and sin." },
      "attrs": {
        "num_heads": 2,
        "rotary_embedding_dim": 0,
        "mrope_layout": 0,
        "interleaved": 0,
        "scale": 0.5,
        "mrope_section": [1, 1, 2]
      },
      "inputs": {
        "x": { "dtype": "float32", "shape": [2, 2, 16], "data": { "kind": "linspace", "start": -2.0, "end": 2.0 } },
        "positionIds": {
          "dtype": "uint32",
          "shape": [3, 2, 2],
          "data": { "kind": "values", "values": [0, 1, 1, 2, 2, 3, 3, 4, 4, 0, 0, 1] }
        },
        "cos": { "dtype": "float32", "shape": [5, 4], "data": { "kind": "linspace", "start": -1.0, "end": 1.0 } },
        "sin": { "dtype": "float32", "shape": [5, 4], "data": { "kind": "linspace", "start": 1.0, "end": -1.0 } }
      },
      "outputs": { "y": { "dtype": "float32", "shape": [2, 2, 16], "tolerance": 0.00001, "relTolerance": 0.00001 } }
    }
  ]
}