Xenova's picture
Xenova HF Staff
sync 2e7068faf55e
c4a6897 verified
Raw
History Blame
4.47 kB
{
"domain": "com.microsoft",
"name": "QuickGelu",
"sinceVersion": 1,
"description": "Computes `x * sigmoid(alpha * x)` elementwise, a fast approximation of GELU activation. The output has the same shape as the input. This WebGPU package implements float16 and float32; the schema-allowed double and bfloat16 types are not supported.",
"inputs": [{ "role": "X", "dtype": "T", "description": "Input tensor of any shape." }],
"outputs": [
{
"role": "Y",
"dtype": "T",
"rank": "ranks.X",
"shape": "shapes.X",
"description": "Output tensor; same shape as the input."
}
],
"attributes": { "alpha": 1.702 },
"attributeDescriptions": {
"alpha": "Scalar multiplier applied to `x` inside the sigmoid; defaults to 1.702, which approximates GELU."
},
"typeConstraints": { "T": ["float32", "float16"] },
"args": {
"X": { "kind": "tensor", "semantic": "X", "role": "input" },
"Y": { "kind": "tensor", "semantic": "Y", "role": "output" }
},
"tunables": { "WORKGROUP_SIZE": 256 },
"derive": {
"deviceWorkgroupCap": "min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX)",
"workgroupOk": "tunables.WORKGROUP_SIZE > 0 and tunables.WORKGROUP_SIZE <= deviceWorkgroupCap",
"baseOk": "workgroupOk and numel(shapes.X) == numel(shapes.Y) and f16Ok(dtypes.T)",
"vec4Ok": "numel(shapes.X) > 0 and numel(shapes.X) % 4 == 0"
},
"bindingSets": {
"scalarTail": [
{ "name": "x", "arg": "X", "semantic": "X", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" },
{ "name": "y", "arg": "Y", "semantic": "Y", "buffer": { "type": "storage" }, "elementType": "$scalar" },
{
"name": "params",
"semantic": "kernel.params",
"buffer": { "type": "uniform" },
"struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.X)" }] }
}
]
},
"variants": [
{
"id": "vec4",
"priority": 20,
"when": ["baseOk", "vec4Ok"],
"constants": {
"scalar": "dtypes.T",
"usesF16": "dtypes.T == \"f16\"",
"vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"",
"vec4": true,
"vec4Tail": false
},
"passes": [
{
"id": "main",
"name": "QuickGelu.vec4",
"source": { "shader": "quick-gelu.wgsl.jinja", "inputs": { "alpha": "attrs.alpha" } },
"bindings": [
{
"name": "x",
"arg": "X",
"semantic": "X",
"buffer": { "type": "read-only-storage" },
"elementType": "$vectorScalar"
},
{
"name": "y",
"arg": "Y",
"semantic": "Y",
"buffer": { "type": "storage" },
"elementType": "$vectorScalar"
},
{
"name": "params",
"semantic": "kernel.params",
"buffer": { "type": "uniform" },
"struct": {
"name": "Params",
"fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.X) / 4" }]
}
}
],
"dispatch": { "threads": "numel(shapes.X) / 4", "workgroupSize": "tunables.WORKGROUP_SIZE" }
}
]
},
{
"id": "vec4_tail",
"priority": 10,
"when": ["baseOk", "numel(shapes.X) > 0"],
"constants": { "scalar": "dtypes.T", "usesF16": "dtypes.T == \"f16\"", "vec4": false, "vec4Tail": true },
"passes": [
{
"id": "main",
"name": "QuickGelu.vec4Tail",
"source": { "shader": "quick-gelu.wgsl.jinja", "inputs": { "alpha": "attrs.alpha" } },
"bindings": "scalarTail",
"dispatch": { "threads": "ceilDiv(numel(shapes.X), 4)", "workgroupSize": "tunables.WORKGROUP_SIZE" }
}
]
},
{
"id": "scalar",
"priority": 0,
"when": ["baseOk", "true"],
"constants": { "scalar": "dtypes.T", "usesF16": "dtypes.T == \"f16\"", "vec4": false, "vec4Tail": false },
"passes": [
{
"id": "main",
"name": "QuickGelu.scalar",
"source": { "shader": "quick-gelu.wgsl.jinja", "inputs": { "alpha": "attrs.alpha" } },
"bindings": "scalarTail",
"dispatch": { "threads": "numel(shapes.X)", "workgroupSize": "tunables.WORKGROUP_SIZE" }
}
]
}
]
}