File size: 18,456 Bytes
38770a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c41d43
 
 
 
38770a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c41d43
38770a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c41d43
38770a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
  "domain": "com.microsoft",
  "name": "MatMulBnb4",
  "sinceVersion": 1,
  "description": "Computes `A @ dequant(B)^T` where `B` uses bitsandbytes 4-bit quantization: `quant_type = 0` selects FP4 and `quant_type = 1` selects NF4. Supports rank-2 float16/float32 `A`, `transB = 1`, and `training_mode = 0`; rank-1 and rank-3-or-higher `A`, bfloat16, `transB = 0`, and training are not implemented. `B` is the flattened `[N, K]` weight, two codes per byte with the even flat index in the high nibble. Each code indexes a fixed 16-entry codebook, and the value is `codebook[code] * absmax[flat_index / block_size]`.",
  "inputs": [
    { "role": "A", "dtype": "T1", "rank": 2, "description": "Float input matrix of shape `(M, K)`, not quantized." },
    {
      "role": "B",
      "dtype": "T2",
      "rank": 1,
      "description": "The `[N, K]` weight, flattened and quantized to 4 bits, stored as `(N * K + 1) / 2` bytes; the ONNX type is uint8 (this WebGPU implementation reads one widened u32 per stored byte)."
    },
    {
      "role": "absmax",
      "dtype": "T1",
      "rank": 1,
      "description": "Per-block absolute-maximum dequantization scales of shape `((N * K + block_size - 1) / block_size)`, same dtype as A."
    }
  ],
  "outputs": [
    {
      "role": "Y",
      "dtype": "T1",
      "rank": 2,
      "shape": "[dim(shapes.A, 0), attrs.N]",
      "description": "Result of `A` multiplied by the dequantized, transposed weight matrix, with shape `(M, N)` and the same dtype as `A`."
    }
  ],
  "attributes": { "training_mode": 0, "transB": 1 },
  "attributeConstraints": {
    "K": { "required": true },
    "N": { "required": true },
    "block_size": { "required": true },
    "quant_type": { "required": true, "values": [0, 1] },
    "training_mode": { "values": [0] },
    "transB": { "values": [1] }
  },
  "attributeDescriptions": {
    "K": "Input feature count (the shared dimension).",
    "N": "Output feature count.",
    "block_size": "Number of weights sharing one absmax scale; a power of two, at least 16.",
    "quant_type": "Codebook selector: 0 = FP4, 1 = NF4.",
    "training_mode": "Whether training outputs are requested. This inference-only implementation supports the standard default value 0.",
    "transB": "Whether the quantized weight is stored transposed. This implementation supports the standard default value 1."
  },
  "typeConstraints": { "T1": ["float32", "float16"], "T2": ["uint8"] },
  "args": {
    "aT": { "kind": "tensor", "semantic": "A", "role": "input" },
    "bT": { "kind": "tensor", "semantic": "B", "role": "input" },
    "absmaxT": { "kind": "tensor", "semantic": "absmax", "role": "input" },
    "yT": { "kind": "tensor", "semantic": "Y", "role": "output" }
  },
  "tunables": {
    "WORKGROUP_SIZE": 64,
    "TILE_MIN_M": 16,
    "PORTABLE_TILE_K": 16,
    "SGMAT_TILE_ROWS": 64,
    "SGMAT_TALL_TILE_ROWS": 128,
    "SGMAT_TALL_MIN_M": 128,
    "SGMAT_TILE_COLS": 64,
    "SGMAT_TILE_K": 32
  },
  "bindingSets": {
    "main": [
      {
        "name": "a",
        "arg": "aT",
        "semantic": "A",
        "buffer": { "type": "read-only-storage" },
        "elementType": "$aScalar"
      },
      { "name": "b", "arg": "bT", "semantic": "B", "buffer": { "type": "read-only-storage" }, "elementType": "u32" },
      {
        "name": "absmax",
        "arg": "absmaxT",
        "semantic": "absmax",
        "buffer": { "type": "read-only-storage" },
        "elementType": "$absmaxScalar",
        "length": "$ABSMAX_LEN"
      },
      { "name": "y", "arg": "yT", "semantic": "Y", "buffer": { "type": "storage" }, "elementType": "$aScalar" },
      {
        "name": "params",
        "semantic": "kernel.params",
        "buffer": { "type": "uniform" },
        "struct": {
          "name": "Params",
          "fields": [
            { "name": "rows", "type": "u32", "value": "dim(shapes.A, 0)" },
            { "name": "K", "type": "u32", "value": "attrs.K" },
            { "name": "N", "type": "u32", "value": "attrs.N" },
            { "name": "blockSize", "type": "u32", "value": "attrs.block_size" }
          ]
        }
      }
    ],
    "gemv": [
      {
        "name": "a",
        "arg": "aT",
        "semantic": "A",
        "buffer": { "type": "read-only-storage" },
        "elementType": "$aScalar"
      },
      { "name": "b", "arg": "bT", "semantic": "B", "buffer": { "type": "read-only-storage" }, "elementType": "u32" },
      {
        "name": "absmax",
        "arg": "absmaxT",
        "semantic": "absmax",
        "buffer": { "type": "read-only-storage" },
        "elementType": "$absmaxScalar",
        "length": "$ABSMAX_LEN"
      },
      { "name": "y", "arg": "yT", "semantic": "Y", "buffer": { "type": "storage" }, "elementType": "$aScalar" },
      {
        "name": "params",
        "semantic": "kernel.params",
        "buffer": { "type": "uniform" },
        "struct": {
          "name": "Params",
          "fields": [
            { "name": "K", "type": "u32", "value": "attrs.K" },
            { "name": "N", "type": "u32", "value": "attrs.N" },
            { "name": "blockSize", "type": "u32", "value": "attrs.block_size" }
          ]
        }
      }
    ],
    "sgmat": [
      {
        "name": "a",
        "arg": "aT",
        "semantic": "A",
        "buffer": { "type": "read-only-storage" },
        "elementType": "$aScalar"
      },
      { "name": "b", "arg": "bT", "semantic": "B", "buffer": { "type": "read-only-storage" }, "elementType": "u32" },
      {
        "name": "absmax",
        "arg": "absmaxT",
        "semantic": "absmax",
        "buffer": { "type": "read-only-storage" },
        "elementType": "$absmaxScalar",
        "length": "$ABSMAX_LEN"
      },
      { "name": "y", "arg": "yT", "semantic": "Y", "buffer": { "type": "storage" }, "elementType": "$aScalar" }
    ],
    "castA": [
      {
        "name": "x",
        "arg": "aT",
        "semantic": "A",
        "buffer": { "type": "read-only-storage" },
        "elementType": "$srcScalar"
      },
      { "name": "y", "semantic": "aF32", "buffer": { "type": "storage" }, "elementType": "f32" },
      {
        "name": "params",
        "semantic": "kernel.params",
        "buffer": { "type": "uniform" },
        "struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.A)" }] }
      }
    ],
    "sgmatWiden": [
      { "name": "a", "semantic": "aF32", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },
      { "name": "b", "arg": "bT", "semantic": "B", "buffer": { "type": "read-only-storage" }, "elementType": "u32" },
      {
        "name": "absmax",
        "arg": "absmaxT",
        "semantic": "absmax",
        "buffer": { "type": "read-only-storage" },
        "elementType": "$absmaxScalar",
        "length": "$ABSMAX_LEN"
      },
      { "name": "y", "semantic": "yF32", "buffer": { "type": "storage" }, "elementType": "f32" }
    ],
    "castY": [
      { "name": "x", "semantic": "yF32", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },
      { "name": "y", "arg": "yT", "semantic": "Y", "buffer": { "type": "storage" }, "elementType": "$srcScalar" },
      {
        "name": "params",
        "semantic": "kernel.params",
        "buffer": { "type": "uniform" },
        "struct": {
          "name": "Params",
          "fields": [{ "name": "count", "type": "u32", "value": "dim(shapes.A, 0) * attrs.N" }]
        }
      }
    ]
  },
  "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",
    "packedBytesExpected": "ceilDiv(attrs.N * attrs.K, 2)",
    "absmaxCountExpected": "ceilDiv(attrs.N * attrs.K, attrs.block_size)",
    "aFloatOk": "(tensorDtypes.A == \"float32\" or tensorDtypes.A == \"float16\") and f16Ok(tensorDtypes.A)",
    "portableWorkgroupSize": "min(tunables.WORKGROUP_SIZE, deviceWorkgroupCap)",
    "commonShapeValid": "ranks.A == 2 and ranks.B == 1 and ranks.absmax == 1 and ranks.Y == 2 and aFloatOk and tensorDtypes.B == \"uint8\" and tensorDtypes.absmax == tensorDtypes.A and tensorDtypes.Y == tensorDtypes.A and attrs.K > 0 and attrs.N > 0 and attrs.block_size >= 16 and pow2ceil(attrs.block_size) == attrs.block_size and dim(shapes.A, 1) == attrs.K and dim(shapes.B, 0) == packedBytesExpected and dim(shapes.absmax, 0) == absmaxCountExpected and dim(shapes.Y, 0) == dim(shapes.A, 0) and dim(shapes.Y, 1) == attrs.N",
    "gemvShapeValid": "commonShapeValid and dim(shapes.A, 0) == 1",
    "portableWorkgroupFits": "portableWorkgroupSize > 0 and portableWorkgroupSize * 16 <= device.limits.maxComputeWorkgroupStorageSize",
    "portableTileKValid": "tunables.PORTABLE_TILE_K >= 8 and tunables.PORTABLE_TILE_K % 8 == 0",
    "tileEligible": "commonShapeValid and dim(shapes.A, 0) >= tunables.TILE_MIN_M and portableTileKValid",
    "tileWorkgroupStorageBytes": "8 * 64 * tunables.PORTABLE_TILE_K",
    "tileWorkgroupFits": "16 <= device.limits.maxComputeWorkgroupSizeX and 8 <= device.limits.maxComputeWorkgroupSizeY and 128 <= device.limits.maxComputeInvocationsPerWorkgroup and tileWorkgroupStorageBytes <= device.limits.maxComputeWorkgroupStorageSize and ceilDiv(attrs.N, 64) <= device.limits.maxComputeWorkgroupsPerDimension and ceilDiv(dim(shapes.A, 0), 64) <= device.limits.maxComputeWorkgroupsPerDimension",
    "sgmatMatrixSize": "8",
    "sgmatTileRows": "tunables.SGMAT_TALL_TILE_ROWS if dim(shapes.A, 0) >= tunables.SGMAT_TALL_MIN_M else tunables.SGMAT_TILE_ROWS",
    "sgmatRowSubtiles": "4",
    "sgmatSubRows": "sgmatTileRows / sgmatRowSubtiles",
    "sgmatSubCols": "4 * sgmatMatrixSize",
    "sgmatLoadWidth": "sgmatMatrixSize",
    "sgmatColSubtiles": "tunables.SGMAT_TILE_COLS / sgmatSubCols",
    "sgmatNumSubgroups": "sgmatRowSubtiles * sgmatColSubtiles",
    "sgmatSubgroupSize": "device.adapterInfo.subgroupMinSize if has(device.adapterInfo, \"subgroupMinSize\") else 1",
    "sgmatWorkgroupSize": "sgmatNumSubgroups * sgmatSubgroupSize",
    "sgmatBLoadsPerRow": "tunables.SGMAT_TILE_K / sgmatLoadWidth",
    "sgmatWorkgroupStorageBytes": "4 * tunables.SGMAT_TILE_COLS * tunables.SGMAT_TILE_K",
    "sgmatDispatchN": "ceilDiv(attrs.N, tunables.SGMAT_TILE_COLS)",
    "sgmatDispatchM": "ceilDiv(dim(shapes.A, 0), sgmatTileRows)",
    "sgmatWorkgroupFits": "sgmatWorkgroupSize <= deviceWorkgroupCap and sgmatWorkgroupStorageBytes <= device.limits.maxComputeWorkgroupStorageSize and sgmatDispatchN <= device.limits.maxComputeWorkgroupsPerDimension and sgmatDispatchM <= device.limits.maxComputeWorkgroupsPerDimension",
    "sgmatWidenBytes": "numel(shapes.A) * 4",
    "sgmatWidenOutBytes": "dim(shapes.A, 0) * attrs.N * 4",
    "sgmatWidenFits": "sgmatWidenBytes <= device.limits.maxStorageBufferBindingSize and sgmatWidenBytes <= device.limits.maxBufferSize and sgmatWidenOutBytes <= device.limits.maxStorageBufferBindingSize and sgmatWidenOutBytes <= device.limits.maxBufferSize"
  },
  "constants": { "quantType": "attrs.quant_type", "ABSMAX_LEN": "ceilDiv(attrs.N * attrs.K, attrs.block_size)" },
  "variants": [
    {
      "id": "gemv",
      "priority": 20,
      "when": ["gemvShapeValid", "portableWorkgroupFits"],
      "constants": {
        "workgroupSize": "portableWorkgroupSize",
        "aScalar": "\"f16\" if tensorDtypes.A == \"float16\" else \"f32\"",
        "usesF16": "tensorDtypes.A == \"float16\"",
        "absmaxScalar": "\"f16\" if tensorDtypes.absmax == \"float16\" else \"f32\""
      },
      "passes": [
        {
          "id": "main",
          "shader": "matmul-bnb4-gemv.wgsl.jinja",
          "bindings": "gemv",
          "dispatch": { "workgroups": "attrs.N" }
        }
      ]
    },
    {
      "id": "sgmat",
      "priority": 15,
      "requires": {
        "features": ["subgroups", "chromium-experimental-subgroup-matrix"],
        "limits": { "maxComputeWorkgroupStorageSize": 8192 },
        "subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }]
      },
      "when": ["commonShapeValid", "tensorDtypes.A == \"float32\"", "dim(shapes.A, 0) >= sgmatTileRows", "dim(shapes.A, 0) % sgmatTileRows == 0", "attrs.N % tunables.SGMAT_TILE_COLS == 0", "attrs.K % tunables.SGMAT_TILE_K == 0", "attrs.K % attrs.block_size == 0", "attrs.block_size % sgmatLoadWidth == 0", "wave32Effective", "sgmatWorkgroupFits"],
      "constants": {
        "K": "attrs.K",
        "N": "attrs.N",
        "blockSize": "attrs.block_size",
        "tileRows": "sgmatTileRows",
        "tileCols": "tunables.SGMAT_TILE_COLS",
        "tileK": "tunables.SGMAT_TILE_K",
        "subRows": "sgmatSubRows",
        "subCols": "sgmatSubCols",
        "matrixSize": "sgmatMatrixSize",
        "rowMatrices": "sgmatSubRows / sgmatMatrixSize",
        "colMatrices": "sgmatSubCols / sgmatMatrixSize",
        "loadWidth": "sgmatLoadWidth",
        "rowSubtiles": "sgmatRowSubtiles",
        "workgroupSize": "sgmatWorkgroupSize",
        "bLoadsPerRow": "sgmatBLoadsPerRow",
        "aScalar": "\"f32\"",
        "usesF16": false,
        "absmaxScalar": "\"f16\" if tensorDtypes.absmax == \"float16\" else \"f32\""
      },
      "passes": [
        {
          "id": "main",
          "shader": "matmul-bnb4-sgmat.wgsl.jinja",
          "bindings": "sgmat",
          "dispatch": { "x": "sgmatDispatchN", "y": "sgmatDispatchM" }
        }
      ]
    },
    {
      "id": "sgmat_widened",
      "priority": 16,
      "requires": {
        "features": ["subgroups", "chromium-experimental-subgroup-matrix"],
        "limits": { "maxComputeWorkgroupStorageSize": 8192 },
        "subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }]
      },
      "when": ["commonShapeValid", "tensorDtypes.A == \"float16\"", "dim(shapes.A, 0) >= sgmatTileRows", "dim(shapes.A, 0) % sgmatTileRows == 0", "attrs.N % tunables.SGMAT_TILE_COLS == 0", "attrs.K % tunables.SGMAT_TILE_K == 0", "attrs.K % attrs.block_size == 0", "attrs.block_size % sgmatLoadWidth == 0", "wave32Effective", "sgmatWorkgroupFits", "sgmatWidenFits"],
      "constants": {
        "K": "attrs.K",
        "N": "attrs.N",
        "blockSize": "attrs.block_size",
        "tileRows": "sgmatTileRows",
        "tileCols": "tunables.SGMAT_TILE_COLS",
        "tileK": "tunables.SGMAT_TILE_K",
        "subRows": "sgmatSubRows",
        "subCols": "sgmatSubCols",
        "matrixSize": "sgmatMatrixSize",
        "rowMatrices": "sgmatSubRows / sgmatMatrixSize",
        "colMatrices": "sgmatSubCols / sgmatMatrixSize",
        "loadWidth": "sgmatLoadWidth",
        "rowSubtiles": "sgmatRowSubtiles",
        "workgroupSize": "sgmatWorkgroupSize",
        "bLoadsPerRow": "sgmatBLoadsPerRow",
        "aScalar": "\"f32\"",
        "usesF16": true,
        "absmaxScalar": "\"f16\" if tensorDtypes.absmax == \"float16\" else \"f32\"",
        "srcScalar": "\"f16\"",
        "outScalar": "\"f32\"",
        "wrapNarrowInt": false,
        "wrapSigned": false
      },
      "passes": [
        {
          "id": "widen_a",
          "name": "MatMulBnb4.WidenActivations",
          "shader": "cast-scalar-x4.wgsl.jinja",
          "bindings": "castA",
          "dispatch": { "threads": "ceilDiv(numel(shapes.A), 4)", "workgroupSize": "tunables.WORKGROUP_SIZE" }
        },
        {
          "id": "main",
          "name": "MatMulBnb4.SubgroupMatrixWidened",
          "shader": "matmul-bnb4-sgmat.wgsl.jinja",
          "bindings": "sgmatWiden",
          "dispatch": { "x": "sgmatDispatchN", "y": "sgmatDispatchM" }
        },
        {
          "id": "narrow_y",
          "name": "MatMulBnb4.NarrowOutput",
          "shader": "cast-scalar-x4.wgsl.jinja",
          "bindings": "castY",
          "constants": { "outScalar": "\"f16\"" },
          "dispatch": {
            "threads": "ceilDiv(dim(shapes.A, 0) * attrs.N, 4)",
            "workgroupSize": "tunables.WORKGROUP_SIZE"
          }
        }
      ],
      "description": "Runs the subgroup-matrix tier for a float16 request by widening the activations to float32 either side of the multiply. The matrix units this operator uses accumulate in float32 from float32 operands; the device's float16 configuration returns a float16 result, so feeding them float16 directly would drop the accumulator's precision.",
      "intermediates": [
        { "id": "aF32", "dtype": "float32", "shape": "[numel(shapes.A)]" },
        { "id": "yF32", "dtype": "float32", "shape": "[dim(shapes.A, 0) * attrs.N]" }
      ]
    },
    {
      "id": "tiled",
      "priority": 10,
      "when": ["tileEligible", "tileWorkgroupFits"],
      "constants": {
        "tileK": "tunables.PORTABLE_TILE_K",
        "aScalar": "\"f16\" if tensorDtypes.A == \"float16\" else \"f32\"",
        "usesF16": "tensorDtypes.A == \"float16\"",
        "absmaxScalar": "\"f16\" if tensorDtypes.absmax == \"float16\" else \"f32\""
      },
      "passes": [
        {
          "id": "main",
          "shader": "matmul-bnb4-tiled.wgsl.jinja",
          "bindings": "main",
          "dispatch": { "x": "ceilDiv(attrs.N, 64)", "y": "ceilDiv(dim(shapes.A, 0), 64)" }
        }
      ]
    },
    {
      "id": "scalar",
      "priority": 0,
      "when": ["commonShapeValid", "portableWorkgroupSize > 0"],
      "constants": {
        "workgroupSize": "portableWorkgroupSize",
        "aScalar": "\"f16\" if tensorDtypes.A == \"float16\" else \"f32\"",
        "usesF16": "tensorDtypes.A == \"float16\"",
        "absmaxScalar": "\"f16\" if tensorDtypes.absmax == \"float16\" else \"f32\""
      },
      "passes": [
        {
          "id": "main",
          "shader": "matmul-bnb4.wgsl.jinja",
          "bindings": "main",
          "dispatch": { "threads": "numel(shapes.Y)", "workgroupSize": "constants.workgroupSize" }
        }
      ]
    }
  ]
}