|
Download README.md from webgpu-kernels/com.microsoft.SkipLayerNormalization: direct link, hf CLI and curl.
- Browser
- Download file 4.37 kB
-
https://huggingface.co/kernels/webgpu-kernels/com.microsoft.SkipLayerNormalization/resolve/62736d3708608a845392f5c1f8a15c8e8e91f3ed/README.md
- Command line
-
hf download hf://webgpu-kernels/com.microsoft.SkipLayerNormalization@62736d3708608a845392f5c1f8a15c8e8e91f3ed/README.md
-
curl -L -o README.md https://huggingface.co/kernels/webgpu-kernels/com.microsoft.SkipLayerNormalization/resolve/62736d3708608a845392f5c1f8a15c8e8e91f3ed/README.md
4.37 kB
| library_name: kernels | |
| license: apache-2.0 | |
| tags: | |
| - kernel | |
| - webgpu | |
| - wgsl | |
| # com.microsoft.SkipLayerNormalization | |
| `com.microsoft` · ONNX Runtime contrib operator · contrib since_version 1 | |
| ## Description | |
| 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 | Upstream name | Logical dtype | Rank | Shape | Description | Presence | | |
| | --- | --- | --- | --- | --- | --- | --- | | |
| | `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 | Upstream name | Logical dtype | Rank | Shape | Description | Presence | | |
| | --- | --- | --- | --- | --- | --- | --- | | |
| | `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 | |
| Default values (overridable per request): | |
| | Attribute | Default | Description | | |
| | --- | --- | --- | | |
| | `epsilon` | `9.999999960041972e-13` | Non-negative epsilon added to the variance before taking the square root. | | |
| ## Type constraints | |
| | Variable | Allowed dtypes | | |
| | --- | --- | | |
| | `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, per-variant templates, provenance) | |
| - [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth) | |
| - [`test.json`](build/webgpu/test.json) — correctness cases | |
| - [`bench.json`](build/webgpu/bench.json) — benchmark + tuning cases | |
| - [`norm-skip-row-vec4.wgsl.jinja`](build/webgpu/norm-skip-row-vec4.wgsl.jinja) | |
| - [`norm-skip-row.wgsl.jinja`](build/webgpu/norm-skip-row.wgsl.jinja) | |
| ## Use with `@huggingface/kernels` | |
| ```sh | |
| npm 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. | |
| ```js | |
| import { getKernel } from "@huggingface/kernels"; | |
| const kernel = await getKernel("webgpu-kernels/com.microsoft.SkipLayerNormalization", { version: 1 }); | |
| const { outputT } = await kernel({ | |
| inputT: { data: inputTData, shape: [2, 4] }, | |
| skipT: { data: skipTData, shape: [2, 4] }, | |
| gammaT: { data: gammaTData, shape: [4] }, | |
| }); | |
| ``` | |