File size: 36,941 Bytes
793c2c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3626d99
 
 
 
793c2c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3626d99
793c2c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
{
  "domain": "com.microsoft",
  "name": "QMoE",
  "sinceVersion": 1,
  "description": "Quantized mixture of experts over float32 activations and raw uint8-packed integer expert weights. The package implements 4- and 8-bit symmetric dequantization, ReLU, and interleaved SwiGLU for rank-2 or rank-3 input. Routing uses the softmax over the selected top-k logits, matching ONNX Runtime QMoE when the omitted `router_weights` input is absent. Biases, explicit zero points, FC3, sparse mixing, provider-prepacked layouts, and FP4/FP8 modes are not implemented.",
  "inputs": [
    {
      "role": "input",
      "dtype": "T",
      "description": "Token activations of shape `(num_tokens, hidden_size)` or `(batch_size, sequence_length, hidden_size)`."
    },
    {
      "role": "router_probs",
      "dtype": "T",
      "rank": 2,
      "description": "Routing logits of shape `(num_tokens, num_experts)`, where `num_tokens` is the product of the leading input dimensions."
    },
    {
      "role": "fc1_experts_weights",
      "dtype": "T1",
      "rank": 3,
      "description": "Raw packed FC1 weights of shape `(num_experts, fusion_size * inter_size, hidden_size / pack_size)`, where `fusion_size` is 2 only for interleaved SwiGLU and `pack_size` is 2 for 4-bit or 1 for 8-bit weights."
    },
    {
      "role": "fc1_scales",
      "dtype": "T2",
      "description": "Required FC1 dequantization scales: rank 2 `(num_experts, fusion_size * inter_size)` for column-wise quantization, or rank 3 with a trailing `hidden_size / block_size` axis."
    },
    {
      "role": "fc2_experts_weights",
      "dtype": "T1",
      "rank": 3,
      "description": "Raw packed FC2 weights of shape `(num_experts, hidden_size, inter_size / pack_size)`."
    },
    {
      "role": "fc2_scales",
      "dtype": "T2",
      "description": "Required FC2 dequantization scales: rank 2 `(num_experts, hidden_size)` for column-wise quantization, or rank 3 with a trailing `inter_size / block_size` axis."
    }
  ],
  "outputs": [
    {
      "role": "output",
      "dtype": "T",
      "shape": "shapes.input",
      "description": "Routed expert output with the same shape as `input`."
    }
  ],
  "attributes": {
    "activation_alpha": 1,
    "activation_beta": 0,
    "activation_type": "relu",
    "expert_weight_bits": 4,
    "k": 1,
    "normalize_routing_weights": 0,
    "quant_type": "int",
    "swiglu_fusion": 0,
    "use_sparse_mixer": 0,
    "weights_prepacked": -1
  },
  "attributeDescriptions": {
    "activation_alpha": "Alpha used by SwiGLU; the exact standard default is 1.",
    "activation_beta": "Beta added to the SwiGLU linear branch; the exact standard default is 0.",
    "activation_type": "Activation applied after FC1. This package supports `relu` and `swiglu`; the exact standard default is `relu`.",
    "block_size": "Optional quantization block size along the reduction dimension. Omission selects column-wise scaling; a supplied value must be a power of two of at least 16 and divide both `hidden_size` and `inter_size`.",
    "expert_weight_bits": "Integer expert-weight bit width. This package supports 4 and 8; the exact standard default is 4.",
    "k": "Number of experts selected per token; the exact standard default is 1.",
    "normalize_routing_weights": "Accepted values are 0 and 1. With the separate `router_weights` input omitted, ONNX Runtime QMoE applies a softmax over the selected top-k logits for either value; the attribute only distinguishes the unsupported separate-weight path.",
    "quant_type": "Quantization family. This package supports only the exact standard default `int`.",
    "swiglu_fusion": "SwiGLU packing mode. ReLU uses the exact standard default 0; supported SwiGLU interleaves gate/up FC1 rows with value 1.",
    "swiglu_limit": "Optional SwiGLU clamp limit. Omission means no finite clamp.",
    "use_sparse_mixer": "Whether to use sparse-mixer routing. The exact standard default and only supported value is 0.",
    "weights_prepacked": "Provider weight-layout selector. Values -1 and 0 both consume the public raw packed tensor layout; provider-specific prepacked value 1 is not portable and is rejected."
  },
  "attributeConstraints": {
    "activation_type": { "values": ["relu", "swiglu"] },
    "expert_weight_bits": { "values": [4, 8] },
    "normalize_routing_weights": { "values": [0, 1] },
    "quant_type": { "values": ["int"] },
    "swiglu_fusion": { "values": [0, 1] },
    "use_sparse_mixer": { "values": [0] },
    "weights_prepacked": { "values": [-1, 0] }
  },
  "typeConstraints": { "T": ["float32"], "T1": ["uint8"], "T2": ["float32"] },
  "args": {
    "inputT": { "kind": "tensor", "semantic": "input", "role": "input" },
    "routerT": { "kind": "tensor", "semantic": "router_probs", "role": "input" },
    "fc1T": { "kind": "tensor", "semantic": "fc1_experts_weights", "role": "input" },
    "fc1ScalesT": { "kind": "tensor", "semantic": "fc1_scales", "role": "input" },
    "fc2T": { "kind": "tensor", "semantic": "fc2_experts_weights", "role": "input" },
    "fc2ScalesT": { "kind": "tensor", "semantic": "fc2_scales", "role": "input" },
    "outputT": { "kind": "tensor", "semantic": "output", "role": "output" }
  },
  "tunables": {
    "workgroupSize": 64,
    "decodeLanes": 32,
    "decodeBlockTarget": 1024,
    "decodeMinLaneTrips": 4,
    "groupThreads": 8,
    "groupRegM": 4,
    "groupRegN": 4,
    "groupTileK": 16,
    "groupRouteWorkgroup": 256
  },
  "derive": {
    "deviceWorkgroupCap": "min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX)",
    "wave32Adapter": "has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize == 32 and device.adapterInfo.subgroupMaxSize == 32",
    "canPinSubgroupSize32": "device.features.has(\"subgroups\") and device.features.has(\"subgroup-size-control\") and has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize <= 32 and device.adapterInfo.subgroupMaxSize >= 32",
    "pinSubgroupSize32": "canPinSubgroupSize32 and not wave32Adapter",
    "wave32Effective": "wave32Adapter or pinSubgroupSize32",
    "hiddenSize": "dim(shapes.input, ranks.input - 1)",
    "numTokens": "numel(shapes.input) / max(1, hiddenSize)",
    "topK": "attrs.k",
    "weightBits": "attrs.expert_weight_bits",
    "quantBlockSize": "attrs.block_size if has(attrs, \"block_size\") else 0",
    "packSize": "2 if weightBits == 4 else 1",
    "quantMidpoint": "8 if weightBits == 4 else 128",
    "fusionSize": "2 if attrs.activation_type == \"swiglu\" and attrs.swiglu_fusion == 1 else 1",
    "interSize": "dim(shapes.fc1_experts_weights, 1) / fusionSize",
    "fc1PackedCols": "dim(shapes.fc1_experts_weights, 2)",
    "fc2PackedCols": "dim(shapes.fc2_experts_weights, 2)",
    "colWiseScales": "quantBlockSize == 0",
    "fc1ScaleBlocks": "1 if colWiseScales else hiddenSize / max(1, quantBlockSize)",
    "fc2ScaleBlocks": "1 if colWiseScales else interSize / max(1, quantBlockSize)",
    "activationSupported": "(attrs.activation_type == \"relu\" and attrs.swiglu_fusion == 0) or (attrs.activation_type == \"swiglu\" and attrs.swiglu_fusion == 1)",
    "routingModeSupported": "attrs.normalize_routing_weights == 0 or attrs.normalize_routing_weights == 1",
    "rawWeightLayout": "attrs.weights_prepacked == -1 or attrs.weights_prepacked == 0",
    "inputOutputShapeOk": "((ranks.input == 2 and ranks.output == 2 and dim(shapes.output, 0) == dim(shapes.input, 0) and dim(shapes.output, 1) == dim(shapes.input, 1)) or (ranks.input == 3 and ranks.output == 3 and dim(shapes.output, 0) == dim(shapes.input, 0) and dim(shapes.output, 1) == dim(shapes.input, 1) and dim(shapes.output, 2) == dim(shapes.input, 2))) and hiddenSize > 0",
    "quantBlockSizeOk": "colWiseScales or (quantBlockSize >= 16 and pow2ceil(quantBlockSize) == quantBlockSize and hiddenSize % quantBlockSize == 0 and interSize % quantBlockSize == 0)",
    "quantScalesOk": "tensorDtypes.fc1_scales == \"float32\" and tensorDtypes.fc2_scales == \"float32\" and dim(shapes.fc1_scales, 0) == dim(shapes.router_probs, 1) and dim(shapes.fc2_scales, 0) == dim(shapes.router_probs, 1) and dim(shapes.fc1_scales, 1) == dim(shapes.fc1_experts_weights, 1) and dim(shapes.fc2_scales, 1) == hiddenSize and ((ranks.fc1_scales == 2 and ranks.fc2_scales == 2) if colWiseScales else (ranks.fc1_scales == 3 and ranks.fc2_scales == 3 and dim(shapes.fc1_scales, 2) == fc1ScaleBlocks and dim(shapes.fc2_scales, 2) == fc2ScaleBlocks))",
    "quantShapeOk": "inputOutputShapeOk and ranks.router_probs == 2 and ranks.fc1_experts_weights == 3 and ranks.fc2_experts_weights == 3 and dim(shapes.router_probs, 0) == numTokens and dim(shapes.fc1_experts_weights, 0) == dim(shapes.router_probs, 1) and dim(shapes.fc2_experts_weights, 0) == dim(shapes.router_probs, 1) and dim(shapes.fc1_experts_weights, 1) % fusionSize == 0 and dim(shapes.fc2_experts_weights, 1) == hiddenSize and dim(shapes.fc1_experts_weights, 2) * packSize == hiddenSize and dim(shapes.fc2_experts_weights, 2) * packSize == interSize and quantBlockSizeOk and quantScalesOk",
    "quantContract": "activationSupported and routingModeSupported and rawWeightLayout and quantShapeOk and topK >= 1 and topK <= dim(shapes.router_probs, 1)",
    "workgroupSizeOk": "tunables.workgroupSize >= 1 and tunables.workgroupSize <= deviceWorkgroupCap",
    "hiddenChunkFits": "topK * interSize * 4 <= device.limits.maxStorageBufferBindingSize and topK * interSize * 4 <= device.limits.maxBufferSize",
    "hiddenChunkTokens": "numTokens if interSize == 0 else min(numTokens, max(1, floor(min(device.limits.maxStorageBufferBindingSize, device.limits.maxBufferSize) / (topK * interSize * 4))))",
    "hiddenChunkCount": "max(1, ceilDiv(numTokens, max(1, hiddenChunkTokens)))",
    "routeScratchBytes": "numTokens * topK * 4",
    "routedScratchFits": "routeScratchBytes <= device.limits.maxStorageBufferBindingSize and routeScratchBytes <= device.limits.maxBufferSize",
    "groupTileM": "tunables.groupThreads * tunables.groupRegM",
    "groupTileN": "tunables.groupThreads * tunables.groupRegN",
    "groupTileKVec": "ceilDiv(tunables.groupTileK, 4)",
    "groupThreadCount": "tunables.groupThreads * tunables.groupThreads",
    "groupSlots": "hiddenChunkTokens * topK",
    "groupMaxTiles": "ceilDiv(groupSlots, max(1, groupTileM)) + dim(shapes.router_probs, 1)",
    "groupSharedBytes": "(groupTileM * tunables.groupTileK + 2 * groupTileN * tunables.groupTileK + groupTileM) * 4",
    "groupSlotOutBytes": "hiddenChunkTokens * topK * hiddenSize * 4",
    "groupedDeviceOk": "groupThreadCount <= device.limits.maxComputeInvocationsPerWorkgroup and tunables.groupThreads <= device.limits.maxComputeWorkgroupSizeX and tunables.groupThreads <= device.limits.maxComputeWorkgroupSizeY and tunables.groupRouteWorkgroup <= deviceWorkgroupCap and groupSharedBytes <= device.limits.maxComputeWorkgroupStorageSize and dim(shapes.router_probs, 1) * 8 <= device.limits.maxComputeWorkgroupStorageSize and tunables.groupTileK % 4 == 0",
    "groupedDispatchOk": "groupMaxTiles <= device.limits.maxComputeWorkgroupsPerDimension and ceilDiv(interSize, max(1, groupTileN)) <= device.limits.maxComputeWorkgroupsPerDimension and ceilDiv(hiddenSize, max(1, groupTileN)) <= device.limits.maxComputeWorkgroupsPerDimension",
    "groupSlotOutFits": "groupSlotOutBytes <= device.limits.maxStorageBufferBindingSize and groupSlotOutBytes <= device.limits.maxBufferSize",
    "groupedShapeOk": "numTokens * topK * 4 >= groupTileM * dim(shapes.router_probs, 1)",
    "groupedContract": "quantContract and workgroupSizeOk and hiddenChunkFits and routedScratchFits and interSize > 0 and groupedDeviceOk and groupedDispatchOk and groupSlotOutFits and groupedShapeOk",
    "sgmatWorkgroup": "128",
    "sgmatSubgroups": "4",
    "sgmatRowSubtiles": "2",
    "groupedSgmatSharedBytes": "groupTileM * 4 + groupTileM * 32 * 4 + 64 * 32 * 4 + sgmatSubgroups * 4 * 64 * 4",
    "groupedSgmatOk": "groupedContract and groupTileM == 32 and interSize % 32 == 0 and groupedSgmatSharedBytes <= device.limits.maxComputeWorkgroupStorageSize and ceilDiv(hiddenSize, 64) <= device.limits.maxComputeWorkgroupsPerDimension and hiddenSize % 32 == 0",
    "decodeLanesOk": "tunables.decodeLanes >= 1 and tunables.decodeLanes <= tunables.workgroupSize and tunables.workgroupSize % tunables.decodeLanes == 0",
    "decodeRows": "max(1, tunables.workgroupSize / max(1, tunables.decodeLanes))",
    "decodeDeviceOk": "workgroupSizeOk and decodeLanesOk and tunables.decodeLanes <= device.limits.maxComputeWorkgroupSizeX and decodeRows <= device.limits.maxComputeWorkgroupSizeY and tunables.workgroupSize * 8 <= device.limits.maxComputeWorkgroupStorageSize",
    "decodeDispatchOk": "ceilDiv(interSize, decodeRows) <= device.limits.maxComputeWorkgroupsPerDimension and ceilDiv(hiddenSize, decodeRows) <= device.limits.maxComputeWorkgroupsPerDimension and hiddenChunkTokens * topK <= device.limits.maxComputeWorkgroupsPerDimension",
    "decodeLaneDepth": "min(hiddenSize, interSize) / max(1, tunables.decodeLanes)",
    "decodeDepthOk": "decodeLaneDepth >= tunables.decodeMinLaneTrips",
    "splitFc1Blocks": "ceilDiv(numTokens * topK * interSize, max(1, tunables.workgroupSize))",
    "decodeOccupancyOk": "splitFc1Blocks <= tunables.decodeBlockTarget",
    "decodeContract": "quantContract and decodeDeviceOk and decodeDispatchOk and hiddenChunkFits and routedScratchFits and interSize > 0 and decodeDepthOk and (decodeOccupancyOk or not groupedContract)"
  },
  "constants": {
    "tokens": "numTokens",
    "hidden": "hiddenSize",
    "experts": "dim(shapes.router_probs, 1)",
    "fc1Rows": "dim(shapes.fc1_experts_weights, 1)",
    "inter": "interSize",
    "topK": "topK",
    "workgroupSize": "tunables.workgroupSize",
    "activationType": "attrs.activation_type",
    "hasSwigluLimit": "has(attrs, \"swiglu_limit\")",
    "swigluLimit": "attrs.swiglu_limit if has(attrs, \"swiglu_limit\") else 0",
    "quantMidpoint": "quantMidpoint",
    "quantBlockSize": "quantBlockSize",
    "packSize": "packSize",
    "fc1PackedCols": "fc1PackedCols",
    "fc2PackedCols": "fc2PackedCols",
    "colWiseScales": "colWiseScales",
    "fc1ScaleBlocks": "fc1ScaleBlocks",
    "fc2ScaleBlocks": "fc2ScaleBlocks"
  },
  "bindingSets": {
    "route": [
      {
        "name": "router_probs",
        "arg": "routerT",
        "semantic": "router_probs",
        "buffer": { "type": "read-only-storage" },
        "elementType": "f32"
      },
      { "name": "route_expert", "semantic": "routeExpert", "buffer": { "type": "storage" }, "elementType": "u32" },
      { "name": "route_mix", "semantic": "routeMix", "buffer": { "type": "storage" }, "elementType": "f32" }
    ],
    "fc1Activation": [
      {
        "name": "input",
        "arg": "inputT",
        "semantic": "input",
        "buffer": { "type": "read-only-storage" },
        "elementType": "f32"
      },
      {
        "name": "route_expert",
        "semantic": "routeExpert",
        "buffer": { "type": "read-only-storage" },
        "elementType": "u32"
      },
      {
        "name": "fc1_experts_weights",
        "arg": "fc1T",
        "semantic": "fc1_experts_weights",
        "buffer": { "type": "read-only-storage" },
        "elementType": "u32"
      },
      {
        "name": "fc1_scales",
        "arg": "fc1ScalesT",
        "semantic": "fc1_scales",
        "buffer": { "type": "read-only-storage" },
        "elementType": "f32"
      },
      { "name": "hidden_act", "semantic": "hiddenAct", "buffer": { "type": "storage" }, "elementType": "f32" },
      {
        "name": "params",
        "semantic": "kernel.params",
        "buffer": { "type": "uniform" },
        "struct": {
          "name": "Params",
          "fields": [
            { "name": "activationAlpha", "type": "f32", "value": "attrs.activation_alpha" },
            { "name": "activationBeta", "type": "f32", "value": "attrs.activation_beta" },
            { "name": "tokenOffset", "type": "u32", "value": "repeat.chunk * hiddenChunkTokens" },
            {
              "name": "tokenCount",
              "type": "u32",
              "value": "min(hiddenChunkTokens, numTokens - repeat.chunk * hiddenChunkTokens)"
            }
          ]
        }
      }
    ],
    "output": [
      { "name": "hidden_act", "semantic": "hiddenAct", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },
      {
        "name": "route_expert",
        "semantic": "routeExpert",
        "buffer": { "type": "read-only-storage" },
        "elementType": "u32"
      },
      { "name": "route_mix", "semantic": "routeMix", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },
      {
        "name": "fc2_experts_weights",
        "arg": "fc2T",
        "semantic": "fc2_experts_weights",
        "buffer": { "type": "read-only-storage" },
        "elementType": "u32"
      },
      {
        "name": "fc2_scales",
        "arg": "fc2ScalesT",
        "semantic": "fc2_scales",
        "buffer": { "type": "read-only-storage" },
        "elementType": "f32"
      },
      {
        "name": "output",
        "arg": "outputT",
        "semantic": "output",
        "buffer": { "type": "storage" },
        "elementType": "f32"
      },
      {
        "name": "params",
        "semantic": "kernel.params",
        "buffer": { "type": "uniform" },
        "struct": {
          "name": "Params",
          "fields": [
            { "name": "tokenOffset", "type": "u32", "value": "repeat.chunk * hiddenChunkTokens" },
            {
              "name": "tokenCount",
              "type": "u32",
              "value": "min(hiddenChunkTokens, numTokens - repeat.chunk * hiddenChunkTokens)"
            }
          ]
        }
      }
    ],
    "zeroInterOutput": [
      {
        "name": "output",
        "arg": "outputT",
        "semantic": "output",
        "buffer": { "type": "storage" },
        "elementType": "f32"
      }
    ],
    "group": [
      {
        "name": "route_expert",
        "semantic": "routeExpert",
        "buffer": { "type": "read-only-storage" },
        "elementType": "u32"
      },
      { "name": "slot_list", "semantic": "slotList", "buffer": { "type": "storage" }, "elementType": "u32" },
      { "name": "tile_meta", "semantic": "tileMeta", "buffer": { "type": "storage" }, "elementType": "u32" },
      {
        "name": "params",
        "semantic": "kernel.params",
        "buffer": { "type": "uniform" },
        "struct": {
          "name": "Params",
          "fields": [
            { "name": "tokenOffset", "type": "u32", "value": "repeat.chunk * hiddenChunkTokens" },
            {
              "name": "tokenCount",
              "type": "u32",
              "value": "min(hiddenChunkTokens, numTokens - repeat.chunk * hiddenChunkTokens)"
            }
          ]
        }
      }
    ],
    "fc1Grouped": [
      {
        "name": "input",
        "arg": "inputT",
        "semantic": "input",
        "buffer": { "type": "read-only-storage" },
        "elementType": "f32"
      },
      { "name": "slot_list", "semantic": "slotList", "buffer": { "type": "read-only-storage" }, "elementType": "u32" },
      { "name": "tile_meta", "semantic": "tileMeta", "buffer": { "type": "read-only-storage" }, "elementType": "u32" },
      {
        "name": "fc1_experts_weights",
        "arg": "fc1T",
        "semantic": "fc1_experts_weights",
        "buffer": { "type": "read-only-storage" },
        "elementType": "u32"
      },
      {
        "name": "fc1_scales",
        "arg": "fc1ScalesT",
        "semantic": "fc1_scales",
        "buffer": { "type": "read-only-storage" },
        "elementType": "f32"
      },
      { "name": "hidden_act", "semantic": "hiddenAct", "buffer": { "type": "storage" }, "elementType": "f32" },
      {
        "name": "params",
        "semantic": "kernel.params",
        "buffer": { "type": "uniform" },
        "struct": {
          "name": "Params",
          "fields": [
            { "name": "activationAlpha", "type": "f32", "value": "attrs.activation_alpha" },
            { "name": "activationBeta", "type": "f32", "value": "attrs.activation_beta" },
            { "name": "tokenOffset", "type": "u32", "value": "repeat.chunk * hiddenChunkTokens" }
          ]
        }
      }
    ],
    "outputGrouped": [
      { "name": "hidden_act", "semantic": "hiddenAct", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },
      { "name": "slot_list", "semantic": "slotList", "buffer": { "type": "read-only-storage" }, "elementType": "u32" },
      { "name": "tile_meta", "semantic": "tileMeta", "buffer": { "type": "read-only-storage" }, "elementType": "u32" },
      {
        "name": "fc2_experts_weights",
        "arg": "fc2T",
        "semantic": "fc2_experts_weights",
        "buffer": { "type": "read-only-storage" },
        "elementType": "u32"
      },
      {
        "name": "fc2_scales",
        "arg": "fc2ScalesT",
        "semantic": "fc2_scales",
        "buffer": { "type": "read-only-storage" },
        "elementType": "f32"
      },
      { "name": "slot_out", "semantic": "slotOut", "buffer": { "type": "storage" }, "elementType": "f32" }
    ],
    "mix": [
      { "name": "slot_out", "semantic": "slotOut", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },
      { "name": "route_mix", "semantic": "routeMix", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },
      {
        "name": "output",
        "arg": "outputT",
        "semantic": "output",
        "buffer": { "type": "storage" },
        "elementType": "f32"
      },
      {
        "name": "params",
        "semantic": "kernel.params",
        "buffer": { "type": "uniform" },
        "struct": {
          "name": "Params",
          "fields": [
            { "name": "tokenOffset", "type": "u32", "value": "repeat.chunk * hiddenChunkTokens" },
            {
              "name": "tokenCount",
              "type": "u32",
              "value": "min(hiddenChunkTokens, numTokens - repeat.chunk * hiddenChunkTokens)"
            }
          ]
        }
      }
    ],
    "fc1ActivationIo": [
      {
        "name": "input",
        "arg": "inputT",
        "semantic": "input",
        "buffer": { "type": "read-only-storage" },
        "elementType": "f32"
      },
      {
        "name": "route_expert",
        "semantic": "routeExpert",
        "buffer": { "type": "read-only-storage" },
        "elementType": "u32"
      },
      {
        "name": "fc1_experts_weights",
        "arg": "fc1T",
        "semantic": "fc1_experts_weights",
        "buffer": { "type": "read-only-storage" },
        "elementType": "u32"
      },
      {
        "name": "fc1_scales",
        "arg": "fc1ScalesT",
        "semantic": "fc1_scales",
        "buffer": { "type": "read-only-storage" },
        "elementType": "f32"
      },
      { "name": "hidden_act", "semantic": "hiddenAct", "buffer": { "type": "storage" }, "elementType": "f32" }
    ],
    "fc1ActivationScheduled": [
      {
        "name": "input",
        "arg": "inputT",
        "semantic": "input",
        "buffer": { "type": "read-only-storage" },
        "elementType": "f32"
      },
      {
        "name": "route_expert",
        "semantic": "routeExpert",
        "buffer": { "type": "read-only-storage" },
        "elementType": "u32"
      },
      {
        "name": "fc1_experts_weights",
        "arg": "fc1T",
        "semantic": "fc1_experts_weights",
        "buffer": { "type": "read-only-storage" },
        "elementType": "u32"
      },
      {
        "name": "fc1_scales",
        "arg": "fc1ScalesT",
        "semantic": "fc1_scales",
        "buffer": { "type": "read-only-storage" },
        "elementType": "f32"
      },
      { "name": "hidden_act", "semantic": "hiddenAct", "buffer": { "type": "storage" }, "elementType": "f32" },
      {
        "name": "params",
        "semantic": "kernel.params",
        "buffer": { "type": "uniform" },
        "struct": {
          "name": "Params",
          "fields": [
            { "name": "activationAlpha", "type": "f32", "value": "attrs.activation_alpha" },
            { "name": "activationBeta", "type": "f32", "value": "attrs.activation_beta" },
            { "name": "tokenOffset", "type": "u32", "value": "repeat.chunk * hiddenChunkTokens" }
          ]
        }
      }
    ],
    "outputIo": [
      { "name": "hidden_act", "semantic": "hiddenAct", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },
      {
        "name": "route_expert",
        "semantic": "routeExpert",
        "buffer": { "type": "read-only-storage" },
        "elementType": "u32"
      },
      { "name": "route_mix", "semantic": "routeMix", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },
      {
        "name": "fc2_experts_weights",
        "arg": "fc2T",
        "semantic": "fc2_experts_weights",
        "buffer": { "type": "read-only-storage" },
        "elementType": "u32"
      },
      {
        "name": "fc2_scales",
        "arg": "fc2ScalesT",
        "semantic": "fc2_scales",
        "buffer": { "type": "read-only-storage" },
        "elementType": "f32"
      },
      {
        "name": "output",
        "arg": "outputT",
        "semantic": "output",
        "buffer": { "type": "storage" },
        "elementType": "f32"
      }
    ],
    "outputScheduled": [
      { "name": "hidden_act", "semantic": "hiddenAct", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },
      {
        "name": "route_expert",
        "semantic": "routeExpert",
        "buffer": { "type": "read-only-storage" },
        "elementType": "u32"
      },
      { "name": "route_mix", "semantic": "routeMix", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },
      {
        "name": "fc2_experts_weights",
        "arg": "fc2T",
        "semantic": "fc2_experts_weights",
        "buffer": { "type": "read-only-storage" },
        "elementType": "u32"
      },
      {
        "name": "fc2_scales",
        "arg": "fc2ScalesT",
        "semantic": "fc2_scales",
        "buffer": { "type": "read-only-storage" },
        "elementType": "f32"
      },
      {
        "name": "output",
        "arg": "outputT",
        "semantic": "output",
        "buffer": { "type": "storage" },
        "elementType": "f32"
      },
      {
        "name": "params",
        "semantic": "kernel.params",
        "buffer": { "type": "uniform" },
        "struct": {
          "name": "Params",
          "fields": [{ "name": "tokenOffset", "type": "u32", "value": "repeat.chunk * hiddenChunkTokens" }]
        }
      }
    ]
  },
  "variants": [
    {
      "id": "quant_zero_inter",
      "priority": 20,
      "when": ["quantContract", "workgroupSizeOk", "interSize == 0"],
      "passes": [
        {
          "id": "output_stage",
          "name": "QMoE.OutputStageZeroInter",
          "source": {
            "shader": "qmoe-output-zero-inter.wgsl.jinja",
            "inputs": { "outputElementCount": "numel(shapes.output)" }
          },
          "bindings": "zeroInterOutput",
          "dispatch": { "threads": "numel(shapes.output)", "workgroupSize": "constants.workgroupSize" }
        }
      ]
    },
    {
      "id": "quant_grouped_sgmat_routed",
      "priority": 32,
      "when": ["groupedSgmatOk", "wave32Effective"],
      "constants": {
        "groupTileM": "groupTileM",
        "groupRouteWorkgroup": "tunables.groupRouteWorkgroup",
        "sgmatWorkgroup": "sgmatWorkgroup",
        "sgmatSubgroups": "sgmatSubgroups",
        "sgmatRowSubtiles": "sgmatRowSubtiles"
      },
      "intermediates": [
        { "id": "routeExpert", "dtype": "uint32", "shape": "[numTokens * topK]" },
        { "id": "routeMix", "dtype": "float32", "shape": "[numTokens * topK]" },
        { "id": "hiddenAct", "dtype": "float32", "shape": "[hiddenChunkTokens * topK * interSize]" },
        { "id": "slotList", "dtype": "uint32", "shape": "[max(1, groupSlots)]" },
        { "id": "tileMeta", "dtype": "uint32", "shape": "[1 + 3 * groupMaxTiles]" },
        { "id": "slotOut", "dtype": "float32", "shape": "[max(1, hiddenChunkTokens * topK * hiddenSize)]" }
      ],
      "passes": [
        {
          "id": "route_stage",
          "name": "QMoE.RouteStage",
          "shader": "qmoe-route-stage.wgsl.jinja",
          "bindings": "route",
          "dispatch": { "threads": "numTokens", "workgroupSize": "constants.workgroupSize" }
        },
        {
          "id": "token_chunks",
          "repeat": { "count": "hiddenChunkCount", "index": "chunk" },
          "passes": [
            {
              "id": "group_stage",
              "name": "QMoE.GroupStage",
              "shader": "expert-group-slots.wgsl.jinja",
              "bindings": "group",
              "dispatch": {
                "threads": "constants.groupRouteWorkgroup",
                "workgroupSize": "constants.groupRouteWorkgroup"
              }
            },
            {
              "id": "fc1_activation_stage",
              "name": "QMoE.FC1ActivationStageGroupedSgmat",
              "shader": "qmoe-fc1-activation-grouped-sgmat.wgsl.jinja",
              "bindings": "fc1Grouped",
              "dispatch": { "x": "groupMaxTiles", "y": "ceilDiv(interSize * fusionSize, 64)" }
            },
            {
              "id": "output_stage",
              "name": "QMoE.OutputStageGroupedSgmat",
              "shader": "qmoe-output-grouped-sgmat.wgsl.jinja",
              "bindings": "outputGrouped",
              "dispatch": { "x": "groupMaxTiles", "y": "ceilDiv(hiddenSize, 64)" }
            },
            {
              "id": "mix_stage",
              "name": "QMoE.MixStage",
              "shader": "qmoe-mix-stage.wgsl.jinja",
              "bindings": "mix",
              "dispatch": {
                "threads": "min(hiddenChunkTokens, numTokens - repeat.chunk * hiddenChunkTokens) * hiddenSize",
                "workgroupSize": "constants.workgroupSize"
              }
            }
          ]
        }
      ],
      "requires": {
        "features": ["subgroups", "chromium-experimental-subgroup-matrix"],
        "limits": { "maxComputeWorkgroupStorageSize": 16512 },
        "subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }]
      }
    },
    {
      "id": "quant_grouped_routed",
      "priority": 30,
      "when": ["groupedContract"],
      "constants": {
        "groupTileM": "groupTileM",
        "groupTileN": "groupTileN",
        "groupTileK": "tunables.groupTileK",
        "groupTileKVec": "groupTileKVec",
        "groupThreads": "tunables.groupThreads",
        "regM": "tunables.groupRegM",
        "regN": "tunables.groupRegN",
        "groupRouteWorkgroup": "tunables.groupRouteWorkgroup"
      },
      "intermediates": [
        { "id": "routeExpert", "dtype": "uint32", "shape": "[numTokens * topK]" },
        { "id": "routeMix", "dtype": "float32", "shape": "[numTokens * topK]" },
        { "id": "hiddenAct", "dtype": "float32", "shape": "[hiddenChunkTokens * topK * interSize]" },
        { "id": "slotList", "dtype": "uint32", "shape": "[max(1, groupSlots)]" },
        { "id": "tileMeta", "dtype": "uint32", "shape": "[1 + 3 * groupMaxTiles]" },
        { "id": "slotOut", "dtype": "float32", "shape": "[max(1, hiddenChunkTokens * topK * hiddenSize)]" }
      ],
      "passes": [
        {
          "id": "route_stage",
          "name": "QMoE.RouteStage",
          "shader": "qmoe-route-stage.wgsl.jinja",
          "bindings": "route",
          "dispatch": { "threads": "numTokens", "workgroupSize": "constants.workgroupSize" }
        },
        {
          "id": "token_chunks",
          "repeat": { "count": "hiddenChunkCount", "index": "chunk" },
          "passes": [
            {
              "id": "group_stage",
              "name": "QMoE.GroupStage",
              "shader": "expert-group-slots.wgsl.jinja",
              "bindings": "group",
              "dispatch": {
                "threads": "constants.groupRouteWorkgroup",
                "workgroupSize": "constants.groupRouteWorkgroup"
              }
            },
            {
              "id": "fc1_activation_stage",
              "name": "QMoE.FC1ActivationStageGrouped",
              "shader": "qmoe-fc1-activation-grouped.wgsl.jinja",
              "bindings": "fc1Grouped",
              "dispatch": { "x": "groupMaxTiles", "y": "ceilDiv(interSize, groupTileN)" }
            },
            {
              "id": "output_stage",
              "name": "QMoE.OutputStageGrouped",
              "shader": "qmoe-output-grouped.wgsl.jinja",
              "bindings": "outputGrouped",
              "dispatch": { "x": "groupMaxTiles", "y": "ceilDiv(hiddenSize, groupTileN)" }
            },
            {
              "id": "mix_stage",
              "name": "QMoE.MixStage",
              "shader": "qmoe-mix-stage.wgsl.jinja",
              "bindings": "mix",
              "dispatch": {
                "threads": "min(hiddenChunkTokens, numTokens - repeat.chunk * hiddenChunkTokens) * hiddenSize",
                "workgroupSize": "constants.workgroupSize"
              }
            }
          ]
        }
      ]
    },
    {
      "id": "quant_gemv_routed",
      "priority": 20,
      "when": ["decodeContract"],
      "constants": { "decodeLanes": "tunables.decodeLanes", "decodeRows": "decodeRows" },
      "intermediates": [
        { "id": "routeExpert", "dtype": "uint32", "shape": "[numTokens * topK]" },
        { "id": "routeMix", "dtype": "float32", "shape": "[numTokens * topK]" },
        { "id": "hiddenAct", "dtype": "float32", "shape": "[hiddenChunkTokens * topK * interSize]" }
      ],
      "passes": [
        {
          "id": "route_stage",
          "name": "QMoE.RouteStage",
          "shader": "qmoe-route-stage.wgsl.jinja",
          "bindings": "route",
          "dispatch": { "threads": "numTokens", "workgroupSize": "constants.workgroupSize" }
        },
        {
          "id": "token_chunks",
          "repeat": { "count": "hiddenChunkCount", "index": "chunk" },
          "passes": [
            {
              "id": "fc1_activation_stage",
              "name": "QMoE.FC1ActivationStageGemv",
              "shader": "qmoe-fc1-activation-gemv.wgsl.jinja",
              "bindings": "fc1ActivationScheduled",
              "dispatch": {
                "x": "ceilDiv(interSize, decodeRows)",
                "y": "min(hiddenChunkTokens, numTokens - repeat.chunk * hiddenChunkTokens) * topK"
              }
            },
            {
              "id": "output_stage",
              "name": "QMoE.OutputStageGemv",
              "shader": "qmoe-output-gemv.wgsl.jinja",
              "bindings": "outputScheduled",
              "dispatch": {
                "x": "ceilDiv(hiddenSize, decodeRows)",
                "y": "min(hiddenChunkTokens, numTokens - repeat.chunk * hiddenChunkTokens)"
              }
            }
          ]
        }
      ]
    },
    {
      "id": "quant_split_routed",
      "priority": 10,
      "when": ["quantContract", "workgroupSizeOk", "hiddenChunkFits", "routedScratchFits", "interSize > 0"],
      "intermediates": [
        { "id": "routeExpert", "dtype": "uint32", "shape": "[numTokens * topK]" },
        { "id": "routeMix", "dtype": "float32", "shape": "[numTokens * topK]" },
        { "id": "hiddenAct", "dtype": "float32", "shape": "[hiddenChunkTokens * topK * interSize]" }
      ],
      "passes": [
        {
          "id": "route_stage",
          "name": "QMoE.RouteStage",
          "shader": "qmoe-route-stage.wgsl.jinja",
          "bindings": "route",
          "dispatch": { "threads": "numTokens", "workgroupSize": "constants.workgroupSize" }
        },
        {
          "id": "token_chunks",
          "repeat": { "count": "hiddenChunkCount", "index": "chunk" },
          "passes": [
            {
              "id": "fc1_activation_stage",
              "name": "QMoE.FC1ActivationStage",
              "shader": "qmoe-fc1-activation-stage.wgsl.jinja",
              "bindings": "fc1Activation",
              "dispatch": {
                "threads": "min(hiddenChunkTokens, numTokens - repeat.chunk * hiddenChunkTokens) * topK * interSize",
                "workgroupSize": "constants.workgroupSize"
              }
            },
            {
              "id": "output_stage",
              "name": "QMoE.OutputStage",
              "shader": "qmoe-output-stage.wgsl.jinja",
              "bindings": "output",
              "dispatch": {
                "threads": "min(hiddenChunkTokens, numTokens - repeat.chunk * hiddenChunkTokens) * hiddenSize",
                "workgroupSize": "constants.workgroupSize"
              }
            }
          ]
        }
      ]
    }
  ]
}