sync 91d990483a17
Browse filesFiles changed (7)
11 unmodified lines1213141515161718192021212223242526272324252627282930313132333433343536379 unmodified lines47484950515253545552565758592 unmodified lines6263646162656667686970717273747511 unmodified lines
## Description
Fuses skip addition with layer normalization. The rank-3 standard surface currently supports float32, required `beta`, no `bias` or residual output, hidden sizes divisible by four, and exact or documented broadcast skip shapes. The provider's rank-2 extension supports float32 output-only with optional `beta`, or `beta` with optional `bias` when emitting the residual; its float16 path requires `beta`, `bias`, a residual output, and four-wide hidden size. Other combinations, bfloat16, and training statistics are not implemented.Fuses skip addition with layer normalization for rank-2 or rank-3 input and a non-empty hidden axis. With exact-shape skip, float32 and float16 output-only paths support optional `beta`; adding `bias` requires `beta`. Returning the residual sum requires `beta`: float32 supports optional `bias` and arbitrary hidden sizes, while float16 requires `bias` and a hidden size divisible by four. Broadcast skip is supported for rank-3 float32 input, required `beta`, no `bias` or residual output, and a hidden size divisible by four. Bfloat16 and training statistics are not implemented.
See the [ONNX Runtime `SkipLayerNormalization` contrib-operator spec](https://github.com/microsoft/onnxruntime/blob/main/docs/ContribOperators.md#com.microsoft.SkipLayerNormalization) for the reference semantics.
## Inputs
| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence || Name | Upstream name | Logical dtype | Rank | Shape | Description | Presence || --- | --- | --- | --- | --- | --- | --- || `input` | `inputT` | `T` | — | — | Primary input normalized over the final hidden-size axis. Rank 3 is the public shape; rank 2 is an ONNX Runtime provider extension supported by this package. | required || `skip` | `skipT` | `T` | — | — | Residual tensor. For rank-3 input it is exact shape, `(1, sequence_length, hidden_size)`, or `(sequence_length, hidden_size)`; rank-2 input requires exact shape. | required || `gamma` | `gammaT` | `T` | `1` | — | Layer-norm scale weights of shape `(hidden_size)`. | required || `beta` | `betaT` | `T` | `1` | — | Layer-norm bias weights of shape `(hidden_size)`. | optional || `bias` | `biasT` | `T` | `1` | — | Optional additive bias of shape `(hidden_size)` added to `input + skip` before normalization. | optional || `inputT` | `input` | `T` | — | — | Primary input normalized over the final hidden-size axis. Rank 3 is the standard shape; rank 2 is a supported extension. | required || `skipT` | `skip` | `T` | — | — | Residual tensor. For rank-3 input it is exact shape, `(1, sequence_length, hidden_size)`, or `(sequence_length, hidden_size)`; rank-2 input requires exact shape. | required || `gammaT` | `gamma` | `T` | `1` | — | Layer-norm scale weights of shape `(hidden_size)`. | required || `betaT` | `beta` | `T` | `1` | — | Layer-norm bias weights of shape `(hidden_size)`. | optional || `biasT` | `bias` | `T` | `1` | — | Optional additive bias of shape `(hidden_size)` added to `input + skip` before normalization. | optional |
## Outputs
| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence || Name | Upstream name | Logical dtype | Rank | Shape | Description | Presence || --- | --- | --- | --- | --- | --- | --- || `output` | `outputT` | `T` | same as `input` | same as `input` | Normalized output tensor with the same shape as `input`. | required || `input_skip_bias_sum` | `residualT` | `T` | same as `input` | same as `input` | Sum of `input`, `skip`, and `bias` (when present) before normalization, with the same shape as `input`. | optional || `outputT` | `output` | `T` | same as `inputT` | same as `inputT` | Normalized output tensor with the same shape as `input`. | required || `residualT` | `input_skip_bias_sum` | `T` | same as `inputT` | same as `inputT` | Sum of `input`, `skip`, and `bias` (when present) before normalization, with the same shape as `input`. | optional |
## Attributes
9 unmodified lines| --- | --- || `T` | `float32`, `float16` |
## Device requirements
Some implementation variants require `shader-f16`. These are route-specific capabilities, not package-wide requirements; availability also depends on the request shape and dtype.
## Files
- [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, provenance)- [`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 cases2 unmodified lines
## Use with `@huggingface/kernels`
The loader derives every required output's shape and logical dtype from the manifest contract and this call.It then allocates the result tensors automatically.```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.
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.
12234101 unmodified lines10610710811010911011111225 unmodified lines13813914014214114214314427 unmodified lines172173174176175176177178{ "op": "com.microsoft.SkipLayerNormalization", "cases": [ { "name": "skip-layernorm-f32-256x128",101 unmodified lines "name": "skip-layernorm-f32-bias-output-only-4096x768", "preset": "model", "provenance": { "notes": "Ordinary inference shape with bias present and all three optional outputs omitted. It uses six storage buffers and writes only the primary output, isolating the output-only path from the full-output sibling at the same geometry." "notes": "An ordinary inference shape with bias omits all three optional outputs, uses six storage buffers, and writes only the primary output." }, "vars": { "rows": 4096, "hidden": 768 }, "attrs": { "epsilon": 0.00001 },25 unmodified lines "bench": { "metrics": [{ "type": "bandwidth", "value": "4 * (4 * args.rows * args.hidden + 2 * args.hidden)" }] } }, { "name": "skip-layernorm-f32-4096x768-hidden768-aligned-sibling", "name": "skip-layernorm-f32-4096x768-hidden768-aligned", "preset": "model", "vars": { "rows": 4096, "hidden": 768 }, "attrs": { "epsilon": 0.00001 },27 unmodified lines "bench": { "metrics": [{ "type": "bandwidth", "value": "4 * (4 * args.rows * args.hidden + 2 * args.hidden)" }] } }, { "name": "skip-layernorm-f32-rows4096-hidden4096-prefill-sibling", "name": "skip-layernorm-f32-rows4096-hidden4096-prefill", "preset": "model", "vars": { "rows": 4096, "hidden": 4096 }, "attrs": { "epsilon": 0.00001 },1 unmodified line23456789101112131415161718192021222324252627282930313233343536373839404142567891011121314151617184647192049505152535455565758592122232425636426272829303132337172343536373876773940417942434445464785484950515290919293949553545556575859606162979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261277401281291301311327457467477487497507517527537547557567577581331341351361371381391401411421431441457591467617627631471481491501511521531541551561571581591601611621631641651661671681691701711 unmodified line1731741757711761771781797751801811821 unmodified line1841851867837847857867877887897907917927937947951871881891901911921931941951961971987961997987998002002012022032042051 unmodified line2072082098082102112122132142152168152172182192 unmodified lines2222232248248258268272252262272282292302311 unmodified line2332342358352362372382392408408418428438448458468478488498508518522412422432442452462472482492502512528532538558568572542552562572582591 unmodified line2612622638652642652662672688708718728738748758768778788798808818822692702712722732742752762772782792808832818858868872822832842852862871 unmodified line2892902918952922932942952962972989022993003012 unmodified lines3043053069119129133073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653661 unmodified line3683693709213713723733749253753763771 unmodified line3793803819339349359369379389399409419429439449453823833843853863873883893903913923939463949489499503953963973983994001 unmodified line4024034049584054064074084094104119654124134142 unmodified lines4174184199749759764204214224234244251 unmodified line4274284299844304314324339884344354361 unmodified line43843944099699799899910001001100210031004100510061007100844144244344444544644744844945045145210094531011101210134544554564574584591 unmodified line461462463102146446546646746846947010284714724732 unmodified lines4764774781037103810394794804814824834841 unmodified line486487488104748949049149210514934944951 unmodified line497498499105910601061106210631064106510661067106810691070107150050150250350450550650750850951051110725121074107510765135145155165175181 unmodified line520521522108452352452552652752852910915305315322 unmodified lines535536537110011011102538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663110611076646651 unmodified line "domain": "com.microsoft", "name": "SkipLayerNormalization", "sinceVersion": 1, "description": "Fuses skip addition with layer normalization. The rank-3 standard surface currently supports float32, required `beta`, no `bias` or residual output, hidden sizes divisible by four, and exact or documented broadcast skip shapes. The provider's rank-2 extension supports float32 output-only with optional `beta`, or `beta` with optional `bias` when emitting the residual; its float16 path requires `beta`, `bias`, a residual output, and four-wide hidden size. Other combinations, bfloat16, and training statistics are not implemented.", "inputs": [ { "role": "input", "dtype": "T", "description": "Primary input normalized over the final hidden-size axis. Rank 3 is the public shape; rank 2 is an ONNX Runtime provider extension supported by this package." }, { "role": "skip", "dtype": "T", "description": "Residual tensor. For rank-3 input it is exact shape, `(1, sequence_length, hidden_size)`, or `(sequence_length, hidden_size)`; rank-2 input requires exact shape." }, { "role": "gamma", "dtype": "T", "rank": 1, "description": "Layer-norm scale weights of shape `(hidden_size)`." }, { "role": "beta", "dtype": "T", "rank": 1, "optional": true, "description": "Layer-norm bias weights of shape `(hidden_size)`." }, { "role": "bias", "dtype": "T", "rank": 1, "optional": true, "description": "Optional additive bias of shape `(hidden_size)` added to `input + skip` before normalization." } ], "outputs": [ { "role": "output", "dtype": "T", "rank": "ranks.inputT", "shape": "shapes.inputT", "description": "Normalized output tensor with the same shape as `input`." }, { "role": "input_skip_bias_sum", "inputs": { "inputT": { "onnx": "input", "dtype": "T" }, "skipT": { "onnx": "skip", "dtype": "T" }, "gammaT": { "onnx": "gamma", "dtype": "T", "rank": 1 }, "betaT": { "onnx": "beta", "dtype": "T", "rank": 1, "optional": true }, "biasT": { "onnx": "bias", "dtype": "T", "rank": 1, "optional": true } }, "outputs": { "outputT": { "onnx": "output", "dtype": "T", "rank": "ranks.inputT", "shape": "shapes.inputT" }, "residualT": { "onnx": "input_skip_bias_sum", "dtype": "T", "rank": "ranks.inputT", "optional": true, "shape": "shapes.inputT", "description": "Sum of `input`, `skip`, and `bias` (when present) before normalization, with the same shape as `input`." "shape": "shapes.inputT" } ], "attributes": { "epsilon": 9.999999960041972e-13 }, "attributeDescriptions": { "epsilon": "Non-negative epsilon added to the variance before taking the square root." }, "args": { "inputT": { "kind": "tensor", "semantic": "input", "role": "input" }, "skipT": { "kind": "tensor", "semantic": "skip", "role": "input" }, "gammaT": { "kind": "tensor", "semantic": "gamma", "role": "input" }, "betaT": { "kind": "tensor", "semantic": "beta", "role": "input", "required": false }, "biasT": { "kind": "tensor", "semantic": "bias", "role": "input", "required": false }, "outputT": { "kind": "tensor", "semantic": "output", "role": "output" }, "residualT": { "kind": "tensor", "semantic": "input_skip_bias_sum", "role": "output", "required": false } }, "attributes": { "epsilon": { "default": 9.999999960041972e-13 } }, "typeConstraints": { "T": ["float32", "float16"] }, "tunables": { "MAX_WORKGROUP_SIZE": { "default": 256 } }, "derive": { "rowCount": "dim(shapes.inputT, 0)", "hiddenSize": "dim(shapes.inputT, 1)", "rowCount": "numel(shapes.inputT) / max(1, dim(shapes.inputT, -1))", "hiddenSize": "dim(shapes.inputT, -1)", "skipWg": "max(1, min(tunables.MAX_WORKGROUP_SIZE, device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX, pow2ceil(hiddenSize)))", "skipWgVec4": "max(1, min(tunables.MAX_WORKGROUP_SIZE, device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX, pow2ceil(ceilDiv(hiddenSize, 4))))", "portableWideExecution": "not has(device.adapterInfo, \"subgroupMinSize\") or device.adapterInfo.subgroupMinSize >= 32", "broadcastRows": "dim(shapes.inputT, 0) * dim(shapes.inputT, 1)", "broadcastHiddenSize": "dim(shapes.inputT, 2)", "broadcastSkipWgVec4": "max(1, min(tunables.MAX_WORKGROUP_SIZE, device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX, pow2ceil(ceilDiv(broadcastHiddenSize, 4))))", "rowDispatchFits": "rowCount <= device.limits.maxComputeWorkgroupsPerDimension * device.limits.maxComputeWorkgroupsPerDimension", "broadcastDispatchFits": "broadcastRows <= device.limits.maxComputeWorkgroupsPerDimension * device.limits.maxComputeWorkgroupsPerDimension", "rowDispatchFits": "rowCount <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) * min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", "broadcastDispatchFits": "broadcastRows <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) * min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", "normResourcesFit": "skipWg * 8 <= device.limits.maxComputeWorkgroupStorageSize and skipWgVec4 * 8 <= device.limits.maxComputeWorkgroupStorageSize", "broadcastResourcesFit": "broadcastSkipWgVec4 * 8 <= device.limits.maxComputeWorkgroupStorageSize", "epsilonOk": "attrs.epsilon >= 0", "rank2CoreContract": "epsilonOk and ranks.inputT == 2 and ranks.skipT == 2 and ranks.gammaT == 1 and ranks.outputT == 2 and dim(shapes.inputT, 0) == dim(shapes.skipT, 0) and dim(shapes.inputT, 1) == dim(shapes.skipT, 1) and dim(shapes.inputT, 1) > 0 and dim(shapes.gammaT, 0) == dim(shapes.inputT, 1) and dim(shapes.outputT, 0) == dim(shapes.inputT, 0) and dim(shapes.outputT, 1) == dim(shapes.inputT, 1)", "residualOutputContract": "present.residualT and ranks.residualT == 2 and dim(shapes.residualT, 0) == dim(shapes.inputT, 0) and dim(shapes.residualT, 1) == dim(shapes.inputT, 1)", "coreContract": "epsilonOk and (ranks.inputT == 2 or ranks.inputT == 3) and ranks.skipT == ranks.inputT and ranks.gammaT == 1 and ranks.outputT == ranks.inputT and sameShape(shapes.inputT, shapes.skipT) and sameShape(shapes.outputT, shapes.inputT) and dim(shapes.inputT, -1) > 0 and dim(shapes.gammaT, 0) == dim(shapes.inputT, -1)", "residualOutputContract": "present.residualT and sameShape(shapes.residualT, shapes.inputT)", "outputOnlyContract": "not present.residualT", "betaContract": "false if not present.betaT else (ranks.betaT == 1 and dim(shapes.betaT, 0) == dim(shapes.inputT, 1))", "betaContract": "false if not present.betaT else (ranks.betaT == 1 and dim(shapes.betaT, 0) == dim(shapes.inputT, -1))", "noBetaContract": "not present.betaT", "f32MainDtypes": "tensorDtypes.inputT == \"float32\" and tensorDtypes.skipT == \"float32\" and tensorDtypes.gammaT == \"float32\" and tensorDtypes.outputT == \"float32\"", "f16MainDtypes": "tensorDtypes.inputT == \"float16\" and tensorDtypes.skipT == \"float16\" and tensorDtypes.gammaT == \"float16\" and tensorDtypes.outputT == \"float16\"", "f32ResidualDtypes": "f32MainDtypes and tensorDtypes.residualT == \"float32\" if present.residualT else false", "f16ResidualDtypes": "f16MainDtypes and tensorDtypes.residualT == \"float16\" if present.residualT else false", "vec4Aligned": "dim(shapes.inputT, 1) % 4 == 0", "vec4Aligned": "dim(shapes.inputT, -1) % 4 == 0", "broadcastSkipShapeOk": "(ranks.skipT == 2 and dim(shapes.skipT, 0) == dim(shapes.inputT, 1) and dim(shapes.skipT, 1) == dim(shapes.inputT, 2)) or (ranks.skipT == 3 and ((dim(shapes.skipT, 0) == 1 and dim(shapes.skipT, 1) == dim(shapes.inputT, 1) and dim(shapes.skipT, 2) == dim(shapes.inputT, 2)) or sameShape(shapes.skipT, shapes.inputT)))", "broadcastOutputOnlyContract": "false if ranks.inputT != 3 or not present.betaT else (epsilonOk and not present.biasT and not present.residualT and dim(shapes.inputT, 2) % 4 == 0 and broadcastSkipShapeOk and ranks.gammaT == 1 and ranks.betaT == 1 and ranks.outputT == 3 and tensorDtypes.inputT == \"float32\" and tensorDtypes.skipT == \"float32\" and tensorDtypes.gammaT == \"float32\" and tensorDtypes.betaT == \"float32\" and tensorDtypes.outputT == \"float32\" and dim(shapes.inputT, 2) > 0 and dim(shapes.gammaT, 0) == dim(shapes.inputT, 2) and dim(shapes.betaT, 0) == dim(shapes.inputT, 2) and sameShape(shapes.outputT, shapes.inputT))", "hasSubgroups": "device.features.has(\"subgroups\") and device.wgslLanguageFeatures.has(\"subgroup_id\")", "hasF16": "device.features.has(\"shader-f16\")", "f32_beta_no_bias_residual_contract": "rank2CoreContract and residualOutputContract and betaContract and f32ResidualDtypes and not present.biasT and tensorDtypes.betaT == \"float32\"", "f32_beta_bias_residual_contract": "false if not present.biasT else (rank2CoreContract and residualOutputContract and betaContract and f32ResidualDtypes and ranks.biasT == 1 and tensorDtypes.betaT == \"float32\" and tensorDtypes.biasT == \"float32\" and dim(shapes.biasT, 0) == hiddenSize)", "f16_beta_bias_residual_contract": "false if not present.biasT else (hasF16 and rank2CoreContract and residualOutputContract and betaContract and f16ResidualDtypes and ranks.biasT == 1 and tensorDtypes.betaT == \"float16\" and tensorDtypes.biasT == \"float16\" and dim(shapes.biasT, 0) == hiddenSize)", "f32_no_beta_output_contract": "rank2CoreContract and outputOnlyContract and noBetaContract and f32MainDtypes and not present.biasT", "f32_beta_no_bias_output_only_contract": "rank2CoreContract and outputOnlyContract and betaContract and f32MainDtypes and not present.biasT and tensorDtypes.betaT == \"float32\"", "f32_beta_bias_output_only_contract": "false if not present.biasT else (rank2CoreContract and outputOnlyContract and betaContract and f32MainDtypes and ranks.biasT == 1 and tensorDtypes.betaT == \"float32\" and tensorDtypes.biasT == \"float32\" and dim(shapes.biasT, 0) == hiddenSize)" "f32_beta_no_bias_residual_contract": "coreContract and residualOutputContract and betaContract and f32ResidualDtypes and not present.biasT and tensorDtypes.betaT == \"float32\"", "f32_beta_bias_residual_contract": "false if not present.biasT else (coreContract and residualOutputContract and betaContract and f32ResidualDtypes and ranks.biasT == 1 and tensorDtypes.betaT == \"float32\" and tensorDtypes.biasT == \"float32\" and dim(shapes.biasT, 0) == hiddenSize)", "f16_beta_bias_residual_contract": "false if not present.biasT else (hasF16 and coreContract and residualOutputContract and betaContract and f16ResidualDtypes and ranks.biasT == 1 and tensorDtypes.betaT == \"float16\" and tensorDtypes.biasT == \"float16\" and dim(shapes.biasT, 0) == hiddenSize)", "f32_no_beta_output_contract": "coreContract and outputOnlyContract and noBetaContract and f32MainDtypes and not present.biasT", "f32_beta_no_bias_output_only_contract": "coreContract and outputOnlyContract and betaContract and f32MainDtypes and not present.biasT and tensorDtypes.betaT == \"float32\"", "f32_beta_bias_output_only_contract": "false if not present.biasT else (coreContract and outputOnlyContract and betaContract and f32MainDtypes and ranks.biasT == 1 and tensorDtypes.betaT == \"float32\" and tensorDtypes.biasT == \"float32\" and dim(shapes.biasT, 0) == hiddenSize)", "f16_no_beta_output_contract": "hasF16 and coreContract and outputOnlyContract and noBetaContract and f16MainDtypes and not present.biasT", "f16_beta_no_bias_output_only_contract": "hasF16 and coreContract and outputOnlyContract and betaContract and f16MainDtypes and not present.biasT and tensorDtypes.betaT == \"float16\"", "f16_beta_bias_output_only_contract": "false if not present.biasT else (hasF16 and coreContract and outputOnlyContract and betaContract and f16MainDtypes and ranks.biasT == 1 and tensorDtypes.betaT == \"float16\" and tensorDtypes.biasT == \"float16\" and dim(shapes.biasT, 0) == hiddenSize)" }, "bindingSets": { "scalar_no_bias_residual": [ { "name": "input", "arg": "inputT", "semantic": "input", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" }, { "name": "skip", "arg": "skipT", "semantic": "skip", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" }, { "name": "gamma", "arg": "gammaT", "semantic": "gamma", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar", "length": "$HIDDEN_LEN" }, { "name": "beta", "arg": "betaT", "semantic": "beta", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar", "length": "$HIDDEN_LEN" }, { "name": "output", "arg": "outputT", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "$scalar" }, { "name": "input_skip_bias_sum", "arg": "residualT", "semantic": "input_skip_bias_sum", "buffer": { "type": "storage" }, "elementType": "$scalar" }, { "name": "params", "semantic": "kernel.params", "buffer": { "type": "uniform" }, "struct": { "name": "Params", "fields": [ { "name": "rows", "type": "u32", "value": "rowCount" }, { "name": "epsilon", "type": "f32", "value": "attrs.epsilon" } ] } } ], "scalar_bias_output_residual": [ { "name": "input", "arg": "inputT", "semantic": "input", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" }, { "name": "skip", "arg": "skipT", "semantic": "skip", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" }, { "name": "bias", "arg": "biasT", "semantic": "bias", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar", "length": "$HIDDEN_LEN" }, { "name": "gamma", "arg": "gammaT", "semantic": "gamma", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar", "length": "$HIDDEN_LEN" }, { "name": "beta", "arg": "betaT", "semantic": "beta", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar", "length": "$HIDDEN_LEN" }, { "name": "output", "arg": "outputT", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "$scalar" }, { "name": "input_skip_bias_sum", "arg": "residualT", "semantic": "input_skip_bias_sum", "buffer": { "type": "storage" }, "elementType": "$scalar" }, { "name": "params", "semantic": "kernel.params", "buffer": { "type": "uniform" }, "struct": { "name": "Params", "fields": [ { "name": "rows", "type": "u32", "value": "rowCount" }, { "name": "epsilon", "type": "f32", "value": "attrs.epsilon" } ] } } ], "vec4_bias_output_residual": [ { "name": "input", "arg": "inputT", "semantic": "input", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar" }, { "name": "skip", "arg": "skipT", "semantic": "skip", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar" }, { "name": "bias", "arg": "biasT", "semantic": "bias", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar", "length": "$HIDDEN_LEN" }, { "name": "gamma", "arg": "gammaT", "semantic": "gamma", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar", "length": "$HIDDEN_LEN" }, { "name": "beta", "arg": "betaT", "semantic": "beta", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar", "length": "$HIDDEN_LEN" }, { "name": "output", "arg": "outputT", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "$vectorScalar" }, { "name": "input_skip_bias_sum", "arg": "residualT", "semantic": "input_skip_bias_sum", "buffer": { "type": "storage" }, "elementType": "$vectorScalar" }, { "name": "params", "semantic": "kernel.params", "buffer": { "type": "uniform" }, "struct": { "name": "Params", "fields": [ { "name": "rows", "type": "u32", "value": "rowCount" }, { "name": "rowStride", "type": "u32", "value": "max(1, min(rowCount, device.limits.maxComputeWorkgroupsPerDimension))" }, { "name": "epsilon", "type": "f32", "value": "attrs.epsilon" } ] } } ], "scalar_no_bias_output_only": [ { "name": "input", "arg": "inputT", "semantic": "input", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" }, { "name": "skip", "arg": "skipT", "semantic": "skip", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" }, { "name": "gamma", "arg": "gammaT", "semantic": "gamma", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar", "length": "$HIDDEN_LEN" }, { "name": "beta", "arg": "betaT", "semantic": "beta", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar", "length": "$HIDDEN_LEN" }, { "name": "output", "arg": "outputT", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "$scalar" }, { "name": "params", "semantic": "kernel.params", "buffer": { "type": "uniform" }, "struct": { "name": "Params", "fields": [ { "name": "rows", "type": "u32", "value": "rowCount" }, { "name": "epsilon", "type": "f32", "value": "attrs.epsilon" } ] } } ], "scalar_bias_output_only": [ { "name": "input", "arg": "inputT", "semantic": "input", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" }, { "name": "skip", "arg": "skipT", "semantic": "skip", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" }, { "name": "bias", "arg": "biasT", "semantic": "bias", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar", "length": "$HIDDEN_LEN" }, { "name": "gamma", "arg": "gammaT", "semantic": "gamma", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar", "length": "$HIDDEN_LEN" }, { "name": "beta", "arg": "betaT", "semantic": "beta", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar", "length": "$HIDDEN_LEN" }, { "name": "output", "arg": "outputT", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "$scalar" }, { "name": "params", "semantic": "kernel.params", "buffer": { "type": "uniform" }, "struct": { "name": "Params", "fields": [ { "name": "rows", "type": "u32", "value": "rowCount" }, { "name": "epsilon", "type": "f32", "value": "attrs.epsilon" } ] } } ], "scalar_no_beta_output_only": [ { "name": "input", "arg": "inputT", "semantic": "input", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" }, { "name": "skip", "arg": "skipT", "semantic": "skip", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" }, { "name": "gamma", "arg": "gammaT", "semantic": "gamma", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar", "length": "$HIDDEN_LEN" }, { "name": "output", "arg": "outputT", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "$scalar" }, { "name": "params", "semantic": "kernel.params", "buffer": { "type": "uniform" }, "struct": { "name": "Params", "fields": [ { "name": "rows", "type": "u32", "value": "rowCount" }, { "name": "epsilon", "type": "f32", "value": "attrs.epsilon" } ] } } ], "vec4_no_bias_residual": [ { "name": "input", "arg": "inputT", "semantic": "input", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar" }, { "name": "skip", "arg": "skipT", "semantic": "skip", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar" }, { "name": "gamma", "arg": "gammaT", "semantic": "gamma", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar", "length": "$HIDDEN_LEN" }, { "name": "beta", "arg": "betaT", "semantic": "beta", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar", "length": "$HIDDEN_LEN" }, { "name": "output", "arg": "outputT", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "$vectorScalar" }, { "name": "input_skip_bias_sum", "arg": "residualT", "semantic": "input_skip_bias_sum", "buffer": { "type": "storage" }, "elementType": "$vectorScalar" }, { "name": "params", "semantic": "kernel.params", "buffer": { "type": "uniform" }, "struct": { "name": "Params", "fields": [ { "name": "rows", "type": "u32", "value": "rowCount" }, { "name": "rowStride", "type": "u32", "value": "max(1, min(rowCount, device.limits.maxComputeWorkgroupsPerDimension))" }, { "name": "epsilon", "type": "f32", "value": "attrs.epsilon" } ] } } ], "vec4_no_bias_output_only": [ { "name": "input", "arg": "inputT", "semantic": "input", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar" }, { "name": "skip", "arg": "skipT", "semantic": "skip", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar" }, { "name": "gamma", "arg": "gammaT", "semantic": "gamma", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar", "length": "$HIDDEN_LEN" }, { "name": "beta", "arg": "betaT", "semantic": "beta", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar", "length": "$HIDDEN_LEN" }, { "name": "output", "arg": "outputT", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "$vectorScalar" }, { "name": "params", "semantic": "kernel.params", "buffer": { "type": "uniform" }, "struct": { "name": "Params", "fields": [ { "name": "rows", "type": "u32", "value": "rowCount" }, { "name": "rowStride", "type": "u32", "value": "max(1, min(rowCount, device.limits.maxComputeWorkgroupsPerDimension))" }, { "name": "epsilon", "type": "f32", "value": "attrs.epsilon" } ] } } ], "vec4_bias_output_only": [ { "name": "input", "arg": "inputT", "semantic": "input", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar" }, { "name": "skip", "arg": "skipT", "semantic": "skip", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar" }, { "name": "gamma", "arg": "gammaT", "semantic": "gamma", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar", "length": "$HIDDEN_LEN" }, { "name": "beta", "arg": "betaT", "semantic": "beta", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar", "length": "$HIDDEN_LEN" }, { "name": "bias", "arg": "biasT", "semantic": "bias", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar", "length": "$HIDDEN_LEN" }, { "name": "output", "arg": "outputT", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "$vectorScalar" }, { "name": "params", "semantic": "kernel.params", "buffer": { "type": "uniform" }, "struct": { "name": "Params", "fields": [ { "name": "rows", "type": "u32", "value": "rowCount" }, { "name": "rowStride", "type": "u32", "value": "max(1, min(rowCount, device.limits.maxComputeWorkgroupsPerDimension))" }, { "name": "epsilon", "type": "f32", "value": "attrs.epsilon" } ] } } ], "vec4_no_beta_output_only": [ { "name": "input", "arg": "inputT", "semantic": "input", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar" }, { "name": "skip", "arg": "skipT", "semantic": "skip", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar" }, { "name": "gamma", "arg": "gammaT", "semantic": "gamma", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar", "length": "$HIDDEN_LEN" }, { "name": "output", "arg": "outputT", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "$vectorScalar" }, { "name": "params", "semantic": "kernel.params", "buffer": { "type": "uniform" }, "struct": { "name": "Params", "fields": [ { "name": "rows", "type": "u32", "value": "rowCount" }, { "name": "rowStride", "type": "u32", "value": "max(1, min(rowCount, device.limits.maxComputeWorkgroupsPerDimension))" }, { "name": "epsilon", "type": "f32", "value": "attrs.epsilon" } ] } } ], "vec4_beta_broadcast_output_only": [ { "name": "input", "arg": "inputT", "semantic": "input", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar" }, { "name": "skip", "arg": "skipT", "semantic": "skip", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar" }, { "name": "gamma", "arg": "gammaT", "semantic": "gamma", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar", "length": "$HIDDEN_LEN" }, { "name": "beta", "arg": "betaT", "semantic": "beta", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar", "length": "$HIDDEN_LEN" }, { "name": "output", "arg": "outputT", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "$vectorScalar" }, { "name": "params", "semantic": "kernel.params", "buffer": { "type": "uniform" }, "struct": { "name": "Params", "fields": [ { "name": "rows", "type": "u32", "value": "dim(shapes.inputT, 0) * dim(shapes.inputT, 1)" }, { "name": "rowStride", "type": "u32", "value": "max(1, min(broadcastRows, device.limits.maxComputeWorkgroupsPerDimension))" }, { "name": "epsilon", "type": "f32", "value": "attrs.epsilon" }, { "name": "skipRows", "type": "u32", "value": "numel(shapes.skipT) / broadcastHiddenSize" } ] } } ] "bindings": { "input": { "arg": "inputT", "buffer": "read-only-storage", "elementType": "$vectorScalar" }, "skip": { "arg": "skipT", "buffer": "read-only-storage", "elementType": "$vectorScalar" }, "gamma": { "arg": "gammaT", "buffer": "read-only-storage", "elementType": "$vectorScalar", "length": "$HIDDEN_LEN" }, "beta": { "arg": "betaT", "buffer": "read-only-storage", "elementType": "$vectorScalar", "length": "$HIDDEN_LEN" }, "output": { "arg": "outputT", "buffer": "storage", "elementType": "$vectorScalar" }, "bias": { "arg": "biasT", "buffer": "read-only-storage", "elementType": "$vectorScalar", "length": "$HIDDEN_LEN" }, "input_skip_bias_sum": { "arg": "residualT", "buffer": "storage", "elementType": "$vectorScalar" }, "params_2": { "name": "params", "buffer": "uniform", "struct": [ { "name": "rows", "type": "u32", "value": "rowCount" }, { "name": "rowStride", "type": "u32", "value": "max(1, min(rowCount, min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))" }, { "name": "epsilon", "type": "f32", "value": "attrs.epsilon" } ] }, "input_2": { "arg": "inputT", "name": "input", "buffer": "read-only-storage", "elementType": "$scalar" }, "skip_2": { "arg": "skipT", "name": "skip", "buffer": "read-only-storage", "elementType": "$scalar" }, "bias_2": { "arg": "biasT", "name": "bias", "buffer": "read-only-storage", "elementType": "$scalar", "length": "$HIDDEN_LEN" }, "gamma_2": { "arg": "gammaT", "name": "gamma", "buffer": "read-only-storage", "elementType": "$scalar", "length": "$HIDDEN_LEN" }, "beta_2": { "arg": "betaT", "name": "beta", "buffer": "read-only-storage", "elementType": "$scalar", "length": "$HIDDEN_LEN" }, "output_2": { "arg": "outputT", "name": "output", "buffer": "storage", "elementType": "$scalar" }, "input_skip_bias_sum_2": { "arg": "residualT", "name": "input_skip_bias_sum", "buffer": "storage", "elementType": "$scalar" }, "params_3": { "name": "params", "buffer": "uniform", "struct": [ { "name": "rows", "type": "u32", "value": "rowCount" }, { "name": "epsilon", "type": "f32", "value": "attrs.epsilon" } ] } }, "variants": [ { "id": "beta_output_only_vec4_broadcast", "priority": 19, "when": ["broadcastOutputOnlyContract", "broadcastResourcesFit", "broadcastDispatchFits"], "constants": { "scalar": "\"f32\"", "vectorScalar": "\"vec4<f32>\"", "HIDDEN_LEN": "broadcastHiddenSize / 4" }, "derive": { "scalar": "\"f32\"", "vectorScalar": "\"vec4<f32>\"", "HIDDEN_LEN": "broadcastHiddenSize / 4" }, "passes": [ { "id": "main", "name": "SkipLayerNormalization.BroadcastSkip", "source": { "shader": "norm-skip-row-vec4.wgsl.jinja", "inputs": { "simplified": false, "hasBias": false, "hasBeta": true, "writeResidualSum": false, "usesF16": false, "broadcastSkip": true, "hidden": "broadcastHiddenSize", "hiddenVec": "broadcastHiddenSize / 4", "wg": "broadcastSkipWgVec4", "vecType": "\"vec4<f32>\"", "useSubgroups": "hasSubgroups" "shader": "norm-skip-row-vec4.wgsl.jinja", "derive": { "simplified": false, "hasBias": false, "hasBeta": true, "writeResidualSum": false, "usesF16Spec": false, "broadcastSkip": true, "hidden": "broadcastHiddenSize", "hiddenVec": "broadcastHiddenSize / 4", "wg": "broadcastSkipWgVec4", "vecType": "\"vec4<f32>\"", "useSubgroups": "hasSubgroups" } }, "subgroupCollectivesWidth": "portable", "bindings": "vec4_beta_broadcast_output_only", "dispatch": { "workgroups": "broadcastRows" } "bindings": [ "input", "skip", "gamma", "beta", "output", { "name": "params", "struct": [ { "name": "rows", "type": "u32", "value": "dim(shapes.inputT, 0) * dim(shapes.inputT, 1)" }, { "name": "rowStride", "type": "u32", "value": "max(1, min(broadcastRows, min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))" }, { "name": "epsilon", "type": "f32", "value": "attrs.epsilon" }, { "name": "skipRows", "type": "u32", "value": "numel(shapes.skipT) / broadcastHiddenSize" } ] } ], "dispatch": { "x": "min(broadcastRows, 65535)", "y": "ceilDiv(broadcastRows, 65535)", "z": 1 }, "subgroupCollectivesWidth": "portable" } ] },1 unmodified line "id": "beta_bias_vec4", "priority": 15, "when": ["f32_beta_bias_residual_contract", "vec4Aligned", "hasSubgroups or \"bias\" == \"bias\" or portableWideExecution", "normResourcesFit", "rowDispatchFits"], "constants": { "derive": { "scalar": "\"f32\"", "vectorScalar": "\"vec4<f32>\"", "hasBias": "\"bias\" == \"bias\"", "hiddenSize": "hiddenSize", "workgroupSize": "skipWg", "HIDDEN_LEN": "hiddenSize / 4" },1 unmodified line { "id": "normalize", "name": "SkipLayerNormalization.Vec4.Normalize", "source": { "shader": "norm-skip-row-vec4.wgsl.jinja", "inputs": { "simplified": false, "hasBias": "\"bias\" == \"bias\"", "hasBeta": true, "writeResidualSum": true, "usesF16": false, "hidden": "hiddenSize", "hiddenVec": "hiddenSize / 4", "wg": "skipWgVec4", "vecType": "\"vec4<f32>\"", "useSubgroups": "hasSubgroups" "shader": "norm-skip-row-vec4.wgsl.jinja", "derive": { "simplified": false, "hasBias": "\"bias\" == \"bias\"", "hasBeta": true, "writeResidualSum": true, "usesF16Spec": false, "hidden": "hiddenSize", "hiddenVec": "hiddenSize / 4", "wg": "skipWgVec4", "vecType": "\"vec4<f32>\"", "useSubgroups": "hasSubgroups" } }, "subgroupCollectivesWidth": "portable", "bindings": "vec4_bias_output_residual", "dispatch": { "workgroups": "rowCount" } "bindings": ["input", "skip", "bias", "gamma", "beta", "output", "input_skip_bias_sum", "params_2"], "dispatch": { "x": "min(rowCount, 65535)", "y": "ceilDiv(rowCount, 65535)", "z": 1 }, "subgroupCollectivesWidth": "portable" } ] },1 unmodified line "id": "beta_bias_row", "priority": 5, "when": ["f32_beta_bias_residual_contract", "normResourcesFit", "rowDispatchFits"], "constants": { "derive": { "simplified": false, "useSubgroups": "hasSubgroups", "hasBeta": true, "writeResidualSum": true, "hasBias": "\"bias\" == \"bias\"", "scalar": "\"f32\"", "hiddenSize": "hiddenSize", "workgroupSize": "skipWg", "HIDDEN_LEN": "hiddenSize" },2 unmodified lines "id": "normalize", "name": "SkipLayerNormalization.Row.Normalize", "shader": "norm-skip-row.wgsl.jinja", "subgroupCollectivesWidth": "portable", "bindings": "scalar_bias_output_residual", "dispatch": { "workgroups": "rowCount" }, "constants": { "writeResidualSum": true } "derive": { "writeResidualSum": true }, "bindings": ["input_2", "skip_2", "bias_2", "gamma_2", "beta_2", "output_2", "input_skip_bias_sum_2", "params_3"], "dispatch": { "x": "min(rowCount, 65535)", "y": "ceilDiv(rowCount, 65535)", "z": 1 }, "subgroupCollectivesWidth": "portable" } ] },1 unmodified line "id": "beta_bias_vec4_f16", "priority": 21, "when": ["f16_beta_bias_residual_contract", "vec4Aligned", "normResourcesFit", "rowDispatchFits"], "constants": { "scalar": "\"f16\"", "vectorScalar": "\"vec4<f16>\"", "HIDDEN_LEN": "hiddenSize / 4" }, "derive": { "scalar": "\"f16\"", "vectorScalar": "\"vec4<f16>\"", "HIDDEN_LEN": "hiddenSize / 4" }, "passes": [ { "id": "main", "name": "SkipLayerNormalization.Vec4", "source": { "shader": "norm-skip-row-vec4.wgsl.jinja", "inputs": { "simplified": false, "hasBias": true, "hasBeta": true, "writeResidualSum": true, "usesF16": true, "hidden": "hiddenSize", "hiddenVec": "hiddenSize / 4", "wg": "skipWgVec4", "vecType": "\"vec4<f16>\"", "useSubgroups": "hasSubgroups" "shader": "norm-skip-row-vec4.wgsl.jinja", "derive": { "simplified": false, "hasBias": true, "hasBeta": true, "writeResidualSum": true, "usesF16Spec": true, "hidden": "hiddenSize", "hiddenVec": "hiddenSize / 4", "wg": "skipWgVec4", "vecType": "\"vec4<f16>\"", "useSubgroups": "hasSubgroups" } }, "subgroupCollectivesWidth": "portable", "bindings": "vec4_bias_output_residual", "dispatch": { "workgroups": "rowCount" } "bindings": ["input", "skip", "bias", "gamma", "beta", "output", "input_skip_bias_sum", "params_2"], "dispatch": { "x": "min(rowCount, 65535)", "y": "ceilDiv(rowCount, 65535)", "z": 1 }, "subgroupCollectivesWidth": "portable" } ] },1 unmodified line "id": "no_beta_output_only_vec4", "priority": 20, "when": ["f32_no_beta_output_contract", "vec4Aligned", "normResourcesFit", "rowDispatchFits"], "constants": { "scalar": "\"f32\"", "vectorScalar": "\"vec4<f32>\"", "HIDDEN_LEN": "hiddenSize / 4" }, "derive": { "scalar": "\"f32\"", "vectorScalar": "\"vec4<f32>\"", "HIDDEN_LEN": "hiddenSize / 4" }, "passes": [ { "id": "main", "name": "SkipLayerNormalization.NoBetaOutputOnly.Vec4", "source": { "shader": "norm-skip-row-vec4.wgsl.jinja", "inputs": { "simplified": false, "hasBias": false, "hasBeta": false, "writeResidualSum": false, "usesF16": false, "hidden": "hiddenSize", "hiddenVec": "hiddenSize / 4", "wg": "skipWgVec4", "vecType": "\"vec4<f32>\"", "useSubgroups": "hasSubgroups" "shader": "norm-skip-row-vec4.wgsl.jinja", "derive": { "simplified": false, "hasBias": false, "hasBeta": false, "writeResidualSum": false, "usesF16Spec": false, "hidden": "hiddenSize", "hiddenVec": "hiddenSize / 4", "wg": "skipWgVec4", "vecType": "\"vec4<f32>\"", "useSubgroups": "hasSubgroups" } }, "subgroupCollectivesWidth": "portable", "bindings": "vec4_no_beta_output_only", "dispatch": { "workgroups": "rowCount" } "bindings": ["input", "skip", "gamma", "output", "params_2"], "dispatch": { "x": "min(rowCount, 65535)", "y": "ceilDiv(rowCount, 65535)", "z": 1 }, "subgroupCollectivesWidth": "portable" } ] },1 unmodified line "id": "no_beta_output_only_row", "priority": 10, "when": ["f32_no_beta_output_contract", "normResourcesFit", "rowDispatchFits"], "constants": { "derive": { "simplified": false, "hasBias": false, "hasBeta": false, "writeResidualSum": false, "useSubgroups": "hasSubgroups", "scalar": "\"f32\"", "hiddenSize": "hiddenSize", "workgroupSize": "skipWg", "HIDDEN_LEN": "hiddenSize" },2 unmodified lines "id": "main", "name": "SkipLayerNormalization.NoBetaOutputOnly.Row", "shader": "norm-skip-row.wgsl.jinja", "subgroupCollectivesWidth": "portable", "bindings": "scalar_no_beta_output_only", "dispatch": { "workgroups": "rowCount" } "bindings": ["input_2", "skip_2", "gamma_2", "output_2", "params_3"], "dispatch": { "x": "min(rowCount, 65535)", "y": "ceilDiv(rowCount, 65535)", "z": 1 }, "subgroupCollectivesWidth": "portable" } ] }, { "id": "no_beta_output_only_vec4_f16", "priority": 20, "when": ["f16_no_beta_output_contract", "vec4Aligned", "normResourcesFit", "rowDispatchFits"], "derive": { "scalar": "\"f16\"", "vectorScalar": "\"vec4<f16>\"", "HIDDEN_LEN": "hiddenSize / 4" }, "passes": [ { "id": "main", "name": "SkipLayerNormalization.NoBetaOutputOnly.Vec4.F16", "shader": "norm-skip-row-vec4.wgsl.jinja", "derive": { "simplified": false, "hasBias": false, "hasBeta": false, "writeResidualSum": false, "usesF16Spec": true, "hidden": "hiddenSize", "hiddenVec": "hiddenSize / 4", "wg": "skipWgVec4", "vecType": "\"vec4<f16>\"", "useSubgroups": "hasSubgroups" }, "bindings": ["input", "skip", "gamma", "output", "params_2"], "dispatch": { "x": "min(rowCount, 65535)", "y": "ceilDiv(rowCount, 65535)", "z": 1 }, "subgroupCollectivesWidth": "portable" } ] }, { "id": "no_beta_output_only_row_f16", "priority": 10, "when": ["f16_no_beta_output_contract", "normResourcesFit", "rowDispatchFits"], "derive": { "simplified": false, "hasBias": false, "hasBeta": false, "writeResidualSum": false, "useSubgroups": "hasSubgroups", "scalar": "\"f16\"", "usesF16": true, "workgroupSize": "skipWg", "HIDDEN_LEN": "hiddenSize" }, "passes": [ { "id": "main", "name": "SkipLayerNormalization.NoBetaOutputOnly.Row.F16", "shader": "norm-skip-row.wgsl.jinja", "bindings": ["input_2", "skip_2", "gamma_2", "output_2", "params_3"], "dispatch": { "x": "min(rowCount, 65535)", "y": "ceilDiv(rowCount, 65535)", "z": 1 }, "subgroupCollectivesWidth": "portable" } ] },1 unmodified line "id": "beta_no_bias_vec4", "priority": 20, "when": ["f32_beta_no_bias_residual_contract", "vec4Aligned", "hasSubgroups or portableWideExecution", "normResourcesFit", "rowDispatchFits"], "constants": { "derive": { "scalar": "\"f32\"", "vectorScalar": "\"vec4<f32>\"", "hasBias": "\"no_bias\" == \"bias\"", "hiddenSize": "hiddenSize", "workgroupSize": "skipWg", "HIDDEN_LEN": "hiddenSize / 4" },1 unmodified line { "id": "main", "name": "SkipLayerNormalization.Vec4", "source": { "shader": "norm-skip-row-vec4.wgsl.jinja", "inputs": { "simplified": false, "hasBias": "\"no_bias\" == \"bias\"", "hasBeta": true, "writeResidualSum": true, "usesF16": false, "hidden": "hiddenSize", "hiddenVec": "hiddenSize / 4", "wg": "skipWgVec4", "vecType": "\"vec4<f32>\"", "useSubgroups": "hasSubgroups" "shader": "norm-skip-row-vec4.wgsl.jinja", "derive": { "simplified": false, "hasBias": "\"no_bias\" == \"bias\"", "hasBeta": true, "writeResidualSum": true, "usesF16Spec": false, "hidden": "hiddenSize", "hiddenVec": "hiddenSize / 4", "wg": "skipWgVec4", "vecType": "\"vec4<f32>\"", "useSubgroups": "hasSubgroups" } }, "subgroupCollectivesWidth": "portable", "bindings": "vec4_no_bias_residual", "dispatch": { "workgroups": "rowCount" } "bindings": ["input", "skip", "gamma", "beta", "output", "input_skip_bias_sum", "params_2"], "dispatch": { "x": "min(rowCount, 65535)", "y": "ceilDiv(rowCount, 65535)", "z": 1 }, "subgroupCollectivesWidth": "portable" } ] },1 unmodified line "id": "beta_no_bias_row", "priority": 10, "when": ["f32_beta_no_bias_residual_contract", "normResourcesFit", "rowDispatchFits"], "constants": { "derive": { "simplified": false, "useSubgroups": "hasSubgroups", "hasBeta": true, "writeResidualSum": true, "hasBias": "\"no_bias\" == \"bias\"", "scalar": "\"f32\"", "hiddenSize": "hiddenSize", "workgroupSize": "skipWg", "HIDDEN_LEN": "hiddenSize" },2 unmodified lines "id": "main", "name": "SkipLayerNormalization.Row", "shader": "norm-skip-row.wgsl.jinja", "subgroupCollectivesWidth": "portable", "bindings": "scalar_no_bias_residual", "dispatch": { "workgroups": "rowCount" } "bindings": ["input_2", "skip_2", "gamma_2", "beta_2", "output_2", "input_skip_bias_sum_2", "params_3"], "dispatch": { "x": "min(rowCount, 65535)", "y": "ceilDiv(rowCount, 65535)", "z": 1 }, "subgroupCollectivesWidth": "portable" } ] },1 unmodified line "id": "beta_no_bias_output_only_vec4", "priority": 20, "when": ["f32_beta_no_bias_output_only_contract", "vec4Aligned", "hasSubgroups or \"no_bias\" == \"bias\" or portableWideExecution", "normResourcesFit", "rowDispatchFits"], "constants": { "derive": { "scalar": "\"f32\"", "vectorScalar": "\"vec4<f32>\"", "hasBias": "\"no_bias\" == \"bias\"", "hiddenSize": "hiddenSize", "workgroupSize": "skipWg", "HIDDEN_LEN": "hiddenSize / 4" },1 unmodified line { "id": "main", "name": "SkipLayerNormalization.Vec4", "source": { "shader": "norm-skip-row-vec4.wgsl.jinja", "inputs": { "simplified": false, "hasBias": "\"no_bias\" == \"bias\"", "hasBeta": true, "writeResidualSum": false, "usesF16": false, "hidden": "hiddenSize", "hiddenVec": "hiddenSize / 4", "wg": "skipWgVec4", "vecType": "\"vec4<f32>\"", "useSubgroups": "hasSubgroups" "shader": "norm-skip-row-vec4.wgsl.jinja", "derive": { "simplified": false, "hasBias": "\"no_bias\" == \"bias\"", "hasBeta": true, "writeResidualSum": false, "usesF16Spec": false, "hidden": "hiddenSize", "hiddenVec": "hiddenSize / 4", "wg": "skipWgVec4", "vecType": "\"vec4<f32>\"", "useSubgroups": "hasSubgroups" } }, "subgroupCollectivesWidth": "portable", "bindings": "vec4_no_bias_output_only", "dispatch": { "workgroups": "rowCount" } "bindings": ["input", "skip", "gamma", "beta", "output", "params_2"], "dispatch": { "x": "min(rowCount, 65535)", "y": "ceilDiv(rowCount, 65535)", "z": 1 }, "subgroupCollectivesWidth": "portable" } ] },1 unmodified line "id": "beta_no_bias_output_only_row", "priority": 10, "when": ["f32_beta_no_bias_output_only_contract", "normResourcesFit", "rowDispatchFits"], "constants": { "derive": { "simplified": false, "useSubgroups": "hasSubgroups", "hasBeta": true, "writeResidualSum": false, "hasBias": "\"no_bias\" == \"bias\"", "scalar": "\"f32\"", "hiddenSize": "hiddenSize", "workgroupSize": "skipWg", "HIDDEN_LEN": "hiddenSize" },2 unmodified lines "id": "main", "name": "SkipLayerNormalization.Row", "shader": "norm-skip-row.wgsl.jinja", "subgroupCollectivesWidth": "portable", "bindings": "scalar_no_bias_output_only", "dispatch": { "workgroups": "rowCount" } "bindings": ["input_2", "skip_2", "gamma_2", "beta_2", "output_2", "params_3"], "dispatch": { "x": "min(rowCount, 65535)", "y": "ceilDiv(rowCount, 65535)", "z": 1 }, "subgroupCollectivesWidth": "portable" } ] },1 unmodified line "id": "beta_bias_output_only_vec4", "priority": 20, "when": ["f32_beta_bias_output_only_contract", "vec4Aligned", "hasSubgroups or \"bias\" == \"bias\" or portableWideExecution", "normResourcesFit", "rowDispatchFits"], "constants": { "derive": { "scalar": "\"f32\"", "vectorScalar": "\"vec4<f32>\"", "hasBias": "\"bias\" == \"bias\"", "hiddenSize": "hiddenSize", "workgroupSize": "skipWg", "HIDDEN_LEN": "hiddenSize / 4" },1 unmodified line { "id": "main", "name": "SkipLayerNormalization.Vec4", "source": { "shader": "norm-skip-row-vec4.wgsl.jinja", "inputs": { "simplified": false, "hasBias": "\"bias\" == \"bias\"", "hasBeta": true, "writeResidualSum": false, "usesF16": false, "hidden": "hiddenSize", "hiddenVec": "hiddenSize / 4", "wg": "skipWgVec4", "vecType": "\"vec4<f32>\"", "useSubgroups": "hasSubgroups" "shader": "norm-skip-row-vec4.wgsl.jinja", "derive": { "simplified": false, "hasBias": "\"bias\" == \"bias\"", "hasBeta": true, "writeResidualSum": false, "usesF16Spec": false, "hidden": "hiddenSize", "hiddenVec": "hiddenSize / 4", "wg": "skipWgVec4", "vecType": "\"vec4<f32>\"", "useSubgroups": "hasSubgroups" } }, "subgroupCollectivesWidth": "portable", "bindings": "vec4_bias_output_only", "dispatch": { "workgroups": "rowCount" } "bindings": ["input", "skip", "gamma", "beta", "bias", "output", "params_2"], "dispatch": { "x": "min(rowCount, 65535)", "y": "ceilDiv(rowCount, 65535)", "z": 1 }, "subgroupCollectivesWidth": "portable" } ] },1 unmodified line "id": "beta_bias_output_only_row", "priority": 10, "when": ["f32_beta_bias_output_only_contract", "normResourcesFit", "rowDispatchFits"], "constants": { "derive": { "simplified": false, "useSubgroups": "hasSubgroups", "hasBeta": true, "writeResidualSum": false, "hasBias": "\"bias\" == \"bias\"", "scalar": "\"f32\"", "hiddenSize": "hiddenSize", "workgroupSize": "skipWg", "HIDDEN_LEN": "hiddenSize" },2 unmodified lines "id": "main", "name": "SkipLayerNormalization.Row", "shader": "norm-skip-row.wgsl.jinja", "subgroupCollectivesWidth": "portable", "bindings": "scalar_bias_output_only", "dispatch": { "workgroups": "rowCount" } "bindings": ["input_2", "skip_2", "bias_2", "gamma_2", "beta_2", "output_2", "params_3"], "dispatch": { "x": "min(rowCount, 65535)", "y": "ceilDiv(rowCount, 65535)", "z": 1 }, "subgroupCollectivesWidth": "portable" } ] }, { "id": "beta_no_bias_output_only_vec4_f16", "priority": 20, "when": ["f16_beta_no_bias_output_only_contract", "vec4Aligned", "hasSubgroups or \"no_bias\" == \"bias\" or portableWideExecution", "normResourcesFit", "rowDispatchFits"], "derive": { "scalar": "\"f16\"", "vectorScalar": "\"vec4<f16>\"", "hasBias": "\"no_bias\" == \"bias\"", "workgroupSize": "skipWg", "HIDDEN_LEN": "hiddenSize / 4" }, "passes": [ { "id": "main", "name": "SkipLayerNormalization.Vec4.F16", "shader": "norm-skip-row-vec4.wgsl.jinja", "derive": { "simplified": false, "hasBias": "\"no_bias\" == \"bias\"", "hasBeta": true, "writeResidualSum": false, "usesF16Spec": true, "hidden": "hiddenSize", "hiddenVec": "hiddenSize / 4", "wg": "skipWgVec4", "vecType": "\"vec4<f16>\"", "useSubgroups": "hasSubgroups" }, "bindings": ["input", "skip", "gamma", "beta", "output", "params_2"], "dispatch": { "x": "min(rowCount, 65535)", "y": "ceilDiv(rowCount, 65535)", "z": 1 }, "subgroupCollectivesWidth": "portable" } ] }, { "id": "beta_no_bias_output_only_row_f16", "priority": 10, "when": ["f16_beta_no_bias_output_only_contract", "normResourcesFit", "rowDispatchFits"], "derive": { "simplified": false, "useSubgroups": "hasSubgroups", "hasBeta": true, "writeResidualSum": false, "hasBias": "\"no_bias\" == \"bias\"", "scalar": "\"f16\"", "usesF16": true, "workgroupSize": "skipWg", "HIDDEN_LEN": "hiddenSize" }, "passes": [ { "id": "main", "name": "SkipLayerNormalization.Row.F16", "shader": "norm-skip-row.wgsl.jinja", "bindings": ["input_2", "skip_2", "gamma_2", "beta_2", "output_2", "params_3"], "dispatch": { "x": "min(rowCount, 65535)", "y": "ceilDiv(rowCount, 65535)", "z": 1 }, "subgroupCollectivesWidth": "portable" } ] }, { "id": "beta_bias_output_only_vec4_f16", "priority": 20, "when": ["f16_beta_bias_output_only_contract", "vec4Aligned", "hasSubgroups or \"bias\" == \"bias\" or portableWideExecution", "normResourcesFit", "rowDispatchFits"], "derive": { "scalar": "\"f16\"", "vectorScalar": "\"vec4<f16>\"", "hasBias": "\"bias\" == \"bias\"", "workgroupSize": "skipWg", "HIDDEN_LEN": "hiddenSize / 4" }, "passes": [ { "id": "main", "name": "SkipLayerNormalization.Vec4.F16", "shader": "norm-skip-row-vec4.wgsl.jinja", "derive": { "simplified": false, "hasBias": "\"bias\" == \"bias\"", "hasBeta": true, "writeResidualSum": false, "usesF16Spec": true, "hidden": "hiddenSize", "hiddenVec": "hiddenSize / 4", "wg": "skipWgVec4", "vecType": "\"vec4<f16>\"", "useSubgroups": "hasSubgroups" }, "bindings": ["input", "skip", "gamma", "beta", "bias", "output", "params_2"], "dispatch": { "x": "min(rowCount, 65535)", "y": "ceilDiv(rowCount, 65535)", "z": 1 }, "subgroupCollectivesWidth": "portable" } ] }, { "id": "beta_bias_output_only_row_f16", "priority": 10, "when": ["f16_beta_bias_output_only_contract", "normResourcesFit", "rowDispatchFits"], "derive": { "simplified": false, "useSubgroups": "hasSubgroups", "hasBeta": true, "writeResidualSum": false, "hasBias": "\"bias\" == \"bias\"", "scalar": "\"f16\"", "usesF16": true, "workgroupSize": "skipWg", "HIDDEN_LEN": "hiddenSize" }, "passes": [ { "id": "main", "name": "SkipLayerNormalization.Row.F16", "shader": "norm-skip-row.wgsl.jinja", "bindings": ["input_2", "skip_2", "bias_2", "gamma_2", "beta_2", "output_2", "params_3"], "dispatch": { "x": "min(rowCount, 65535)", "y": "ceilDiv(rowCount, 65535)", "z": 1 }, "subgroupCollectivesWidth": "portable" } ] } ], "tunables": { "MAX_WORKGROUP_SIZE": 256 } ]}1233456789101112131410111213141516171817181920212223242526272829303132333435363738394041{ "name": "com.microsoft.SkipLayerNormalization", "id": "_com_microsoft_skiplayernormalization_webgpu_1767bd7", "id": "_com_microsoft_skiplayernormalization_webgpu_28a934b", "version": 1, "license": "Apache-2.0", "backend": { "type": "webgpu" }, "digest": { "algorithm": "sha256", "files": { "bench.json": "STz1miuskWFMJijUblWNS3pG/DHJsRwQo0M+up/ng3s=", "manifest.json": "MM5RYZ3xnC2rbelhnBH9kdS+qwkWaQmvEVXhBmag8jg=", "norm-skip-row-vec4.wgsl.jinja": "qHoa8QjoRD1rgxTGGuJpfVb16Jou8PEg2CF1GjDt78s=", "norm-skip-row.wgsl.jinja": "ck3s/G7WRph2YZRJs4LTft+R0IDjMPeE5Oy4UXDsqQs=", "test.json": "Dkphsy4eO4Z8f2ZY1wfBJVmLcKNVWcOupJHOighE3RU=" "bench.json": "dZADuGnHvG3kWGPS0BGgmikuwdi16tD/Sk4HbGC9UV0=", "manifest.json": "G6ZofqPdSuhkAxEuuKIlW4fQ/fCsDwxEzafKwVqGEY8=", "norm-skip-row-vec4.wgsl.jinja": "bH8L9BYJ/3XQXE2zP8kvZc4wlhAbcAolI4/p0xXskzM=", "norm-skip-row.wgsl.jinja": "aERQfDDXx6lwKuyahwcemgFllRSq46egf2++7f6bNtA=", "test.json": "K+KtXhWTSxbRlFwFfszdd1YKz9JnAOuDZ9ebLg7Y8w0=" } }, "provenance": { "kernel": { "sha": "2e7068faf55e7f43df740015f6d1ee49391a41c5", "dirty": false } }, "webgpu": { "manifestSpec": "1.0", "specialized": true, "opPath": "ops/com.microsoft.SkipLayerNormalization" } "provenance": { "kernel": { "sha": "91d990483a174128daf7673f3f37a7c890493ae1", "dirty": false } }, "webgpu": { "manifestSpec": "2.0", "variants": { "beta_output_only_vec4_broadcast": ["norm-skip-row-vec4.wgsl.jinja"], "beta_bias_vec4": ["norm-skip-row-vec4.wgsl.jinja"], "beta_bias_row": ["norm-skip-row.wgsl.jinja"], "beta_bias_vec4_f16": ["norm-skip-row-vec4.wgsl.jinja"], "no_beta_output_only_vec4": ["norm-skip-row-vec4.wgsl.jinja"], "no_beta_output_only_row": ["norm-skip-row.wgsl.jinja"], "no_beta_output_only_vec4_f16": ["norm-skip-row-vec4.wgsl.jinja"], "no_beta_output_only_row_f16": ["norm-skip-row.wgsl.jinja"], "beta_no_bias_vec4": ["norm-skip-row-vec4.wgsl.jinja"], "beta_no_bias_row": ["norm-skip-row.wgsl.jinja"], "beta_no_bias_output_only_vec4": ["norm-skip-row-vec4.wgsl.jinja"], "beta_no_bias_output_only_row": ["norm-skip-row.wgsl.jinja"], "beta_bias_output_only_vec4": ["norm-skip-row-vec4.wgsl.jinja"], "beta_bias_output_only_row": ["norm-skip-row.wgsl.jinja"], "beta_no_bias_output_only_vec4_f16": ["norm-skip-row-vec4.wgsl.jinja"], "beta_no_bias_output_only_row_f16": ["norm-skip-row.wgsl.jinja"], "beta_bias_output_only_vec4_f16": ["norm-skip-row-vec4.wgsl.jinja"], "beta_bias_output_only_row_f16": ["norm-skip-row.wgsl.jinja"] } }}41 unmodified lines42434445464546474849501 unmodified line52535454555655565758596024 unmodified lines858687878889899091929313 unmodified lines1071081091091101111121131 unmodified line1151161171171181191201211211221231241257 unmodified lines13313413513513613713613713813914014014114214314314414514641 unmodified lines {{ svar }} = {{ svar }} / 2u;{% endif %} }{%- endmacro %}{% set useSubgroups = source.useSubgroups %}{% if source.usesF16 %}{%- endmacro %}{% set broadcastSkip = broadcastSkip is defined and broadcastSkip %}{% set useSubgroups = useSubgroups %}{% if usesF16Spec %}enable f16;{% endif %}{% if useSubgroups %}1 unmodified line{% endif %}{{ env.wgsl.resourceDeclarations }}
const HIDDEN: u32 = {{ source.hidden }}u;const HIDDEN_V: u32 = {{ source.hiddenVec }}u;const WG: u32 = {{ source.wg }}u;const HIDDEN: u32 = {{ hidden }}u;const HIDDEN_V: u32 = {{ hiddenVec }}u;const WG: u32 = {{ wg }}u;
var<workgroup> sg_partials: array<vec2<f32>, WG>;
24 unmodified lines// 4 contiguous residual elements (input[idx] + skip[skip_idx] [+ bias]) at vec4// index `vi`. skip_idx == idx for the normal (non-broadcast) path; for a skip// that broadcasts across the leading/batch dim uses a folded index.fn residual_value(idx: u32, skip_idx: u32{% if source.hasBias %}, vi: u32{% endif %}) -> vec4<f32> {fn residual_value(idx: u32, skip_idx: u32{% if hasBias %}, vi: u32{% endif %}) -> vec4<f32> { var value = vec4<f32>(input[idx]) + vec4<f32>(skip[skip_idx]);{% if source.hasBias %}{% if hasBias %} value = value + vec4<f32>(bias[vi]);{% endif %} return value;13 unmodified lines } let tid = lid.x; let base = row * HIDDEN_V;{% if source.broadcastSkip %}{% if broadcastSkip %} // skip broadcasts across the batch dim: fold row into [0, skipRows) so every // batch reuses the same skip row (skipRows == params.rows ⇒ identity). let skip_base = (row % params.skipRows) * HIDDEN_V;1 unmodified line let skip_base = base;{% endif %}
let shift = residual_value(base, skip_base{% if source.hasBias %}, 0u{% endif %}).x; let shift = residual_value(base, skip_base{% if hasBias %}, 0u{% endif %}).x;
var acc = vec2<f32>(0.0, 0.0); for (var i = tid; i < HIDDEN_V; i = i + WG) { let v = residual_value(base + i, skip_base + i{% if source.hasBias %}, i{% endif %}); let v = residual_value(base + i, skip_base + i{% if hasBias %}, i{% endif %}); let d = v - vec4<f32>(shift); acc.x = acc.x + d.x + d.y + d.z + d.w; acc.y = acc.y + dot(d, d);7 unmodified lines
for (var i = tid; i < HIDDEN_V; i = i + WG) { let idx = base + i; let residual = residual_value(idx, skip_base + i{% if source.hasBias %}, i{% endif %});{% if source.writeResidualSum %} input_skip_bias_sum[idx] = {{ source.vecType }}(residual); let residual = residual_value(idx, skip_base + i{% if hasBias %}, i{% endif %});{% if writeResidualSum %} input_skip_bias_sum[idx] = {{ vecType }}(residual);{% endif %} var value = (residual - vec4<f32>(row_mean)) * row_inv * vec4<f32>(gamma[i]);{% if source.hasBeta %}{% if hasBeta %} value = value + vec4<f32>(beta[i]);{% endif %} output[idx] = {{ source.vecType }}(value); output[idx] = {{ vecType }}(value); }}46 unmodified lines4748495051525354553 unmodified lines5960615960616263646566676869707172737475767778798081828384858687888990919293949596979862636423 unmodified lines8889901289192938 unmodified lines10210310414314410510610710810911015015111111211315311411511611711811912016016116216316416516616716816917017117217317417517617717817918018118218312112212312446 unmodified lines/* One workgroup normalizes each row of residual = input + skip, with an * optional bias. */{% set degenerateRow = (not simplified) and hiddenSize == 1 %}{% if usesF16 %}enable f16;{% endif %}{% if useSubgroups and not degenerateRow %}enable subgroups;{% endif %}3 unmodified linesconst HIDDEN: u32 = {{ hiddenSize }}u;{% endif %}const WG: u32 = {{ workgroupSize }}u;{% if simplified %}
var<workgroup> partial: array<f32, WG>;{% macro wgsl_tree_reduce_f32(name, mode, buffer="partial", wg="WG", trailingBarrier=true) %}fn {{ name }}(value: f32, tid: u32) -> f32 { {{ buffer }}[tid] = value; workgroupBarrier(); // Ceil-halving keeps every lane when the workgroup size is not a power of // two. For even n this matches the power-of-two tree order; for odd n, lanes // [0, n-half) fold the upper tail while the middle lane carries forward. var n: u32 = {{ wg }}; loop { let half = (n + 1u) / 2u; if (tid < n - half) {{% if mode == "max" %} {{ buffer }}[tid] = max({{ buffer }}[tid], {{ buffer }}[tid + half]);{% else %} {{ buffer }}[tid] = {{ buffer }}[tid] + {{ buffer }}[tid + half];{% endif %} } workgroupBarrier(); n = half; if (n == 1u) { break; } } // The default trailing barrier makes this helper safe for back-to-back calls: every lane reads // slot 0 here, so the next call's first store must not run until all lanes have read it. // `trailingBarrier=false` is safe only when the buffer is never written again before kernel exit. let reduced = {{ buffer }}[0];{% if trailingBarrier %} workgroupBarrier();{% endif %} return reduced;}{% endmacro %}
{{ wgsl_tree_reduce_f32("reduce_sum", "add", "partial", "WG") }}var<workgroup> row_inv: f32;{% else %}{% if not degenerateRow %}
var<workgroup> pair_partial: array<vec2<f32>, WG>;23 unmodified lines}{% endif %}{% endif %}{% endif %}
{% if not degenerateRow or writeResidualSum %}fn residual_value(row: u32, d: u32) -> f32 {8 unmodified lines
@compute @workgroup_size(WG, 1, 1)fn main( @builtin(workgroup_id) wg: vec3<u32>, @builtin(num_workgroups) nwg: vec3<u32>{% if not degenerateRow %}, @builtin(workgroup_id) wg: vec3<u32>{% if not degenerateRow %}, @builtin(local_invocation_id) lid: vec3<u32>{% endif %}{% if useSubgroups and not degenerateRow %}, @builtin(subgroup_invocation_id) sg_lane: u32, @builtin(subgroup_id) sg_id: u32, @builtin(num_subgroups) num_sg: u32{% endif %}) { // 2D-folded row index: wg.y carries the high bits past the maxComputeWorkgroupsPerDimension // workgroup-per-dimension dispatch limit. Reduces to wg.x when nwg.y == 1; // 2D-folded row index: wg.y carries the high bits past the per-axis dispatch fold width. // Reduces to wg.x when the dispatch does not fold; // the row >= params.rows guard drops the over-dispatched tail. let row = wg.x + wg.y * nwg.x; let row = wg.x + wg.y * {{ DISPATCH_FOLD_WIDTH }}u; if (row >= params.rows) { return; }{% if not degenerateRow %} let tid = lid.x;{% endif %}{% if simplified %}
// RMS normalization uses one sum-of-squares sweep, without a mean or beta.
var local_sq = 0.0; for (var d: u32 = tid; d < HIDDEN; d = d + WG) { let value = residual_value(row, d); local_sq = local_sq + value * value; } let sq = reduce_sum(local_sq, tid); if (tid == 0u) { row_inv = inverseSqrt(sq / f32(HIDDEN) + params.epsilon); } workgroupBarrier();
for (var d: u32 = tid; d < HIDDEN; d = d + WG) { let index = row * HIDDEN + d; let residual = residual_value(row, d);{% if writeResidualSum %} input_skip_bias_sum[index] = {{ scalar }}(residual);{% endif %} output[index] = {{ scalar }}(residual * row_inv * f32(gamma[d])); }{% elif degenerateRow %}{% if degenerateRow %}
// HIDDEN == 1: the row's mean is its only element, so the centered value and // the variance are exactly zero and the output reduces to beta. The closed12234183 unmodified lines18818919019219119219319428 unmodified lines22322422522722622722822927 unmodified lines25725825926126026126226319 unmodified lines28328428528728628728828927 unmodified lines317318319321320321322323152 unmodified lines47647747848047948048148248 unmodified lines531532533535534535536537162 unmodified lines70070170270470370470570661 unmodified lines768769770772771772773774135 unmodified lines91091191291491591691391491591614 unmodified lines9319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177{ "op": "com.microsoft.SkipLayerNormalization", "fixtureArrays": { "ort_batch2_bias_flattened_tokens_input_skipT": [0.1, -0.2, 0.3, 1, 0.5, 0.1, 0.4, 1.6, 1.8, -0.3, 0, 1, -0.5, 0.4, 0.8, -0.6], "ort_batch2_flattened_tokens_input_inputT": [0.8, -0.5, 0, 1, 0.5, 0.2, 0.3, -0.6, 0.8, -0.5, 0, 1, 0.5, 0.2, 0.3, -0.6],183 unmodified lines { "name": "hidden_size_one_bias_rows65535_dispatch_edge", "provenance": { "notes": "Correctness sibling for the low-occupancy hidden=1 benchmark at rows=65535, the maximum single-dimension workgroup count edge." "notes": "Hidden size 1 across 65,535 rows exercises the maximum single-dimension workgroup count with one value per normalization row." }, "attrs": { "epsilon": 0.00001 }, "inputs": {28 unmodified lines "skipT": { "dtype": "float32", "shape": [1, 4], "data": { "kind": "values", "values": [-39999.0, -40000.0, -40001.0, -40002.0] } "data": { "kind": "values", "values": [-39999.0, -39999.5, -40000.0, -40000.5] } }, "gammaT": { "dtype": "float32", "shape": [4], "data": { "kind": "values", "values": [1.0, 2.0, -1.0, 0.5] } }, "betaT": { "dtype": "float32", "shape": [4], "data": { "kind": "values", "values": [0.0, 0.5, -0.25, 1.0] } }27 unmodified lines "provenance": { "source": "onnxruntime/test/contrib_ops/skiplayernorm_op_test.cc", "test": "SkipLayerNormTest.SkipLayerNormBatch1", "notes": "ORT shape [1, 2, 4] is represented as [2, 4] tokens by this lowered kernel. Epsilon is omitted to exercise the schema default of 1e-12." "notes": "This package flattens ORT shape [1, 2, 4] to two four-wide token rows. Epsilon is omitted to exercise the schema default of 1e-12." }, "inputs": { "inputT": {19 unmodified lines "provenance": { "source": "onnxruntime/test/contrib_ops/skiplayernorm_op_test.cc", "test": "SkipLayerNormTest.SkipLayerNormBatch2_Bias", "notes": "ORT shape [2, 2, 4] is represented as [4, 4] tokens by this lowered kernel." "notes": "This package flattens ORT shape [2, 2, 4] to four four-wide token rows." }, "attrs": { "epsilon": 1e-12 }, "inputs": {27 unmodified lines "provenance": { "source": "onnxruntime/test/contrib_ops/skiplayernorm_op_test.cc", "test": "SkipLayerNormTest.SkipLayerNormBatch2", "notes": "ORT shape [2, 2, 4] is represented as [4, 4] tokens by this lowered kernel." "notes": "This package flattens ORT shape [2, 2, 4] to four four-wide token rows." }, "attrs": { "epsilon": 1e-12 }, "inputs": {152 unmodified lines { "name": "no_beta_output_only_hidden6_unaligned_row", "provenance": { "notes": "Only coverage for the scalar no_beta_output_only_row variant: beta omitted with output as the sole output picks the no-beta output-only pair, and hidden=6 is not a multiple of 4, so the vec4 sibling's vec4Aligned guard is false and the row kernel is selected on every tier." "notes": "Beta and optional outputs are omitted, and hidden size 6 is not divisible by four, selecting the scalar no-beta output-only row path on every tier." }, "attrs": { "epsilon": 0.00001 }, "inputs": {48 unmodified lines { "name": "beta_no_bias_output_only_hidden6_unaligned_row", "provenance": { "notes": "Row-kernel arm of beta_no_bias_output_only: hidden=6 fails vec4Aligned, so the scalar sibling is selected on every tier." "notes": "Beta is present, bias and optional outputs are omitted, and hidden size 6 selects the scalar output-only row path on every tier." }, "attrs": { "epsilon": 0.00001 }, "inputs": {162 unmodified lines { "name": "f32_hidden768_no_bias_residual", "provenance": { "notes": "Compact companion for bench cases skip-layernorm-f32-4096x768 and skip-layernorm-f32-4096x768-hidden768-aligned-sibling, where reduced tiers expose a subgroup fallback gap." "notes": "A compact hidden-size-768 residual normalization exercises the subgroup route and its reduced-tier fallback without bias." }, "attrs": { "epsilon": 0.00001 }, "inputs": {61 unmodified lines { "name": "f32_hidden1025_bias_residual", "provenance": { "notes": "Compact companion for bench case skip-layernorm-f32-bias-8192x1025-unaligned-twopass-fallback, preserving the odd hidden-size bias path." "notes": "A compact hidden-size-1025 normalization exercises the unaligned two-pass path with bias and residual output." }, "attrs": { "epsilon": 0.00001 }, "inputs": {135 unmodified lines }, { "name": "hidden_size_one_bias_many_rows", "provenance": { "notes": "Compact correctness sibling for the hidden-size-one low-occupancy benchmark; many rows with hidden=1 keep the variance-zero bias path honest without using benchmark-scale dimensions." }, "provenance": { "notes": "Many hidden-size-one rows exercise the variance-zero bias path at a compact scale." }, "attrs": { "epsilon": 0.00001 }, "inputs": { "inputT": {14 unmodified lines "outputT": { "dtype": "float32", "shape": [257, 1], "tolerance": 0.000001 }, "residualT": { "dtype": "float32", "shape": [257, 1], "tolerance": 0.000001 } } }, { "name": "rank3_no_bias_residual", "provenance": { "notes": "Rank-3 activation shape carrying the residual output, the form ONNX Runtime's transformer fusion emits when the pre-normalization sum feeds the next block." }, "attrs": { "epsilon": 0.00001 }, "inputs": { "inputT": { "dtype": "float32", "shape": [1, 4, 768], "data": { "kind": "fillFloat32", "scale": 0.2, "sinStep": 0.017, "cosStep": 0.031 } }, "skipT": { "dtype": "float32", "shape": [1, 4, 768], "data": { "kind": "fillFloat32", "scale": 0.2, "sinStep": 0.011, "cosStep": 0.023 } }, "gammaT": { "dtype": "float32", "shape": [768], "data": { "kind": "fillFloat32", "scale": 0.1, "offset": 1.0, "sinStep": 0.007, "cosStep": 0.041 } }, "betaT": { "dtype": "float32", "shape": [768], "data": { "kind": "fillFloat32", "scale": 0.1, "sinStep": 0.019, "cosStep": 0.013 } } }, "outputs": { "outputT": { "dtype": "float32", "shape": [1, 4, 768], "tolerance": 0.0002 }, "residualT": { "dtype": "float32", "shape": [1, 4, 768], "tolerance": 0.000002 } } }, { "name": "rank3_beta_no_bias_output_only_hidden6_unaligned_row", "provenance": { "notes": "Rank-3 at a hidden size that is not a multiple of four, so the scalar row route serves it." }, "attrs": { "epsilon": 0.00001 }, "inputs": { "inputT": { "dtype": "float32", "shape": [1, 2, 6], "data": { "kind": "fillFloat32", "sinStep": 0.19, "cosStep": 0.37 } }, "skipT": { "dtype": "float32", "shape": [1, 2, 6], "data": { "kind": "fillFloat32", "sinStep": 0.23, "cosStep": 0.43 } }, "gammaT": { "dtype": "float32", "shape": [6], "data": { "kind": "fillFloat32", "sinStep": 0.07, "cosStep": 0.41, "scale": 0.2 } }, "betaT": { "dtype": "float32", "shape": [6], "data": { "kind": "fillFloat32", "sinStep": 0.13, "cosStep": 0.29, "scale": 0.1 } } }, "outputs": { "outputT": { "dtype": "float32", "shape": [1, 2, 6], "tolerance": 0.00002 } } }, { "name": "f16_rank3_beta_bias_output_only", "provenance": { "notes": "Half-precision beta and bias at a rank-3 activation shape, the ordinary on-device inference form." }, "requires": { "features": ["shader-f16"] }, "attrs": { "epsilon": 0.00001 }, "inputs": { "inputT": { "dtype": "float16", "shape": [1, 3, 8], "data": { "kind": "fillFloat32", "sinStep": 0.17, "cosStep": 0.31 } }, "skipT": { "dtype": "float16", "shape": [1, 3, 8], "data": { "kind": "fillFloat32", "sinStep": 0.11, "cosStep": 0.23 } }, "gammaT": { "dtype": "float16", "shape": [8], "data": { "kind": "fillFloat32", "sinStep": 0.07, "cosStep": 0.41, "scale": 0.2 } }, "betaT": { "dtype": "float16", "shape": [8], "data": { "kind": "fillFloat32", "sinStep": 0.13, "cosStep": 0.29, "scale": 0.1 } }, "biasT": { "dtype": "float16", "shape": [8], "data": { "kind": "fillFloat32", "sinStep": 0.05, "cosStep": 0.47, "scale": 0.3 } } }, "outputs": { "outputT": { "dtype": "float16", "shape": [1, 3, 8], "tolerance": 0.01 } } }, { "name": "f16_beta_bias_output_only_hidden6_unaligned_row", "provenance": { "notes": "Half precision at an unaligned hidden size, which the scalar row route serves." }, "requires": { "features": ["shader-f16"] }, "attrs": { "epsilon": 0.00001 }, "inputs": { "inputT": { "dtype": "float16", "shape": [2, 6], "data": { "kind": "fillFloat32", "sinStep": 0.19, "cosStep": 0.37 } }, "skipT": { "dtype": "float16", "shape": [2, 6], "data": { "kind": "fillFloat32", "sinStep": 0.23, "cosStep": 0.43 } }, "gammaT": { "dtype": "float16", "shape": [6], "data": { "kind": "fillFloat32", "sinStep": 0.07, "cosStep": 0.41, "scale": 0.2 } }, "betaT": { "dtype": "float16", "shape": [6], "data": { "kind": "fillFloat32", "sinStep": 0.13, "cosStep": 0.29, "scale": 0.1 } }, "biasT": { "dtype": "float16", "shape": [6], "data": { "kind": "fillFloat32", "sinStep": 0.05, "cosStep": 0.47, "scale": 0.3 } } }, "outputs": { "outputT": { "dtype": "float16", "shape": [2, 6], "tolerance": 0.01 } } }, { "name": "f16_beta_no_bias_output_only", "provenance": { "notes": "Half precision with beta and no bias." }, "requires": { "features": ["shader-f16"] }, "attrs": { "epsilon": 0.00001 }, "inputs": { "inputT": { "dtype": "float16", "shape": [3, 8], "data": { "kind": "fillFloat32", "sinStep": 0.17, "cosStep": 0.31 } }, "skipT": { "dtype": "float16", "shape": [3, 8], "data": { "kind": "fillFloat32", "sinStep": 0.11, "cosStep": 0.23 } }, "gammaT": { "dtype": "float16", "shape": [8], "data": { "kind": "fillFloat32", "sinStep": 0.07, "cosStep": 0.41, "scale": 0.2 } }, "betaT": { "dtype": "float16", "shape": [8], "data": { "kind": "fillFloat32", "sinStep": 0.13, "cosStep": 0.29, "scale": 0.1 } } }, "outputs": { "outputT": { "dtype": "float16", "shape": [3, 8], "tolerance": 0.01 } } }, { "name": "f16_beta_no_bias_output_only_hidden6_unaligned_row", "provenance": { "notes": "Half precision with beta, no bias, at an unaligned hidden size." }, "requires": { "features": ["shader-f16"] }, "attrs": { "epsilon": 0.00001 }, "inputs": { "inputT": { "dtype": "float16", "shape": [2, 6], "data": { "kind": "fillFloat32", "sinStep": 0.19, "cosStep": 0.37 } }, "skipT": { "dtype": "float16", "shape": [2, 6], "data": { "kind": "fillFloat32", "sinStep": 0.23, "cosStep": 0.43 } }, "gammaT": { "dtype": "float16", "shape": [6], "data": { "kind": "fillFloat32", "sinStep": 0.07, "cosStep": 0.41, "scale": 0.2 } }, "betaT": { "dtype": "float16", "shape": [6], "data": { "kind": "fillFloat32", "sinStep": 0.13, "cosStep": 0.29, "scale": 0.1 } } }, "outputs": { "outputT": { "dtype": "float16", "shape": [2, 6], "tolerance": 0.01 } } }, { "name": "f16_no_beta_output_only_hidden6_unaligned_row", "provenance": { "notes": "Half precision with neither beta nor bias, at an unaligned hidden size." }, "requires": { "features": ["shader-f16"] }, "attrs": { "epsilon": 0.00001 }, "inputs": { "inputT": { "dtype": "float16", "shape": [2, 6], "data": { "kind": "fillFloat32", "sinStep": 0.17, "cosStep": 0.31 } }, "skipT": { "dtype": "float16", "shape": [2, 6], "data": { "kind": "fillFloat32", "sinStep": 0.11, "cosStep": 0.23 } }, "gammaT": { "dtype": "float16", "shape": [6], "data": { "kind": "fillFloat32", "sinStep": 0.07, "cosStep": 0.41, "scale": 0.2 } } }, "outputs": { "outputT": { "dtype": "float16", "shape": [2, 6], "tolerance": 0.002 } } }, { "name": "f16_no_beta_output_only", "provenance": { "notes": "Half precision with neither beta nor bias at an aligned hidden size, which is the vec4 arm of that pair." }, "requires": { "features": ["shader-f16"] }, "attrs": { "epsilon": 0.00001 }, "inputs": { "inputT": { "dtype": "float16", "shape": [3, 8], "data": { "kind": "fillFloat32", "sinStep": 0.17, "cosStep": 0.31 } }, "skipT": { "dtype": "float16", "shape": [3, 8], "data": { "kind": "fillFloat32", "sinStep": 0.11, "cosStep": 0.23 } }, "gammaT": { "dtype": "float16", "shape": [8], "data": { "kind": "fillFloat32", "sinStep": 0.07, "cosStep": 0.41, "scale": 0.2 } } }, "outputs": { "outputT": { "dtype": "float16", "shape": [3, 8], "tolerance": 0.002 } } } ]}README.md+21-13
build/webgpu/bench.json+3-4
build/webgpu/manifest.json+418-861
build/webgpu/metadata.json+30-8
build/webgpu/norm-skip-row-vec4.wgsl.jinja+16-15
build/webgpu/norm-skip-row.wgsl.jinja+8-70
build/webgpu/test.json+251-13