| { |
| "domain": "com.microsoft", |
| "name": "GemmaRotaryEmbedding", |
| "sinceVersion": 1, |
| "inputs": { |
| "embT": { "onnx": "emb", "dtype": "U", "rank": 3, "storage": "float32" }, |
| "qT": { "onnx": "q", "dtype": "T", "rank": 4 }, |
| "qRotT": { "onnx": "q_rot", "dtype": "T", "rank": 4 }, |
| "kT": { "onnx": "k", "dtype": "T", "rank": 4 }, |
| "kRotT": { "onnx": "k_rot", "dtype": "T", "rank": 4 } |
| }, |
| "outputs": { |
| "output1T": { "onnx": "output1", "dtype": "T", "rank": "ranks.qT", "shape": "shapes.qT" }, |
| "output2T": { "onnx": "output2", "dtype": "T", "rank": "ranks.qT", "shape": "shapes.qT" } |
| }, |
| "typeConstraints": { "T": ["float16"], "U": ["float32"] }, |
| "tunables": { "workgroupSize": { "default": 256 } }, |
| "derive": { |
| "batchSize": "dim(shapes.qT, 0)", |
| "numHeads": "dim(shapes.qT, 1)", |
| "seqLen": "dim(shapes.qT, 2)", |
| "headDim": "dim(shapes.qT, 3)", |
| "sameAsQ": "ranks.qRotT == 4 and ranks.kT == 4 and ranks.kRotT == 4 and sameShape(shapes.qRotT, shapes.qT) and sameShape(shapes.kT, shapes.qT) and sameShape(shapes.kRotT, shapes.qT)", |
| "dtypesMatch": "tensorDtypes.qRotT == tensorDtypes.qT and tensorDtypes.kT == tensorDtypes.qT and tensorDtypes.kRotT == tensorDtypes.qT and tensorDtypes.output1T == tensorDtypes.qT and tensorDtypes.output2T == tensorDtypes.qT", |
| "contract": "ranks.qT == 4 and ranks.embT == 3 and sameAsQ and dtypesMatch and tensorDtypes.qT == \"float16\" and f16Ok(dtypes.T) and tensorDtypes.embT == \"float32\" and dim(shapes.embT, 0) == batchSize and dim(shapes.embT, 1) == seqLen and dim(shapes.embT, 2) == headDim and sameShape(shapes.output1T, shapes.qT) and sameShape(shapes.output2T, shapes.qT)", |
| "vec4Ok": "(seqLen * headDim) % 4 == 0" |
| }, |
| "when": ["contract", "tunables.workgroupSize >= 1", "floor(tunables.workgroupSize) == tunables.workgroupSize", "tunables.workgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup", "tunables.workgroupSize <= device.limits.maxComputeWorkgroupSizeX"], |
| "variants": [ |
| { |
| "id": "vec4", |
| "priority": 10, |
| "when": ["vec4Ok"], |
| "requires": { "features": ["shader-f16"] }, |
| "derive": { |
| "vec4": true, |
| "scalar": "dtypes.T", |
| "vector": "\"vec4<f16>\"", |
| "workgroupSize": "tunables.workgroupSize" |
| }, |
| "passes": [ |
| { |
| "id": "main", |
| "name": "GemmaRotaryEmbedding.Vec4", |
| "shader": "gemma-rotary-embedding.wgsl.jinja", |
| "bindings": [ |
| { "arg": "embT", "name": "emb", "elementType": "vec4<f32>" }, |
| { "arg": "qT", "name": "q", "elementType": "$vector" }, |
| { "arg": "qRotT", "name": "q_rot", "elementType": "$vector" }, |
| { "arg": "kT", "name": "k", "elementType": "$vector" }, |
| { "arg": "kRotT", "name": "k_rot", "elementType": "$vector" }, |
| { "arg": "output1T", "name": "output1", "elementType": "$vector" }, |
| { "arg": "output2T", "name": "output2", "elementType": "$vector" }, |
| { |
| "name": "params", |
| "struct": [ |
| { "name": "count", "type": "u32", "value": "numel(shapes.qT) / 4" }, |
| { "name": "seqDim", "type": "u32", "value": "(seqLen * headDim) / 4" }, |
| { "name": "headSeqDim", "type": "u32", "value": "(numHeads * seqLen * headDim) / 4" } |
| ] |
| } |
| ], |
| "dispatch": { |
| "x": "min(ceilDiv((numel(shapes.qT) / 4), (workgroupSize)), 65535)", |
| "y": "ceilDiv(ceilDiv((numel(shapes.qT) / 4), (workgroupSize)), 65535)", |
| "z": 1 |
| } |
| } |
| ] |
| }, |
| { |
| "id": "scalar", |
| "priority": 0, |
| "requires": { "features": ["shader-f16"] }, |
| "derive": { |
| "vec4": false, |
| "scalar": "dtypes.T", |
| "vector": "\"vec4<f16>\"", |
| "workgroupSize": "tunables.workgroupSize" |
| }, |
| "passes": [ |
| { |
| "id": "main", |
| "name": "GemmaRotaryEmbedding", |
| "shader": "gemma-rotary-embedding.wgsl.jinja", |
| "bindings": [ |
| { "arg": "embT", "name": "emb" }, |
| { "arg": "qT", "name": "q", "elementType": "$scalar" }, |
| { "arg": "qRotT", "name": "q_rot", "elementType": "$scalar" }, |
| { "arg": "kT", "name": "k", "elementType": "$scalar" }, |
| { "arg": "kRotT", "name": "k_rot", "elementType": "$scalar" }, |
| { "arg": "output1T", "name": "output1", "elementType": "$scalar" }, |
| { "arg": "output2T", "name": "output2", "elementType": "$scalar" }, |
| { |
| "name": "params", |
| "struct": [ |
| { "name": "count", "type": "u32", "value": "numel(shapes.qT)" }, |
| { "name": "seqDim", "type": "u32", "value": "(seqLen * headDim)" }, |
| { "name": "headSeqDim", "type": "u32", "value": "(numHeads * seqLen * headDim)" } |
| ] |
| } |
| ], |
| "dispatch": { |
| "x": "min(ceilDiv((max(1, numel(shapes.qT))), (workgroupSize)), 65535)", |
| "y": "ceilDiv(ceilDiv((max(1, numel(shapes.qT))), (workgroupSize)), 65535)", |
| "z": 1 |
| } |
| } |
| ] |
| } |
| ] |
| } |
|
|