sync 6fdf6301e2bb
Browse filesFiles changed (6)
54 unmodified lines5556575858596061626364656566676854 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- [`bench.json`](build/webgpu/bench.json) — benchmark cases- [`gather-block-quantized-q4-pair.wgsl.jinja`](build/webgpu/gather-block-quantized-q4-pair.wgsl.jinja)- [`gather-block-quantized-q8-vec4.wgsl.jinja`](build/webgpu/gather-block-quantized-q8-vec4.wgsl.jinja)
## Use with `@huggingface/kernels`
```shnpm install --save-exact @huggingface/kernels@0.0.1-preview.2npm 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.173 unmodified lines17417517617717717817918052 unmodified lines233234235236236237238239173 unmodified lines } }, { "name": "gather-block-q8-alignment-healthy-cols1024-vec4", "name": "gather-block-q8-alignment-control-cols1024-vec4", "preset": "smoke", "vars": { "rows": 4096, "cols": 1024, "indexCount": 1024, "bits": 8, "blockSize": 32 }, "attrs": { "bits": 8, "block_size": 32 },52 unmodified lines } }, { "name": "gather-block-q8-dispatch-healthy-idx1024-cols4096-1d", "name": "gather-block-q8-dispatch-control-idx1024-cols4096-1d", "preset": "stress", "provenance": { "notes": "Widened uint8 GPU storage gives this capacity stress case a declared footprint of 280 MiB."123456789101178912131415{% 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;
@compute @workgroup_size(WG, 1, 1)fn main(@builtin(global_invocation_id) gid: vec3<u32>) { // 2D-folded flat index: gid.y carries the high bits past the per-axis dispatch fold width. // Reduces to gid.x when the dispatch does not fold. let pair_index = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * WG;{{ flat_index_2d("WG", "pair_index", "") }} let total = params.indexCount * params.packedCols; if (pair_index >= total) { return;123456789101178912131415{% 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;
@compute @workgroup_size(WG, 1, 1)fn main(@builtin(global_invocation_id) gid: vec3<u32>) { // 2D-folded flat index: gid.y carries the high bits past the per-axis dispatch fold width. // Reduces to gid.x when the dispatch does not fold. let vec_index = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * WG;{{ flat_index_2d("WG", "vec_index", "") }}{% if scalarTail %} let row_vecs = (params.cols + 3u) / 4u;{% else %}42 unmodified lines434445464748495051525354515253545556575859566061622 unmodified lines656667656869677071722 unmodified lines7576777677787980798182833 unmodified lines878889899091919293949 unmodified lines1041051061071081091101111121131141071081091108 unmodified lines1191201211291221231311321331341351361371381241251261271281421431291301311451461321331341351361371381391531401411551561571581591601611621631421431441451461471681481491501513 unmodified lines1551561571781581591801811821831841851861871881891601611621631641931941651661671961971681691701711723 unmodified lines1761771782072082092102112122132141791801811821832191841851861876 unmodified lines19419519623223323423523623723823924019719819920020124520220320420542 unmodified lines "zeroPointsValid": "present.zeroPointsT and ranks.zeroPointsT == 2 and tensorDtypes.zeroPointsT == \"uint8\" and dim(shapes.zeroPointsT, 0) == dim(shapes.dataT, 0) and dim(shapes.zeroPointsT, 1) == zeroPointCols", "noZeroMode": "not present.zeroPointsT", "zeroMode": "zeroPointsValid", "hasZero": "zeroMode", "indexScalar": "\"u32\"", "scaleScalar": "\"f32\"", "zeroPointElement": "\"u32\"", "workgroupFits": "workgroupSize > 0", "foldedDispatchFits": "ceil(ceil(numel(shapes.outputT) / min(device.limits.maxComputeWorkgroupsPerDimension, 65535)) / workgroupSize) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)" }, "when": ["foldedDispatchFits", "workgroupFits"], "bindings": { "data": { "arg": "dataT", "buffer": "read-only-storage", "elementType": "$dataElement" }, "indices": { "arg": "indicesT", "buffer": "read-only-storage", "elementType": "$indexScalar" }, "scales": { "arg": "scalesT", "buffer": "read-only-storage", "elementType": "$scaleScalar" }, "output": { "arg": "outputT", "buffer": "storage", "elementType": "$outputElement" }, "data": { "arg": "dataT", "elementType": "$dataElement" }, "indices": { "arg": "indicesT", "elementType": "$indexScalar" }, "scales": { "arg": "scalesT", "elementType": "$scaleScalar" }, "output": { "arg": "outputT", "elementType": "$outputElement" }, "params": { "buffer": "uniform", "struct": [ { "name": "indexCount", "type": "u32", "value": "dim(shapes.indicesT, 0)" }, { "name": "cols", "type": "u32", "value": "dim(shapes.outputT, 1)" },2 unmodified lines { "name": "rows", "type": "u32", "value": "dim(shapes.dataT, 0)" } ] }, "params_2": { "params_main": { "name": "params", "buffer": "uniform", "struct": [ { "name": "indexCount", "type": "u32", "value": "dim(shapes.indicesT, 0)" }, { "name": "packedCols", "type": "u32", "value": "dim(shapes.dataT, 1)" },2 unmodified lines { "name": "rows", "type": "u32", "value": "dim(shapes.dataT, 0)" } ] }, "zero_points": { "arg": "zeroPointsT", "buffer": "read-only-storage", "elementType": "$zeroPointElement" }, "params_3": { "zero_points": { "arg": "zeroPointsT", "elementType": "$zeroPointElement" }, "params__uniform": { "name": "params", "buffer": "uniform", "struct": [ { "name": "indexCount", "type": "u32", "value": "dim(shapes.indicesT, 0)" }, { "name": "packedCols", "type": "u32", "value": "dim(shapes.dataT, 1)" },3 unmodified lines { "name": "rows", "type": "u32", "value": "dim(shapes.dataT, 0)" } ] }, "params_4": { "params_q8_zero_tail4": { "name": "params", "buffer": "uniform", "struct": [ { "name": "indexCount", "type": "u32", "value": "dim(shapes.indicesT, 0)" }, { "name": "cols", "type": "u32", "value": "dim(shapes.outputT, 1)" },9 unmodified lines "id": "q8_no_zero_vec4", "priority": 10, "when": ["q8ShapeValid", "noZeroMode", "bits == 8", "blockSize % 4 == 0", "dim(shapes.outputT, 1) % 4 == 0"], "derive": { "hasZero": false, "scalarTail": false, "dataElement": "\"vec4<u32>\"", "indexScalar": "\"u32\"", "scaleScalar": "\"f32\"", "outputElement": "\"vec4<f32>\"" }, "derive": { "scalarTail": false, "dataElement": "\"vec4<u32>\"", "outputElement": "\"vec4<f32>\"" }, "passes": [ { "id": "main",8 unmodified lines ] }, { "id": "q4_no_zero_pair", "id": "q8_zero_vec4", "priority": 10, "when": ["q4ShapeValid", "noZeroMode", "bits == 4"], "derive": { "hasZero": false, "dataElement": "\"u32\"", "indexScalar": "\"u32\"", "scaleScalar": "\"f32\"", "outputElement": "\"vec2<f32>\"" }, "when": ["q8ShapeValid", "zeroMode", "bits == 8", "blockSize % 4 == 0", "dim(shapes.outputT, 1) % 4 == 0"], "derive": { "scalarTail": false, "dataElement": "\"vec4<u32>\"", "outputElement": "\"vec4<f32>\"" }, "passes": [ { "id": "main", "shader": "gather-block-quantized-q4-pair.wgsl.jinja", "bindings": ["data", "indices", "scales", "output", "params_2"], "shader": "gather-block-quantized-q8-vec4.wgsl.jinja", "bindings": ["data", "indices", "scales", "zero_points", "output", "params"], "dispatch": { "x": "min(ceilDiv((dim(shapes.indicesT, 0) * dim(shapes.dataT, 1)), (workgroupSize)), 65535)", "y": "ceilDiv(ceilDiv((dim(shapes.indicesT, 0) * dim(shapes.dataT, 1)), (workgroupSize)), 65535)", "x": "min(ceilDiv((dim(shapes.indicesT, 0) * (dim(shapes.outputT, 1) / 4)), (workgroupSize)), 65535)", "y": "ceilDiv(ceilDiv((dim(shapes.indicesT, 0) * (dim(shapes.outputT, 1) / 4)), (workgroupSize)), 65535)", "z": 1 } } ] }, { "id": "q4_zero_pair", "id": "q4_no_zero_pair", "priority": 10, "when": ["q4ShapeValid", "zeroMode", "bits == 4"], "derive": { "hasZero": true, "dataElement": "\"u32\"", "indexScalar": "\"u32\"", "scaleScalar": "\"f32\"", "outputElement": "\"vec2<f32>\"", "zeroPointElement": "\"u32\"" }, "when": ["q4ShapeValid", "noZeroMode", "bits == 4"], "derive": { "dataElement": "\"u32\"", "outputElement": "\"vec2<f32>\"" }, "passes": [ { "id": "main", "shader": "gather-block-quantized-q4-pair.wgsl.jinja", "bindings": ["data", "indices", "scales", "zero_points", "output", "params_3"], "bindings": ["data", "indices", "scales", "output", "params_main"], "dispatch": { "x": "min(ceilDiv((dim(shapes.indicesT, 0) * dim(shapes.dataT, 1)), (workgroupSize)), 65535)", "y": "ceilDiv(ceilDiv((dim(shapes.indicesT, 0) * dim(shapes.dataT, 1)), (workgroupSize)), 65535)",3 unmodified lines ] }, { "id": "q8_zero_vec4", "id": "q4_zero_pair", "priority": 10, "when": ["q8ShapeValid", "zeroMode", "bits == 8", "blockSize % 4 == 0", "dim(shapes.outputT, 1) % 4 == 0"], "derive": { "hasZero": true, "scalarTail": false, "dataElement": "\"vec4<u32>\"", "zeroPointElement": "\"u32\"", "indexScalar": "\"u32\"", "scaleScalar": "\"f32\"", "outputElement": "\"vec4<f32>\"" }, "when": ["q4ShapeValid", "zeroMode", "bits == 4"], "derive": { "dataElement": "\"u32\"", "outputElement": "\"vec2<f32>\"" }, "passes": [ { "id": "main", "shader": "gather-block-quantized-q8-vec4.wgsl.jinja", "bindings": ["data", "indices", "scales", "zero_points", "output", "params"], "shader": "gather-block-quantized-q4-pair.wgsl.jinja", "bindings": ["data", "indices", "scales", "zero_points", "output", "params__uniform"], "dispatch": { "x": "min(ceilDiv((dim(shapes.indicesT, 0) * (dim(shapes.outputT, 1) / 4)), (workgroupSize)), 65535)", "y": "ceilDiv(ceilDiv((dim(shapes.indicesT, 0) * (dim(shapes.outputT, 1) / 4)), (workgroupSize)), 65535)", "x": "min(ceilDiv((dim(shapes.indicesT, 0) * dim(shapes.dataT, 1)), (workgroupSize)), 65535)", "y": "ceilDiv(ceilDiv((dim(shapes.indicesT, 0) * dim(shapes.dataT, 1)), (workgroupSize)), 65535)", "z": 1 } }3 unmodified lines "id": "q8_no_zero_tail4", "priority": 5, "when": ["q8ShapeValid", "noZeroMode", "bits == 8"], "derive": { "hasZero": false, "scalarTail": true, "dataElement": "\"u32\"", "indexScalar": "\"u32\"", "scaleScalar": "\"f32\"", "outputElement": "\"f32\"" }, "derive": { "scalarTail": true, "dataElement": "\"u32\"", "outputElement": "\"f32\"" }, "passes": [ { "id": "main", "shader": "gather-block-quantized-q8-vec4.wgsl.jinja", "bindings": ["data", "indices", "scales", "output", "params_4"], "bindings": ["data", "indices", "scales", "output", "params_q8_zero_tail4"], "dispatch": { "x": "min(ceilDiv((dim(shapes.indicesT, 0) * ceilDiv(dim(shapes.outputT, 1), 4)), (workgroupSize)), 65535)", "y": "ceilDiv(ceilDiv((dim(shapes.indicesT, 0) * ceilDiv(dim(shapes.outputT, 1), 4)), (workgroupSize)), 65535)",6 unmodified lines "id": "q8_zero_tail4", "priority": 5, "when": ["q8ShapeValid", "zeroMode", "bits == 8"], "derive": { "hasZero": true, "scalarTail": true, "dataElement": "\"u32\"", "indexScalar": "\"u32\"", "scaleScalar": "\"f32\"", "outputElement": "\"f32\"", "zeroPointElement": "\"u32\"" }, "derive": { "scalarTail": true, "dataElement": "\"u32\"", "outputElement": "\"f32\"" }, "passes": [ { "id": "main", "shader": "gather-block-quantized-q8-vec4.wgsl.jinja", "bindings": ["data", "indices", "scales", "zero_points", "output", "params_4"], "bindings": ["data", "indices", "scales", "zero_points", "output", "params_q8_zero_tail4"], "dispatch": { "x": "min(ceilDiv((dim(shapes.indicesT, 0) * ceilDiv(dim(shapes.outputT, 1), 4)), (workgroupSize)), 65535)", "y": "ceilDiv(ceilDiv((dim(shapes.indicesT, 0) * ceilDiv(dim(shapes.outputT, 1), 4)), (workgroupSize)), 65535)",123345678910111213101112131415161717181919202122232424252627{ "name": "com.microsoft.GatherBlockQuantized", "id": "_com_microsoft_gatherblockquantized_webgpu_dceac49", "id": "_com_microsoft_gatherblockquantized_webgpu_7698e56", "version": 1, "license": "Apache-2.0", "backend": { "type": "webgpu" }, "digest": { "algorithm": "sha256", "files": { "bench.json": "iQN5nfNOefh08J/5z4Vc63omCfclP0JZggomZracQjI=", "gather-block-quantized-q4-pair.wgsl.jinja": "9LBelD9NWvia8DuYSL/FCXreyJ6mLtpiiddFdbronSM=", "gather-block-quantized-q8-vec4.wgsl.jinja": "3RQDkgbVbh8TiZZzROkXVWxlFTYBgz4IqY27DOvuVyY=", "manifest.json": "3+GjaCq6H0K41bzVOxcw9rg9vf0MVERgqWjUqBgopq4=", "bench.json": "jKDPiApwDuwewTrNn1DOYD7gMVHY+vME4qUAe2kUbsw=", "gather-block-quantized-q4-pair.wgsl.jinja": "szEkOKfzt9XFHiIsEiQY0g5efbe36fXYBCE3v4SVo6s=", "gather-block-quantized-q8-vec4.wgsl.jinja": "akD5Z/+o9Q/HRnbH8yPrD8Y6Pd0SWPgiDRwgHEqt/YQ=", "manifest.json": "1/OD0zneUAu2ddg/neSEu+dpmmWqZiMNA9AVO6AI1W8=", "test.json": "+2tkFsiI9bP4xaQI+hw2wX3CbMkCEqUzgTHYrTAL6bg=" } }, "provenance": { "kernel": { "sha": "91d990483a174128daf7673f3f37a7c890493ae1", "dirty": false } }, "provenance": { "kernel": { "sha": "6fdf6301e2bbcc2f03bf1eaf493b7ad55ef33afc", "dirty": false } }, "webgpu": { "manifestSpec": "2.0", "manifestSpec": "2.1", "variants": { "q8_no_zero_vec4": ["gather-block-quantized-q8-vec4.wgsl.jinja"], "q8_zero_vec4": ["gather-block-quantized-q8-vec4.wgsl.jinja"], "q4_no_zero_pair": ["gather-block-quantized-q4-pair.wgsl.jinja"], "q4_zero_pair": ["gather-block-quantized-q4-pair.wgsl.jinja"], "q8_zero_vec4": ["gather-block-quantized-q8-vec4.wgsl.jinja"], "q8_no_zero_tail4": ["gather-block-quantized-q8-vec4.wgsl.jinja"], "q8_zero_tail4": ["gather-block-quantized-q8-vec4.wgsl.jinja"] }README.md+2-2
build/webgpu/bench.json+2-2
build/webgpu/gather-block-quantized-q4-pair.wgsl.jinja+6-3
build/webgpu/gather-block-quantized-q8-vec4.wgsl.jinja+6-3
build/webgpu/manifest.json+35-78
build/webgpu/metadata.json+8-8