|
Download README.md from webgpu-kernels/com.microsoft.SkipSimplifiedLayerNormalization: direct link, hf CLI and curl.
- Browser
- Download file 5.23 kB
-
https://huggingface.co/kernels/webgpu-kernels/com.microsoft.SkipSimplifiedLayerNormalization/resolve/v1/README.md
- Command line
-
hf download hf://webgpu-kernels/com.microsoft.SkipSimplifiedLayerNormalization@v1/README.md
-
curl -L -o README.md https://huggingface.co/kernels/webgpu-kernels/com.microsoft.SkipSimplifiedLayerNormalization/resolve/v1/README.md
5.23 kB
| library_name: kernels | |
| license: apache-2.0 | |
| tags: | |
| - kernel | |
| - webgpu | |
| - wgsl | |
| # com.microsoft.SkipSimplifiedLayerNormalization | |
| `com.microsoft` · ONNX Runtime contrib operator · contrib since_version 1 | |
| ## Description | |
| Adds `input` and `skip` (plus optional `bias`), then applies RMS normalization scaled by `gamma`. Optional outputs return the per-row mean (zero for RMS normalization), the inverse RMS and the pre-normalization sum. | |
| See the [ONNX Runtime `SkipSimplifiedLayerNormalization` contrib-operator spec](https://github.com/microsoft/onnxruntime/blob/main/docs/ContribOperators.md#com.microsoft.SkipSimplifiedLayerNormalization) for the reference semantics. | |
| ## Inputs | |
| | Name | Upstream name | Logical dtype | Rank | Shape | Description | Presence | | |
| | --- | --- | --- | --- | --- | --- | --- | | |
| | `inputT` | `input` | `T` | — | — | Input tensor of shape `(token_count, hidden_size)` or `(batch, sequence, hidden_size)`, normalized over the last axis. | required | | |
| | `skipT` | `skip` | `T` | — | — | Residual tensor of the same shape as `input`, added before normalization. | required | | |
| | `gammaT` | `gamma` | `T` | `1` | — | 1-D scale tensor with shape `(hidden_size)` applied after normalization. | required | | |
| | `biasT` | `bias` | `T` | `1` | — | Optional 1-D bias tensor with shape `(hidden_size)` added to the `input + skip` sum. | 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 | | |
| | `meanT` | `mean` | `U` | same as `inputT` | derived | Per-row mean; zero for simplified RMS normalization. Shape matches the input with its final axis replaced by one. | optional | | |
| | `invStdT` | `inv_std_var` | `U` | same as `inputT` | derived | Per-row inverse standard deviation, or inverse RMS for simplified normalization. Shape matches the input with its final axis replaced by one. | optional | | |
| | `residualT` | `input_skip_bias_sum` | `T` | same as `inputT` | same as `inputT` | Sum of `input`, `skip`, and optional `bias` 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 mean square before taking the square root. | | |
| ## Type constraints | |
| | Variable | Allowed dtypes | | |
| | --- | --- | | |
| | `T` | `float32`, `float16` | | |
| | `U` | `float32` | | |
| ## Implementation variants | |
| One implementation is selected per call from the device capabilities, the request shapes and the dtypes; these notes say what each one covers. | |
| - `row` — Row normalization in float32 and, on devices with shader-f16, float16; it also returns the requested mean (zero) and inverse-RMS statistics. | |
| ## Files | |
| - [`metadata.json`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.SkipSimplifiedLayerNormalization/blob/v1/build/webgpu/metadata.json) — kernel metadata (id, file digests, manifest spec, provenance) | |
| - [`manifest.json`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.SkipSimplifiedLayerNormalization/blob/v1/build/webgpu/manifest.json) — the op contract (source of truth) | |
| - [`test.json`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.SkipSimplifiedLayerNormalization/blob/v1/build/webgpu/test.json) — correctness cases | |
| - [`bench.json`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.SkipSimplifiedLayerNormalization/blob/v1/build/webgpu/bench.json) — benchmark cases | |
| - [`norm-skip-row-vec4.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.SkipSimplifiedLayerNormalization/blob/v1/build/webgpu/norm-skip-row-vec4.wgsl.jinja) | |
| - [`norm-skip-row.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.SkipSimplifiedLayerNormalization/blob/v1/build/webgpu/norm-skip-row.wgsl.jinja) | |
| ## Use with `@huggingface/kernels` | |
| ```sh | |
| npm 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`. | |
| ```js | |
| import { getKernel } from "@huggingface/kernels"; | |
| const kernel = await getKernel("webgpu-kernels/com.microsoft.SkipSimplifiedLayerNormalization", { version: 1 }); | |
| const inputTData = Float32Array.of(0.8, -0.5, 0, 1, 0.5, 0.2, 0.3, -0.6); | |
| const skipTData = new Float32Array(8); | |
| const gammaTData = Float32Array.of(0.3, 0.2, 4, 2.2); | |
| const { outputT } = await kernel({ | |
| inputT: { data: inputTData, shape: [2, 4] }, | |
| skipT: { data: skipTData, shape: [2, 4] }, | |
| gammaT: { data: gammaTData, shape: [4] }, | |
| }); | |
| console.log({ outputT }); | |
| ``` | |