sync 6fdf6301e2bb
Browse filesFiles changed (8)
67 unmodified lines686970717273743 unmodified lines7879808182838467 unmodified lines- [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, per-variant templates, provenance)- [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)- [`test.json`](build/webgpu/test.json) — correctness cases- [`bench.json`](build/webgpu/bench.json) — benchmark + tuning cases- [`cast-scalar-x4.wgsl.jinja`](build/webgpu/cast-scalar-x4.wgsl.jinja)- [`matmul-bnb4-gemv.wgsl.jinja`](build/webgpu/matmul-bnb4-gemv.wgsl.jinja)- [`matmul-bnb4-sgmat.wgsl.jinja`](build/webgpu/matmul-bnb4-sgmat.wgsl.jinja)3 unmodified lines## Use with `@huggingface/kernels````shnpm install --save-exact @huggingface/kernels@0.0.1-preview.2```Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.67 unmodified lines686970717273743 unmodified lines7879808182838467 unmodified lines- [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, per-variant templates, provenance)- [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)- [`test.json`](build/webgpu/test.json) — correctness cases- [`bench.json`](build/webgpu/bench.json) — benchmark cases- [`cast-scalar-x4.wgsl.jinja`](build/webgpu/cast-scalar-x4.wgsl.jinja)- [`matmul-bnb4-gemv.wgsl.jinja`](build/webgpu/matmul-bnb4-gemv.wgsl.jinja)- [`matmul-bnb4-sgmat.wgsl.jinja`](build/webgpu/matmul-bnb4-sgmat.wgsl.jinja)3 unmodified lines## Use with `@huggingface/kernels````shnpm install --save-exact @huggingface/kernels@0.0.1-preview.3```Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.
121 unmodified lines122123124125126127128121 unmodified lines{"name": "bnb4-nf4-speculative-m15-k4096-n4096-b64-band","provenance": {"notes": "Fifteen rows represent a speculative decoder's verification width and exercise the tiled route immediately below M=16. `nf4-tiled-speculative-band-m16-control` brackets that boundary."},"preset": "model","vars": { "M": 15, "K": 4096, "N": 4096, "blockSize": 64 },121 unmodified lines122123124125126127128121 unmodified lines{"name": "bnb4-nf4-speculative-m15-k4096-n4096-b64-band","provenance": {"notes": "Measures a 15-row NF4 multiply (K=4096, N=4096, block size 64), the verification width of a speculative decoder. `bnb4-nf4-speculative-m16-k4096-n4096-b64-tile-floor-control` is the same multiply with 16 rows."},"preset": "model","vars": { "M": 15, "K": 4096, "N": 4096, "blockSize": 64 },
71 unmodified lines72737475767720 unmodified lines989910010110210310410510610710810911011111211311413 unmodified lines12812913013113213313413513613713813914014114214314414514614714814915015118 unmodified lines17017117217317417517617717817918018118218318418518618718818919019119219319419519619758 unmodified lines25625725825926026126226326426526626726826927027127227327427527627727827910 unmodified lines29029129229329429529629729829930030126 unmodified lines32832933033133233333433533633733833934034134234334434534634734834935035114 unmodified lines36636736836937037137237337437537637737837938038138238338438538638738838939039139239349 unmodified lines4434444454464474484494504514524534544557 unmodified lines46346446546646746846947047147247347471 unmodified lines"sgmatWidenOutBytes": "dim(shapes.aT, 0) * attrs.N * 4","sgmatWidenFits": "sgmatWidenBytes <= device.limits.maxStorageBufferBindingSize and sgmatWidenBytes <= device.limits.maxBufferSize and sgmatWidenOutBytes <= device.limits.maxStorageBufferBindingSize and sgmatWidenOutBytes <= device.limits.maxBufferSize","quantType": "attrs.quant_type","ABSMAX_LEN": "ceilDiv(attrs.N * attrs.K, attrs.block_size)","stagedGeometryValid": "tunables.SGMAT_TILE_COLS >= sgmatSubCols and tunables.SGMAT_TILE_COLS % sgmatSubCols == 0 and tunables.SGMAT_TILE_K >= sgmatMatrixSize and tunables.SGMAT_TILE_K % sgmatMatrixSize == 0","stagedRowSubtiles": "max(1, min(sgmatRowSubtiles, pow2ceil(ceilDiv(dim(shapes.aT, 0), sgmatMatrixSize)), floor(deviceWorkgroupCap / (32 * max(1, sgmatColSubtiles))), floor(tunables.SGMAT_TILE_K / sgmatMatrixSize), floor((device.limits.maxComputeWorkgroupStorageSize - sgmatWorkgroupStorageBytes) / (4 * sgmatMatrixSize * max(1, tunables.SGMAT_TILE_K)))))",20 unmodified lines"hybridResourcesFit": "prefixResourcesFit and hybridStorageBytes <= device.limits.maxComputeWorkgroupStorageSize and hybridDispatchRows <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)"},"bindings": {"a": { "arg": "aT", "buffer": "read-only-storage", "elementType": "$aScalar" },"b": { "arg": "bT", "buffer": "read-only-storage", "elementType": "u32" },"absmax": {"arg": "absmaxT","buffer": "read-only-storage","elementType": "$absmaxScalar","length": "$ABSMAX_LEN"},"y": { "arg": "yT", "buffer": "storage", "elementType": "$aScalar" },"params": {"buffer": "uniform","struct": [{ "name": "rows", "type": "u32", "value": "dim(shapes.aT, 0)" },{ "name": "K", "type": "u32", "value": "attrs.K" },13 unmodified lines"subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }]},"derive": {"K": "attrs.K","N": "attrs.N","blockSize": "attrs.block_size","tileRows": "prefixTileRows","tileCols": "tunables.SGMAT_TILE_COLS","tileK": "tunables.SGMAT_TILE_K","subRows": "prefixTileRows / sgmatRowSubtiles","subCols": "sgmatSubCols","matrixSize": "sgmatMatrixSize","rowMatrices": "prefixTileRows / (sgmatRowSubtiles * sgmatMatrixSize)","colMatrices": "sgmatSubCols / sgmatMatrixSize","loadWidth": "sgmatLoadWidth","rowSubtiles": "sgmatRowSubtiles","workgroupSize": "sgmatWorkgroupSize","bLoadsPerRow": "sgmatBLoadsPerRow","aScalar": "\"f32\"","usesF16": false,"absmaxScalar": "\"f16\" if tensorDtypes.absmaxT == \"float16\" else \"f32\"","hybridRows": true,"rowCount": "dim(shapes.aT, 0)","fullDispatchRows": "sgmatFullRows / prefixTileRows",18 unmodified lines"subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }]},"derive": {"K": "attrs.K","N": "attrs.N","blockSize": "attrs.block_size","tileRows": "prefixTileRows","tileCols": "tunables.SGMAT_TILE_COLS","tileK": "tunables.SGMAT_TILE_K","subRows": "prefixTileRows / sgmatRowSubtiles","subCols": "sgmatSubCols","matrixSize": "sgmatMatrixSize","rowMatrices": "prefixTileRows / (sgmatRowSubtiles * sgmatMatrixSize)","colMatrices": "sgmatSubCols / sgmatMatrixSize","loadWidth": "sgmatLoadWidth","rowSubtiles": "sgmatRowSubtiles","workgroupSize": "sgmatWorkgroupSize","bLoadsPerRow": "sgmatBLoadsPerRow","aScalar": "\"f32\"","usesF16": true,"absmaxScalar": "\"f16\" if tensorDtypes.absmaxT == \"float16\" else \"f32\"","srcScalar": "\"f16\"","outScalar": "\"f32\"","wrapNarrowInt": false,"wrapSigned": false,"hybridRows": true,"rowCount": "dim(shapes.aT, 0)","fullDispatchRows": "sgmatFullRows / prefixTileRows",58 unmodified lines"subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }]},"derive": {"K": "attrs.K","N": "attrs.N","blockSize": "attrs.block_size","tileRows": "stagedTileRows","tileCols": "tunables.SGMAT_TILE_COLS","tileK": "tunables.SGMAT_TILE_K","subRows": "sgmatMatrixSize","subCols": "stagedSubCols","matrixSize": "sgmatMatrixSize","rowMatrices": 1,"colMatrices": "stagedColumnMatrices","loadWidth": "sgmatLoadWidth","rowSubtiles": "stagedRowSubtiles","workgroupSize": "stagedWorkgroupSize","bLoadsPerRow": "sgmatBLoadsPerRow","aScalar": "\"f16\" if tensorDtypes.aT == \"float16\" else \"f32\"","usesF16": "tensorDtypes.aT == \"float16\"","absmaxScalar": "\"f16\" if tensorDtypes.absmaxT == \"float16\" else \"f32\"","stageActivations": true,"rowCount": "dim(shapes.aT, 0)"},10 unmodified lines"id": "gemv","priority": 20,"when": ["gemvShapeValid", "portableWorkgroupFits"],"derive": {"workgroupSize": "portableWorkgroupSize","aScalar": "\"f16\" if tensorDtypes.aT == \"float16\" else \"f32\"","usesF16": "tensorDtypes.aT == \"float16\"","absmaxScalar": "\"f16\" if tensorDtypes.absmaxT == \"float16\" else \"f32\""},"passes": [{"id": "main",26 unmodified lines"subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }]},"derive": {"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.absmaxT == \"float16\" else \"f32\""},"passes": [{14 unmodified lines"subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }]},"derive": {"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.absmaxT == \"float16\" else \"f32\"","srcScalar": "\"f16\"","outScalar": "\"f32\"","wrapNarrowInt": false,"wrapSigned": false},"intermediates": [{ "id": "aF32", "dtype": "float32", "shape": "[numel(shapes.aT)]" },49 unmodified lines"id": "tiled","priority": 10,"when": ["tileEligible", "tileWorkgroupFits"],"derive": {"tileK": "tunables.PORTABLE_TILE_K","aScalar": "\"f16\" if tensorDtypes.aT == \"float16\" else \"f32\"","usesF16": "tensorDtypes.aT == \"float16\"","absmaxScalar": "\"f16\" if tensorDtypes.absmaxT == \"float16\" else \"f32\"","tileRows": "portableTileRows"},"passes": [{"id": "main",7 unmodified lines"id": "scalar","priority": 0,"when": ["commonShapeValid", "portableWorkgroupSize > 0"],"derive": {"workgroupSize": "portableWorkgroupSize","aScalar": "\"f16\" if tensorDtypes.aT == \"float16\" else \"f32\"","usesF16": "tensorDtypes.aT == \"float16\"","absmaxScalar": "\"f16\" if tensorDtypes.absmaxT == \"float16\" else \"f32\""},"passes": [{"id": "main",71 unmodified lines72737475767778798081828384858687888990919220 unmodified lines11311411511611711811912012112212313 unmodified lines13713813914014114214314414518 unmodified lines16416516616716816917017117217317417558 unmodified lines23423523623723823924024124224324424524610 unmodified lines25725825926026126226326 unmodified lines29029129229329429529629729814 unmodified lines31331431531631731831932032132232332449 unmodified lines3743753763773783793807 unmodified lines38838939039139239339471 unmodified lines"sgmatWidenOutBytes": "dim(shapes.aT, 0) * attrs.N * 4","sgmatWidenFits": "sgmatWidenBytes <= device.limits.maxStorageBufferBindingSize and sgmatWidenBytes <= device.limits.maxBufferSize and sgmatWidenOutBytes <= device.limits.maxStorageBufferBindingSize and sgmatWidenOutBytes <= device.limits.maxBufferSize","quantType": "attrs.quant_type","K": "attrs.K","N": "attrs.N","blockSize": "attrs.block_size","tileCols": "tunables.SGMAT_TILE_COLS","tileK": "tunables.SGMAT_TILE_K","matrixSize": "sgmatMatrixSize","subCols": "sgmatSubCols","colMatrices": "sgmatSubCols / sgmatMatrixSize","loadWidth": "sgmatLoadWidth","rowSubtiles": "sgmatRowSubtiles","workgroupSize": "sgmatWorkgroupSize","bLoadsPerRow": "sgmatBLoadsPerRow","aScalar": "\"f16\" if tensorDtypes.aT == \"float16\" else \"f32\"","usesF16": "tensorDtypes.aT == \"float16\"","absmaxScalar": "\"f16\" if tensorDtypes.absmaxT == \"float16\" else \"f32\"","ABSMAX_LEN": "ceilDiv(attrs.N * attrs.K, attrs.block_size)","stagedGeometryValid": "tunables.SGMAT_TILE_COLS >= sgmatSubCols and tunables.SGMAT_TILE_COLS % sgmatSubCols == 0 and tunables.SGMAT_TILE_K >= sgmatMatrixSize and tunables.SGMAT_TILE_K % sgmatMatrixSize == 0","stagedRowSubtiles": "max(1, min(sgmatRowSubtiles, pow2ceil(ceilDiv(dim(shapes.aT, 0), sgmatMatrixSize)), floor(deviceWorkgroupCap / (32 * max(1, sgmatColSubtiles))), floor(tunables.SGMAT_TILE_K / sgmatMatrixSize), floor((device.limits.maxComputeWorkgroupStorageSize - sgmatWorkgroupStorageBytes) / (4 * sgmatMatrixSize * max(1, tunables.SGMAT_TILE_K)))))",20 unmodified lines"hybridResourcesFit": "prefixResourcesFit and hybridStorageBytes <= device.limits.maxComputeWorkgroupStorageSize and hybridDispatchRows <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)"},"bindings": {"a": { "arg": "aT", "elementType": "$aScalar" },"b": { "arg": "bT", "elementType": "u32" },"absmax": { "arg": "absmaxT", "elementType": "$absmaxScalar", "length": "$ABSMAX_LEN" },"y": { "arg": "yT", "elementType": "$aScalar" },"params": {"struct": [{ "name": "rows", "type": "u32", "value": "dim(shapes.aT, 0)" },{ "name": "K", "type": "u32", "value": "attrs.K" },13 unmodified lines"subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }]},"derive": {"tileRows": "prefixTileRows","subRows": "prefixTileRows / sgmatRowSubtiles","rowMatrices": "prefixTileRows / (sgmatRowSubtiles * sgmatMatrixSize)","hybridRows": true,"rowCount": "dim(shapes.aT, 0)","fullDispatchRows": "sgmatFullRows / prefixTileRows",18 unmodified lines"subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }]},"derive": {"tileRows": "prefixTileRows","subRows": "prefixTileRows / sgmatRowSubtiles","rowMatrices": "prefixTileRows / (sgmatRowSubtiles * sgmatMatrixSize)","aScalar": "\"f32\"","srcScalar": "\"f16\"","outScalar": "\"f32\"","hybridRows": true,"rowCount": "dim(shapes.aT, 0)","fullDispatchRows": "sgmatFullRows / prefixTileRows",58 unmodified lines"subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }]},"derive": {"tileRows": "stagedTileRows","subRows": "sgmatMatrixSize","subCols": "stagedSubCols","rowMatrices": 1,"colMatrices": "stagedColumnMatrices","rowSubtiles": "stagedRowSubtiles","workgroupSize": "stagedWorkgroupSize","stageActivations": true,"rowCount": "dim(shapes.aT, 0)"},10 unmodified lines"id": "gemv","priority": 20,"when": ["gemvShapeValid", "portableWorkgroupFits"],"derive": { "workgroupSize": "portableWorkgroupSize" },"passes": [{"id": "main",26 unmodified lines"subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }]},"derive": {"tileRows": "sgmatTileRows","subRows": "sgmatSubRows","rowMatrices": "sgmatSubRows / sgmatMatrixSize"},"passes": [{14 unmodified lines"subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }]},"derive": {"tileRows": "sgmatTileRows","subRows": "sgmatSubRows","rowMatrices": "sgmatSubRows / sgmatMatrixSize","aScalar": "\"f32\"","srcScalar": "\"f16\"","outScalar": "\"f32\""},"intermediates": [{ "id": "aF32", "dtype": "float32", "shape": "[numel(shapes.aT)]" },49 unmodified lines"id": "tiled","priority": 10,"when": ["tileEligible", "tileWorkgroupFits"],"derive": { "tileK": "tunables.PORTABLE_TILE_K", "tileRows": "portableTileRows" },"passes": [{"id": "main",7 unmodified lines"id": "scalar","priority": 0,"when": ["commonShapeValid", "portableWorkgroupSize > 0"],"derive": { "workgroupSize": "portableWorkgroupSize" },"passes": [{"id": "main",
20 unmodified lines21222324252627282930313233342 unmodified lines373839404142434420 unmodified lines-0.0, -5.208333333e-03, -0.66666667, -1.0,-0.33333333, -0.5, -0.16666667, -0.25);{%- else %}var<private> quant_map: array<f32, 16> = array<f32, 16>(-1.0, -0.6961928009986877, -0.5250730514526367, -0.39491748809814453,-0.28444138169288635, -0.18477343022823334, -0.09105003625154495, 0.0,0.07958029955625534, 0.16093020141124725, 0.24611230194568634, 0.33791524171829224,0.44070982933044434, 0.5626170039176941, 0.7229568362236023, 1.0);{%- endif %}// One dequantized weight at flat index `flat` into the [N, K] weight.fn dequant_weight(flat: u32) -> f32 {2 unmodified linesreturn quant_map[code] * f32(absmax[flat / params.blockSize]);}// Decode (M == 1): one workgroup owns each output column, with lanes striding K.// Each lane keeps one accumulator and the workgroup closes with a tree reduction.@compute @workgroup_size(WG, 1, 1)20 unmodified lines21222324252627282930313233342 unmodified lines37383940414220 unmodified lines-0.0, -5.208333333e-03, -0.66666667, -1.0,-0.33333333, -0.5, -0.16666667, -0.25);{% else %}var<private> quant_map: array<f32, 16> = array<f32, 16>(-1.0, -0.6961928009986877, -0.5250730514526367, -0.39491748809814453,-0.28444138169288635, -0.18477343022823334, -0.09105003625154495, 0.0,0.07958029955625534, 0.16093020141124725, 0.24611230194568634, 0.33791524171829224,0.44070982933044434, 0.5626170039176941, 0.7229568362236023, 1.0);{% endif %}// One dequantized weight at flat index `flat` into the [N, K] weight.fn dequant_weight(flat: u32) -> f32 {2 unmodified linesreturn quant_map[code] * f32(absmax[flat / params.blockSize]);}// Decode (M == 1): one workgroup owns each output column, with lanes striding K.// Each lane keeps one accumulator and the workgroup closes with a tree reduction.@compute @workgroup_size(WG, 1, 1)
8 unmodified lines91011121314152 unmodified lines1819202122232434 unmodified lines59606162636465666768697071727374758 unmodified lines{% if usesF16 %}// The widened path keeps the activations and the output in f32 for the matrix// units, but the quantization scales stay in the request's own dtype.enable f16;{% endif %}enable subgroups;{% if pinSubgroupSize32 %}2 unmodified linesenable chromium_experimental_subgroup_matrix;diagnostic(off, chromium.subgroup_matrix_uniformity);{{ env.wgsl.resourceDeclarations }}const K: u32 = {{ K }}u;34 unmodified lines-0.0, -5.208333333e-03, -0.66666667, -1.0,-0.33333333, -0.5, -0.16666667, -0.25);{%- else %}var<private> quant_map: array<f32, 16> = array<f32, 16>(-1.0, -0.6961928009986877, -0.5250730514526367, -0.39491748809814453,-0.28444138169288635, -0.18477343022823334, -0.09105003625154495, 0.0,0.07958029955625534, 0.16093020141124725, 0.24611230194568634, 0.33791524171829224,0.44070982933044434, 0.5626170039176941, 0.7229568362236023, 1.0);{%- endif %}fn load_b(tile_base: u32, k_base: u32, row: u32, col_group: u32) {let col = col_group * LOAD_WIDTH;8 unmodified lines910111213142 unmodified lines17181920212234 unmodified lines57585960616263646566676869708 unmodified lines{% if usesF16 %}// The widened path keeps the activations and the output in f32 for the matrix// units, but the quantization scales stay in the request's own dtype.{% endif %}enable subgroups;{% if pinSubgroupSize32 %}2 unmodified linesenable chromium_experimental_subgroup_matrix;diagnostic(off, chromium.subgroup_matrix_uniformity);{{ env.wgsl.resourceDeclarations }}const K: u32 = {{ K }}u;34 unmodified lines-0.0, -5.208333333e-03, -0.66666667, -1.0,-0.33333333, -0.5, -0.16666667, -0.25);{% else %}var<private> quant_map: array<f32, 16> = array<f32, 16>(-1.0, -0.6961928009986877, -0.5250730514526367, -0.39491748809814453,-0.28444138169288635, -0.18477343022823334, -0.09105003625154495, 0.0,0.07958029955625534, 0.16093020141124725, 0.24611230194568634, 0.33791524171829224,0.44070982933044434, 0.5626170039176941, 0.7229568362236023, 1.0);{% endif %}fn load_b(tile_base: u32, k_base: u32, row: u32, col_group: u32) {let col = col_group * LOAD_WIDTH;
40 unmodified lines41424344454647484950515253545526 unmodified lines8283848586878840 unmodified lines-0.0, -5.208333333e-03, -0.66666667, -1.0,-0.33333333, -0.5, -0.16666667, -0.25);{%- else %}var<private> quant_map: array<f32, 16> = array<f32, 16>(-1.0, -0.6961928009986877, -0.5250730514526367, -0.39491748809814453,-0.28444138169288635, -0.18477343022823334, -0.09105003625154495, 0.0,0.07958029955625534, 0.16093020141124725, 0.24611230194568634, 0.33791524171829224,0.44070982933044434, 0.5626170039176941, 0.7229568362236023, 1.0);{%- endif %}// Four consecutive dequantized weights starting at flat index `flat` into the// [N, K] weight. Consecutive indices share a stored byte, so the run costs two26 unmodified linesreturn vec4<f32>(quant_map[codes.x], quant_map[codes.y], quant_map[codes.z], quant_map[codes.w]) * scales;}@compute @workgroup_size(16, 8, 1)fn main(@builtin(workgroup_id) wg: vec3<u32>,40 unmodified lines414243444546474849505152535426 unmodified lines81828384858640 unmodified lines-0.0, -5.208333333e-03, -0.66666667, -1.0,-0.33333333, -0.5, -0.16666667, -0.25);{% else %}var<private> quant_map: array<f32, 16> = array<f32, 16>(-1.0, -0.6961928009986877, -0.5250730514526367, -0.39491748809814453,-0.28444138169288635, -0.18477343022823334, -0.09105003625154495, 0.0,0.07958029955625534, 0.16093020141124725, 0.24611230194568634, 0.33791524171829224,0.44070982933044434, 0.5626170039176941, 0.7229568362236023, 1.0);{% endif %}// Four consecutive dequantized weights starting at flat index `flat` into the// [N, K] weight. Consecutive indices share a stored byte, so the run costs two26 unmodified linesreturn vec4<f32>(quant_map[codes.x], quant_map[codes.y], quant_map[codes.z], quant_map[codes.w]) * scales;}@compute @workgroup_size(16, 8, 1)fn main(@builtin(workgroup_id) wg: vec3<u32>,
12315 unmodified lines19202122232425262728293031322 unmodified lines3536373839404142434445464748{{ env.wgsl.resourceDeclarations }}const WG: u32 = {{ workgroupSize }}u;15 unmodified lines-0.0, -5.208333333e-03, -0.66666667, -1.0,-0.33333333, -0.5, -0.16666667, -0.25);{%- else %}var<private> quant_map: array<f32, 16> = array<f32, 16>(-1.0, -0.6961928009986877, -0.5250730514526367, -0.39491748809814453,-0.28444138169288635, -0.18477343022823334, -0.09105003625154495, 0.0,0.07958029955625534, 0.16093020141124725, 0.24611230194568634, 0.33791524171829224,0.44070982933044434, 0.5626170039176941, 0.7229568362236023, 1.0);{%- endif %}// One dequantized weight at flat index `flat` into the [N, K] weight.fn dequant_weight(flat: u32) -> f32 {2 unmodified linesreturn quant_map[code] * f32(absmax[flat / params.blockSize]);}@compute @workgroup_size(WG, 1, 1)fn main(@builtin(global_invocation_id) gid: vec3<u32>) {// 2D-folded flat output-element index: gid.y carries the high bits past the// per-axis dispatch fold width. With no fold this// reduces to gid.x; the index >= total guard drops the tail.let index = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * WG;let total = params.rows * params.N;if (index >= total) {1234567815 unmodified lines24252627282930313233343536372 unmodified lines404142434445464748{% macro flat_index_2d(workgroupSize, name="i", bound="params.count", guardInline=false) %}{% set wgTerm = workgroupSize ~ "u" if workgroupSize is number else workgroupSize %}// 2D-folded flat index: gid.y carries the high bits past the dispatch's// per-axis workgroup fold width.let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};{% endmacro %}{{ env.wgsl.resourceDeclarations }}const WG: u32 = {{ workgroupSize }}u;15 unmodified lines-0.0, -5.208333333e-03, -0.66666667, -1.0,-0.33333333, -0.5, -0.16666667, -0.25);{% else %}var<private> quant_map: array<f32, 16> = array<f32, 16>(-1.0, -0.6961928009986877, -0.5250730514526367, -0.39491748809814453,-0.28444138169288635, -0.18477343022823334, -0.09105003625154495, 0.0,0.07958029955625534, 0.16093020141124725, 0.24611230194568634, 0.33791524171829224,0.44070982933044434, 0.5626170039176941, 0.7229568362236023, 1.0);{% endif %}// One dequantized weight at flat index `flat` into the [N, K] weight.fn dequant_weight(flat: u32) -> f32 {2 unmodified linesreturn quant_map[code] * f32(absmax[flat / params.blockSize]);}@compute @workgroup_size(WG, 1, 1)fn main(@builtin(global_invocation_id) gid: vec3<u32>) {{{ flat_index_2d("WG", "index", "") }}let total = params.rows * params.N;if (index >= total) {
12345678910111213141516171819202122232425{"name": "com.microsoft.MatMulBnb4","id": "_com_microsoft_matmulbnb4_webgpu_237048a","version": 1,"license": "Apache-2.0","backend": { "type": "webgpu" },"digest": {"algorithm": "sha256","files": {"bench.json": "/Z1zFaT4D+0TEFMxG/zqun5CjI9irI93GNGwLZdLXHQ=","cast-scalar-x4.wgsl.jinja": "s8Y9E2+D7cFgYTUEJhiuPsUzvHjv2mXVoiRmv0A0vTU=","manifest.json": "TEJfUwu6Isit+t0fBCRp0Ny+uC8hUjSe2jgG5kCFcEg=","matmul-bnb4-gemv.wgsl.jinja": "7W3L5RH+5dk5/dKNnjwVFtBt+xgCxorJJ04/8zHrySw=","matmul-bnb4-sgmat.wgsl.jinja": "9WS5F6zd/KFztTpbZjBgJe7WIl0l7uiRelcDv/9YbBc=","matmul-bnb4-tiled.wgsl.jinja": "bADcd5OFuhrZ33Qntqh1PXREZolJZ+RKS+VlweAjPo0=","matmul-bnb4.wgsl.jinja": "6rtf2K0op1IJv2+l66HJjq8XnBATGyefxit0Hj5QREI=","test.json": "KPAf0hjucty64auyD+xOS5RAGDEPYeAlUSJPhbig7CA="}},"provenance": { "kernel": { "sha": "91d990483a174128daf7673f3f37a7c890493ae1", "dirty": false } },"webgpu": {"manifestSpec": "2.0","variants": {"sgmat_hybrid_rows": ["matmul-bnb4-sgmat.wgsl.jinja"],"sgmat_hybrid_rows_widened": ["cast-scalar-x4.wgsl.jinja", "matmul-bnb4-sgmat.wgsl.jinja"],12345678910111213141516171819202122232425{"name": "com.microsoft.MatMulBnb4","id": "_com_microsoft_matmulbnb4_webgpu_2efe1ae","version": 1,"license": "Apache-2.0","backend": { "type": "webgpu" },"digest": {"algorithm": "sha256","files": {"bench.json": "Ixtu6FBToeEWEbpbM/+lGVS3jt0IPtrmZrxRfxo7Uj8=","cast-scalar-x4.wgsl.jinja": "s8Y9E2+D7cFgYTUEJhiuPsUzvHjv2mXVoiRmv0A0vTU=","manifest.json": "TTpD+bhv4VB93QlNQ4Z2xGHvG4ClFxnokPMIbKMH2Bc=","matmul-bnb4-gemv.wgsl.jinja": "5mV78S/5vyeTFu8anlXAsKA+OVz7iy3fmo990lgf/yU=","matmul-bnb4-sgmat.wgsl.jinja": "A0jgHcIQrjdodubOI3bgHSYU9SsGew+/3IJwkMMr6eo=","matmul-bnb4-tiled.wgsl.jinja": "auoAXKsuYOXVbPmzjXMm6IQ5L1HxzjDWaPTSxD+Wd/s=","matmul-bnb4.wgsl.jinja": "81lKMMKBPnPeNbcFXiZZe4KBGefTeBfNaHH1LSgP/6U=","test.json": "KPAf0hjucty64auyD+xOS5RAGDEPYeAlUSJPhbig7CA="}},"provenance": { "kernel": { "sha": "6fdf6301e2bbcc2f03bf1eaf493b7ad55ef33afc", "dirty": false } },"webgpu": {"manifestSpec": "2.1","variants": {"sgmat_hybrid_rows": ["matmul-bnb4-sgmat.wgsl.jinja"],"sgmat_hybrid_rows_widened": ["cast-scalar-x4.wgsl.jinja", "matmul-bnb4-sgmat.wgsl.jinja"],
README.md+2-2
build/webgpu/bench.json+1-1
build/webgpu/manifest.json+24-104
build/webgpu/matmul-bnb4-gemv.wgsl.jinja+2-4
build/webgpu/matmul-bnb4-sgmat.wgsl.jinja+2-7
build/webgpu/matmul-bnb4-tiled.wgsl.jinja+2-4
build/webgpu/matmul-bnb4.wgsl.jinja+8-8
build/webgpu/metadata.json+9-9