sync 4385228f788d
Browse filesFiles changed (9)
- README.md+17-12
- build/webgpu/bench.json+3-1
- build/webgpu/manifest.json+1-277
- build/webgpu/metadata.json+1-32
- build/webgpu/norm-row-stats.wgsl.jinja+22-11
- build/webgpu/rms-normalization-splitk-normalize.wgsl.jinja+69-2
- build/webgpu/rms-normalization-splitk-partials.wgsl.jinja+10-4
- build/webgpu/rms-normalization.wgsl.jinja+11-9
- build/webgpu/test.json+83-22
47 unmodified lines484950515253545556575859606162636465666768697071727374757677787980818247 unmodified lines## Files- [`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- [`norm-row-stats.wgsl.jinja`](build/webgpu/norm-row-stats.wgsl.jinja)- [`rms-normalization-splitk-normalize.wgsl.jinja`](build/webgpu/rms-normalization-splitk-normalize.wgsl.jinja)- [`rms-normalization-splitk-partials.wgsl.jinja`](build/webgpu/rms-normalization-splitk-partials.wgsl.jinja)- [`rms-normalization-stash-f16-serial.wgsl.jinja`](build/webgpu/rms-normalization-stash-f16-serial.wgsl.jinja)- [`rms-normalization.wgsl.jinja`](build/webgpu/rms-normalization.wgsl.jinja)## 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.The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.It follows the `v1` branch as fixes land. To pin exact artifact bytes, pass a 40-character commit `revision` instead of `version`.Replace each `*Data` placeholder with a typed array containing the corresponding input data.```jsimport { getKernel } from "@huggingface/kernels";const kernel = await getKernel("webgpu-kernels/ai.onnx.RMSNormalization", { version: 1 });const { y } = await kernel({x: { data: xData, shape: [1, 2, 3] },scale: { data: scaleData, shape: [3] },});```47 unmodified lines4849505152535455565758596061626364656667686970717273747576777879808182838485868747 unmodified lines## Files- [`metadata.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.RMSNormalization/blob/v1/build/webgpu/metadata.json) — kernel metadata (id, file digests, manifest spec, provenance)- [`manifest.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.RMSNormalization/blob/v1/build/webgpu/manifest.json) — the op contract (source of truth)- [`test.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.RMSNormalization/blob/v1/build/webgpu/test.json) — correctness cases- [`bench.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.RMSNormalization/blob/v1/build/webgpu/bench.json) — benchmark cases- [`norm-row-stats.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.RMSNormalization/blob/v1/build/webgpu/norm-row-stats.wgsl.jinja)- [`rms-normalization-splitk-normalize.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.RMSNormalization/blob/v1/build/webgpu/rms-normalization-splitk-normalize.wgsl.jinja)- [`rms-normalization-splitk-partials.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.RMSNormalization/blob/v1/build/webgpu/rms-normalization-splitk-partials.wgsl.jinja)- [`rms-normalization-stash-f16-serial.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.RMSNormalization/blob/v1/build/webgpu/rms-normalization-stash-f16-serial.wgsl.jinja)- [`rms-normalization.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.RMSNormalization/blob/v1/build/webgpu/rms-normalization.wgsl.jinja)## Use with `@huggingface/kernels````shnpm install --save-exact @huggingface/kernels@0.0.1-preview.4```Paste the example into a browser app that resolves npm imports. Serve the app over HTTPS or localhost with WebGPU available.Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.It follows the `v1` branch as fixes land. To pin exact artifact bytes, pass a 40-character commit `revision` instead of `version`.```jsimport { getKernel } from "@huggingface/kernels";const kernel = await getKernel("webgpu-kernels/ai.onnx.RMSNormalization", { version: 1 });const xData = Float32Array.of(1, 2, 3, 4, 5, 6);const scaleData = Float32Array.of(1, 1, 1);const { y } = await kernel({x: { data: xData, shape: [1, 2, 3] },scale: { data: scaleData, shape: [3] },});console.log({ y });```
125 unmodified lines126127128129130131132125 unmodified lines{"name": "rmsnorm-f32-70000x512-rows-dispatchcliff","preset": "stress","provenance": { "notes": "Stress-only dispatch/capacity case: declared tensors occupy 273 MiB of GPU storage." },"vars": { "dtype": "float32", "rows": 70000, "dim": 512 },"attrs": { "epsilon": 0.000001, "axis": -1 },"inputs": {125 unmodified lines126127128129130131132133134125 unmodified lines{"name": "rmsnorm-f32-70000x512-rows-dispatchcliff","preset": "stress","provenance": {"notes": "float32 RMSNorm over [70000,512] rows (273 MiB of declared tensors); the metric is bandwidth."},"vars": { "dtype": "float32", "rows": 70000, "dim": 512 },"attrs": { "epsilon": 0.000001, "axis": -1 },"inputs": {
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277{"domain": "ai.onnx","name": "RMSNormalization","sinceVersion": 23,"inputs": { "x": { "onnx": "X", "dtype": "T" }, "scale": { "dtype": "V" } },"outputs": { "y": { "onnx": "Y", "dtype": "V", "rank": "ranks.x", "shape": "shapes.x" } },"attributes": { "axis": { "default": -1 }, "epsilon": { "default": 0.00001 }, "stash_type": { "default": 1 } },"attributeConstraints": { "stash_type": { "values": [1, 10] } },"typeConstraints": { "T": ["float32", "float16"], "V": ["float32", "float16"] },"tunables": {"WORKGROUP_SIZE": { "default": 256 },"SPLIT_MAX_ROWS": { "default": 256 },"SPLIT_MIN_HIDDEN": { "default": 16384 },"SPLIT_TARGET_ELEMENTS": { "default": 4096 },"MAX_SPLITS": { "default": 64 }},"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","reportedNonWave32Adapter": "not wave32Adapter and (has(device.adapterInfo, \"subgroupMinSize\") or has(device.adapterInfo, \"subgroupMaxSize\"))","variableSubgroup16To32": "device.features.has(\"subgroups\") and has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize == 16 and device.adapterInfo.subgroupMaxSize == 32","normMaxWorkgroup": "min(tunables.WORKGROUP_SIZE, deviceWorkgroupCap)","hasSubgroupId": "device.features.has(\"subgroups\") and device.wgslLanguageFeatures.has(\"subgroup_id\")","axisNorm": "attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x","normalizedRows": "outer(shapes.x, axisNorm)","normalizedHidden": "dim(shapes.x, axisNorm) * inner(shapes.x, axisNorm)","normalizedDispatchRows": "0 if normalizedHidden == 0 else normalizedRows","normalizedWorkgroupHidden": "max(1, normalizedHidden)","normalizationShapeOk": "ranks.x >= 1 and ranks.scale >= 0 and ranks.scale <= ranks.x and sameShape(shapes.y, shapes.x) and attrs.axis + ranks.x >= 0 and attrs.axis < ranks.x and broadcastable(shapes.scale, shapes.x) and f16Ok(dtypes.T) and f16Ok(dtypes.V)","baseOk": "normalizationShapeOk and attrs.stash_type == onnxDtypeCode(\"float32\")","stashF16Ok": "normalizationShapeOk and attrs.stash_type == onnxDtypeCode(\"float16\")","lastAxisOk": "baseOk and (attrs.axis == -1 or attrs.axis == ranks.x - 1)","suffixAxisOk": "baseOk and ranks.x >= 2 and not (attrs.axis == -1 or attrs.axis == ranks.x - 1)"},"bindings": {"x": { "elementType": "$xElement" },"scale": { "elementType": "$ioElement" },"y": { "elementType": "$ioElement" },"params": {"struct": [{ "name": "rows", "type": "u32", "value": "normalizedRows" },{"name": "rowStride","type": "u32","value": "max(1, min(normalizedRows, min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))"}]},"params__uniform": {"name": "params","struct": [{ "name": "rows", "type": "u32", "value": "splitRows" },{"name": "rowStride","type": "u32","value": "max(1, min(splitRows, min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))"}]}},"variants": [{"id": "stash_f16_serial","priority": 1000,"when": ["stashF16Ok"],"derive": {"scalar": "dtypes.V","xElement": "dtypes.T","ioElement": "dtypes.V","hiddenSize": "normalizedHidden","epsilon": "attrs.epsilon"},"passes": [{"id": "main","name": "RMSNormalization.StashF16Serial","shader": "rms-normalization-stash-f16-serial.wgsl.jinja","derive": {"xShape": "shapes.x","scaleShape": "shapes.scale","xRank": "ranks.x","scaleRank": "ranks.scale"},"bindings": ["x", "scale", "y", "params"],"dispatch": {"x": "min(normalizedDispatchRows, 65535)","y": "ceilDiv(normalizedDispatchRows, 65535)","z": 1}}]},{"id": "suffix_axis_splitk","priority": 15,"when": ["baseOk", "ranks.x >= 2", "normalizedRows <= tunables.SPLIT_MAX_ROWS", "normalizedHidden >= tunables.SPLIT_MIN_HIDDEN", "min(tunables.MAX_SPLITS, pow2ceil(ceilDiv(normalizedHidden, tunables.SPLIT_TARGET_ELEMENTS))) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", "normalizedRows * min(tunables.MAX_SPLITS, pow2ceil(ceilDiv(normalizedHidden, tunables.SPLIT_TARGET_ELEMENTS))) * 4 <= device.limits.maxStorageBufferBindingSize", "normalizedRows * min(tunables.MAX_SPLITS, pow2ceil(ceilDiv(normalizedHidden, tunables.SPLIT_TARGET_ELEMENTS))) * 4 <= device.limits.maxBufferSize", "not (variableSubgroup16To32 and dtypes.T == \"f16\" and dtypes.V == \"f32\")"],"demoteWhen": ["reportedNonWave32Adapter and not variableSubgroup16To32"],"derive": {"splitRows": "normalizedRows","splitHidden": "normalizedHidden","split": "min(tunables.MAX_SPLITS, pow2ceil(ceilDiv(splitHidden, tunables.SPLIT_TARGET_ELEMENTS)))","scalar": "dtypes.V","xElement": "dtypes.T","ioElement": "dtypes.V","hiddenSize": "splitHidden","workgroupSize": "normMaxWorkgroup","epsilon": "attrs.epsilon","normalizeRows": "splitRows"},"intermediates": [{ "id": "partials", "dtype": "float32", "shape": "[splitRows * split]" }],"passes": [{"id": "partials","name": "RMSNormalization.SplitKPartials","shader": "rms-normalization-splitk-partials.wgsl.jinja","bindings": ["x", { "name": "partials", "elementType": "f32" }, "params__uniform"],"dispatch": {"x": "min(splitRows, DISPATCH_FOLD_WIDTH)","y": "ceilDiv(splitRows, DISPATCH_FOLD_WIDTH)","z": "split"}},{"id": "normalize","name": "RMSNormalization.SplitKNormalize","shader": "rms-normalization-splitk-normalize.wgsl.jinja","derive": {"xShape": "shapes.x","scaleShape": "shapes.scale","xRank": "ranks.x","scaleRank": "ranks.scale","normalizeBlocks": "max(split, min(min(device.limits.maxComputeWorkgroupsPerDimension, 65535), ceilDiv(workgroupSize, max(1, normalizeRows)), ceilDiv(hiddenSize, workgroupSize * 4)))","normalizeChunk": "ceilDiv(hiddenSize, normalizeBlocks)"},"bindings": ["x","scale",{ "name": "partials", "buffer": "read-only-storage", "elementType": "f32" },"y","params__uniform"],"dispatch": {"x": "min(splitRows, DISPATCH_FOLD_WIDTH)","y": "ceilDiv(splitRows, DISPATCH_FOLD_WIDTH)","z": "normalizeBlocks"}}]},{"id": "last_axis","priority": 0,"when": ["lastAxisOk"],"derive": {"scalar": "dtypes.V","xElement": "dtypes.T","ioElement": "dtypes.V","hiddenSize": "normalizedHidden","workgroupSize": "min(normMaxWorkgroup, pow2ceil(normalizedWorkgroupHidden))","epsilon": "attrs.epsilon"},"passes": [{"id": "main","name": "RMSNormalization","shader": "rms-normalization.wgsl.jinja","derive": {"compensateHalfStats": true,"xShape": "shapes.x","scaleShape": "shapes.scale","xRank": "ranks.x","scaleRank": "ranks.scale"},"bindings": ["x", "scale", "y", "params"],"dispatch": {"x": "min(normalizedDispatchRows, 65535)","y": "ceilDiv(normalizedDispatchRows, 65535)","z": 1}}]},{"id": "suffix_axis","priority": 10,"when": ["suffixAxisOk"],"derive": {"scalar": "dtypes.V","xElement": "dtypes.T","ioElement": "dtypes.V","hiddenSize": "normalizedHidden","workgroupSize": "min(normMaxWorkgroup, pow2ceil(normalizedWorkgroupHidden))","epsilon": "attrs.epsilon"},"passes": [{"id": "main","name": "RMSNormalization.SuffixAxis","shader": "rms-normalization.wgsl.jinja","derive": {"compensateHalfStats": true,"xShape": "shapes.x","scaleShape": "shapes.scale","xRank": "ranks.x","scaleRank": "ranks.scale"},"bindings": ["x", "scale", "y", "params"],"dispatch": {"x": "min(normalizedDispatchRows, 65535)","y": "ceilDiv(normalizedDispatchRows, 65535)","z": 1}}]},{"id": "last_axis_row_vec4","priority": 110,"when": ["lastAxisOk", "dtypes.T == dtypes.V", "ranks.scale >= 1", "numel(shapes.scale) == dim(shapes.x, -1)", "dim(shapes.scale, -1) == dim(shapes.x, -1)", "dim(shapes.x, -1) % 4 == 0"],"derive": { "xElement": "\"vec4<\" ~ dtypes.T ~ \">\"", "ioElement": "\"vec4<\" ~ dtypes.T ~ \">\"" },"passes": [{"id": "main","name": "RMSNormalization.LastAxisRow","shader": "norm-row-stats.wgsl.jinja","derive": {"compensateHalfStats": true,"vec4": true,"scalar": "dtypes.T","hidden": "dim(shapes.x, -1)","wg": "min(normMaxWorkgroup, pow2ceil(max(1, dim(shapes.x, -1) / 4)))","epsilon": "attrs.epsilon","hiddenVec": "dim(shapes.x, -1) / 4","vecType": "\"vec4<\" ~ dtypes.T ~ \">\"","combineSubgroups": "hasSubgroupId"},"bindings": ["x", "scale", "y", "params"],"dispatch": {"x": "min(normalizedDispatchRows, 65535)","y": "ceilDiv(normalizedDispatchRows, 65535)","z": 1}}]},{"id": "last_axis_row","priority": 100,"when": ["lastAxisOk", "dtypes.T == dtypes.V", "ranks.scale >= 1", "numel(shapes.scale) == dim(shapes.x, -1)", "dim(shapes.scale, -1) == dim(shapes.x, -1)", "true"],"derive": { "xElement": "dtypes.T", "ioElement": "dtypes.T" },"passes": [{"id": "main","name": "RMSNormalization.LastAxisRow","shader": "norm-row-stats.wgsl.jinja","derive": {"compensateHalfStats": true,"vec4": false,"scalar": "dtypes.T","hidden": "dim(shapes.x, -1)","wg": "min(normMaxWorkgroup, pow2ceil(max(1, dim(shapes.x, -1))))","epsilon": "attrs.epsilon","hiddenVec": 1,"vecType": "\"vec4<\" ~ dtypes.T ~ \">\"","combineSubgroups": "hasSubgroupId"},"bindings": ["x", "scale", "y", "params"],"dispatch": {"x": "min(normalizedDispatchRows, 65535)","y": "ceilDiv(normalizedDispatchRows, 65535)","z": 1}}]}]}1{"domain":"ai.onnx","name":"RMSNormalization","sinceVersion":23,"inputs":{"x":{"onnx":"X","dtype":"T"},"scale":{"dtype":"V"}},"outputs":{"y":{"onnx":"Y","dtype":"V","rank":"ranks.x","shape":"shapes.x"}},"attributes":{"axis":{"default":-1},"epsilon":{"default":0.00001},"stash_type":{"default":1}},"attributeConstraints":{"stash_type":{"values":[1,10]}},"typeConstraints":{"T":["float32","float16"],"V":["float32","float16"]},"tunables":{"WORKGROUP_SIZE":{"default":256},"SPLIT_MAX_ROWS":{"default":256},"SPLIT_MIN_HIDDEN":{"default":16384},"SPLIT_TARGET_ELEMENTS":{"default":4096},"MAX_SPLITS":{"default":64}},"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","reportedNonWave32Adapter":"not wave32Adapter and (has(device.adapterInfo, \"subgroupMinSize\") or has(device.adapterInfo, \"subgroupMaxSize\"))","variableSubgroup16To32":"device.features.has(\"subgroups\") and has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize == 16 and device.adapterInfo.subgroupMaxSize == 32","normMaxWorkgroup":"min(tunables.WORKGROUP_SIZE, deviceWorkgroupCap)","hasSubgroupId":"device.features.has(\"subgroups\") and device.wgslLanguageFeatures.has(\"subgroup_id\")","axisNorm":"attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x","normalizedRows":"outer(shapes.x, axisNorm)","normalizedHidden":"dim(shapes.x, axisNorm) * inner(shapes.x, axisNorm)","normalizedDispatchRows":"0 if normalizedHidden == 0 else normalizedRows","normalizedWorkgroupHidden":"max(1, normalizedHidden)","normalizationShapeOk":"ranks.x >= 1 and ranks.scale >= 0 and ranks.scale <= ranks.x and sameShape(shapes.y, shapes.x) and attrs.axis + ranks.x >= 0 and attrs.axis < ranks.x and broadcastable(shapes.scale, shapes.x) and f16Ok(dtypes.T) and f16Ok(dtypes.V)","baseOk":"normalizationShapeOk and attrs.stash_type == onnxDtypeCode(\"float32\")","stashF16Ok":"normalizationShapeOk and attrs.stash_type == onnxDtypeCode(\"float16\")","lastAxisOk":"baseOk and (attrs.axis == -1 or attrs.axis == ranks.x - 1)"},"bindings":{"x":{"elementType":"$xElement"},"scale":{"elementType":"$ioElement"},"y":{"elementType":"$ioElement"},"params":{"struct":[{"name":"rows","type":"u32","value":"normalizedRows"},{"name":"rowStride","type":"u32","value":"max(1, min(normalizedRows, min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))"}]},"params__uniform":{"name":"params","struct":[{"name":"rows","type":"u32","value":"splitRows"},{"name":"rowStride","type":"u32","value":"max(1, min(splitRows, min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))"}]}},"variants":[{"id":"stash_f16_serial","priority":1000,"when":["stashF16Ok"],"derive":{"scalar":"dtypes.V","xElement":"dtypes.T","ioElement":"dtypes.V","hiddenSize":"normalizedHidden","epsilon":"attrs.epsilon"},"passes":[{"id":"main","name":"RMSNormalization.StashF16Serial","shader":"rms-normalization-stash-f16-serial.wgsl.jinja","derive":{"xShape":"shapes.x","scaleShape":"shapes.scale","xRank":"ranks.x","scaleRank":"ranks.scale"},"bindings":["x","scale","y","params"],"dispatch":{"x":"min(normalizedDispatchRows, 65535)","y":"ceilDiv(normalizedDispatchRows, 65535)","z":1}}]},{"id":"suffix_axis_splitk","priority":15,"when":["baseOk","ranks.x >= 2","normalizedRows <= tunables.SPLIT_MAX_ROWS","normalizedHidden >= tunables.SPLIT_MIN_HIDDEN","min(tunables.MAX_SPLITS, pow2ceil(ceilDiv(normalizedHidden, tunables.SPLIT_TARGET_ELEMENTS))) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","normalizedRows * min(tunables.MAX_SPLITS, pow2ceil(ceilDiv(normalizedHidden, tunables.SPLIT_TARGET_ELEMENTS))) * 4 <= device.limits.maxStorageBufferBindingSize","normalizedRows * min(tunables.MAX_SPLITS, pow2ceil(ceilDiv(normalizedHidden, tunables.SPLIT_TARGET_ELEMENTS))) * 4 <= device.limits.maxBufferSize"],"demoteWhen":["reportedNonWave32Adapter and not variableSubgroup16To32"],"derive":{"splitRows":"normalizedRows","splitHidden":"normalizedHidden","split":"min(tunables.MAX_SPLITS, pow2ceil(ceilDiv(splitHidden, tunables.SPLIT_TARGET_ELEMENTS)))","scalar":"dtypes.V","xElement":"dtypes.T","ioElement":"dtypes.V","hiddenSize":"splitHidden","workgroupSize":"normMaxWorkgroup","epsilon":"attrs.epsilon","normalizeRows":"splitRows"},"intermediates":[{"id":"partials","dtype":"float32","shape":"[splitRows * split]"}],"passes":[{"id":"partials","name":"RMSNormalization.SplitKPartials","shader":"rms-normalization-splitk-partials.wgsl.jinja","bindings":["x",{"name":"partials","elementType":"f32"},"params__uniform"],"dispatch":{"x":"min(splitRows, DISPATCH_FOLD_WIDTH)","y":"ceilDiv(splitRows, DISPATCH_FOLD_WIDTH)","z":"split"}},{"id":"normalize","name":"RMSNormalization.SplitKNormalize","shader":"rms-normalization-splitk-normalize.wgsl.jinja","derive":{"xShape":"shapes.x","scaleShape":"shapes.scale","xRank":"ranks.x","scaleRank":"ranks.scale","rmsScaleAfterCast":true,"normalizeBlocks":"max(split, min(min(device.limits.maxComputeWorkgroupsPerDimension, 65535), ceilDiv(workgroupSize, max(1, normalizeRows)), ceilDiv(hiddenSize, workgroupSize * 4)))","normalizeChunk":"ceilDiv(hiddenSize, normalizeBlocks)"},"bindings":["x","scale",{"name":"partials","buffer":"read-only-storage","elementType":"f32"},"y","params__uniform"],"dispatch":{"x":"min(splitRows, DISPATCH_FOLD_WIDTH)","y":"ceilDiv(splitRows, DISPATCH_FOLD_WIDTH)","z":"normalizeBlocks"}}]},{"id":"any_axis","when":["baseOk"],"derive":{"scalar":"dtypes.V","xElement":"dtypes.T","ioElement":"dtypes.V","hiddenSize":"normalizedHidden","workgroupSize":"min(normMaxWorkgroup, pow2ceil(normalizedWorkgroupHidden))","epsilon":"attrs.epsilon"},"passes":[{"id":"main","name":"RMSNormalization","shader":"rms-normalization.wgsl.jinja","derive":{"compensateHalfStats":true,"xShape":"shapes.x","scaleShape":"shapes.scale","xRank":"ranks.x","scaleRank":"ranks.scale","rmsScaleAfterCast":true},"bindings":["x","scale","y","params"],"dispatch":{"x":"min(normalizedDispatchRows, 65535)","y":"ceilDiv(normalizedDispatchRows, 65535)","z":1}}]},{"id":"last_axis_row_vec4","priority":110,"when":["lastAxisOk","dtypes.T == dtypes.V","ranks.scale >= 1","numel(shapes.scale) == dim(shapes.x, -1)","dim(shapes.scale, -1) == dim(shapes.x, -1)","dim(shapes.x, -1) % 4 == 0"],"derive":{"xElement":"\"vec4<\" ~ dtypes.T ~ \">\"","ioElement":"\"vec4<\" ~ dtypes.T ~ \">\""},"passes":[{"id":"main","name":"RMSNormalization.LastAxisRow","shader":"norm-row-stats.wgsl.jinja","derive":{"compensateHalfStats":true,"vec4":true,"rmsScaleAfterCast":true,"scalar":"dtypes.T","hidden":"dim(shapes.x, -1)","wg":"min(normMaxWorkgroup, pow2ceil(max(1, dim(shapes.x, -1) / 4)))","epsilon":"attrs.epsilon","hiddenVec":"dim(shapes.x, -1) / 4","vecType":"\"vec4<\" ~ dtypes.T ~ \">\"","combineSubgroups":"hasSubgroupId"},"bindings":["x","scale","y","params"],"dispatch":{"x":"min(normalizedDispatchRows, 65535)","y":"ceilDiv(normalizedDispatchRows, 65535)","z":1}}]},{"id":"last_axis_row","priority":100,"when":["lastAxisOk","dtypes.T == dtypes.V","ranks.scale >= 1","numel(shapes.scale) == dim(shapes.x, -1)","dim(shapes.scale, -1) == dim(shapes.x, -1)","true"],"derive":{"xElement":"dtypes.T","ioElement":"dtypes.T"},"passes":[{"id":"main","name":"RMSNormalization.LastAxisRow","shader":"norm-row-stats.wgsl.jinja","derive":{"compensateHalfStats":true,"vec4":false,"rmsScaleAfterCast":true,"scalar":"dtypes.T","hidden":"dim(shapes.x, -1)","wg":"min(normMaxWorkgroup, pow2ceil(max(1, dim(shapes.x, -1))))","epsilon":"attrs.epsilon","hiddenVec":1,"vecType":"\"vec4<\" ~ dtypes.T ~ \">\"","combineSubgroups":"hasSubgroupId"},"bindings":["x","scale","y","params"],"dispatch":{"x":"min(normalizedDispatchRows, 65535)","y":"ceilDiv(normalizedDispatchRows, 65535)","z":1}}]}]}
1234567891011121314151617181920212223242526272829303132{"name": "ai.onnx.RMSNormalization","id": "_ai_onnx_rmsnormalization_webgpu_79e305f","version": 1,"license": "Apache-2.0","backend": { "type": "webgpu" },"digest": {"algorithm": "sha256","files": {"bench.json": "aQq6UMoOU5W6oOnS6tWV1CjBpS0e4r93laCsON1jvqk=","manifest.json": "yeH/EnaDGr2egsF8QVQs3KXw6ntjk/KVHH0h44Mdr58=","norm-row-stats.wgsl.jinja": "z9fPI5NfWmJ207kdnob9/md3Cc2yVtW3Uui89r8JKDs=","rms-normalization-splitk-normalize.wgsl.jinja": "LZOLQQd6JVX8rA5YOlcl3cw3cyaAvRYKh6h1lvVEiu4=","rms-normalization-splitk-partials.wgsl.jinja": "KnvI9/ZZe4zPBS+v4ieFHw7RTg/2c/MqVHH1Zj3T/F4=","rms-normalization-stash-f16-serial.wgsl.jinja": "7ZVEC2w1SegkxBz3V2T1DKhGKzmf7q32dqAfKXYr35Q=","rms-normalization.wgsl.jinja": "qpO/TCUizsL9TYtnpqNh1rwf3ZYy+Y5EboJ4j4jZqNc=","test.json": "cXXefTiwUMuJYGZSdIBjsMAyw0EO31uh2QXxrbZBNmU="}},"provenance": { "kernel": { "sha": "6fdf6301e2bbcc2f03bf1eaf493b7ad55ef33afc", "dirty": false } },"webgpu": {"manifestSpec": "2.1","variants": {"stash_f16_serial": ["rms-normalization-stash-f16-serial.wgsl.jinja"],"suffix_axis_splitk": ["rms-normalization-splitk-normalize.wgsl.jinja", "rms-normalization-splitk-partials.wgsl.jinja"],"last_axis": ["rms-normalization.wgsl.jinja"],"suffix_axis": ["rms-normalization.wgsl.jinja"],"last_axis_row_vec4": ["norm-row-stats.wgsl.jinja"],"last_axis_row": ["norm-row-stats.wgsl.jinja"]}}}1{"name":"ai.onnx.RMSNormalization","id":"_ai_onnx_rmsnormalization_webgpu_48cc5de","version":1,"license":"Apache-2.0","backend":{"type":"webgpu"},"digest":{"algorithm":"sha256","files":{"bench.json":"laHjjuDScA4i2yJhJB7Losvbmz5w6vGnJq3M61CxJUs=","manifest.json":"y9Q3Xv6luqBSXd4kgjwXsN0e5Q5TqzjgeOoBQ3aG6aw=","norm-row-stats.wgsl.jinja":"zUxfUr7V3AnLyuP9nBQ41OSmxyDesqcfElQOdq436tk=","rms-normalization-splitk-normalize.wgsl.jinja":"vsmmJeG4x7qAMhRGhaFxFyxFqi26cYvtZtofl+TWFy4=","rms-normalization-splitk-partials.wgsl.jinja":"7C+mdjZBZKHo5jeZ8NWWXvOAxTVul5WHF9N1OFV5/WA=","rms-normalization-stash-f16-serial.wgsl.jinja":"7ZVEC2w1SegkxBz3V2T1DKhGKzmf7q32dqAfKXYr35Q=","rms-normalization.wgsl.jinja":"XG491n9V+fDDALKx712Ar3qf0CIg9wFp7WwLK9a+1qI=","test.json":"bhiO/h0dE3HYg1H7UfY1b1RB2tShx/THdyKrP4uLVk4="}},"provenance":{"kernel":{"sha":"4385228f788ddaa1bd7aec6a80a20f3ddffd8011","dirty":false}},"webgpu":{"manifestSpec":"2.2"}}
1234567891011121314151666 unmodified lines8384858687888964 unmodified lines15415515615715815916016116216316496 unmodified lines26126226326426526626726826927027127227327427527627721 unmodified lines299300301302303304305306307{% set scalarIo = false %}{% set packedF32 = "vec4<f32>" %}{% set rmsScaleVec = "vec4<f32>(scale[i])" %}{% set rmsScaleScalar = "f32(scale[i])" %}{% set reduceThreadParameters = ", sg_lane: u32, sg_id: u32, num_sg: u32"if combineSubgroups else ", tid: u32" %}{% set reduceThreadArguments = ", sg_lane, sg_id, num_sg"if combineSubgroups else ", tid" %}{% if combineSubgroups %}enable subgroups;{% endif %}{{ env.wgsl.resourceDeclarations }}{% if scalar == "f16" and compensateHalfStats is defined and compensateHalfStats %}{% set halfOutputScalar = "f16" %}{% set halfStageVector = vec4 %}fn round_f16_bits_rte(value: f32) -> u32 {66 unmodified lines// Half output magnifies statistics errors at rounding midpoints. Keep a low// residual through the reduction and normalization, then round the typed// float32-normalized/half-scale/half-bias edges explicitly. This is the standard ONNX half path;// other normalization contracts retain their existing arithmetic.const HIDDEN: u32 = {{ hidden }}u;const WG: u32 = {{ wg }}u;const EPSILON: f32 = {{ epsilon }};64 unmodified lines}}}if (num_sg == 1u) { return s; }if (subgroupElect()) { sg_partials[sg_id] = s; }workgroupBarrier();var total = vec2<f32>(0.0);for (var i = 0u; i < num_sg; i++) { total = pair_add(total, sg_partials[i]); }// Another reduction may immediately reuse the same storage.workgroupBarrier();return total;96 unmodified linesfn reduce_scalar(value: f32{{ reduceThreadParameters }}) -> f32 {let s = subgroupAdd(value);if (num_sg == 1u) {return s;}if (sg_lane == 0u) {sg_partials[sg_id] = s;}workgroupBarrier();var total = 0.0;for (var i = 0u; i < num_sg; i++) {total += sg_partials[i];}return total;}{% else %}21 unmodified linesfn main(@builtin(workgroup_id) wg_id: vec3<u32>,@builtin(local_invocation_id) lid: vec3<u32>{% if combineSubgroups %},@builtin(subgroup_invocation_id) sg_lane: u32,@builtin(subgroup_id) sg_id: u32,@builtin(num_subgroups) num_sg: u32{% endif %}) {let row = wg_id.x + wg_id.y * params.rowStride;if (row >= params.rows) {123456789101112131415161766 unmodified lines8485868788899064 unmodified lines15515615715815916016116216316416516616716896 unmodified lines26526626726826927027127227327427527627727827928028128228328428528628728821 unmodified lines310311312313314315316317318{% set combineSubgroups = combineSubgroups and not (scalar == "f16" and compensateHalfStats is defined and compensateHalfStats and (device.adapterInfo.subgroupMinSize | default(0)) > 32) %}{% set scalarIo = false %}{% set packedF32 = "vec4<f32>" %}{% set rmsScaleVec = "vec4<f32>(scale[i])" %}{% set rmsScaleScalar = "f32(scale[i])" %}{% set reduceThreadParameters = ", sg_id: u32, num_sg: u32, sg_size: u32"if combineSubgroups else ", tid: u32" %}{% set reduceThreadArguments = ", sg_id, num_sg, sg_size"if combineSubgroups else ", tid" %}{% if combineSubgroups %}enable subgroups;{% endif %}{{ env.wgsl.resourceDeclarations }}{% if scalar == "f16" %}{% set halfOutputScalar = "f16" %}{% set halfStageVector = vec4 %}fn round_f16_bits_rte(value: f32) -> u32 {66 unmodified lines// Half output magnifies statistics errors at rounding midpoints. Keep a low// residual through the reduction and normalization, then round the typed// float32-normalized/half-scale/half-bias edges explicitly. This is the standard ONNX half path;// other normalization contracts use their own arithmetic.const HIDDEN: u32 = {{ hidden }}u;const WG: u32 = {{ wg }}u;const EPSILON: f32 = {{ epsilon }};64 unmodified lines}}}// Chrome on Qualcomm Adreno reports num_subgroups = 1 for a multi-subgroup workgroup.// The reported subgroup count can be too low; the fewest subgroups the workgroup can occupy bounds it from below.let fold_count = max(num_sg, (WG + sg_size - 1u) >> firstTrailingBit(sg_size));if (fold_count == 1u) { return s; }if (subgroupElect()) { sg_partials[sg_id] = s; }workgroupBarrier();var total = vec2<f32>(0.0);for (var i = 0u; i < fold_count; i++) { total = pair_add(total, sg_partials[i]); }// Another reduction may immediately reuse the same storage.workgroupBarrier();return total;96 unmodified linesfn reduce_scalar(value: f32{{ reduceThreadParameters }}) -> f32 {let s = subgroupAdd(value);// Chrome on Qualcomm Adreno reports num_subgroups = 1 for a workgroup that spans several subgroups.// The reported subgroup count can be too low. Raise it to the fewest subgroups the workgroup can occupy, so an// under-reported count can neither take the one-subgroup return nor cut the fold short; a conformant count// always wins.let fold_count = max(num_sg, (WG + sg_size - 1u) >> firstTrailingBit(sg_size));if (fold_count == 1u) {return s;}if (subgroupElect()) {sg_partials[sg_id] = s;}workgroupBarrier();var total = 0.0;for (var i = 0u; i < fold_count; i++) {total += sg_partials[i];}// Protect the bank from the next row-statistics reduction.workgroupBarrier();return total;}{% else %}21 unmodified linesfn main(@builtin(workgroup_id) wg_id: vec3<u32>,@builtin(local_invocation_id) lid: vec3<u32>{% if combineSubgroups %},@builtin(subgroup_id) sg_id: u32,@builtin(num_subgroups) num_sg: u32,@builtin(subgroup_size) sg_size: u32{% endif %}) {let row = wg_id.x + wg_id.y * params.rowStride;if (row >= params.rows) {
52 unmodified lines53545556575827 unmodified lines868788899091929352 unmodified linesreturn offset;{% endif %}}var<workgroup> shared_inv: f32;27 unmodified lineslet index = base + d;// Preserve the ONNX stage boundary: round Normalized to X's dtype before// the affine scale is applied.let normalized = {{ xElement }}(f32(x[index]) * inv);let value = f32(normalized) * f32(scale[scale_offset({% if scaleRank > 0 %}index{% endif %})]);y[index] = {{ scalar }}(value);d = d + WG;}52 unmodified lines535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012127 unmodified lines14915015115215315415515615715815916052 unmodified linesreturn offset;{% endif %}}{% set halfStageToWideOutput = rmsScaleAfterCast and xElement == "f16" and scalar == "f32" %}{% if halfStageToWideOutput %}fn round_f16_bits_rte(value: f32) -> u32 {let bits = bitcast<u32>(value);let sign = (bits >> 16u) & 0x8000u;let exponent_f32 = (bits >> 23u) & 0xffu;let mantissa_f32 = bits & 0x7fffffu;if (exponent_f32 == 0xffu) {if (mantissa_f32 != 0u) {return 0x7e00u;}return sign | 0x7c00u;}var exponent_f16 = i32(exponent_f32) - 127 + 15;if (exponent_f16 >= 0x1f) {return sign | 0x7c00u;}if (exponent_f16 <= 0) {if (exponent_f16 < -10) {return sign;}let significand = mantissa_f32 | 0x800000u;let shift = u32(14 - exponent_f16);let halfway = 1u << (shift - 1u);let discarded = significand & ((1u << shift) - 1u);var fraction = significand >> shift;if (discarded > halfway || (discarded == halfway && (fraction & 1u) == 1u)) {fraction = fraction + 1u;}return sign | fraction;}let halfway = 1u << 12u;let discarded = mantissa_f32 & 0x1fffu;var mantissa_f16 = mantissa_f32 >> 13u;if (discarded > halfway || (discarded == halfway && (mantissa_f16 & 1u) == 1u)) {mantissa_f16 = mantissa_f16 + 1u;if (mantissa_f16 == 0x400u) {mantissa_f16 = 0u;exponent_f16 = exponent_f16 + 1;}}if (exponent_f16 >= 0x1f) {return sign | 0x7c00u;}return sign | (u32(exponent_f16) << 10u) | mantissa_f16;}fn widen_f16_bits(value: u32) -> f32 {return unpack2x16float(value & 0xffffu).x;}// Typed ONNX edges must survive arithmetic fusion and narrow/wide casts.// Integer rounding also fixes the ties-to-even rule independently of the// implementation's floating-point conversion rounding mode.fn half_stage(value: f32) -> f32 {return widen_f16_bits(round_f16_bits_rte(value));}{% endif %}var<workgroup> shared_inv: f32;27 unmodified lineslet index = base + d;// Preserve the ONNX stage boundary: round Normalized to X's dtype before// the affine scale is applied.{% if halfStageToWideOutput %}let normalized = half_stage(f32(x[index]) * inv);{% else %}let normalized = f32({{ xElement }}(f32(x[index]) * inv));{% endif %}let value = normalized * f32(scale[scale_offset({% if scaleRank > 0 %}index{% endif %})]);y[index] = {{ scalar }}(value);d = d + WG;}
1 unmodified line2345678910111236 unmodified lines495051525354551 unmodified line{% if op == "max" or op == "min" %}{{ a }}[{{ idx }}] = {{ op }}({{ a }}[{{ idx }}], {{ a }}[{{ idx }} + {{ svar }}]);{% else %}{{ a }}[{{ idx }}] = {{ a }}[{{ idx }}] {{ "*" if op == "prod" else "+" }} {{ a }}[{{ idx }} + {{ svar }}];{% endif %}{% endmacro %}{% macro wgsl_tree_fold(arrays, op="add", idx="lid", wg="WORKGROUP_SIZE", svar="stride", typed=false, form="tail", breakInline=false, bodyInline=false, barrierFirst=false, reuse=false) %}var {{ svar }}{{ ": u32 " if typed else " " }}= {{ wg }} / 2u;loop {if ({{ svar }} == 0u) { break; }if ({{ idx }} < {{ svar }}) { {{ wgsl_tree_fold_stmt(arrays[0], op, idx, svar) }} }{{ svar }} = {{ svar }} / 2u;workgroupBarrier();}{% endmacro %}36 unmodified lines}red[tid] = acc;workgroupBarrier();{{ wgsl_tree_fold(["red"], idx="tid", wg="WG", typed=true, form="head", breakInline=true, bodyInline=true) }}if (tid == 0u) {partials[row * SPLIT + k] = red[0];}1 unmodified line2345678910111213141516171836 unmodified lines555657585960611 unmodified line{% if op == "max" or op == "min" %}{{ a }}[{{ idx }}] = {{ op }}({{ a }}[{{ idx }}], {{ a }}[{{ idx }} + {{ svar }}]);{% else %}{{ a }}[{{ idx }}] = {{ a }}[{{ idx }}] {{ "*" if op == "prod" else "+" }} {{ a }}[{{ idx }} + {{ svar }}];{% endif %}{% endmacro %}{% macro wgsl_tree_fold(arrays, op="add", idx="lid", wg="WORKGROUP_SIZE", svar="stride", typed=false, form="tail", barrierFirst=false, reuse=false) %}var {{ svar }}{{ ": u32 " if typed else " " }}= {{ wg }} / 2u;loop {if ({{ svar }} == 0u) {break;}if ({{ idx }} < {{ svar }}) {{% for a in arrays %}{{ wgsl_tree_fold_stmt(a, op, idx, svar) }}{% endfor %}}{{ svar }} = {{ svar }} / 2u;workgroupBarrier();}{% endmacro %}36 unmodified lines}red[tid] = acc;workgroupBarrier();{{ wgsl_tree_fold(["red"], idx="tid", wg="WG", typed=true, form="head") }}if (tid == 0u) {partials[row * SPLIT + k] = red[0];}
48 unmodified lines49505152535455115 unmodified lines17117217317417517617787 unmodified lines2652662672682692702717 unmodified lines27928028128228328428528628728828929029148 unmodified lines{% endif %}}{% if compensateHalfStats is defined and compensateHalfStats and xElement == "f16" %}{% set halfOutputScalar = scalar %}{% set halfScaleOffset = "scale_offset(base + i)" if scaleRank > 0 else "scale_offset()" %}{% set halfOutputScalar = halfOutputScalar | default("f16") %}115 unmodified lines// Half output magnifies statistics errors at rounding midpoints. Keep a low// residual through the reduction and normalization, then round the typed// float32-normalized/half-scale/half-bias edges explicitly. This is the standard ONNX half path;// other normalization contracts retain their existing arithmetic.fn pair_add(a: vec2<f32>, b: vec2<f32>) -> vec2<f32> {let s = fma(a.x, 1.0, b.x);87 unmodified lines{% if op == "max" or op == "min" %}{{ a }}[{{ idx }}] = {{ op }}({{ a }}[{{ idx }}], {{ a }}[{{ idx }} + {{ svar }}]);{% else %}{{ a }}[{{ idx }}] = {{ a }}[{{ idx }}] {{ "*" if op == "prod" else "+" }} {{ a }}[{{ idx }} + {{ svar }}];{% endif %}{% endmacro %}{% macro wgsl_tree_fold(arrays, op="add", idx="lid", wg="WORKGROUP_SIZE", svar="stride", typed=false, form="tail", breakInline=false, bodyInline=false, barrierFirst=false, reuse=false) %}var {{ svar }}{{ ": u32 " if typed else " " }}= {{ wg }} / 2u;loop {if ({{ svar }} == 0u) {7 unmodified lines{{ svar }} = {{ svar }} / 2u;workgroupBarrier();}{% endmacro %}// Reusing partial after this reduction requires a barrier between the read of// partial[0] and the next write, or the next round can race the prior readers.fn reduce_sum(value: f32, tid: u32) -> f32 {partial[tid] = value;workgroupBarrier();{{ wgsl_tree_fold(["partial"], idx="tid", wg="WG", form="head") }}return partial[0];}@compute @workgroup_size(WG, 1, 1)48 unmodified lines49505152535455115 unmodified lines17117217317417517617787 unmodified lines2652662672682692702717 unmodified lines27928028128228328428528628728828929029129229348 unmodified lines{% endif %}}{% if xElement == "f16" %}{% set halfOutputScalar = scalar %}{% set halfScaleOffset = "scale_offset(base + i)" if scaleRank > 0 else "scale_offset()" %}{% set halfOutputScalar = halfOutputScalar | default("f16") %}115 unmodified lines// Half output magnifies statistics errors at rounding midpoints. Keep a low// residual through the reduction and normalization, then round the typed// float32-normalized/half-scale/half-bias edges explicitly. This is the standard ONNX half path;// other normalization contracts use their own arithmetic.fn pair_add(a: vec2<f32>, b: vec2<f32>) -> vec2<f32> {let s = fma(a.x, 1.0, b.x);87 unmodified lines{% if op == "max" or op == "min" %}{{ a }}[{{ idx }}] = {{ op }}({{ a }}[{{ idx }}], {{ a }}[{{ idx }} + {{ svar }}]);{% else %}{{ a }}[{{ idx }}] = {{ a }}[{{ idx }}] {{ "*" if op == "prod" else "+" }} {{ a }}[{{ idx }} + {{ svar }}];{% endif %}{% endmacro %}{% macro wgsl_tree_fold(arrays, op="add", idx="lid", wg="WORKGROUP_SIZE", svar="stride", typed=false, form="tail", barrierFirst=false, reuse=false) %}var {{ svar }}{{ ": u32 " if typed else " " }}= {{ wg }} / 2u;loop {if ({{ svar }} == 0u) {7 unmodified lines{{ svar }} = {{ svar }} / 2u;workgroupBarrier();}{% endmacro %}{% set reduceSumName = "reduce_sum" %}{% set reduceSumBank = "partial" %}// Reusing {{ reduceSumBank }} after this reduction requires a barrier between the read of// {{ reduceSumBank }}[0] and the next write, or the next round can race the prior readers.fn {{ reduceSumName }}(value: f32, tid: u32) -> f32 {{{ reduceSumBank }}[tid] = value;workgroupBarrier();{{ wgsl_tree_fold([reduceSumBank], idx="tid", wg="WG", form="head") }}return {{ reduceSumBank }}[0];}@compute @workgroup_size(WG, 1, 1)
1234567834 unmodified lines43444546474849503 unmodified lines545556575859606162636465666768692 unmodified lines727374757677787980818283848586871356 unmodified lines14441445144614471448144914501451145234 unmodified lines1487148814891490149114921493149414951496149714981499150015 unmodified lines1516151715181519152015211522152315241525152615271528152916 unmodified lines15461547154815491550155115521 unmodified line1554155515561557155815591560{"fixtureArrays": {"f16_scalar_cast_x": [-1.1103515625, 2.982421875, 1.248046875, -1.8544921875],"f16_scalar_cast_scale": [2.015625],"f16_scalar_cast_y": [-1.150390625, 3.091796875, 1.29296875, -1.921875],"onnx_backend_rms_normalization_3d_input_x": [1.764052391052246, 0.40015721321105957, 0.978738009929657, 2.2408931255340576, 1.8675580024719238, -0.9772778749465942, 0.9500884413719177, -0.15135720372200012, -0.10321885347366333, 0.4105985164642334, 0.14404356479644775, 1.4542734622955322, 0.7610377073287964, 0.12167501449584961, 0.44386324286460876, 0.3336743414402008, 1.4940791130065918, -0.2051582634449005, 0.3130677044391632, -0.8540957570075989, -2.5529897212982178, 0.653618574142456, 0.8644362092018127, -0.7421650290489197, 2.269754648208618, -1.4543657302856445, 0.04575851559638977, -0.18718385696411133, 1.5327792167663574, 1.4693588018417358],"onnx_backend_rms_normalization_input_x": [1.764052391052246, 0.40015721321105957, 0.978738009929657, 2.2408931255340576, 1.8675580024719238, -0.9772778749465942, 0.9500884413719177, -0.15135720372200012, -0.10321885347366333, 0.4105985164642334, 0.14404356479644775, 1.4542734622955322, 0.7610377073287964, 0.12167501449584961, 0.44386324286460876, 0.3336743414402008, 1.4940791130065918, -0.2051582634449005, 0.3130677044391632, -0.8540957570075989, -2.5529897212982178, 0.653618574142456, 0.8644362092018127, -0.7421650290489197, 2.269754648208618, -1.4543657302856445, 0.04575851559638977, -0.18718385696411133, 1.5327792167663574, 1.4693588018417358, 0.154947429895401, 0.37816253304481506, -0.8877857327461243, -1.980796456336975, -0.34791216254234314, 0.15634897351264954, 1.2302906513214111, 1.202379822731018, -0.38732680678367615, -0.302302747964859, -1.0485529899597168, -1.420017957687378, -1.7062702178955078, 1.950775384902954, -0.5096521973609924, -0.4380742907524109, -1.2527953386306763, 0.7774903774261475, -1.6138978004455566, -0.21274028718471527, -0.8954665660858154, 0.38690251111984253, -0.5108051300048828, -1.18063223361969, -0.02818222902715206, 0.4283318817615509, 0.06651721894741058, 0.30247190594673157, -0.6343221068382263, -0.3627411723136902, -0.6724604368209839, -0.35955315828323364, -0.8131462931632996, -1.7262825965881348, 0.17742614448070526, -0.4017809331417084, -1.630198359489441, 0.46278226375579834, -0.9072983860969543, 0.05194539576768875, 0.7290905714035034, 0.12898291647434235, 1.1394007205963135, -1.234825849533081, 0.4023416340351105, -0.6848101019859314, -0.8707971572875977, -0.5788496732711792, -0.3115525245666504, 0.056165341287851334, -1.1651498079299927, 0.9008265137672424, 0.4656624495983124, -1.5362436771392822, 1.4882521629333496, 1.895889163017273, 1.1787796020507812, -0.1799248307943344, -1.0707526206970215, 1.0544517040252686, -0.4031769335269928, 1.222445011138916, 0.2082749754190445, 0.9766390323638916, 0.3563663959503174, 0.7065731883049011, 0.01050002034753561, 1.7858705520629883, 0.12691208720207214, 0.4019893705844879, 1.8831506967544556, -1.3477590084075928, -1.2704850435256958, 0.969396710395813, -1.1731233596801758, 1.9436211585998535, -0.4136189818382263, -0.747454822063446, 1.922942042350769, 1.4805147647857666, 1.8675589561462402, 0.9060446619987488, -0.8612256646156311, 1.910064935684204, -0.26800337433815, 0.8024563789367676, 0.9472519755363464, -0.15501008927822113, 0.6140793561935425, 0.922206699848175],"ort_axis2_vector3_scale_input_x": [0, 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],34 unmodified lines},"provenance": {"source": "ONNX RMSNormalization typed normalization and scale stages","notes": "Float32 Normalized midpoint followed by cast to half and affine half rounding. The CPU reference and independent PyTorch float32 typed stages agree; rounding float64 Normalized directly to half gives a different result."}},{"name": "half_normalized_midpoint_vec4",3 unmodified lines"dtype": "float16","shape": [1, 28],"data": {"kind": "values","values": [0.333984375, -0.82177734375, 0.35009765625, -1.189453125, -0.8701171875, 0.043914794921875, -0.35595703125, 0.333984375, -0.82177734375, 0.35009765625, -1.189453125, -0.8701171875, 0.043914794921875, -0.35595703125, 0.333984375, -0.82177734375, 0.35009765625, -1.189453125, -0.8701171875, 0.043914794921875, -0.35595703125, 0.333984375, -0.82177734375, 0.35009765625, -1.189453125, -0.8701171875, 0.043914794921875, -0.35595703125]}},"scale": {"dtype": "float16","shape": [28],"data": {"kind": "values","values": [1.1455078125, 1.0283203125, 0.92626953125, 1.0771484375, 1.232421875, 0.89990234375, 1.060546875, 1.1455078125, 1.0283203125, 0.92626953125, 1.0771484375, 1.232421875, 0.89990234375, 1.060546875, 1.1455078125, 1.0283203125, 0.92626953125, 1.0771484375, 1.232421875, 0.89990234375, 1.060546875, 1.1455078125, 1.0283203125, 0.92626953125, 1.0771484375, 1.232421875, 0.89990234375, 1.060546875]}}},2 unmodified lines"dtype": "float16","shape": [1, 28],"data": {"kind": "values","values": [0.56494140625, -1.248046875, 0.47900390625, -1.892578125, -1.583984375, 0.058319091796875, -0.5576171875, 0.56494140625, -1.248046875, 0.47900390625, -1.892578125, -1.583984375, 0.058319091796875, -0.5576171875, 0.56494140625, -1.248046875, 0.47900390625, -1.892578125, -1.583984375, 0.058319091796875, -0.5576171875, 0.56494140625, -1.248046875, 0.47900390625, -1.892578125, -1.583984375, 0.058319091796875, -0.5576171875]},"tolerance": 0.000002}},"provenance": {"source": "ONNX RMSNormalization typed normalization and scale stages","notes": "Float32 Normalized midpoint followed by cast to half and affine half rounding. The CPU reference and independent PyTorch float32 typed stages agree; rounding float64 Normalized directly to half gives a different result."}},{"name": "subgroup_vec4_2x512",1356 unmodified lines},{"name": "f16_lastaxis_unaligned_hidden4094","provenance": {"notes": "A float16 hidden dimension of 4,094 exercises scalar-tail handling after vectorized normalization."},"attrs": { "epsilon": 0.000001, "axis": -1 },"inputs": {"x": {34 unmodified lines"shape": [1, 4],"tolerance": 0,"relTolerance": 0,"data": { "kind": "values", "values": [-0.312255859375, 3.47265625, -0.08624267578125, 1.4921875] }}}},{"name": "onnx23_f16_cast_before_scale_generic_scalar_exact","provenance": {"notes": "ONNX RMSNormalization-23 stage-one cast boundary on the generic broadcast kernel. A scalar Scale prevents the specialized row variant; two outputs differ by one f16 ULP if normalization stays in float32 through the multiply."},"requires": { "features": ["shader-f16"] },"attrs": { "epsilon": 0.00001, "axis": -1 },15 unmodified lines"shape": [1, 4],"tolerance": 0,"relTolerance": 0,"data": { "kind": "values", "values": { "$ref": "#/fixtureArrays/f16_scalar_cast_y" } }}}},{"name": "onnx23_f16_cast_before_scale_splitk_exact","provenance": {"notes": "A four-element float16 row with a scalar Scale checks the standardized cast of Normalized back to X's dtype before Scale."},"requires": { "features": ["shader-f16"] },"tunables": { "SPLIT_MIN_HIDDEN": 1, "SPLIT_TARGET_ELEMENTS": 1 },16 unmodified lines"shape": [1, 4],"tolerance": 0,"relTolerance": 0,"data": { "kind": "values", "values": { "$ref": "#/fixtureArrays/f16_scalar_cast_y" } }}}},1 unmodified line"name": "onnx23_f16_stash_float16_rounding","provenance": {"source": "onnx/defs/nn/defs.cc RMSNormalization-23 function body","notes": "TensorProto FLOAT16 stash (10). Sequential f16 sum-of-squares and normalization produce outputs separated by multiple f16 ULPs from the default float32-stash route."},"requires": { "features": ["shader-f16"] },"attrs": { "epsilon": 0.00001, "axis": -1, "stash_type": 10 },1234567834 unmodified lines434445464748495051525354555657583 unmodified lines626364656667686970717273747576772 unmodified lines80818283848586878889909192939495969798991001011021031041051061071081356 unmodified lines146514661467146814691470147134 unmodified lines15061507150815091510151115121513151415151516151715181519152015 unmodified lines15361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158916 unmodified lines160616071608160916101611161216131 unmodified line1615161616171618161916201621{"fixtureArrays": {"f16_scalar_cast_x": [-1.11328125, 2.98046875, 1.248046875, -1.8564453125],"f16_scalar_cast_scale": [3.0859375],"f16_scalar_cast_y": [-1.765625, 4.7265625, 1.9794921875, -2.9453125],"onnx_backend_rms_normalization_3d_input_x": [1.764052391052246, 0.40015721321105957, 0.978738009929657, 2.2408931255340576, 1.8675580024719238, -0.9772778749465942, 0.9500884413719177, -0.15135720372200012, -0.10321885347366333, 0.4105985164642334, 0.14404356479644775, 1.4542734622955322, 0.7610377073287964, 0.12167501449584961, 0.44386324286460876, 0.3336743414402008, 1.4940791130065918, -0.2051582634449005, 0.3130677044391632, -0.8540957570075989, -2.5529897212982178, 0.653618574142456, 0.8644362092018127, -0.7421650290489197, 2.269754648208618, -1.4543657302856445, 0.04575851559638977, -0.18718385696411133, 1.5327792167663574, 1.4693588018417358],"onnx_backend_rms_normalization_input_x": [1.764052391052246, 0.40015721321105957, 0.978738009929657, 2.2408931255340576, 1.8675580024719238, -0.9772778749465942, 0.9500884413719177, -0.15135720372200012, -0.10321885347366333, 0.4105985164642334, 0.14404356479644775, 1.4542734622955322, 0.7610377073287964, 0.12167501449584961, 0.44386324286460876, 0.3336743414402008, 1.4940791130065918, -0.2051582634449005, 0.3130677044391632, -0.8540957570075989, -2.5529897212982178, 0.653618574142456, 0.8644362092018127, -0.7421650290489197, 2.269754648208618, -1.4543657302856445, 0.04575851559638977, -0.18718385696411133, 1.5327792167663574, 1.4693588018417358, 0.154947429895401, 0.37816253304481506, -0.8877857327461243, -1.980796456336975, -0.34791216254234314, 0.15634897351264954, 1.2302906513214111, 1.202379822731018, -0.38732680678367615, -0.302302747964859, -1.0485529899597168, -1.420017957687378, -1.7062702178955078, 1.950775384902954, -0.5096521973609924, -0.4380742907524109, -1.2527953386306763, 0.7774903774261475, -1.6138978004455566, -0.21274028718471527, -0.8954665660858154, 0.38690251111984253, -0.5108051300048828, -1.18063223361969, -0.02818222902715206, 0.4283318817615509, 0.06651721894741058, 0.30247190594673157, -0.6343221068382263, -0.3627411723136902, -0.6724604368209839, -0.35955315828323364, -0.8131462931632996, -1.7262825965881348, 0.17742614448070526, -0.4017809331417084, -1.630198359489441, 0.46278226375579834, -0.9072983860969543, 0.05194539576768875, 0.7290905714035034, 0.12898291647434235, 1.1394007205963135, -1.234825849533081, 0.4023416340351105, -0.6848101019859314, -0.8707971572875977, -0.5788496732711792, -0.3115525245666504, 0.056165341287851334, -1.1651498079299927, 0.9008265137672424, 0.4656624495983124, -1.5362436771392822, 1.4882521629333496, 1.895889163017273, 1.1787796020507812, -0.1799248307943344, -1.0707526206970215, 1.0544517040252686, -0.4031769335269928, 1.222445011138916, 0.2082749754190445, 0.9766390323638916, 0.3563663959503174, 0.7065731883049011, 0.01050002034753561, 1.7858705520629883, 0.12691208720207214, 0.4019893705844879, 1.8831506967544556, -1.3477590084075928, -1.2704850435256958, 0.969396710395813, -1.1731233596801758, 1.9436211585998535, -0.4136189818382263, -0.747454822063446, 1.922942042350769, 1.4805147647857666, 1.8675589561462402, 0.9060446619987488, -0.8612256646156311, 1.910064935684204, -0.26800337433815, 0.8024563789367676, 0.9472519755363464, -0.15501008927822113, 0.6140793561935425, 0.922206699848175],"ort_axis2_vector3_scale_input_x": [0, 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],34 unmodified lines},"provenance": {"source": "ONNX RMSNormalization typed normalization and scale stages","notes": "Float32 Normalized midpoint followed by cast to half and affine half rounding. The CPU reference and independent PyTorch float32 typed stages agree; rounding float64 Normalized directly to half gives a different result. WGSL arithmetic does not guarantee the float32 accuracy the midpoint needs; see the conformant alternative."},"conformantAlternatives": [{"name": "float32-normalized-above-midpoint","reason": "Exact Normalized of x = 0.043914794921875 is 0.4 float32 ULP above the float16 midpoint 0.064849853515625, so only a correctly rounded float32 Normalized lands on the tie that rounds down to 0.0648193359375. WGSL bounds inverseSqrt to 2 ULP and division to 2.5 ULP, lets fma round its product separately (section 15.7.4) and lets an implementation reassociate (section 15.7.5), so a conforming implementation need not hold that 0.4 ULP margin; a float32 Normalized one ULP higher rounds up to 0.06488037109375 and Scale gives 0.058380126953125. That is also the result of rounding float64 Normalized directly to half, so this case cannot detect that defect on an implementation that produces it; no portable case can separate the two.","reviewed": "2026-10-13","outputs": { "y": { "indices": [5], "values": [0.058380126953125] } }}]},{"name": "half_normalized_midpoint_vec4",3 unmodified lines"dtype": "float16","shape": [1, 28],"data": {"kind": "cycle","values": [0.333984375, -0.82177734375, 0.35009765625, -1.189453125, -0.8701171875, 0.043914794921875, -0.35595703125]}},"scale": {"dtype": "float16","shape": [28],"data": {"kind": "cycle","values": [1.1455078125, 1.0283203125, 0.92626953125, 1.0771484375, 1.232421875, 0.89990234375, 1.060546875]}}},2 unmodified lines"dtype": "float16","shape": [1, 28],"data": {"kind": "cycle","values": [0.56494140625, -1.248046875, 0.47900390625, -1.892578125, -1.583984375, 0.058319091796875, -0.5576171875]},"tolerance": 0.000002}},"provenance": {"source": "ONNX RMSNormalization typed normalization and scale stages","notes": "Float32 Normalized midpoint followed by cast to half and affine half rounding. The CPU reference and independent PyTorch float32 typed stages agree; rounding float64 Normalized directly to half gives a different result. WGSL arithmetic does not guarantee the float32 accuracy the midpoint needs; see the conformant alternative."},"conformantAlternatives": [{"name": "float32-normalized-above-midpoint","reason": "Exact Normalized of x = 0.043914794921875 is 0.4 float32 ULP above the float16 midpoint 0.064849853515625, so only a correctly rounded float32 Normalized lands on the tie that rounds down to 0.0648193359375. WGSL bounds inverseSqrt to 2 ULP and division to 2.5 ULP, lets fma round its product separately (section 15.7.4) and lets an implementation reassociate (section 15.7.5), so a conforming implementation need not hold that 0.4 ULP margin; a float32 Normalized one ULP higher rounds up to 0.06488037109375 and Scale gives 0.058380126953125. That is also the result of rounding float64 Normalized directly to half, so this case cannot detect that defect on an implementation that produces it; no portable case can separate the two.","reviewed": "2026-10-13","outputs": {"y": {"indices": [5, 12, 19, 26],"values": [0.058380126953125, 0.058380126953125, 0.058380126953125, 0.058380126953125]}}}]},{"name": "subgroup_vec4_2x512",1356 unmodified lines},{"name": "f16_lastaxis_unaligned_hidden4094","provenance": { "notes": "A float16 hidden dimension of 4,094, which is not a multiple of four." },"attrs": { "epsilon": 0.000001, "axis": -1 },"inputs": {"x": {34 unmodified lines"shape": [1, 4],"tolerance": 0,"relTolerance": 0,"data": { "kind": "values", "values": [-0.312255859375, 3.47265625, -0.08624267578125, 1.4921875] },"exactRounding": true}}},{"name": "onnx23_f16_cast_before_scale_generic_scalar_exact","provenance": {"notes": "ONNX RMSNormalization-23 stage-one cast boundary with a scalar Scale; three outputs differ by one f16 ULP if normalization stays in float32 through the multiply and that single conversion rounds to nearest even, and two if it rounds toward zero."},"requires": { "features": ["shader-f16"] },"attrs": { "epsilon": 0.00001, "axis": -1 },15 unmodified lines"shape": [1, 4],"tolerance": 0,"relTolerance": 0,"data": { "kind": "values", "values": { "$ref": "#/fixtureArrays/f16_scalar_cast_y" } },"exactRounding": true}}},{"name": "onnx23_f16_cast_before_scale_row_scalar_exact","provenance": {"notes": "A six-element row, so its length is not a multiple of four. Deferring the cast to X's dtype past Scale moves two of the six outputs by one float16 ULP, and rounding both float32 -> float16 conversions toward zero instead of to nearest even moves three."},"requires": { "features": ["shader-f16"] },"attrs": { "epsilon": 0.00001, "axis": -1 },"inputs": {"x": {"dtype": "float16","shape": [1, 6],"data": {"kind": "values","values": [-1.4765625, -1.861328125, 1.4697265625, 1.0703125, 0.8173828125, -0.5537109375]}},"scale": {"dtype": "float16","shape": [6],"data": {"kind": "values","values": [0.316162109375, -2.791015625, -0.0877685546875, 2.0859375, 1.529296875, -0.6904296875]}}},"outputs": {"y": {"dtype": "float16","shape": [1, 6],"tolerance": 0,"relTolerance": 0,"exactRounding": true,"data": {"kind": "values","values": [-0.363037109375, 4.0390625, -0.10028076171875, 1.7353515625, 0.97216796875, 0.297119140625]}}}},{"name": "onnx23_f16_cast_before_scale_splitk_exact","provenance": {"notes": "A four-element float16 row with a scalar Scale checks the standardized cast of Normalized back to X's dtype before Scale. At every element, Normalized and its product with Scale lie nearer their float16 neighbour toward zero, so rounding either conversion to nearest even or toward zero gives the same outputs. Converting once after Scale instead moves outputs 0 and 2 by one float16 step under either rule, and output 1 as well when that conversion rounds to nearest even."},"requires": { "features": ["shader-f16"] },"tunables": { "SPLIT_MIN_HIDDEN": 1, "SPLIT_TARGET_ELEMENTS": 1 },16 unmodified lines"shape": [1, 4],"tolerance": 0,"relTolerance": 0,"data": { "kind": "values", "values": { "$ref": "#/fixtureArrays/f16_scalar_cast_y" } },"exactRounding": true}}},1 unmodified line"name": "onnx23_f16_stash_float16_rounding","provenance": {"source": "onnx/defs/nn/defs.cc RMSNormalization-23 function body","notes": "stash_type FLOAT16 (10): sequential float16 sum-of-squares and normalization give outputs separated by multiple float16 ULPs from the result with the default float32 stash."},"requires": { "features": ["shader-f16"] },"attrs": { "epsilon": 0.00001, "axis": -1, "stash_type": 10 },
README.md+17-12
build/webgpu/bench.json+3-1
build/webgpu/manifest.json+1-277
build/webgpu/metadata.json+1-32
build/webgpu/norm-row-stats.wgsl.jinja+22-11
build/webgpu/rms-normalization-splitk-normalize.wgsl.jinja+69-2
build/webgpu/rms-normalization-splitk-partials.wgsl.jinja+10-4
build/webgpu/rms-normalization.wgsl.jinja+11-9
build/webgpu/test.json+83-22