sync 91d990483a17
Browse filesFiles changed (6)
17 unmodified lines181920212122232425262324252627282930303132323334354 unmodified lines40414243444546464748494 unmodified lines54555657575859601 unmodified line6263646566656667686970717273747517 unmodified lines
## Inputs
| Name | Bind key | Logical dtype | WebGPU storage | Rank | Shape | Description | Presence || Name | Upstream name | Logical dtype | WebGPU storage | Rank | Shape | Description | Presence || --- | --- | --- | --- | --- | --- | --- | --- || `input` | `x` | `T` | same as logical dtype | — | — | Input token embeddings. Shape is `(batch_size, sequence_length, hidden_size)` for rank 3 or `(batch_size, num_heads, sequence_length, head_size)` for rank 4. The effective rotary dimension must be even, and `num_heads` is required for rank-3 input. | required || `position_ids` | `positionIds` | `M` | `uint32` | `3` | — | Logical int64 position indices of shape `(3, batch_size, sequence_length)`, holding the temporal, height and width streams in that order along the first axis. Valid positions are non-negative cache-row indices and use uint32 WebGPU storage. | required || `cos_cache` | `cos` | `T` | same as logical dtype | `2` | — | Precomputed cosine values of shape `(max_sequence_length, rotary_dim/2)`, shared by all three position streams. | required || `sin_cache` | `sin` | `T` | same as logical dtype | `2` | — | Precomputed sine values with the same shape and type as `cos_cache`. | required || `x` | `input` | `T` | same as logical dtype | — | — | Input token embeddings. Shape is `(batch_size, sequence_length, hidden_size)` for rank 3 or `(batch_size, num_heads, sequence_length, head_size)` for rank 4. The effective rotary dimension must be even, and `num_heads` is required for rank-3 input. | required || `positionIds` | `position_ids` | `M` | `uint32` | `3` | — | Logical int64 position indices of shape `(3, batch_size, sequence_length)`, holding the temporal, height and width streams in that order along the first axis. Valid positions are non-negative cache-row indices and use uint32 WebGPU storage. | required || `cos` | `cos_cache` | `T` | same as logical dtype | `2` | — | Precomputed cosine values of shape `(max_sequence_length, rotary_dim/2)`, shared by all three position streams. | required || `sin` | `sin_cache` | `T` | same as logical dtype | `2` | — | Precomputed sine values with the same shape and type as `cos_cache`. | required |
## Outputs
| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence || Name | Upstream name | Logical dtype | Rank | Shape | Description | Presence || --- | --- | --- | --- | --- | --- | --- || `output` | `y` | `T` | same as `input` | same as `input` | Rotary-position-encoded tensor with the same shape and type as `input`. | required || `y` | `output` | `T` | same as `x` | same as `x` | Rotary-position-encoded tensor with the same shape and type as `input`. | required |
## Attributes
4 unmodified lines| `interleaved` | `0` | Set to 1 to rotate using an interleaved pattern (even/odd elements), or 0 to split the head dimension into two contiguous halves. Default is 0. This is the rotation pairing and is independent of `mrope_layout`. || `is_packed_batching` | `0` | Whether `position_ids` uses packed-batch metadata. The default and only supported value is 0; packed batching (1) is not implemented. || `mrope_layout` | `0` | How the three sections are combined into one per-token cos/sin vector: `0` for the sectioned/chunked layout (Qwen2-VL, Qwen2.5-VL) or `1` for the interleaved layout (Qwen3-VL, Qwen3.5). Default is 0. || `mrope_section` | — | Three non-negative integers `[section_t, section_h, section_w]` dividing the half-rotary axis among the temporal, height and width streams. They must sum to `rotary_embedding_dim / 2`, or to `head_size / 2` when `rotary_embedding_dim` is 0. Required. || `num_heads` | `0` | Number of attention heads. The schema default is 0. A positive value is required for rank-3 `input` and whenever `rotary_embedding_dim` is nonzero; rank-4 execution otherwise infers the head count from `input`. || `rotary_embedding_dim` | `0` | Positive even number of head-dimension elements to rotate; `0` means the full head dimension, which must then be even. A smaller even value permits an odd head size and copies the remaining tail unchanged. || `scale` | `1` | Scale applied to the gathered cosine and sine values before the rotation. Default is 1.0. || `mrope_section` | — | Three non-negative integers `[section_t, section_h, section_w]` dividing the half-rotary axis among the temporal, height and width streams. They must sum to `rotary_embedding_dim / 2`, or to `head_size / 2` when `rotary_embedding_dim` is 0. Required. |
## Type constraints
4 unmodified lines
## 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 cases1 unmodified line
## 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.
12234{ "op": "com.microsoft.MRotaryEmbedding", "tunableSpace": { "WORKGROUP_SIZE": [64, 128, 256] }, "cases": [ {1 unmodified line2345678910111213141516171819202122232425262728293031323334353637383956789101112414243444546131415161718192021221 unmodified line24252654555657585960616227646566676869707172737475767728297980303132338384853435363738888990394041429293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209434445464748495051525354555657585960616263646566676869707172737475767778798081828384858621421587888990913 unmodified lines95969722522622798991001011021031041051061071081091102332341111121131141153 unmodified lines1191201212442452461221231241251261271281291301311321 unmodified line "domain": "com.microsoft", "name": "MRotaryEmbedding", "sinceVersion": 1, "description": "Multimodal rotary position embedding (M-RoPE) for Qwen models. Each token has temporal, height, and width position streams; `mrope_section` partitions the half-rotary axis and `mrope_layout` assigns them. Text-only tokens set all streams equal, reducing the op to `RotaryEmbedding`. The effective rotary dimension must be positive and even; an odd head size is supported with a smaller even `rotary_embedding_dim`. This package supports float16/float32 and non-packed mode; bfloat16 and packed batching are not implemented. Position ids must be valid non-negative cache-row indices.", "inputs": [ { "role": "input", "dtype": "T", "description": "Input token embeddings. Shape is `(batch_size, sequence_length, hidden_size)` for rank 3 or `(batch_size, num_heads, sequence_length, head_size)` for rank 4. The effective rotary dimension must be even, and `num_heads` is required for rank-3 input." }, { "role": "position_ids", "dtype": "M", "rank": 3, "description": "Logical int64 position indices of shape `(3, batch_size, sequence_length)`, holding the temporal, height and width streams in that order along the first axis. Valid positions are non-negative cache-row indices and use uint32 WebGPU storage." }, { "role": "cos_cache", "dtype": "T", "rank": 2, "description": "Precomputed cosine values of shape `(max_sequence_length, rotary_dim/2)`, shared by all three position streams." }, { "role": "sin_cache", "dtype": "T", "rank": 2, "description": "Precomputed sine values with the same shape and type as `cos_cache`." } ], "outputs": [ { "role": "output", "dtype": "T", "rank": "ranks.input", "shape": "shapes.input", "description": "Rotary-position-encoded tensor with the same shape and type as `input`." } ], "inputs": { "x": { "onnx": "input", "dtype": "T" }, "positionIds": { "onnx": "position_ids", "dtype": "M", "rank": 3, "storage": "uint32", "narrowing": "checked" }, "cos": { "onnx": "cos_cache", "dtype": "T", "rank": 2 }, "sin": { "onnx": "sin_cache", "dtype": "T", "rank": 2 } }, "outputs": { "y": { "onnx": "output", "dtype": "T", "rank": "ranks.x", "shape": "shapes.x" } }, "attributes": { "interleaved": 0, "is_packed_batching": 0, "mrope_layout": 0, "num_heads": 0, "rotary_embedding_dim": 0, "scale": 1 "interleaved": { "default": 0 }, "is_packed_batching": { "default": 0 }, "mrope_layout": { "default": 0 }, "num_heads": { "default": 0 }, "rotary_embedding_dim": { "default": 0 }, "scale": { "default": 1 }, "mrope_section": {} }, "attributeConstraints": { "interleaved": { "values": [0, 1] },1 unmodified line "mrope_layout": { "values": [0, 1] }, "mrope_section": { "required": true } }, "attributeDescriptions": { "interleaved": "Set to 1 to rotate using an interleaved pattern (even/odd elements), or 0 to split the head dimension into two contiguous halves. Default is 0. This is the rotation pairing and is independent of `mrope_layout`.", "is_packed_batching": "Whether `position_ids` uses packed-batch metadata. The default and only supported value is 0; packed batching (1) is not implemented.", "mrope_layout": "How the three sections are combined into one per-token cos/sin vector: `0` for the sectioned/chunked layout (Qwen2-VL, Qwen2.5-VL) or `1` for the interleaved layout (Qwen3-VL, Qwen3.5). Default is 0.", "mrope_section": "Three non-negative integers `[section_t, section_h, section_w]` dividing the half-rotary axis among the temporal, height and width streams. They must sum to `rotary_embedding_dim / 2`, or to `head_size / 2` when `rotary_embedding_dim` is 0. Required.", "num_heads": "Number of attention heads. The schema default is 0. A positive value is required for rank-3 `input` and whenever `rotary_embedding_dim` is nonzero; rank-4 execution otherwise infers the head count from `input`.", "rotary_embedding_dim": "Positive even number of head-dimension elements to rotate; `0` means the full head dimension, which must then be even. A smaller even value permits an odd head size and copies the remaining tail unchanged.", "scale": "Scale applied to the gathered cosine and sine values before the rotation. Default is 1.0." }, "typeConstraints": { "T": ["float32", "float16"], "M": ["int64"] }, "args": { "x": { "kind": "tensor", "semantic": "input", "role": "input" }, "positionIds": { "kind": "tensor", "semantic": "position_ids", "role": "input", "dtype": "uint32", "narrowing": "checked" }, "cos": { "kind": "tensor", "semantic": "cos_cache", "role": "input" }, "sin": { "kind": "tensor", "semantic": "sin_cache", "role": "input" }, "y": { "kind": "tensor", "semantic": "output", "role": "output" } }, "tunables": { "WORKGROUP_SIZE": 256 }, "tunables": { "WORKGROUP_SIZE": { "default": 256 } }, "derive": { "rank3HeadSize": "dim(shapes.input, 2) / attrs.num_heads if attrs.num_heads is defined and attrs.num_heads > 0 else 0", "headSize": "rank3HeadSize if ranks.input == 3 else dim(shapes.input, 3)", "rank3HeadSize": "dim(shapes.x, 2) / attrs.num_heads if attrs.num_heads is defined and attrs.num_heads > 0 else 0", "headSize": "rank3HeadSize if ranks.x == 3 else dim(shapes.x, 3)", "effectiveRotaryDim": "attrs.rotary_embedding_dim if attrs.rotary_embedding_dim != 0 else headSize", "tasksPerHead": "ceilDiv(headSize, 2)", "pairCount": "(numel(shapes.input) / max(1, headSize)) * tasksPerHead", "pairDispatchOk": "ceilDiv(pairCount, tunables.WORKGROUP_SIZE) <= device.limits.maxComputeWorkgroupsPerDimension * device.limits.maxComputeWorkgroupsPerDimension", "halfRotaryDim": "dim(shapes.cos_cache, 1)", "pairCount": "(numel(shapes.x) / max(1, headSize)) * tasksPerHead", "pairDispatchOk": "ceilDiv(pairCount, tunables.WORKGROUP_SIZE) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) * min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", "halfRotaryDim": "dim(shapes.cos, 1)", "sectionsDefined": "attrs.mrope_section is defined and (attrs.mrope_section | length) == 3", "sectionsValid": "sectionsDefined and attrs.mrope_section[0] >= 0 and attrs.mrope_section[1] >= 0 and attrs.mrope_section[2] >= 0 and attrs.mrope_section[0] + attrs.mrope_section[1] + attrs.mrope_section[2] == halfRotaryDim", "commonContract": "f16Ok(dtypes.T) and sameShape(shapes.input, shapes.output) and (attrs.interleaved == 0 or attrs.interleaved == 1) and (attrs.mrope_layout == 0 or attrs.mrope_layout == 1) and attrs.num_heads >= 0 and attrs.rotary_embedding_dim >= 0 and (attrs.rotary_embedding_dim == 0 or attrs.num_heads > 0) and sameShape(shapes.cos_cache, shapes.sin_cache) and ranks.cos_cache == 2 and ranks.sin_cache == 2 and sectionsValid and ranks.position_ids == 3 and dim(shapes.position_ids, 0) == 3 and dim(shapes.position_ids, 1) == dim(shapes.input, 0) and dim(shapes.position_ids, 2) == dim(shapes.input, 1 if ranks.input == 3 else 2)", "rank3Contract": "commonContract and ranks.input == 3 and ranks.output == 3 and attrs.num_heads is defined and attrs.num_heads >= 1 and dim(shapes.input, 2) % attrs.num_heads == 0 and rank3HeadSize > 0 and effectiveRotaryDim % 2 == 0 and (attrs.rotary_embedding_dim == 0 or attrs.rotary_embedding_dim <= rank3HeadSize) and halfRotaryDim * 2 == effectiveRotaryDim", "rank4Contract": "commonContract and ranks.input == 4 and ranks.output == 4 and dim(shapes.input, 3) > 0 and effectiveRotaryDim % 2 == 0 and (attrs.rotary_embedding_dim == 0 or attrs.rotary_embedding_dim <= dim(shapes.input, 3)) and halfRotaryDim * 2 == effectiveRotaryDim" "commonContract": "f16Ok(dtypes.T) and sameShape(shapes.x, shapes.y) and (attrs.interleaved == 0 or attrs.interleaved == 1) and (attrs.mrope_layout == 0 or attrs.mrope_layout == 1) and attrs.num_heads >= 0 and attrs.rotary_embedding_dim >= 0 and (attrs.rotary_embedding_dim == 0 or attrs.num_heads > 0) and sameShape(shapes.cos, shapes.sin) and ranks.cos == 2 and ranks.sin == 2 and sectionsValid and ranks.positionIds == 3 and dim(shapes.positionIds, 0) == 3 and dim(shapes.positionIds, 1) == dim(shapes.x, 0) and dim(shapes.positionIds, 2) == dim(shapes.x, 1 if ranks.x == 3 else 2)", "rank3Contract": "commonContract and ranks.x == 3 and ranks.y == 3 and attrs.num_heads is defined and attrs.num_heads >= 1 and dim(shapes.x, 2) % attrs.num_heads == 0 and rank3HeadSize > 0 and effectiveRotaryDim % 2 == 0 and (attrs.rotary_embedding_dim == 0 or attrs.rotary_embedding_dim <= rank3HeadSize) and halfRotaryDim * 2 == effectiveRotaryDim", "rank4Contract": "commonContract and ranks.x == 4 and ranks.y == 4 and dim(shapes.x, 3) > 0 and effectiveRotaryDim % 2 == 0 and (attrs.rotary_embedding_dim == 0 or attrs.rotary_embedding_dim <= dim(shapes.x, 3)) and halfRotaryDim * 2 == effectiveRotaryDim" }, "bindingSets": { "$common": [ { "name": "x", "arg": "x", "semantic": "input", "buffer": { "type": "read-only-storage" }, "elementType": "$T" }, { "name": "position_ids", "arg": "positionIds", "semantic": "position_ids", "buffer": { "type": "read-only-storage" }, "elementType": "u32" }, { "name": "cos_cache", "arg": "cos", "semantic": "cos_cache", "buffer": { "type": "read-only-storage" }, "elementType": "$T" }, { "name": "sin_cache", "arg": "sin", "semantic": "sin_cache", "buffer": { "type": "read-only-storage" }, "elementType": "$T" }, { "name": "y", "arg": "y", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "$T" } ], "rank3": [ { "name": "x", "arg": "x", "semantic": "input", "buffer": { "type": "read-only-storage" }, "elementType": "$T" }, { "name": "position_ids", "arg": "positionIds", "semantic": "position_ids", "buffer": { "type": "read-only-storage" }, "elementType": "u32" }, { "name": "cos_cache", "arg": "cos", "semantic": "cos_cache", "buffer": { "type": "read-only-storage" }, "elementType": "$T" }, { "name": "sin_cache", "arg": "sin", "semantic": "sin_cache", "buffer": { "type": "read-only-storage" }, "elementType": "$T" }, { "name": "y", "arg": "y", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "$T" }, { "name": "params", "semantic": "kernel.params", "buffer": { "type": "uniform" }, "struct": { "name": "Params", "fields": [ { "name": "pairCount", "type": "u32", "value": "pairCount" }, { "name": "batchSize", "type": "u32", "value": "dim(shapes.input, 0)" }, { "name": "sequenceLength", "type": "u32", "value": "dim(shapes.input, 1)" }, { "name": "numHeads", "type": "u32", "value": "attrs.num_heads" }, { "name": "headSize", "type": "u32", "value": "rank3HeadSize" }, { "name": "rotaryDim", "type": "u32", "value": "halfRotaryDim * 2" }, { "name": "halfRotaryDim", "type": "u32", "value": "halfRotaryDim" }, { "name": "section0", "type": "u32", "value": "attrs.mrope_section[0]" }, { "name": "section1", "type": "u32", "value": "attrs.mrope_section[1]" }, { "name": "section2", "type": "u32", "value": "attrs.mrope_section[2]" }, { "name": "scale", "type": "f32", "value": "attrs.scale" } ] } } ], "rank4": [ { "name": "x", "arg": "x", "semantic": "input", "buffer": { "type": "read-only-storage" }, "elementType": "$T" }, { "name": "position_ids", "arg": "positionIds", "semantic": "position_ids", "buffer": { "type": "read-only-storage" }, "elementType": "u32" }, { "name": "cos_cache", "arg": "cos", "semantic": "cos_cache", "buffer": { "type": "read-only-storage" }, "elementType": "$T" }, { "name": "sin_cache", "arg": "sin", "semantic": "sin_cache", "buffer": { "type": "read-only-storage" }, "elementType": "$T" }, { "name": "y", "arg": "y", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "$T" }, { "name": "params", "semantic": "kernel.params", "buffer": { "type": "uniform" }, "struct": { "name": "Params", "fields": [ { "name": "pairCount", "type": "u32", "value": "pairCount" }, { "name": "batchSize", "type": "u32", "value": "dim(shapes.input, 0)" }, { "name": "sequenceLength", "type": "u32", "value": "dim(shapes.input, 2)" }, { "name": "numHeads", "type": "u32", "value": "dim(shapes.input, 1)" }, { "name": "headSize", "type": "u32", "value": "dim(shapes.input, 3)" }, { "name": "rotaryDim", "type": "u32", "value": "halfRotaryDim * 2" }, { "name": "halfRotaryDim", "type": "u32", "value": "halfRotaryDim" }, { "name": "section0", "type": "u32", "value": "attrs.mrope_section[0]" }, { "name": "section1", "type": "u32", "value": "attrs.mrope_section[1]" }, { "name": "section2", "type": "u32", "value": "attrs.mrope_section[2]" }, { "name": "scale", "type": "f32", "value": "attrs.scale" } ] } } ] "when": ["pairDispatchOk"], "bindings": { "x": { "buffer": "read-only-storage", "elementType": "$T" }, "position_ids": { "arg": "positionIds", "buffer": "read-only-storage", "elementType": "u32" }, "cos_cache": { "arg": "cos", "buffer": "read-only-storage", "elementType": "$T" }, "sin_cache": { "arg": "sin", "buffer": "read-only-storage", "elementType": "$T" }, "y": { "buffer": "storage", "elementType": "$T" }, "params": { "buffer": "uniform", "struct": [ { "name": "pairCount", "type": "u32", "value": "pairCount" }, { "name": "batchSize", "type": "u32", "value": "dim(shapes.x, 0)" }, { "name": "sequenceLength", "type": "u32", "value": "dim(shapes.x, 1)" }, { "name": "numHeads", "type": "u32", "value": "attrs.num_heads" }, { "name": "headSize", "type": "u32", "value": "rank3HeadSize" }, { "name": "rotaryDim", "type": "u32", "value": "halfRotaryDim * 2" }, { "name": "halfRotaryDim", "type": "u32", "value": "halfRotaryDim" }, { "name": "section0", "type": "u32", "value": "attrs.mrope_section[0]" }, { "name": "section1", "type": "u32", "value": "attrs.mrope_section[1]" }, { "name": "section2", "type": "u32", "value": "attrs.mrope_section[2]" }, { "name": "scale", "type": "f32", "value": "attrs.scale" } ] }, "params_2": { "name": "params", "buffer": "uniform", "struct": [ { "name": "pairCount", "type": "u32", "value": "pairCount" }, { "name": "batchSize", "type": "u32", "value": "dim(shapes.x, 0)" }, { "name": "sequenceLength", "type": "u32", "value": "dim(shapes.x, 2)" }, { "name": "numHeads", "type": "u32", "value": "dim(shapes.x, 1)" }, { "name": "headSize", "type": "u32", "value": "dim(shapes.x, 3)" }, { "name": "rotaryDim", "type": "u32", "value": "halfRotaryDim * 2" }, { "name": "halfRotaryDim", "type": "u32", "value": "halfRotaryDim" }, { "name": "section0", "type": "u32", "value": "attrs.mrope_section[0]" }, { "name": "section1", "type": "u32", "value": "attrs.mrope_section[1]" }, { "name": "section2", "type": "u32", "value": "attrs.mrope_section[2]" }, { "name": "scale", "type": "f32", "value": "attrs.scale" } ] } }, "variants": [ { "id": "rank3", "when": ["rank3Contract", "pairDispatchOk"], "constants": { "when": ["rank3Contract"], "derive": { "interleaved": "attrs.interleaved != 0", "mropeSectioned": "attrs.mrope_layout == 0", "usesF16": "dtypes.T == \"f16\"",3 unmodified lines { "id": "main", "name": "mrotary_embedding3d", "source": { "shader": "mrotary-embedding.wgsl.jinja", "inputs": { "rank": 3 } }, "bindings": "rank3", "dispatch": { "threads": "pairCount", "workgroupSize": "tunables.WORKGROUP_SIZE" } "shader": "mrotary-embedding.wgsl.jinja", "derive": { "rank": 3 }, "bindings": ["x", "position_ids", "cos_cache", "sin_cache", "y", "params"], "dispatch": { "x": "min(ceilDiv((pairCount), (tunables.WORKGROUP_SIZE)), 65535)", "y": "ceilDiv(ceilDiv((pairCount), (tunables.WORKGROUP_SIZE)), 65535)", "z": 1 } } ] }, { "id": "rank4", "when": ["rank4Contract", "pairDispatchOk"], "constants": { "when": ["rank4Contract"], "derive": { "interleaved": "attrs.interleaved != 0", "mropeSectioned": "attrs.mrope_layout == 0", "usesF16": "dtypes.T == \"f16\"",3 unmodified lines { "id": "main", "name": "mrotary_embedding4d", "source": { "shader": "mrotary-embedding.wgsl.jinja", "inputs": { "rank": 4 } }, "bindings": "rank4", "dispatch": { "threads": "pairCount", "workgroupSize": "tunables.WORKGROUP_SIZE" } "shader": "mrotary-embedding.wgsl.jinja", "derive": { "rank": 4 }, "bindings": ["x", "position_ids", "cos_cache", "sin_cache", "y", "params_2"], "dispatch": { "x": "min(ceilDiv((pairCount), (tunables.WORKGROUP_SIZE)), 65535)", "y": "ceilDiv(ceilDiv((pairCount), (tunables.WORKGROUP_SIZE)), 65535)", "z": 1 } } ] }1233456789101112131011121314151617161718192021{ "name": "com.microsoft.MRotaryEmbedding", "id": "_com_microsoft_mrotaryembedding_webgpu_396a9ed", "id": "_com_microsoft_mrotaryembedding_webgpu_83feafb", "version": 1, "license": "Apache-2.0", "backend": { "type": "webgpu" }, "digest": { "algorithm": "sha256", "files": { "bench.json": "FKPQK85F0NG70BrG2nvS4WDZWmkLLUtw0hjkaNqyfWI=", "manifest.json": "rNhF7mp6GzPe1XKu5djfgpCv5MKyJdPU7G06AvbgLXE=", "mrotary-embedding.wgsl.jinja": "ywEaYPPZeG6tSo/Ulh3lIOBwXLhdu70TAZJAgus88cA=", "test.json": "0mcf/8uDq9fTEq082qLPOGoRnjowxCk+vqzBBFVA0Ls=" "bench.json": "46hHXwN4zErrNbI5Kkvb00wSEt7LAjuixrnpiOUnuC8=", "manifest.json": "n2gNx3yadn8wpDXYWYTOGWFQVAiDogbtn03dXyQEAfE=", "mrotary-embedding.wgsl.jinja": "meXniZyv3KTe/4K0hd7HSYDjxS0ADty/sNevs/l3es8=", "test.json": "mQy2yFi3T6iEpqSliA+KGAipEQeV8moe0jnzSwH9ICI=" } }, "provenance": { "kernel": { "sha": "c928d21e6cc1310861cba3bafb75f5f679ecf5f3", "dirty": false } }, "webgpu": { "manifestSpec": "1.0", "specialized": true, "opPath": "ops/com.microsoft.MRotaryEmbedding" } "provenance": { "kernel": { "sha": "91d990483a174128daf7673f3f37a7c890493ae1", "dirty": false } }, "webgpu": { "manifestSpec": "2.0", "variants": { "rank3": ["mrotary-embedding.wgsl.jinja"], "rank4": ["mrotary-embedding.wgsl.jinja"] } }}123434567678910910111213121314151616171819181920212222232424252627272829308 unmodified lines394041424243444514 unmodified lines6061626363646566{% macro flat_index_2d(name="i", bound="params.count", guardInline=false, note="dispatch-limit") %}{% if note == "dispatch-limit" %} // 2D-folded flat index: gid.y carries the high bits past the // maxComputeWorkgroupsPerDimension dispatch limit (outputs > 16.7M elements). // 2D-folded flat index: gid.y carries the high bits past the dispatch's // per-axis workgroup fold width (outputs > 16.7M elements).{% elif note == "limit" %} // 2D-folded flat index: gid.y carries the high bits past the // maxComputeWorkgroupsPerDimension limit. // 2D-folded flat index: gid.y carries the high bits past the dispatch's // per-axis workgroup fold width.{% elif note == "device-axis" %} // The flat dispatch is folded across x/y at the device's per-axis workgroup // limit; gid.y carries the high portion of the output index. // The flat dispatch is folded across x/y at a fixed per-axis workgroup // width; gid.y carries the high portion of the output index.{% elif note == "vec4-limit" %} // 2D-folded flat vec4 index: gid.y carries the high bits past the // maxComputeWorkgroupsPerDimension limit (the dispatch caps x and spills into y). // 2D-folded flat vec4 index: gid.y carries the high bits past the dispatch's // per-axis workgroup fold width (the dispatch caps x and spills into y).{% elif note == "element-limit" %} // 2D-folded flat element index: gid.y carries the high bits past the // maxComputeWorkgroupsPerDimension limit. // dispatch's per-axis workgroup fold width.{% elif note == "dispatch" %} // 2D-folded flat index: gid.y carries the high bits past the // maxComputeWorkgroupsPerDimension dispatch limit. // 2D-folded flat index: gid.y carries the high bits past the dispatch's // per-axis workgroup fold width.{% endif %}{% if bound == "" %} let {{ name }} = gid.x + gid.y * nwg.x * {{ tunables.WORKGROUP_SIZE }}u; let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ tunables.WORKGROUP_SIZE }}u;{%- elif guardInline %} let {{ name }} = gid.x + gid.y * nwg.x * {{ tunables.WORKGROUP_SIZE }}u; let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ tunables.WORKGROUP_SIZE }}u; if ({{ name }} >= {{ bound }}) { return; }{%- else %} let {{ name }} = gid.x + gid.y * nwg.x * {{ tunables.WORKGROUP_SIZE }}u; let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ tunables.WORKGROUP_SIZE }}u; if ({{ name }} >= {{ bound }}) { return; }8 unmodified lines// owns both outputs of a rotated pair, so x/cos/sin are read once; partial rotations// use the remaining pair lanes to copy two unchanged tail values.@compute @workgroup_size({{ tunables.WORKGROUP_SIZE }})fn main(@builtin(global_invocation_id) gid: vec3<u32>, @builtin(num_workgroups) nwg: vec3<u32>) {fn main(@builtin(global_invocation_id) gid: vec3<u32>) {{{ flat_index_2d("p", "params.pairCount", note="") }}
let tasksPerHead = (params.headSize + 1u) / 2u;14 unmodified lines // under both rotation pairings: interleaved reads column channel/2 and the split // form reads channel % halfRotaryDim, and this lane owns channel == pair in each. let pair = task;{% if source.rank == 3 %}{% if rank == 3 %} let token = (headFlat / params.numHeads) % params.sequenceLength; let batch = headFlat / (params.numHeads * params.sequenceLength);{% else %}122342 unmodified lines7891110111213183 unmodified lines197198199201200201202203{ "op": "com.microsoft.MRotaryEmbedding", "fixtureArrays": { "ort_sectioned_rank3_input_x": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] },2 unmodified lines "name": "rank4_odd_head_even_partial_rotation", "provenance": { "source": "onnxruntime/contrib_ops/cuda/bert/mrotary_embedding_impl.cu", "notes": "The provider requires the effective rotary dimension, not the full head size, to be even. The singleton tail element is copied unchanged." "notes": "The effective rotary dimension is even while the full head size is odd, leaving one unrotated tail element that must be copied unchanged." }, "attrs": { "num_heads": 1,183 unmodified lines { "name": "f16_rank4_layout1_interleaved", "provenance": { "notes": "f16 storage, including the provider's T-rounded scaled-cache intermediate, on the interleaved layout and pairing." "notes": "The interleaved layout uses float16 storage, including float16 rounding of the scaled cache intermediate before pairing." }, "attrs": { "rotary_embedding_dim": 0,README.md+15-11
build/webgpu/bench.json-1
build/webgpu/manifest.json+83-200
build/webgpu/metadata.json+10-7
build/webgpu/mrotary-embedding.wgsl.jinja+16-16
build/webgpu/test.json+2-3