diff --git "a/build/webgpu/manifest.json" "b/build/webgpu/manifest.json" --- "a/build/webgpu/manifest.json" +++ "b/build/webgpu/manifest.json" @@ -1,4302 +1 @@ -{ - "domain": "com.microsoft", - "name": "GroupQueryAttention", - "sinceVersion": 1, - "inputs": { - "queryT": { "onnx": "query", "dtype": "T", "rank": 3 }, - "keyT": { "onnx": "key", "dtype": "T", "rank": 3 }, - "valueT": { "onnx": "value", "dtype": "T", "rank": 3 }, - "pastKeyT": { "onnx": "past_key", "dtype": "T_CACHE", "rank": 4, "optional": true }, - "pastValueT": { "onnx": "past_value", "dtype": "T_CACHE", "rank": 4, "optional": true }, - "seqlensKT": { "onnx": "seqlens_k", "dtype": "M", "rank": 1 }, - "totalSequenceLengthT": { "onnx": "total_sequence_length", "dtype": "M", "rank": 1 }, - "cosCacheT": { "onnx": "cos_cache", "dtype": "T", "rank": 2, "optional": true }, - "sinCacheT": { "onnx": "sin_cache", "dtype": "T", "rank": 2, "optional": true }, - "attentionBiasT": { "onnx": "attention_bias", "dtype": "T", "rank": 4, "optional": true }, - "headSinkT": { "onnx": "head_sink", "dtype": "T", "rank": 1, "optional": true }, - "kScaleT": { "onnx": "k_scale", "dtype": "T_KV_SCALE", "rank": 1, "optional": true }, - "vScaleT": { "onnx": "v_scale", "dtype": "T_KV_SCALE", "rank": 1, "optional": true }, - "qNormWeightT": { "onnx": "q_norm_weight", "dtype": "T", "rank": 1, "optional": true }, - "kNormWeightT": { "onnx": "k_norm_weight", "dtype": "T", "rank": 1, "optional": true } - }, - "outputs": { - "outputT": { "onnx": "output", "dtype": "T", "rank": 3, "shape": "shapes.queryT" }, - "presentKeyT": { "onnx": "present_key", "dtype": "T_CACHE", "rank": 4 }, - "presentValueT": { "onnx": "present_value", "dtype": "T_CACHE", "rank": 4 } - }, - "attributes": { - "causal": { "default": 1 }, - "do_rotary": { "default": 0 }, - "k_quant_type": { "default": "NONE" }, - "local_window_size": { "default": -1 }, - "qk_norm_epsilon": { "default": 0.000001 }, - "sliding_window_cache": { "default": 0 }, - "smooth_softmax": { "default": -1 }, - "softcap": { "default": 0 }, - "v_quant_type": { "default": "NONE" }, - "kv_cache_bit_width": {}, - "kv_num_heads": {}, - "num_heads": {}, - "scale": {} - }, - "attributeConstraints": { - "causal": { "values": [0, 1] }, - "do_rotary": { "values": [0, 1] }, - "k_quant_type": { "values": ["NONE", "PER_TENSOR", "PER_CHANNEL"] }, - "kv_cache_bit_width": { "values": [4, 8] }, - "kv_num_heads": { "required": true }, - "num_heads": { "required": true }, - "sliding_window_cache": { "values": [0, 1] }, - "v_quant_type": { "values": ["NONE", "PER_TENSOR", "PER_CHANNEL"] } - }, - "typeConstraints": { - "T": ["float32", "float16"], - "T_CACHE": ["float32", "float16", "uint8", "int8"], - "T_KV_SCALE": ["float32"], - "M": ["int32"] - }, - "tunables": { - "WORKGROUP_SIZE": { "default": 256 }, - "COPY_WORKGROUP_SIZE": { "default": 64 }, - "SCALAR_WORKGROUP_SIZE": { "default": 64 }, - "COOPERATIVE_QUERY_THRESHOLD": { "default": 6144 }, - "MAX_SPLITS": { "default": 16 }, - "QKV_SPLIT_TILE_K": { "default": 128 }, - "CACHED_SPLIT_TILE_K": { "default": 256 }, - "FLASH_MIN_HEAD_DIM": { "default": 32 }, - "FLASH_MAX_HEAD_DIM": { "default": 256 }, - "PREFILL_QUERY_TILE": { "default": 32 }, - "PREFILL_LANES_PER_QUERY": { "default": 8 }, - "PREFILL_QUERY_TILE_F16": { "default": 16 }, - "PREFILL_LANES_PER_QUERY_F16": { "default": 8 }, - "QKV_PREFILL_MIN_QUERY_TOKENS": { "default": 31 }, - "QKV_DECODE_MIN_KV_TOKENS": { "default": 512 }, - "CACHED_FLASH_MIN_HEAD_DIM": { "default": 16 }, - "CACHED_DECODE_MIN_KV_TOKENS": { "default": 1024 }, - "CLUSTER_TILE_K_F32": { "default": 8 }, - "CLUSTER_TILE_K_F16": { "default": 8 }, - "NO_SG_TILE_K_MAX": { "default": 16 }, - "COOPERATIVE_WORKGROUP_SIZE": { "default": 32 }, - "CLUSTER_MAX_SLICE": { "default": 8 }, - "MATERIALIZED_SGMAT_QUERY_TILE": { "default": 64 }, - "MATERIALIZED_SGMAT_KEY_TILE": { "default": 64 }, - "MATERIALIZED_SGMAT_INNER_TILE": { "default": 32 }, - "MATERIALIZED_SOFTMAX_WORKGROUP_SIZE": { "default": 256 }, - "MATERIALIZED_SGMAT_MIN_SEQ": { "default": 256 }, - "MATERIALIZED_SGMAT_PAST_MIN_SEQ": { "default": 256 }, - "MATERIALIZED_SGMAT_WINDOW_MIN_QSEQ": { "default": 128 }, - "MATERIALIZED_SGMAT_APPEND_MIN_QSEQ": { "default": 128 } - }, - "derive": { - "deviceWorkgroupCap": "min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX)", - "wave32Adapter": "has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize == 32 and device.adapterInfo.subgroupMaxSize == 32", - "subgroupsWave32": "device.features.has(\"subgroups\") and wave32Adapter", - "narrowSubgroupRange": "has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize < device.adapterInfo.subgroupMaxSize and device.adapterInfo.subgroupMaxSize <= 16", - "canPinSubgroupSize32": "device.features.has(\"subgroups\") and device.features.has(\"subgroup-size-control\") and has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize <= 32 and device.adapterInfo.subgroupMaxSize >= 32", - "pinSubgroupSize32": "canPinSubgroupSize32 and not wave32Adapter", - "wave32Effective": "wave32Adapter or pinSubgroupSize32", - "wave32SubgroupsUsable": "subgroupsWave32 or pinSubgroupSize32", - "windowCacheRequested": "attrs.sliding_window_cache == 1", - "headDimPlan": "dim(shapes.queryT, 2) / attrs.num_heads if (ranks.queryT == 3 and attrs.num_heads > 0) else 0", - "copyWorkgroupSize": "min(tunables.COPY_WORKGROUP_SIZE, min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX))", - "scalarWorkgroupSize": "min(tunables.SCALAR_WORKGROUP_SIZE, min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX))", - "copyWorkgroupOk": "copyWorkgroupSize >= 1", - "scalarWorkgroupOk": "scalarWorkgroupSize >= 1", - "metadataInputsOk": "present.seqlensKT and present.totalSequenceLengthT", - "unquantizedCacheAttrs": "attrs.k_quant_type == \"NONE\" and attrs.v_quant_type == \"NONE\" and not attrs.kv_cache_bit_width and not present.kScaleT and not present.vScaleT", - "qkNormInputsOk": "present.qNormWeightT == present.kNormWeightT", - "rotaryRequested": "attrs.do_rotary == 1", - "noAuxAttentionInputs": "not present.cosCacheT and not rotaryRequested and not present.qNormWeightT and not present.attentionBiasT and not present.headSinkT", - "standardSoftmax": "attrs.softcap == 0 and attrs.smooth_softmax != 1", - "plainAttentionOptions": "noAuxAttentionInputs and standardSoftmax", - "causalNoWindow": "attrs.causal == 1 and attrs.local_window_size <= 0", - "qkvMaskModeOk": "(attrs.causal == 0 and attrs.local_window_size == -1) or (attrs.causal == 1 and attrs.local_window_size > 0) or causalNoWindow", - "qkvContractOk": "plainAttentionOptions and not windowCacheRequested and copyWorkgroupOk and metadataInputsOk and unquantizedCacheAttrs and qkNormInputsOk and qkvMaskModeOk and (not present.pastKeyT) and (not present.pastValueT) and ranks.queryT == 3 and ranks.keyT == 3 and ranks.valueT == 3 and ranks.outputT == 3 and ranks.presentKeyT == 4 and ranks.presentValueT == 4 and (tensorDtypes.queryT == \"float32\" or tensorDtypes.queryT == \"float16\") and f16Ok(tensorDtypes.queryT) and tensorDtypes.keyT == tensorDtypes.queryT and tensorDtypes.valueT == tensorDtypes.queryT and tensorDtypes.outputT == tensorDtypes.queryT and (tensorDtypes.presentKeyT == \"float32\" or tensorDtypes.presentKeyT == \"float16\") and f16Ok(tensorDtypes.presentKeyT) and tensorDtypes.presentValueT == tensorDtypes.presentKeyT and attrs.num_heads > 0 and attrs.kv_num_heads > 0 and attrs.num_heads % attrs.kv_num_heads == 0 and dim(shapes.queryT, 2) % attrs.num_heads == 0 and dim(shapes.keyT, 2) == attrs.kv_num_heads * headDimPlan and dim(shapes.valueT, 2) == dim(shapes.keyT, 2) and dim(shapes.queryT, 0) == dim(shapes.keyT, 0) and dim(shapes.queryT, 0) == dim(shapes.valueT, 0) and dim(shapes.keyT, 1) == dim(shapes.valueT, 1) and dim(shapes.outputT, 0) == dim(shapes.queryT, 0) and dim(shapes.outputT, 1) == dim(shapes.queryT, 1) and dim(shapes.outputT, 2) == dim(shapes.queryT, 2) and dim(shapes.presentKeyT, 0) == dim(shapes.queryT, 0) and dim(shapes.presentKeyT, 1) == attrs.kv_num_heads and dim(shapes.presentKeyT, 2) == dim(shapes.keyT, 1) and dim(shapes.presentKeyT, 3) == headDimPlan and dim(shapes.presentValueT, 0) == dim(shapes.presentKeyT, 0) and dim(shapes.presentValueT, 1) == dim(shapes.presentKeyT, 1) and dim(shapes.presentValueT, 2) == dim(shapes.presentKeyT, 2) and dim(shapes.presentValueT, 3) == dim(shapes.presentKeyT, 3)", - "flashWorkgroupOk": "tunables.WORKGROUP_SIZE <= deviceWorkgroupCap", - "flashShapeOk": "qkvContractOk and flashWorkgroupOk and headDimPlan % 4 == 0 and headDimPlan >= tunables.FLASH_MIN_HEAD_DIM and headDimPlan <= tunables.FLASH_MAX_HEAD_DIM and (dim(shapes.queryT, 1) * attrs.num_heads >= 248 or (dim(shapes.queryT, 1) == 1 and dim(shapes.keyT, 1) >= tunables.QKV_DECODE_MIN_KV_TOKENS) or (dim(shapes.queryT, 1) > 1 and dim(shapes.keyT, 1) >= 2048)) and dim(shapes.queryT, 0) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 1) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", - "decodeSplitKShapeOk": "qkvContractOk and flashWorkgroupOk and dim(shapes.queryT, 1) == 1 and dim(shapes.keyT, 1) >= tunables.QKV_DECODE_MIN_KV_TOKENS and headDimPlan % 4 == 0 and headDimPlan >= tunables.FLASH_MIN_HEAD_DIM and headDimPlan <= tunables.FLASH_MAX_HEAD_DIM and dim(shapes.queryT, 0) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", - "fallbackShapeOk": "qkvContractOk and headDimPlan <= deviceWorkgroupCap and headDimPlan <= tunables.FLASH_MAX_HEAD_DIM", - "gqaHeadDim": "dim(shapes.queryT, 2) / attrs.num_heads", - "qkvScalar": "\"f16\" if tensorDtypes.queryT == \"float16\" else \"f32\"", - "qkvInputVec4": "\"vec4\" if tensorDtypes.queryT == \"float16\" else \"vec4\"", - "qkvCacheScalar": "\"f16\" if tensorDtypes.presentKeyT == \"float16\" else \"f32\"", - "qkvCacheVec4": "\"vec4\" if tensorDtypes.presentKeyT == \"float16\" else \"vec4\"", - "qkvUsesF16": "tensorDtypes.queryT == \"float16\" or tensorDtypes.presentKeyT == \"float16\"", - "gqaScalar": "\"f16\" if tensorDtypes.queryT == \"float16\" else \"f32\"", - "gqaInputVec4": "\"vec4\" if tensorDtypes.queryT == \"float16\" else \"vec4\"", - "qkvNumSplits": "min(tunables.MAX_SPLITS, ceilDiv(dim(shapes.keyT, 1), tunables.QKV_SPLIT_TILE_K))", - "cachedNumSplits": "min(tunables.MAX_SPLITS, ceilDiv(dim(shapes.presentKeyT, 2), tunables.CACHED_SPLIT_TILE_K))", - "cachedBaseOk": "attrs.causal == 1 and metadataInputsOk and qkNormInputsOk", - "sharedKvCacheOk": "cachedBaseOk and unquantizedCacheAttrs and not windowCacheRequested and copyWorkgroupOk and present.pastKeyT and present.pastValueT and dim(shapes.keyT, 1) == 0 and dim(shapes.queryT, 2) % attrs.num_heads == 0 and dim(shapes.pastKeyT, 1) == attrs.kv_num_heads and dim(shapes.pastKeyT, 3) == gqaHeadDim", - "gqaFlashHd": "gqaHeadDim >= tunables.CACHED_FLASH_MIN_HEAD_DIM and gqaHeadDim <= tunables.FLASH_MAX_HEAD_DIM", - "f16OrF32": "(tensorDtypes.queryT == \"float32\" or tensorDtypes.queryT == \"float16\") and f16Ok(tensorDtypes.queryT) and tensorDtypes.keyT == tensorDtypes.queryT and tensorDtypes.valueT == tensorDtypes.queryT and tensorDtypes.outputT == tensorDtypes.queryT and tensorDtypes.presentKeyT == tensorDtypes.queryT and tensorDtypes.presentValueT == tensorDtypes.queryT and ((not present.pastKeyT) or tensorDtypes.pastKeyT == tensorDtypes.queryT) and ((not present.pastValueT) or tensorDtypes.pastValueT == tensorDtypes.queryT)", - "subgroupCluster8": "device.features.has(\"subgroups\") and has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize >= 8 and device.adapterInfo.subgroupMinSize % 8 == 0 and device.adapterInfo.subgroupMaxSize % 8 == 0", - "qkvPrefillQueryTile": "tunables.PREFILL_QUERY_TILE_F16 if tensorDtypes.queryT == \"float16\" else tunables.PREFILL_QUERY_TILE", - "qkvPrefillLanesPerQuery": "max(tunables.PREFILL_LANES_PER_QUERY_F16 if tensorDtypes.queryT == \"float16\" else tunables.PREFILL_LANES_PER_QUERY, ceilDiv(headDimPlan / 4, tunables.CLUSTER_MAX_SLICE))", - "cachedPrefillQueryTile": "tunables.PREFILL_QUERY_TILE_F16 if tensorDtypes.queryT == \"float16\" else tunables.PREFILL_QUERY_TILE", - "biasPrefillQueryTile": "min(cachedPrefillQueryTile, 16) if tensorDtypes.queryT == \"float32\" and not device.features.has(\"subgroups\") and has(device.adapterInfo, \"vendor\") and device.adapterInfo.vendor == \"intel\" else cachedPrefillQueryTile", - "cachedPrefillLanesPerQuery": "max(tunables.PREFILL_LANES_PER_QUERY_F16 if tensorDtypes.queryT == \"float16\" else tunables.PREFILL_LANES_PER_QUERY, ceilDiv(gqaHeadDim / 4, tunables.CLUSTER_MAX_SLICE))", - "subgroupQkvPrefillCluster": "not narrowSubgroupRange and device.features.has(\"subgroups\") and has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize >= qkvPrefillLanesPerQuery and device.adapterInfo.subgroupMinSize % qkvPrefillLanesPerQuery == 0 and device.adapterInfo.subgroupMaxSize % qkvPrefillLanesPerQuery == 0", - "subgroupCachedPrefillCluster": "not narrowSubgroupRange and device.features.has(\"subgroups\") and has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize >= cachedPrefillLanesPerQuery and device.adapterInfo.subgroupMinSize % cachedPrefillLanesPerQuery == 0 and device.adapterInfo.subgroupMaxSize % cachedPrefillLanesPerQuery == 0", - "subgroupSplitK": "subgroupCluster8 and device.adapterInfo.subgroupMaxSize <= tunables.WORKGROUP_SIZE and tunables.WORKGROUP_SIZE % device.adapterInfo.subgroupMinSize == 0 and tunables.WORKGROUP_SIZE % device.adapterInfo.subgroupMaxSize == 0", - "gqaQueryCount": "dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)", - "gqaCooperativeLaneCapacity": "floor((floor(device.limits.maxComputeWorkgroupStorageSize / 16) * 4 - gqaHeadDim) / (gqaHeadDim + 2))", - "gqaCooperativeWorkgroupSize": "min(tunables.COOPERATIVE_WORKGROUP_SIZE, deviceWorkgroupCap, max(1, gqaCooperativeLaneCapacity))", - "cooperativeWorkgroupOk": "gqaCooperativeWorkgroupSize >= 1 and gqaCooperativeWorkgroupSize <= deviceWorkgroupCap", - "gqaCoopWorkgroupBytes": "ceilDiv(((gqaCooperativeWorkgroupSize + 1) * gqaHeadDim + gqaCooperativeWorkgroupSize * 2) * 4, 16) * 16", - "gqaCoop": "cooperativeWorkgroupOk and gqaQueryCount < tunables.COOPERATIVE_QUERY_THRESHOLD and gqaCoopWorkgroupBytes <= device.limits.maxComputeWorkgroupStorageSize", - "gqaScalarDispatchOk": "gqaCoop or scalarWorkgroupOk", - "gqaDispatchUnits": "gqaQueryCount if gqaCoop else ceilDiv(gqaQueryCount, scalarWorkgroupSize)", - "gqaDispatchFits": "dim(shapes.queryT, 0) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", - "sharedKvFloatOk": "sharedKvCacheOk and f16OrF32", - "newKvPastOk": "cachedBaseOk and unquantizedCacheAttrs and not windowCacheRequested and copyWorkgroupOk and present.pastKeyT and present.pastValueT and dim(shapes.keyT, 1) > 0 and f16OrF32 and dim(shapes.queryT, 2) % attrs.num_heads == 0 and dim(shapes.pastKeyT, 1) == attrs.kv_num_heads and dim(shapes.pastKeyT, 3) == gqaHeadDim and dim(shapes.presentKeyT, 2) == dim(shapes.pastKeyT, 2) + dim(shapes.keyT, 1)", - "windowCapacity": "dim(shapes.pastKeyT, 2) if present.pastKeyT else 0", - "windowFitsCapacity": "attrs.local_window_size <= windowCapacity if attrs.local_window_size > 0 else true", - "windowShiftCacheOk": "cachedBaseOk and unquantizedCacheAttrs and copyWorkgroupOk and present.pastKeyT and present.pastValueT and dim(shapes.keyT, 1) > 0 and f16OrF32 and dim(shapes.queryT, 2) % attrs.num_heads == 0 and dim(shapes.pastKeyT, 1) == attrs.kv_num_heads and dim(shapes.pastKeyT, 3) == gqaHeadDim and windowCacheRequested and dim(shapes.presentKeyT, 2) == windowCapacity and dim(shapes.keyT, 1) <= windowCapacity and windowFitsCapacity", - "windowShiftOk": "windowShiftCacheOk and not present.cosCacheT and not rotaryRequested", - "windowShiftRotaryOk": "windowShiftCacheOk and present.cosCacheT and present.sinCacheT and rotaryRequested and tensorDtypes.queryT == \"float32\" and gqaHeadDim % 2 == 0 and dim(shapes.keyT, 1) == dim(shapes.queryT, 1)", - "shareAppendShapeOk": "unquantizedCacheAttrs and copyWorkgroupOk and present.pastKeyT and present.pastValueT and dim(shapes.keyT, 1) > 0 and f16OrF32 and dim(shapes.queryT, 2) % attrs.num_heads == 0 and dim(shapes.pastKeyT, 1) == attrs.kv_num_heads and dim(shapes.pastKeyT, 3) == gqaHeadDim and not windowCacheRequested and dim(shapes.presentKeyT, 2) == dim(shapes.pastKeyT, 2) and dim(shapes.keyT, 1) <= dim(shapes.pastKeyT, 2)", - "shareAppendOk": "cachedBaseOk and shareAppendShapeOk", - "cachedBidirectionalBaseOk": "attrs.causal == 0 and attrs.local_window_size == -1 and metadataInputsOk and qkNormInputsOk", - "shareAppendBidirectionalOk": "cachedBidirectionalBaseOk and shareAppendShapeOk", - "decodeFlashShapeOk": "flashWorkgroupOk and dim(shapes.queryT, 1) == 1 and gqaHeadDim % 4 == 0 and gqaFlashHd and dim(shapes.presentKeyT, 2) >= tunables.CACHED_DECODE_MIN_KV_TOKENS and gqaDispatchFits", - "qkvPrefillClusterWorkgroupSize": "qkvPrefillQueryTile * qkvPrefillLanesPerQuery", - "cachedPrefillClusterWorkgroupSize": "cachedPrefillQueryTile * cachedPrefillLanesPerQuery", - "cachedPrefillClusterWorkgroupOk": "cachedPrefillClusterWorkgroupSize <= deviceWorkgroupCap", - "prefillFlashShapeOk": "cachedPrefillClusterWorkgroupOk and gqaHeadDim % (4 * cachedPrefillLanesPerQuery) == 0 and gqaFlashHd and dim(shapes.queryT, 1) >= cachedPrefillQueryTile and gqaDispatchFits and ceilDiv(dim(shapes.queryT, 1), cachedPrefillQueryTile) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", - "quantScaleShapeOk": "((attrs.k_quant_type == \"PER_TENSOR\" and numel(shapes.kScaleT) == 1) or (attrs.k_quant_type == \"PER_CHANNEL\" and numel(shapes.kScaleT) == attrs.kv_num_heads * gqaHeadDim)) and ((attrs.v_quant_type == \"PER_TENSOR\" and numel(shapes.vScaleT) == 1) or (attrs.v_quant_type == \"PER_CHANNEL\" and numel(shapes.vScaleT) == attrs.kv_num_heads * gqaHeadDim))", - "quantizedNewKvOk": "cachedBaseOk and not windowCacheRequested and copyWorkgroupOk and present.kScaleT and present.vScaleT and attrs.k_quant_type == attrs.v_quant_type and attrs.k_quant_type != \"NONE\" and (attrs.kv_cache_bit_width == 4 or attrs.kv_cache_bit_width == 8) and quantScaleShapeOk and tensorDtypes.queryT == \"float32\" and tensorDtypes.keyT == \"float32\" and tensorDtypes.valueT == \"float32\" and tensorDtypes.outputT == \"float32\" and tensorDtypes.presentKeyT == (\"uint8\" if attrs.kv_cache_bit_width == 4 else \"int8\") and tensorDtypes.presentValueT == tensorDtypes.presentKeyT and dim(shapes.presentKeyT, 3) == gqaHeadDim / (8 / attrs.kv_cache_bit_width) and dim(shapes.presentValueT, 3) == dim(shapes.presentKeyT, 3) and dim(shapes.keyT, 1) > 0 and gqaHeadDim % 2 == 0", - "quantizedPromptOk": "quantizedNewKvOk and dim(shapes.keyT, 1) == dim(shapes.presentKeyT, 2)", - "quantizedDecodeOptionsOk": "plainAttentionOptions and not present.sinCacheT and not present.kNormWeightT", - "quantizedCachedDecodeOk": "not windowCacheRequested and quantizedNewKvOk and quantizedDecodeOptionsOk and attrs.kv_cache_bit_width == 8 and present.pastKeyT and present.pastValueT and dim(shapes.queryT, 1) == 1 and dim(shapes.keyT, 1) == 1 and tensorDtypes.pastKeyT == \"int8\" and tensorDtypes.pastValueT == \"int8\" and tensorDtypes.presentKeyT == \"int8\" and tensorDtypes.presentValueT == \"int8\" and dim(shapes.pastKeyT, 0) == dim(shapes.presentKeyT, 0) and dim(shapes.pastKeyT, 1) == dim(shapes.presentKeyT, 1) and dim(shapes.pastKeyT, 2) == dim(shapes.presentKeyT, 2) and dim(shapes.pastKeyT, 3) == dim(shapes.presentKeyT, 3)", - "qkvSplitScratchBytes": "dim(shapes.queryT, 0) * attrs.num_heads * qkvNumSplits * headDimPlan * 4", - "qkvSplitStatsBytes": "2 * dim(shapes.queryT, 0) * attrs.num_heads * qkvNumSplits * 4", - "qkvSplitScratchFits": "qkvSplitScratchBytes <= device.limits.maxStorageBufferBindingSize and qkvSplitScratchBytes <= device.limits.maxBufferSize and qkvSplitStatsBytes <= device.limits.maxStorageBufferBindingSize and qkvSplitStatsBytes <= device.limits.maxBufferSize", - "cachedSplitScratchBytes": "dim(shapes.queryT, 0) * attrs.num_heads * cachedNumSplits * gqaHeadDim * 4", - "cachedSplitStatsBytes": "2 * dim(shapes.queryT, 0) * attrs.num_heads * cachedNumSplits * 4", - "cachedSplitScratchFits": "cachedSplitScratchBytes <= device.limits.maxStorageBufferBindingSize and cachedSplitScratchBytes <= device.limits.maxBufferSize and cachedSplitStatsBytes <= device.limits.maxStorageBufferBindingSize and cachedSplitStatsBytes <= device.limits.maxBufferSize", - "qPrepScratchBytes": "numel(shapes.queryT) * 4", - "qPrepScratchFits": "qPrepScratchBytes <= device.limits.maxStorageBufferBindingSize and qPrepScratchBytes <= device.limits.maxBufferSize", - "qkvTiledWorkgroupBytes": "dim(shapes.valueT, 2) / attrs.kv_num_heads * 32 * 4", - "qkvTiledStorageOk": "qkvTiledWorkgroupBytes <= device.limits.maxComputeWorkgroupStorageSize", - "qkvClusterTileK": "tunables.CLUSTER_TILE_K_F32 if tensorDtypes.queryT == \"float32\" and headDimPlan <= tunables.QKV_SPLIT_TILE_K else tunables.CLUSTER_TILE_K_F16", - "qkvClusterWorkgroupBytes": "qkvClusterTileK * headDimPlan * (8 if tensorDtypes.queryT == \"float32\" else 4)", - "qkvClusterStorageOk": "qkvClusterWorkgroupBytes <= device.limits.maxComputeWorkgroupStorageSize", - "qkvF32ClusterRegisterGeometry": "tensorDtypes.queryT != \"float32\" or (headDimPlan % 4 == 0 and headDimPlan / (4 * qkvPrefillLanesPerQuery) <= tunables.CLUSTER_MAX_SLICE)", - "cachedF32ClusterRegisterGeometry": "tensorDtypes.queryT != \"float32\" or (gqaHeadDim % 4 == 0 and gqaHeadDim / (4 * cachedPrefillLanesPerQuery) <= tunables.CLUSTER_MAX_SLICE)", - "qkvNoSgReductionBytesPerKey": "qkvPrefillClusterWorkgroupSize * 4", - "cachedNoSgReductionBytesPerKey": "cachedPrefillClusterWorkgroupSize * 4", - "qkvNoSgTileBytes": "headDimPlan * (8 if tensorDtypes.queryT == \"float32\" else 4) + qkvNoSgReductionBytesPerKey", - "qkvNoSgTileK": "min(tunables.NO_SG_TILE_K_MAX, max(1, floor(device.limits.maxComputeWorkgroupStorageSize / qkvNoSgTileBytes)))", - "qkvNoSgWorkgroupBytes": "qkvNoSgTileK * qkvNoSgTileBytes", - "qkvNoSgClusterStorageOk": "qkvNoSgWorkgroupBytes <= device.limits.maxComputeWorkgroupStorageSize", - "qkvSgClusterOk": "qkvClusterStorageOk and qkvF32ClusterRegisterGeometry and subgroupQkvPrefillCluster", - "cachedClusterTileK": "tunables.CLUSTER_TILE_K_F32 if tensorDtypes.queryT == \"float32\" and gqaHeadDim <= tunables.QKV_SPLIT_TILE_K else tunables.CLUSTER_TILE_K_F16", - "cachedClusterWorkgroupBytes": "cachedClusterTileK * gqaHeadDim * (8 if tensorDtypes.queryT == \"float32\" else 4)", - "cachedClusterStorageOk": "cachedClusterWorkgroupBytes <= device.limits.maxComputeWorkgroupStorageSize", - "cachedMaskClusterWorkgroupBytes": "cachedClusterWorkgroupBytes + cachedPrefillQueryTile * cachedClusterTileK * 4", - "cachedMaskClusterStorageOk": "cachedMaskClusterWorkgroupBytes <= device.limits.maxComputeWorkgroupStorageSize", - "cachedNoSgTileBytes": "gqaHeadDim * (8 if tensorDtypes.queryT == \"float32\" else 4) + cachedNoSgReductionBytesPerKey", - "cachedNoSgTileK": "min(tunables.NO_SG_TILE_K_MAX, max(1, floor(device.limits.maxComputeWorkgroupStorageSize / cachedNoSgTileBytes)))", - "cachedNoSgWorkgroupBytes": "cachedNoSgTileK * cachedNoSgTileBytes", - "cachedNoSgClusterStorageOk": "cachedNoSgWorkgroupBytes <= device.limits.maxComputeWorkgroupStorageSize", - "cachedSgPrefillOk": "cachedClusterStorageOk and subgroupCachedPrefillCluster and cachedF32ClusterRegisterGeometry", - "cachedMaskSgPrefillOk": "cachedMaskClusterStorageOk and subgroupCachedPrefillCluster and cachedF32ClusterRegisterGeometry", - "gqaMatQueryTile": "tunables.MATERIALIZED_SGMAT_QUERY_TILE", - "gqaMatKeyTile": "tunables.MATERIALIZED_SGMAT_KEY_TILE", - "gqaMatInnerTile": "tunables.MATERIALIZED_SGMAT_INNER_TILE", - "gqaMatSubgroupRows": "floor(gqaMatQueryTile / 16)", - "gqaMatSubgroupCols": "floor(gqaMatKeyTile / 32)", - "gqaMatWorkgroupSize": "gqaMatSubgroupRows * gqaMatSubgroupCols * 32", - "gqaMatCompactStorageBytes": "(gqaMatQueryTile + gqaMatKeyTile) * gqaMatInnerTile * 4", - "gqaMatGeometryOk": "gqaMatQueryTile >= 16 and gqaMatQueryTile % 16 == 0 and gqaMatKeyTile >= 32 and gqaMatKeyTile <= 64 and gqaMatKeyTile % 32 == 0 and gqaMatInnerTile == 32 and gqaMatQueryTile >= 64 and gqaMatKeyTile >= 64", - "gqaMatResourcesFit": "gqaMatGeometryOk and gqaMatWorkgroupSize <= deviceWorkgroupCap and gqaMatCompactStorageBytes <= device.limits.maxComputeWorkgroupStorageSize", - "gqaMatScoreBytes": "dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.keyT, 1) * 4", - "gqaMatScoreFits": "gqaMatScoreBytes <= device.limits.maxStorageBufferBindingSize and gqaMatScoreBytes <= device.limits.maxBufferSize", - "gqaMatBuffersFit": "numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.keyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.valueT) * 4 <= device.limits.maxStorageBufferBindingSize", - "gqaMatDispatchFits": "ceilDiv(dim(shapes.keyT, 1), gqaMatKeyTile) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", - "gqaMatStatSlots": "ceilDiv(dim(shapes.keyT, 1), gqaMatKeyTile) * gqaMatSubgroupCols", - "gqaMatRowStatsWg": "min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)", - "gqaMatRowStatsElements": "dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * 2", - "gqaMatScorePartialElements": "dim(shapes.queryT, 0) * attrs.num_heads * gqaMatStatSlots * dim(shapes.queryT, 1) * 2", - "gqaMatCoreOk": "qkvContractOk and attrs.causal == 0 and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and headDimPlan >= 64 and headDimPlan <= 256 and headDimPlan % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_MIN_SEQ and dim(shapes.keyT, 1) >= tunables.MATERIALIZED_SGMAT_MIN_SEQ and device.features.has(\"subgroups\") and wave32Effective and device.features.has(\"chromium-experimental-subgroup-matrix\") and gqaMatScoreFits and gqaMatBuffersFit and gqaMatResourcesFit and gqaMatDispatchFits", - "gqaMatPastQSeq": "dim(shapes.queryT, 1)", - "gqaMatPastKvSeq": "dim(shapes.presentKeyT, 2)", - "gqaMatPastScoreBytes": "dim(shapes.queryT, 0) * attrs.num_heads * gqaMatPastQSeq * gqaMatPastKvSeq * 4", - "gqaMatPastScoreFits": "gqaMatPastScoreBytes <= device.limits.maxStorageBufferBindingSize and gqaMatPastScoreBytes <= device.limits.maxBufferSize", - "gqaMatPastBuffersFit": "numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentKeyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentValueT) * 4 <= device.limits.maxStorageBufferBindingSize", - "gqaMatPastStatSlots": "ceilDiv(gqaMatPastKvSeq, gqaMatKeyTile) * gqaMatSubgroupCols", - "gqaMatPastRowStatsElements": "dim(shapes.queryT, 0) * attrs.num_heads * gqaMatPastQSeq * 2", - "gqaMatPastScorePartialElements": "dim(shapes.queryT, 0) * attrs.num_heads * gqaMatPastStatSlots * gqaMatPastQSeq * 2", - "gqaMatPastDispatchFits": "ceilDiv(gqaMatPastKvSeq, gqaMatKeyTile) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(gqaMatPastQSeq, gqaMatQueryTile) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", - "gqaMatShareAppendOk": "shareAppendOk and plainAttentionOptions and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and dim(shapes.queryT, 1) == dim(shapes.keyT, 1) and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_APPEND_MIN_QSEQ and dim(shapes.presentKeyT, 2) >= dim(shapes.queryT, 1) and device.features.has(\"subgroups\") and wave32Effective and device.features.has(\"chromium-experimental-subgroup-matrix\") and gqaMatPastScoreFits and gqaMatPastBuffersFit and gqaMatResourcesFit and gqaMatPastDispatchFits", - "gqaMatWindowOk": "windowShiftOk and plainAttentionOptions and tensorDtypes.queryT == \"float32\" and attrs.local_window_size > 0 and dim(shapes.queryT, 1) == dim(shapes.keyT, 1) and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_WINDOW_MIN_QSEQ and windowCapacity >= dim(shapes.queryT, 1) and attrs.local_window_size + dim(shapes.queryT, 1) >= windowCapacity and device.features.has(\"subgroups\") and wave32Effective and device.features.has(\"chromium-experimental-subgroup-matrix\") and gqaMatPastScoreFits and gqaMatPastBuffersFit and gqaMatResourcesFit and gqaMatPastDispatchFits", - "gqaMatPastCoreOk": "sharedKvFloatOk and plainAttentionOptions and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and gqaMatPastQSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= gqaMatPastQSeq and device.features.has(\"subgroups\") and wave32Effective and device.features.has(\"chromium-experimental-subgroup-matrix\") and gqaMatPastScoreFits and gqaMatPastBuffersFit and gqaMatResourcesFit and gqaMatPastDispatchFits", - "gqaMatPastRotaryOk": "sharedKvFloatOk and standardSoftmax and present.cosCacheT and rotaryRequested and not present.qNormWeightT and not present.attentionBiasT and not present.headSinkT and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and gqaHeadDim % 8 == 0 and gqaMatPastQSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= gqaMatPastQSeq and device.features.has(\"subgroups\") and wave32Effective and device.features.has(\"chromium-experimental-subgroup-matrix\") and gqaMatPastScoreFits and gqaMatPastBuffersFit and gqaMatResourcesFit and gqaMatPastDispatchFits", - "gqaMatNewPastOk": "newKvPastOk and plainAttentionOptions and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and gqaMatPastQSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= gqaMatPastQSeq and device.features.has(\"subgroups\") and wave32Effective and device.features.has(\"chromium-experimental-subgroup-matrix\") and gqaMatPastScoreFits and gqaMatPastBuffersFit and gqaMatResourcesFit and gqaMatPastDispatchFits", - "gqaMatPastCoreF16Ok": "sharedKvFloatOk and plainAttentionOptions and tensorDtypes.queryT == \"float16\" and device.features.has(\"shader-f16\") and attrs.local_window_size == -1 and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and gqaMatPastQSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= gqaMatPastQSeq and device.features.has(\"subgroups\") and wave32Effective and device.features.has(\"chromium-experimental-subgroup-matrix\") and gqaMatPastScoreFits and gqaMatPastBuffersFit and gqaMatResourcesFit and gqaMatPastDispatchFits", - "gqaMatPastRotaryF16Ok": "sharedKvFloatOk and standardSoftmax and present.cosCacheT and rotaryRequested and not present.qNormWeightT and not present.attentionBiasT and not present.headSinkT and tensorDtypes.queryT == \"float16\" and device.features.has(\"shader-f16\") and attrs.local_window_size == -1 and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and gqaHeadDim % 8 == 0 and gqaMatPastQSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= gqaMatPastQSeq and device.features.has(\"subgroups\") and wave32Effective and device.features.has(\"chromium-experimental-subgroup-matrix\") and gqaMatPastScoreFits and gqaMatPastBuffersFit and gqaMatResourcesFit and gqaMatPastDispatchFits", - "gqaMatPastBiasOk": "sharedKvFloatOk and standardSoftmax and not present.cosCacheT and not rotaryRequested and not present.qNormWeightT and not present.headSinkT and present.attentionBiasT and ranks.attentionBiasT == 4 and tensorDtypes.attentionBiasT == \"float32\" and (dim(shapes.attentionBiasT, 0) == dim(shapes.queryT, 0) or dim(shapes.attentionBiasT, 0) == 1) and (dim(shapes.attentionBiasT, 1) == attrs.num_heads or dim(shapes.attentionBiasT, 1) == 1) and dim(shapes.attentionBiasT, 2) == dim(shapes.queryT, 1) and dim(shapes.attentionBiasT, 3) == dim(shapes.presentKeyT, 2) and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and gqaMatPastQSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= gqaMatPastQSeq and device.features.has(\"subgroups\") and wave32Effective and device.features.has(\"chromium-experimental-subgroup-matrix\") and gqaMatPastScoreFits and gqaMatPastBuffersFit and gqaMatResourcesFit and gqaMatPastDispatchFits", - "qNumHeads": "attrs.num_heads", - "attentionScaleExpression": "\"select(inverseSqrt(f32(HEAD_DIM)), params.scale, params.scale != 0.0)\"", - "materializedSgmatQueryTile": "gqaMatQueryTile", - "materializedSgmatKeyTile": "gqaMatKeyTile", - "materializedSgmatInnerTile": "gqaMatInnerTile", - "materializedSgmatRuntimeDirectStore": false, - "materializedRowStatsWg": "gqaMatRowStatsWg", - "statQuerySeq": "dim(shapes.queryT, 1)", - "hasWindow": "attrs.local_window_size > 0" - }, - "bindings": { - "query": { "arg": "queryT", "elementType": "f32" }, - "key": { "arg": "keyT", "elementType": "f32" }, - "scores": { "scratch": "materializedScores", "elementType": "f32" }, - "scorePartials": { "scratch": "materializedScorePartials", "elementType": "f32" }, - "scorePartials_f32": { - "scratch": "materializedScorePartials", - "name": "scorePartials", - "buffer": "read-only-storage", - "elementType": "f32" - }, - "rowStats": { "scratch": "materializedRowStats", "elementType": "f32" }, - "scores_f32": { - "scratch": "materializedScores", - "name": "scores", - "buffer": "read-only-storage", - "elementType": "f32" - }, - "value": { "arg": "valueT", "elementType": "f32" }, - "rowStats_f32": { - "scratch": "materializedRowStats", - "name": "rowStats", - "buffer": "read-only-storage", - "elementType": "f32" - }, - "output": { "arg": "outputT", "elementType": "f32" }, - "key_key_t": { "arg": "keyT", "name": "key", "elementType": "$inputElement" }, - "value_value_t": { "arg": "valueT", "name": "value", "elementType": "$inputElement" }, - "present_key": { "arg": "presentKeyT", "elementType": "$presentElement" }, - "present_value": { "arg": "presentValueT", "elementType": "$presentElement" }, - "params": { - "struct": [ - { "name": "batchSize", "type": "u32", "value": "dim(shapes.queryT, 0)" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.keyT, 1)" } - ] - }, - "src_k": { "arg": "pastKeyT", "elementType": "$inputScalar" }, - "src_v": { "arg": "pastValueT", "elementType": "$inputScalar" }, - "present_key_present": { "arg": "presentKeyT", "name": "present_key", "elementType": "$inputScalar" }, - "present_value_present": { "arg": "presentValueT", "name": "present_value", "elementType": "$inputScalar" }, - "params_count": { - "name": "params", - "struct": [ - { - "name": "count", - "type": "u32", - "value": "dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)" - } - ] - }, - "key_f32": { "arg": "presentKeyT", "name": "key", "buffer": "read-only-storage", "elementType": "f32" }, - "params_scores": { - "name": "params", - "struct": [ - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" } - ] - }, - "params_rows": { - "name": "params", - "struct": [ - { "name": "rows", "type": "u32", "value": "dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)" } - ] - }, - "value_f32": { "arg": "presentValueT", "name": "value", "buffer": "read-only-storage", "elementType": "f32" }, - "params_apply": { - "name": "params", - "struct": [ - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" } - ] - }, - "key_f16": { "arg": "presentKeyT", "name": "key", "buffer": "read-only-storage", "elementType": "f16" }, - "value_f16": { "arg": "presentValueT", "name": "value", "buffer": "read-only-storage", "elementType": "f16" }, - "output_f16": { "arg": "outputT", "name": "output", "elementType": "f16" }, - "query_qprep": { "arg": "queryT", "name": "query", "elementType": "$inputScalar" }, - "cos_cache": { "arg": "cosCacheT", "elementType": "$cosScalar" }, - "sin_cache": { "arg": "sinCacheT", "elementType": "$cosScalar" }, - "qout": { "scratch": "qPrep", "elementType": "vec4" }, - "params_qprep": { - "name": "params", - "struct": [ - { "name": "batch", "type": "u32", "value": "dim(shapes.queryT, 0)" }, - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "totalSeq", "type": "u32", "value": "dim(shapes.pastKeyT, 2)" } - ] - }, - "past_k": { "arg": "pastKeyT", "elementType": "$inputScalar" }, - "past_v": { "arg": "pastValueT", "elementType": "$inputScalar" }, - "new_k": { "arg": "keyT", "elementType": "$inputScalar" }, - "new_v": { "arg": "valueT", "elementType": "$inputScalar" }, - "params_present": { - "name": "params", - "struct": [ - { - "name": "count", - "type": "u32", - "value": "dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)" - }, - { "name": "seq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" }, - { "name": "pastSeq", "type": "u32", "value": "dim(shapes.pastKeyT, 2)" }, - { "name": "keySeq", "type": "u32", "value": "dim(shapes.keyT, 1)" } - ] - }, - "seqlens_k": { "arg": "seqlensKT", "elementType": "i32" }, - "params__uniform": { - "name": "params", - "struct": [ - { - "name": "count", - "type": "u32", - "value": "dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)" - }, - { "name": "seq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" }, - { "name": "keySeq", "type": "u32", "value": "dim(shapes.keyT, 1)" } - ] - }, - "params_gqa_present": { - "name": "params", - "struct": [ - { "name": "count", "type": "u32", "value": "dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)" }, - { "name": "seq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" }, - { "name": "keySeq", "type": "u32", "value": "dim(shapes.keyT, 1)" } - ] - }, - "kcache": { "arg": "presentKeyT", "buffer": "read-only-storage", "elementType": "$inputScalar" }, - "vcache": { "arg": "presentValueT", "buffer": "read-only-storage", "elementType": "$inputScalar" }, - "output_past_kv": { "arg": "outputT", "name": "output", "elementType": "$inputScalar" }, - "params_attention": { - "name": "params", - "struct": [ - { "name": "batch", "type": "u32", "value": "dim(shapes.queryT, 0)" }, - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "totalSeq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" }, - { - "name": "windowSize", - "type": "u32", - "value": "attrs.local_window_size if attrs.local_window_size > 0 else 0" - }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { "name": "softcap", "type": "f32", "value": "attrs.softcap" }, - { "name": "smoothSoftmax", "type": "u32", "value": "1 if attrs.smooth_softmax == 1 else 0" } - ] - }, - "head_sink": { "arg": "headSinkT", "elementType": "$inputScalar" }, - "cos_cache_f32": { "arg": "cosCacheT", "name": "cos_cache", "elementType": "f32" }, - "sin_cache_f32": { "arg": "sinCacheT", "name": "sin_cache", "elementType": "f32" }, - "query_query_t": { "arg": "queryT", "name": "query", "elementType": "$inputElement" }, - "output_output_t": { "arg": "outputT", "name": "output", "elementType": "$outputElement" }, - "params_qkv_present": { - "name": "params", - "struct": [ - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.keyT, 1)" }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { - "name": "windowSize", - "type": "u32", - "value": "attrs.local_window_size if attrs.local_window_size > 0 else 0" - } - ] - }, - "params_qkv_present_causal": { - "name": "params", - "struct": [ - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.keyT, 1)" }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { "name": "isCausal", "type": "u32", "value": "attrs.causal" } - ] - }, - "src_k_f32": { "arg": "keyT", "name": "src_k", "elementType": "f32" }, - "src_v_f32": { "arg": "valueT", "name": "src_v", "elementType": "f32" }, - "k_scale": { "arg": "kScaleT", "elementType": "f32" }, - "v_scale": { "arg": "vScaleT", "elementType": "f32" }, - "present_key_quant_int8": { "arg": "presentKeyT", "name": "present_key", "elementType": "$quantCacheElement" }, - "present_value_quant_int8": { "arg": "presentValueT", "name": "present_value", "elementType": "$quantCacheElement" }, - "params_quant_int8": { - "name": "params", - "struct": [ - { "name": "count", "type": "u32", "value": "dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)" }, - { "name": "seq", "type": "u32", "value": "dim(shapes.keyT, 1)" }, - { "name": "perChannel", "type": "u32", "value": "1 if dim(shapes.kScaleT, 0) > 1 else 0" } - ] - }, - "partial_out": { "scratch": "partialOut", "elementType": "vec4" }, - "partial_stats": { "scratch": "partialStats", "elementType": "vec2" }, - "partial_out_merge": { - "scratch": "partialOut", - "name": "partial_out", - "buffer": "read-only-storage", - "elementType": "vec4" - }, - "partial_stats_merge": { - "scratch": "partialStats", - "name": "partial_stats", - "buffer": "read-only-storage", - "elementType": "vec2" - }, - "output_merge": { "arg": "outputT", "name": "output", "elementType": "$inputVec4" }, - "query_attention": { "arg": "queryT", "name": "query", "elementType": "$inputVec4" }, - "key_attention": { "arg": "presentKeyT", "name": "key", "buffer": "read-only-storage", "elementType": "$inputVec4" }, - "value_attention": { - "arg": "presentValueT", - "name": "value", - "buffer": "read-only-storage", - "elementType": "$inputVec4" - }, - "attn_mask": { "arg": "attentionBiasT", "elementType": "$inputScalar" }, - "params_attn_flash_prefill_cluster": { - "name": "params", - "struct": [ - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.pastKeyT, 2)" }, - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "isCausal", "type": "u32", "value": 1 }, - { - "name": "windowSize", - "type": "u32", - "value": "attrs.local_window_size if attrs.local_window_size > 0 else 0" - }, - { - "name": "maskBatchStride", - "type": "u32", - "value": "0 if dim(shapes.attentionBiasT, 0) == 1 else dim(shapes.attentionBiasT, 1) * dim(shapes.attentionBiasT, 2) * dim(shapes.attentionBiasT, 3)" - }, - { - "name": "maskHeadStride", - "type": "u32", - "value": "0 if dim(shapes.attentionBiasT, 1) == 1 else dim(shapes.attentionBiasT, 2) * dim(shapes.attentionBiasT, 3)" - }, - { "name": "maskSeqStride", "type": "u32", "value": "dim(shapes.attentionBiasT, 3)" } - ] - }, - "q_norm_weight": { "arg": "qNormWeightT", "elementType": "$qNormScalar" }, - "params_past_kv_flash_prefill": { - "name": "params", - "struct": [ - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.pastKeyT, 2)" }, - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "isCausal", "type": "u32", "value": 1 }, - { - "name": "windowSize", - "type": "u32", - "value": "attrs.local_window_size if attrs.local_window_size > 0 else 0" - } - ] - }, - "params_split_attention": { - "name": "params", - "struct": [ - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { - "name": "windowSize", - "type": "u32", - "value": "attrs.local_window_size if attrs.local_window_size > 0 else 0" - } - ] - }, - "params_new_kv_past_flash_prefill": { - "name": "params", - "struct": [ - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" }, - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "isCausal", "type": "u32", "value": 1 }, - { - "name": "windowSize", - "type": "u32", - "value": "attrs.local_window_size if attrs.local_window_size > 0 else 0" - } - ] - }, - "params_new_kv_past_flash_bidirectional": { - "name": "params", - "struct": [ - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" }, - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" } - ] - }, - "params_past_kv_softcap_flash_prefill": { - "name": "params", - "struct": [ - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.pastKeyT, 2)" }, - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "isCausal", "type": "u32", "value": 1 }, - { - "name": "windowSize", - "type": "u32", - "value": "attrs.local_window_size if attrs.local_window_size > 0 else 0" - }, - { "name": "softcap", "type": "f32", "value": "attrs.softcap" } - ] - }, - "kcache_past_kv": { "arg": "pastKeyT", "name": "kcache", "elementType": "$inputScalar" }, - "vcache_past_kv": { "arg": "pastValueT", "name": "vcache", "elementType": "$inputScalar" }, - "params_past_kv": { - "name": "params", - "struct": [ - { "name": "batch", "type": "u32", "value": "dim(shapes.queryT, 0)" }, - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "totalSeq", "type": "u32", "value": "dim(shapes.pastKeyT, 2)" }, - { - "name": "windowSize", - "type": "u32", - "value": "attrs.local_window_size if attrs.local_window_size > 0 else 0" - }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { "name": "softcap", "type": "f32", "value": "attrs.softcap" }, - { "name": "smoothSoftmax", "type": "u32", "value": "1 if attrs.smooth_softmax == 1 else 0" } - ] - }, - "k_norm_weight": { "arg": "kNormWeightT", "elementType": "f32" }, - "present_key_f32": { "arg": "presentKeyT", "name": "present_key", "elementType": "f32" }, - "present_value_f32": { "arg": "presentValueT", "name": "present_value", "elementType": "f32" }, - "params_count_seq_past_seq": { - "name": "params", - "struct": [ - { "name": "count", "type": "u32", "value": "dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)" }, - { "name": "seq", "type": "u32", "value": "dim(shapes.keyT, 1)" }, - { "name": "pastSeq", "type": "u32", "value": 0 } - ] - }, - "kcache_f32": { "arg": "presentKeyT", "name": "kcache", "buffer": "read-only-storage", "elementType": "f32" }, - "vcache_f32": { "arg": "presentValueT", "name": "vcache", "buffer": "read-only-storage", "elementType": "f32" }, - "q_norm_weight_f32": { "arg": "qNormWeightT", "name": "q_norm_weight", "elementType": "f32" }, - "kcache_f32_read": { "arg": "pastKeyT", "name": "kcache", "elementType": "f32" }, - "vcache_f32_read": { "arg": "pastValueT", "name": "vcache", "elementType": "f32" }, - "attn_bias": { "arg": "attentionBiasT", "elementType": "$inputScalar" }, - "params_past_kv_bias": { - "name": "params", - "struct": [ - { "name": "batch", "type": "u32", "value": "dim(shapes.queryT, 0)" }, - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "totalSeq", "type": "u32", "value": "dim(shapes.pastKeyT, 2)" }, - { - "name": "windowSize", - "type": "u32", - "value": "attrs.local_window_size if attrs.local_window_size > 0 else 0" - }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { "name": "softcap", "type": "f32", "value": "attrs.softcap" }, - { "name": "smoothSoftmax", "type": "u32", "value": "1 if attrs.smooth_softmax == 1 else 0" }, - { "name": "biasBatch", "type": "u32", "value": "dim(shapes.attentionBiasT, 0)" }, - { "name": "biasHeads", "type": "u32", "value": "dim(shapes.attentionBiasT, 1)" } - ] - }, - "params_window_bias": { - "name": "params", - "struct": [ - { "name": "batch", "type": "u32", "value": "dim(shapes.queryT, 0)" }, - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "totalSeq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" }, - { - "name": "windowSize", - "type": "u32", - "value": "attrs.local_window_size if attrs.local_window_size > 0 else 0" - }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { "name": "softcap", "type": "f32", "value": "attrs.softcap" }, - { "name": "smoothSoftmax", "type": "u32", "value": "1 if attrs.smooth_softmax == 1 else 0" }, - { "name": "biasBatch", "type": "u32", "value": "dim(shapes.attentionBiasT, 0)" }, - { "name": "biasHeads", "type": "u32", "value": "dim(shapes.attentionBiasT, 1)" }, - { "name": "biasCols", "type": "u32", "value": "dim(shapes.attentionBiasT, 3)" } - ] - }, - "params_gqa_attention": { - "name": "params", - "struct": [ - { "name": "batch", "type": "u32", "value": "dim(shapes.queryT, 0)" }, - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "totalSeq", "type": "u32", "value": "dim(shapes.pastKeyT, 2)" }, - { - "name": "windowSize", - "type": "u32", - "value": "attrs.local_window_size if attrs.local_window_size > 0 else 0" - }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { "name": "softcap", "type": "f32", "value": "attrs.softcap" } - ] - }, - "params_past_kv_bias_headsink": { - "name": "params", - "struct": [ - { "name": "batch", "type": "u32", "value": "dim(shapes.queryT, 0)" }, - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "totalSeq", "type": "u32", "value": "dim(shapes.pastKeyT, 2)" }, - { - "name": "windowSize", - "type": "u32", - "value": "attrs.local_window_size if attrs.local_window_size > 0 else 0" - }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { "name": "softcap", "type": "f32", "value": "attrs.softcap" }, - { "name": "biasBatch", "type": "u32", "value": "dim(shapes.attentionBiasT, 0)" }, - { "name": "biasHeads", "type": "u32", "value": "dim(shapes.attentionBiasT, 1)" } - ] - }, - "key_present_key_t": { - "arg": "presentKeyT", - "name": "key", - "buffer": "read-only-storage", - "elementType": "$quantCacheReadElement" - }, - "value_present_value_t": { - "arg": "presentValueT", - "name": "value", - "buffer": "read-only-storage", - "elementType": "$quantCacheReadElement" - }, - "params_quant_int8_flash_prefill": { - "name": "params", - "struct": [ - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" }, - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "isCausal", "type": "u32", "value": 1 }, - { - "name": "windowSize", - "type": "u32", - "value": "attrs.local_window_size if attrs.local_window_size > 0 else 0" - }, - { "name": "perChannel", "type": "u32", "value": "1 if dim(shapes.kScaleT, 0) > 1 else 0" } - ] - } - }, - "variants": [ - { - "id": "qkv_present_materialized_sgmat_f32", - "priority": 23, - "when": ["gqaMatCoreOk"], - "requires": { - "features": ["subgroups", "chromium-experimental-subgroup-matrix"], - "subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }] - }, - "derive": { - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "dim(shapes.queryT, 2) / attrs.num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "kvHidden": "dim(shapes.keyT, 2)", - "statSlots": "gqaMatStatSlots", - "presentScalar": "qkvCacheScalar", - "presentElement": "qkvCacheVec4", - "presentVec4": true, - "inputElement": "qkvInputVec4", - "headDimV4": "(dim(shapes.queryT, 2) / attrs.num_heads) / 4", - "kvHiddenV4": "dim(shapes.keyT, 2) / 4" - }, - "intermediates": [ - { - "id": "materializedScores", - "dtype": "float32", - "shape": "[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.keyT, 1)]" - }, - { "id": "materializedRowStats", "dtype": "float32", "shape": "[gqaMatRowStatsElements]" }, - { "id": "materializedScorePartials", "dtype": "float32", "shape": "[gqaMatScorePartialElements]" } - ], - "passes": [ - { - "id": "scores", - "name": "GroupQueryAttention.MaterializedScoresSgmat", - "shader": "attn-materialized-sgmat-f32.wgsl.jinja", - "derive": { "phase": "\"score\"", "emitRowStats": true, "layout": "\"bsh\"" }, - "bindings": [ - "query", - "key", - "scores", - "scorePartials", - { - "name": "params", - "struct": [ - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.keyT, 1)" }, - { "name": "scale", "type": "f32", "value": "attrs.scale if has(attrs, \"scale\") else 0" } - ] - } - ], - "dispatch": { - "x": "ceilDiv(dim(shapes.keyT, 1), gqaMatKeyTile)", - "y": "ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)", - "z": "dim(shapes.queryT, 0) * attrs.num_heads" - } - }, - { - "id": "rowstats", - "name": "GroupQueryAttention.MaterializedRowStatsCombine", - "shader": "attn-materialized-rowstats-combine-f32.wgsl.jinja", - "bindings": [ - "scorePartials_f32", - "rowStats", - { - "name": "params", - "struct": [ - { - "name": "rows", - "type": "u32", - "value": "dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)" - } - ] - } - ], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (gqaMatRowStatsWg)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))", - "y": 1, - "z": 1 - } - }, - { - "id": "apply", - "name": "GroupQueryAttention.MaterializedApplySgmat", - "shader": "attn-materialized-sgmat-f32.wgsl.jinja", - "derive": { "phase": "\"apply\"", "fusedSoftmax": true, "layout": "\"bsh\"" }, - "bindings": [ - "scores_f32", - "value", - "rowStats_f32", - "output", - { - "name": "params", - "struct": [ - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.keyT, 1)" } - ] - } - ], - "dispatch": { - "x": "ceilDiv(headDim, gqaMatKeyTile)", - "y": "ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)", - "z": "dim(shapes.queryT, 0) * attrs.num_heads" - } - }, - { - "id": "present", - "name": "GroupQueryAttention.MaterializedPresent", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["key_key_t", "value_value_t", "present_key", "present_value", "params"], - "dispatch": { - "x": "min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)", - "z": 1 - } - } - ] - }, - { - "id": "past_kv_materialized_sgmat_f32", - "priority": 35, - "when": ["gqaMatPastCoreOk"], - "requires": { - "features": ["subgroups", "chromium-experimental-subgroup-matrix"], - "subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }] - }, - "derive": { - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "gqaHeadDim", - "qHidden": "dim(shapes.queryT, 2)", - "statSlots": "gqaMatPastStatSlots", - "mode": "\"copy\"", - "packed": "gqaHeadDim", - "kvHeads": "attrs.kv_num_heads", - "inputScalar": "gqaScalar" - }, - "intermediates": [ - { - "id": "materializedScores", - "dtype": "float32", - "shape": "[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.presentKeyT, 2)]" - }, - { "id": "materializedRowStats", "dtype": "float32", "shape": "[gqaMatPastRowStatsElements]" }, - { "id": "materializedScorePartials", "dtype": "float32", "shape": "[gqaMatPastScorePartialElements]" } - ], - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - }, - { - "id": "scores", - "name": "GroupQueryAttention.PastMaterializedScores", - "shader": "attn-materialized-sgmat-f32.wgsl.jinja", - "derive": { - "phase": "\"score\"", - "emitRowStats": true, - "layout": "\"bsh\"", - "kvLayout": "\"bhsd\"", - "causalRightAlign": true - }, - "bindings": ["query", "key_f32", "scores", "scorePartials", "params_scores"], - "dispatch": { - "x": "ceilDiv(dim(shapes.presentKeyT, 2), gqaMatKeyTile)", - "y": "ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)", - "z": "dim(shapes.queryT, 0) * attrs.num_heads" - } - }, - { - "id": "rowstats", - "name": "GroupQueryAttention.PastMaterializedRowStats", - "shader": "attn-materialized-rowstats-combine-f32.wgsl.jinja", - "bindings": ["scorePartials_f32", "rowStats", "params_rows"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (gqaMatRowStatsWg)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))", - "y": 1, - "z": 1 - } - }, - { - "id": "apply", - "name": "GroupQueryAttention.PastMaterializedApply", - "shader": "attn-materialized-sgmat-f32.wgsl.jinja", - "derive": { - "phase": "\"apply\"", - "fusedSoftmax": true, - "layout": "\"bsh\"", - "kvLayout": "\"bhsd\"", - "causalRightAlign": true - }, - "bindings": ["scores_f32", "value_f32", "rowStats_f32", "output", "params_apply"], - "dispatch": { - "x": "ceilDiv(gqaHeadDim, gqaMatKeyTile)", - "y": "ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)", - "z": "dim(shapes.queryT, 0) * attrs.num_heads" - } - } - ] - }, - { - "id": "past_kv_bias_materialized_sgmat_f32", - "priority": 36, - "when": ["gqaMatPastBiasOk"], - "requires": { - "features": ["subgroups", "chromium-experimental-subgroup-matrix"], - "subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }] - }, - "derive": { - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "gqaHeadDim", - "qHidden": "dim(shapes.queryT, 2)", - "statSlots": "gqaMatPastStatSlots", - "mode": "\"copy\"", - "packed": "gqaHeadDim", - "kvHeads": "attrs.kv_num_heads", - "inputScalar": "gqaScalar" - }, - "intermediates": [ - { - "id": "materializedScores", - "dtype": "float32", - "shape": "[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.presentKeyT, 2)]" - }, - { "id": "materializedRowStats", "dtype": "float32", "shape": "[gqaMatPastRowStatsElements]" }, - { "id": "materializedScorePartials", "dtype": "float32", "shape": "[gqaMatPastScorePartialElements]" } - ], - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - }, - { - "id": "scores", - "name": "GroupQueryAttention.PastMaterializedScores", - "shader": "attn-materialized-sgmat-f32.wgsl.jinja", - "derive": { - "phase": "\"score\"", - "emitRowStats": true, - "layout": "\"bsh\"", - "kvLayout": "\"bhsd\"", - "causalRightAlign": true, - "scoreBias": true - }, - "bindings": [ - "query", - "key_f32", - { "arg": "attentionBiasT", "name": "attention_bias", "elementType": "f32" }, - "scores", - "scorePartials", - { - "name": "params", - "struct": [ - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { "name": "biasBatch", "type": "u32", "value": "dim(shapes.attentionBiasT, 0)" }, - { "name": "biasHeads", "type": "u32", "value": "dim(shapes.attentionBiasT, 1)" } - ] - } - ], - "dispatch": { - "x": "ceilDiv(dim(shapes.presentKeyT, 2), gqaMatKeyTile)", - "y": "ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)", - "z": "dim(shapes.queryT, 0) * attrs.num_heads" - } - }, - { - "id": "rowstats", - "name": "GroupQueryAttention.PastMaterializedRowStats", - "shader": "attn-materialized-rowstats-combine-f32.wgsl.jinja", - "bindings": ["scorePartials_f32", "rowStats", "params_rows"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (gqaMatRowStatsWg)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))", - "y": 1, - "z": 1 - } - }, - { - "id": "apply", - "name": "GroupQueryAttention.PastMaterializedApply", - "shader": "attn-materialized-sgmat-f32.wgsl.jinja", - "derive": { - "phase": "\"apply\"", - "fusedSoftmax": true, - "layout": "\"bsh\"", - "kvLayout": "\"bhsd\"", - "causalRightAlign": true - }, - "bindings": ["scores_f32", "value_f32", "rowStats_f32", "output", "params_apply"], - "dispatch": { - "x": "ceilDiv(gqaHeadDim, gqaMatKeyTile)", - "y": "ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)", - "z": "dim(shapes.queryT, 0) * attrs.num_heads" - } - } - ] - }, - { - "id": "past_kv_materialized_sgmat_f16", - "priority": 35, - "when": ["gqaMatPastCoreF16Ok"], - "requires": { - "features": ["subgroups", "chromium-experimental-subgroup-matrix"], - "subgroupMatrixConfigs": [{ "componentType": "f16", "M": 8, "N": 8, "K": 8 }] - }, - "derive": { - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "gqaHeadDim", - "qHidden": "dim(shapes.queryT, 2)", - "statSlots": "gqaMatPastStatSlots", - "mode": "\"copy\"", - "packed": "gqaHeadDim", - "kvHeads": "attrs.kv_num_heads", - "inputScalar": "gqaScalar", - "operandF16": true - }, - "intermediates": [ - { - "id": "materializedScores", - "dtype": "float32", - "shape": "[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.presentKeyT, 2)]" - }, - { "id": "materializedRowStats", "dtype": "float32", "shape": "[gqaMatPastRowStatsElements]" }, - { "id": "materializedScorePartials", "dtype": "float32", "shape": "[gqaMatPastScorePartialElements]" } - ], - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - }, - { - "id": "scores", - "name": "GroupQueryAttention.PastMaterializedScores", - "shader": "attn-materialized-sgmat-f32.wgsl.jinja", - "derive": { - "phase": "\"score\"", - "emitRowStats": true, - "layout": "\"bsh\"", - "kvLayout": "\"bhsd\"", - "causalRightAlign": true - }, - "bindings": [ - { "arg": "queryT", "name": "query", "elementType": "f16" }, - "key_f16", - "scores", - "scorePartials", - "params_scores" - ], - "dispatch": { - "x": "ceilDiv(dim(shapes.presentKeyT, 2), gqaMatKeyTile)", - "y": "ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)", - "z": "dim(shapes.queryT, 0) * attrs.num_heads" - } - }, - { - "id": "rowstats", - "name": "GroupQueryAttention.PastMaterializedRowStats", - "shader": "attn-materialized-rowstats-combine-f32.wgsl.jinja", - "bindings": ["scorePartials_f32", "rowStats", "params_rows"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (gqaMatRowStatsWg)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))", - "y": 1, - "z": 1 - } - }, - { - "id": "apply", - "name": "GroupQueryAttention.PastMaterializedApply", - "shader": "attn-materialized-sgmat-f32.wgsl.jinja", - "derive": { - "phase": "\"apply\"", - "fusedSoftmax": true, - "layout": "\"bsh\"", - "kvLayout": "\"bhsd\"", - "causalRightAlign": true - }, - "bindings": ["scores_f32", "value_f16", "rowStats_f32", "output_f16", "params_apply"], - "dispatch": { - "x": "ceilDiv(gqaHeadDim, gqaMatKeyTile)", - "y": "ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)", - "z": "dim(shapes.queryT, 0) * attrs.num_heads" - } - } - ] - }, - { - "id": "past_kv_rotary_materialized_sgmat_f32", - "priority": 37, - "when": ["gqaMatPastRotaryOk"], - "requires": { - "features": ["subgroups", "chromium-experimental-subgroup-matrix"], - "subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }] - }, - "derive": { - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "gqaHeadDim", - "qHidden": "dim(shapes.queryT, 2)", - "statSlots": "gqaMatPastStatSlots", - "mode": "\"copy\"", - "packed": "gqaHeadDim", - "kvHeads": "attrs.kv_num_heads", - "inputScalar": "gqaScalar", - "half": "gqaHeadDim / 2", - "qHeads": "attrs.num_heads", - "cosScalar": "\"f16\" if tensorDtypes.cosCacheT == \"float16\" else \"f32\"", - "hasQNorm": false - }, - "intermediates": [ - { - "id": "qPrep", - "dtype": "float32", - "shape": "[dim(shapes.queryT, 0), dim(shapes.queryT, 1), dim(shapes.queryT, 2)]" - }, - { - "id": "materializedScores", - "dtype": "float32", - "shape": "[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.presentKeyT, 2)]" - }, - { "id": "materializedRowStats", "dtype": "float32", "shape": "[gqaMatPastRowStatsElements]" }, - { "id": "materializedScorePartials", "dtype": "float32", "shape": "[gqaMatPastScorePartialElements]" } - ], - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - }, - { - "id": "qprep", - "name": "GroupQueryAttention.RotaryQPrep", - "shader": "gqa-qprep.wgsl.jinja", - "bindings": ["query_qprep", "cos_cache", "sin_cache", "qout", "params_qprep"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "scores", - "name": "GroupQueryAttention.PastRotaryMaterializedScores", - "shader": "attn-materialized-sgmat-f32.wgsl.jinja", - "derive": { - "phase": "\"score\"", - "emitRowStats": true, - "layout": "\"bsh\"", - "kvLayout": "\"bhsd\"", - "causalRightAlign": true - }, - "bindings": [ - { "scratch": "qPrep", "name": "query", "buffer": "read-only-storage", "elementType": "f32" }, - "key_f32", - "scores", - "scorePartials", - "params_scores" - ], - "dispatch": { - "x": "ceilDiv(dim(shapes.presentKeyT, 2), gqaMatKeyTile)", - "y": "ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)", - "z": "dim(shapes.queryT, 0) * attrs.num_heads" - } - }, - { - "id": "rowstats", - "name": "GroupQueryAttention.PastRotaryMaterializedRowStats", - "shader": "attn-materialized-rowstats-combine-f32.wgsl.jinja", - "bindings": ["scorePartials_f32", "rowStats", "params_rows"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (gqaMatRowStatsWg)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))", - "y": 1, - "z": 1 - } - }, - { - "id": "apply", - "name": "GroupQueryAttention.PastRotaryMaterializedApply", - "shader": "attn-materialized-sgmat-f32.wgsl.jinja", - "derive": { - "phase": "\"apply\"", - "fusedSoftmax": true, - "layout": "\"bsh\"", - "kvLayout": "\"bhsd\"", - "causalRightAlign": true - }, - "bindings": ["scores_f32", "value_f32", "rowStats_f32", "output", "params_apply"], - "dispatch": { - "x": "ceilDiv(gqaHeadDim, gqaMatKeyTile)", - "y": "ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)", - "z": "dim(shapes.queryT, 0) * attrs.num_heads" - } - } - ] - }, - { - "id": "past_kv_rotary_materialized_sgmat_f16", - "priority": 37, - "when": ["gqaMatPastRotaryF16Ok"], - "requires": { - "features": ["subgroups", "chromium-experimental-subgroup-matrix"], - "subgroupMatrixConfigs": [{ "componentType": "f16", "M": 8, "N": 8, "K": 8 }] - }, - "derive": { - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "gqaHeadDim", - "qHidden": "dim(shapes.queryT, 2)", - "statSlots": "gqaMatPastStatSlots", - "mode": "\"copy\"", - "packed": "gqaHeadDim", - "kvHeads": "attrs.kv_num_heads", - "inputScalar": "gqaScalar", - "half": "gqaHeadDim / 2", - "qHeads": "attrs.num_heads", - "cosScalar": "\"f16\" if tensorDtypes.cosCacheT == \"float16\" else \"f32\"", - "hasQNorm": false, - "operandF16": true - }, - "intermediates": [ - { - "id": "qPrep", - "dtype": "float16", - "shape": "[dim(shapes.queryT, 0), dim(shapes.queryT, 1), dim(shapes.queryT, 2)]" - }, - { - "id": "materializedScores", - "dtype": "float32", - "shape": "[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.presentKeyT, 2)]" - }, - { "id": "materializedRowStats", "dtype": "float32", "shape": "[gqaMatPastRowStatsElements]" }, - { "id": "materializedScorePartials", "dtype": "float32", "shape": "[gqaMatPastScorePartialElements]" } - ], - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - }, - { - "id": "qprep", - "name": "GroupQueryAttention.RotaryQPrep", - "shader": "gqa-qprep.wgsl.jinja", - "bindings": [ - "query_qprep", - "cos_cache", - "sin_cache", - { "scratch": "qPrep", "name": "qout", "elementType": "vec4" }, - "params_qprep" - ], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "derive": { "qPrepF16": true } - }, - { - "id": "scores", - "name": "GroupQueryAttention.PastRotaryMaterializedScores", - "shader": "attn-materialized-sgmat-f32.wgsl.jinja", - "derive": { - "phase": "\"score\"", - "emitRowStats": true, - "layout": "\"bsh\"", - "kvLayout": "\"bhsd\"", - "causalRightAlign": true - }, - "bindings": [ - { "scratch": "qPrep", "name": "query", "buffer": "read-only-storage", "elementType": "f16" }, - "key_f16", - "scores", - "scorePartials", - "params_scores" - ], - "dispatch": { - "x": "ceilDiv(dim(shapes.presentKeyT, 2), gqaMatKeyTile)", - "y": "ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)", - "z": "dim(shapes.queryT, 0) * attrs.num_heads" - } - }, - { - "id": "rowstats", - "name": "GroupQueryAttention.PastRotaryMaterializedRowStats", - "shader": "attn-materialized-rowstats-combine-f32.wgsl.jinja", - "bindings": ["scorePartials_f32", "rowStats", "params_rows"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (gqaMatRowStatsWg)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))", - "y": 1, - "z": 1 - } - }, - { - "id": "apply", - "name": "GroupQueryAttention.PastRotaryMaterializedApply", - "shader": "attn-materialized-sgmat-f32.wgsl.jinja", - "derive": { - "phase": "\"apply\"", - "fusedSoftmax": true, - "layout": "\"bsh\"", - "kvLayout": "\"bhsd\"", - "causalRightAlign": true - }, - "bindings": ["scores_f32", "value_f16", "rowStats_f32", "output_f16", "params_apply"], - "dispatch": { - "x": "ceilDiv(gqaHeadDim, gqaMatKeyTile)", - "y": "ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)", - "z": "dim(shapes.queryT, 0) * attrs.num_heads" - } - } - ] - }, - { - "id": "new_kv_past_materialized_sgmat_f32", - "priority": 35, - "when": ["gqaMatNewPastOk"], - "requires": { - "features": ["subgroups", "chromium-experimental-subgroup-matrix"], - "subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }] - }, - "derive": { - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "gqaHeadDim", - "qHidden": "dim(shapes.queryT, 2)", - "statSlots": "gqaMatPastStatSlots", - "mode": "\"merge\"", - "packed": "gqaHeadDim", - "kvHeads": "attrs.kv_num_heads", - "inputScalar": "gqaScalar" - }, - "intermediates": [ - { - "id": "materializedScores", - "dtype": "float32", - "shape": "[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.presentKeyT, 2)]" - }, - { "id": "materializedRowStats", "dtype": "float32", "shape": "[gqaMatPastRowStatsElements]" }, - { "id": "materializedScorePartials", "dtype": "float32", "shape": "[gqaMatPastScorePartialElements]" } - ], - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Merge", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["past_k", "past_v", "new_k", "new_v", "present_key_present", "present_value_present", "params_present"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "scores", - "name": "GroupQueryAttention.NewPastMaterializedScores", - "shader": "attn-materialized-sgmat-f32.wgsl.jinja", - "derive": { - "phase": "\"score\"", - "emitRowStats": true, - "layout": "\"bsh\"", - "kvLayout": "\"bhsd\"", - "causalRightAlign": true - }, - "bindings": ["query", "key_f32", "scores", "scorePartials", "params_scores"], - "dispatch": { - "x": "ceilDiv(dim(shapes.presentKeyT, 2), gqaMatKeyTile)", - "y": "ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)", - "z": "dim(shapes.queryT, 0) * attrs.num_heads" - } - }, - { - "id": "rowstats", - "name": "GroupQueryAttention.NewPastMaterializedRowStats", - "shader": "attn-materialized-rowstats-combine-f32.wgsl.jinja", - "bindings": ["scorePartials_f32", "rowStats", "params_rows"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (gqaMatRowStatsWg)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))", - "y": 1, - "z": 1 - } - }, - { - "id": "apply", - "name": "GroupQueryAttention.NewPastMaterializedApply", - "shader": "attn-materialized-sgmat-f32.wgsl.jinja", - "derive": { - "phase": "\"apply\"", - "fusedSoftmax": true, - "layout": "\"bsh\"", - "kvLayout": "\"bhsd\"", - "causalRightAlign": true - }, - "bindings": ["scores_f32", "value_f32", "rowStats_f32", "output", "params_apply"], - "dispatch": { - "x": "ceilDiv(gqaHeadDim, gqaMatKeyTile)", - "y": "ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)", - "z": "dim(shapes.queryT, 0) * attrs.num_heads" - } - } - ] - }, - { - "id": "window_shift_materialized_sgmat_f32", - "priority": 36, - "when": ["gqaMatWindowOk"], - "requires": { - "features": ["subgroups", "chromium-experimental-subgroup-matrix"], - "subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }] - }, - "derive": { - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "gqaHeadDim", - "qHidden": "dim(shapes.queryT, 2)", - "statSlots": "gqaMatPastStatSlots", - "mode": "\"window_shift\"", - "packed": "gqaHeadDim", - "kvHeads": "attrs.kv_num_heads", - "inputScalar": "gqaScalar", - "zeroScalar": "gqaScalar" - }, - "intermediates": [ - { - "id": "materializedScores", - "dtype": "float32", - "shape": "[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.presentKeyT, 2)]" - }, - { "id": "materializedRowStats", "dtype": "float32", "shape": "[gqaMatPastRowStatsElements]" }, - { "id": "materializedScorePartials", "dtype": "float32", "shape": "[gqaMatPastScorePartialElements]" } - ], - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.WindowShift", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["past_k", "past_v", "new_k", "new_v", "present_key_present", "present_value_present", "seqlens_k", "params__uniform"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "scores", - "name": "GroupQueryAttention.WindowMaterializedScores", - "shader": "attn-materialized-sgmat-f32.wgsl.jinja", - "derive": { - "phase": "\"score\"", - "emitRowStats": true, - "layout": "\"bsh\"", - "kvLayout": "\"bhsd\"", - "causalRightAlign": true, - "scoreWindow": true, - "useSeqlens": true - }, - "bindings": [ - "query", - "key_f32", - "scores", - "scorePartials", - "seqlens_k", - { - "name": "params", - "struct": [ - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" }, - { "name": "windowSize", "type": "u32", "value": "attrs.local_window_size" }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" } - ] - } - ], - "dispatch": { - "x": "ceilDiv(dim(shapes.presentKeyT, 2), gqaMatKeyTile)", - "y": "ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)", - "z": "dim(shapes.queryT, 0) * attrs.num_heads" - } - }, - { - "id": "rowstats", - "name": "GroupQueryAttention.WindowMaterializedRowStats", - "shader": "attn-materialized-rowstats-combine-f32.wgsl.jinja", - "bindings": ["scorePartials_f32", "rowStats", "params_rows"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (gqaMatRowStatsWg)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))", - "y": 1, - "z": 1 - } - }, - { - "id": "apply", - "name": "GroupQueryAttention.WindowMaterializedApply", - "shader": "attn-materialized-sgmat-f32.wgsl.jinja", - "derive": { - "phase": "\"apply\"", - "fusedSoftmax": true, - "layout": "\"bsh\"", - "kvLayout": "\"bhsd\"", - "causalRightAlign": true, - "scoreWindow": true, - "useSeqlens": true - }, - "bindings": [ - "scores_f32", - "value_f32", - "rowStats_f32", - "output", - "seqlens_k", - { - "name": "params", - "struct": [ - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" }, - { "name": "windowSize", "type": "u32", "value": "attrs.local_window_size" } - ] - } - ], - "dispatch": { - "x": "ceilDiv(gqaHeadDim, gqaMatKeyTile)", - "y": "ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)", - "z": "dim(shapes.queryT, 0) * attrs.num_heads" - } - } - ] - }, - { - "id": "share_append_materialized_sgmat_f32", - "priority": 36, - "when": ["gqaMatShareAppendOk"], - "requires": { - "features": ["subgroups", "chromium-experimental-subgroup-matrix"], - "subgroupMatrixConfigs": [{ "componentType": "f32", "resultComponentType": "f32", "M": 8, "N": 8, "K": 8 }] - }, - "derive": { - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "gqaHeadDim", - "qHidden": "dim(shapes.queryT, 2)", - "statSlots": "gqaMatPastStatSlots", - "mode": "\"merge_share\"", - "packed": "gqaHeadDim", - "kvHeads": "attrs.kv_num_heads", - "inputScalar": "gqaScalar", - "useSeqlens": true - }, - "intermediates": [ - { - "id": "materializedScores", - "dtype": "float32", - "shape": "[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.presentKeyT, 2)]" - }, - { "id": "materializedRowStats", "dtype": "float32", "shape": "[gqaMatPastRowStatsElements]" }, - { "id": "materializedScorePartials", "dtype": "float32", "shape": "[gqaMatPastScorePartialElements]" } - ], - "passes": [ - { - "id": "present_retain", - "name": "GroupQueryAttention.MergeShareRetain", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shareRegion": "\"retain\"" }, - "bindings": ["past_k", "past_v", "present_key_present", "present_value_present", "seqlens_k", "params__uniform"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [ - { "input": "past_k", "output": "present_key" }, - { "input": "past_v", "output": "present_value" } - ] - }, - { - "id": "present_append", - "name": "GroupQueryAttention.MergeShareAppend", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shareRegion": "\"append\"" }, - "bindings": ["new_k", "new_v", "present_key_present", "present_value_present", "seqlens_k", "params_gqa_present"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "scores", - "name": "GroupQueryAttention.ShareAppendMaterializedScores", - "shader": "attn-materialized-sgmat-f32.wgsl.jinja", - "derive": { - "phase": "\"score\"", - "emitRowStats": true, - "layout": "\"bsh\"", - "kvLayout": "\"bhsd\"", - "causalRightAlign": true, - "useSeqlens": true - }, - "bindings": ["query", "key_f32", "scores", "scorePartials", "seqlens_k", "params_scores"], - "dispatch": { - "x": "ceilDiv(dim(shapes.presentKeyT, 2), gqaMatKeyTile)", - "y": "ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)", - "z": "dim(shapes.queryT, 0) * attrs.num_heads" - } - }, - { - "id": "rowstats", - "name": "GroupQueryAttention.ShareAppendMaterializedRowStats", - "shader": "attn-materialized-rowstats-combine-f32.wgsl.jinja", - "bindings": ["scorePartials_f32", "rowStats", "params_rows"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (gqaMatRowStatsWg)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))", - "y": 1, - "z": 1 - } - }, - { - "id": "apply", - "name": "GroupQueryAttention.ShareAppendMaterializedApply", - "shader": "attn-materialized-sgmat-f32.wgsl.jinja", - "derive": { - "phase": "\"apply\"", - "fusedSoftmax": true, - "layout": "\"bsh\"", - "kvLayout": "\"bhsd\"", - "causalRightAlign": true, - "useSeqlens": true - }, - "bindings": ["scores_f32", "value_f32", "rowStats_f32", "output", "seqlens_k", "params_apply"], - "dispatch": { - "x": "ceilDiv(gqaHeadDim, gqaMatKeyTile)", - "y": "ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)", - "z": "dim(shapes.queryT, 0) * attrs.num_heads" - } - } - ] - }, - { - "id": "new_kv_share_append_split", - "priority": 32, - "when": ["shareAppendOk", "gqaScalarDispatchOk", "noAuxAttentionInputs", "not present.kNormWeightT", "gqaHeadDim % 2 == 0"], - "derive": { - "useSeqlens": true, - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim", - "mode": "\"merge_share\"", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "inputScalar": "gqaScalar" - }, - "passes": [ - { - "id": "present_retain", - "name": "GroupQueryAttention.MergeShareRetain", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shareRegion": "\"retain\"" }, - "bindings": ["past_k", "past_v", "present_key_present", "present_value_present", "seqlens_k", "params__uniform"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [ - { "input": "past_k", "output": "present_key" }, - { "input": "past_v", "output": "present_value" } - ] - }, - { - "id": "present_append", - "name": "GroupQueryAttention.MergeShareAppend", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shareRegion": "\"append\"" }, - "bindings": ["new_k", "new_v", "present_key_present", "present_value_present", "seqlens_k", "params_gqa_present"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "bindings": ["query_qprep", "kcache", "vcache", "output_past_kv", "seqlens_k", "params_attention"], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - } - ] - }, - { - "id": "new_kv_share_append_headsink_split", - "priority": 30, - "when": ["shareAppendOk", "gqaScalarDispatchOk", "gqaHeadDim % 2 == 0", "not present.cosCacheT and not rotaryRequested", "not present.qNormWeightT", "not present.kNormWeightT", "not present.attentionBiasT", "present.headSinkT"], - "derive": { - "useSeqlens": true, - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim", - "mode": "\"merge_share\"", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "inputScalar": "gqaScalar", - "hasHeadSink": true - }, - "passes": [ - { - "id": "present_retain", - "name": "GroupQueryAttention.MergeShareRetain", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shareRegion": "\"retain\"" }, - "bindings": ["past_k", "past_v", "present_key_present", "present_value_present", "seqlens_k", "params__uniform"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [ - { "input": "past_k", "output": "present_key" }, - { "input": "past_v", "output": "present_value" } - ] - }, - { - "id": "present_append", - "name": "GroupQueryAttention.MergeShareAppend", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shareRegion": "\"append\"" }, - "bindings": ["new_k", "new_v", "present_key_present", "present_value_present", "seqlens_k", "params_gqa_present"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "bindings": [ - "query_qprep", - "kcache", - "vcache", - "head_sink", - "output_past_kv", - "seqlens_k", - { - "name": "params", - "struct": [ - { "name": "batch", "type": "u32", "value": "dim(shapes.queryT, 0)" }, - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "totalSeq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" }, - { - "name": "windowSize", - "type": "u32", - "value": "attrs.local_window_size if attrs.local_window_size > 0 else 0" - }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { "name": "softcap", "type": "f32", "value": "attrs.softcap" } - ] - } - ], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - } - ] - }, - { - "id": "new_kv_share_append_rotary_split", - "priority": 30, - "when": ["shareAppendOk", "gqaScalarDispatchOk", "gqaHeadDim % 2 == 0", "present.cosCacheT and rotaryRequested", "not present.qNormWeightT", "not present.kNormWeightT", "not present.attentionBiasT", "not present.headSinkT", "tensorDtypes.queryT == \"float32\""], - "derive": { - "useSeqlens": true, - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim", - "mode": "\"merge_share\"", - "inputScalar": "\"f32\"", - "half": "gqaHeadDim / 2", - "hasRotary": true - }, - "passes": [ - { - "id": "present_retain", - "name": "GroupQueryAttention.MergeShareRetain", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shareRegion": "\"retain\"" }, - "bindings": ["past_k", "past_v", "present_key_present", "present_value_present", "seqlens_k", "params__uniform"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [ - { "input": "past_k", "output": "present_key" }, - { "input": "past_v", "output": "present_value" } - ] - }, - { - "id": "present_append", - "name": "GroupQueryAttention.MergeShareAppend", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shareRegion": "\"append\"" }, - "bindings": ["new_k", "new_v", "cos_cache_f32", "sin_cache_f32", "present_key_present", "present_value_present", "seqlens_k", "params_gqa_present"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "bindings": ["query_qprep", "kcache", "vcache", "cos_cache_f32", "sin_cache_f32", "output_past_kv", "seqlens_k", "params_attention"], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - } - ] - }, - { - "id": "new_kv_share_append_bidirectional_split", - "priority": 32, - "when": ["shareAppendBidirectionalOk", "gqaScalarDispatchOk", "noAuxAttentionInputs", "not present.kNormWeightT", "gqaHeadDim % 2 == 0"], - "derive": { - "useSeqlens": true, - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim", - "mode": "\"merge_share\"", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "inputScalar": "gqaScalar", - "bidirectional": true - }, - "passes": [ - { - "id": "present_retain", - "name": "GroupQueryAttention.MergeShareRetain", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shareRegion": "\"retain\"" }, - "bindings": ["past_k", "past_v", "present_key_present", "present_value_present", "seqlens_k", "params__uniform"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [ - { "input": "past_k", "output": "present_key" }, - { "input": "past_v", "output": "present_value" } - ] - }, - { - "id": "present_append", - "name": "GroupQueryAttention.MergeShareAppend", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shareRegion": "\"append\"" }, - "bindings": ["new_k", "new_v", "present_key_present", "present_value_present", "seqlens_k", "params_gqa_present"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "bindings": ["query_qprep", "kcache", "vcache", "output_past_kv", "seqlens_k", "params_attention"], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - } - ] - }, - { - "id": "qkv_present_tiled_nosg", - "priority": 19, - "when": ["plainAttentionOptions", "flashShapeOk", "qkvTiledStorageOk", "headDimPlan % 4 == 0", "headDimPlan <= 128", "dim(shapes.queryT, 1) >= tunables.QKV_PREFILL_MIN_QUERY_TOKENS", "attrs.local_window_size <= 0", "not causalNoWindow"], - "derive": { - "scalar": "qkvScalar", - "inputScalar": "qkvScalar", - "presentScalar": "qkvCacheScalar", - "inputElement": "qkvScalar", - "presentElement": "qkvCacheScalar", - "blockM": 32, - "vHeadCap": "dim(shapes.valueT, 2) / attrs.kv_num_heads", - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "dim(shapes.queryT, 2) / attrs.num_heads", - "kvHidden": "dim(shapes.keyT, 2)" - }, - "passes": [ - { - "id": "attention", - "name": "GroupQueryAttention.PrefillTiledNoSg", - "shader": "attention-rank4-tiled.wgsl.jinja", - "derive": { "layout": "\"bsh\"" }, - "bindings": [ - { "arg": "queryT", "name": "q", "elementType": "$scalar" }, - { "arg": "keyT", "name": "k", "elementType": "$scalar" }, - { "arg": "valueT", "name": "v", "elementType": "$scalar" }, - { "arg": "outputT", "name": "y", "elementType": "$scalar" }, - { - "name": "params", - "struct": [ - { "name": "count", "type": "u32", "value": "numel(shapes.outputT)" }, - { "name": "qHeads", "type": "u32", "value": "attrs.num_heads" }, - { "name": "kvHeads", "type": "u32", "value": "attrs.kv_num_heads" }, - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.keyT, 1)" }, - { "name": "headSize", "type": "u32", "value": "dim(shapes.queryT, 2) / attrs.num_heads" }, - { "name": "vHeadSize", "type": "u32", "value": "dim(shapes.valueT, 2) / attrs.kv_num_heads" }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { "name": "softcap", "type": "f32", "value": "0" }, - { "name": "isCausal", "type": "u32", "value": "0" }, - { "name": "qHidden", "type": "u32", "value": "dim(shapes.queryT, 2)" }, - { "name": "kvHidden", "type": "u32", "value": "dim(shapes.keyT, 2)" }, - { "name": "vHidden", "type": "u32", "value": "dim(shapes.valueT, 2)" } - ] - } - ], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.outputT, 0) * attrs.num_heads * ceilDiv(dim(shapes.outputT, 1), blockM) * blockM), (blockM)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.outputT, 0) * attrs.num_heads * ceilDiv(dim(shapes.outputT, 1), blockM) * blockM), (blockM)), 65535)", - "z": 1 - } - }, - { - "id": "present", - "name": "GroupQueryAttention.PresentTiledNoSg", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["key_key_t", "value_value_t", "present_key", "present_value", "params"], - "dispatch": { - "x": "min(ceilDiv((numel(shapes.presentKeyT)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((numel(shapes.presentKeyT)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - } - ] - }, - { - "id": "qkv_present_flash", - "priority": 20, - "when": ["flashShapeOk", "not causalNoWindow"], - "requires": { "features": ["subgroups"] }, - "derive": { - "hasCausal": false, - "combineSubgroups": true, - "scalar": "qkvScalar", - "presentScalar": "qkvCacheScalar", - "inputElement": "qkvInputVec4", - "outputElement": "qkvInputVec4", - "presentElement": "qkvCacheVec4", - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "dim(shapes.queryT, 2) / attrs.num_heads", - "headDimV4": "(dim(shapes.queryT, 2) / attrs.num_heads) / 4", - "qHiddenV4": "dim(shapes.queryT, 2) / 4", - "kvHidden": "dim(shapes.keyT, 2)", - "kvHiddenV4": "dim(shapes.keyT, 2) / 4", - "presentVec4": true - }, - "passes": [ - { - "id": "attention", - "name": "GroupQueryAttention.Flash", - "shader": "attn-flash-online.wgsl.jinja", - "derive": { "layout": "\"bsh\"" }, - "bindings": ["query_query_t", "key_key_t", "value_value_t", "output_output_t", "params_qkv_present"], - "dispatch": { "x": "dim(shapes.queryT, 1)", "y": "attrs.num_heads", "z": "dim(shapes.queryT, 0)" } - }, - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["key_key_t", "value_value_t", "present_key", "present_value", "params"], - "dispatch": { - "x": "min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)", - "z": 1 - } - } - ] - }, - { - "id": "qkv_present_flash_causal", - "priority": 20, - "when": ["flashShapeOk", "causalNoWindow", "dim(shapes.keyT, 1) == dim(shapes.queryT, 1)"], - "requires": { "features": ["subgroups"] }, - "derive": { - "hasCausal": true, - "combineSubgroups": true, - "scalar": "qkvScalar", - "presentScalar": "qkvCacheScalar", - "inputElement": "qkvInputVec4", - "outputElement": "qkvInputVec4", - "presentElement": "qkvCacheVec4", - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "dim(shapes.queryT, 2) / attrs.num_heads", - "headDimV4": "(dim(shapes.queryT, 2) / attrs.num_heads) / 4", - "qHiddenV4": "dim(shapes.queryT, 2) / 4", - "kvHidden": "dim(shapes.keyT, 2)", - "kvHiddenV4": "dim(shapes.keyT, 2) / 4", - "presentVec4": true - }, - "passes": [ - { - "id": "attention", - "name": "GroupQueryAttention.Flash", - "shader": "attn-flash-online.wgsl.jinja", - "derive": { "layout": "\"bsh\"" }, - "bindings": ["query_query_t", "key_key_t", "value_value_t", "output_output_t", "params_qkv_present_causal"], - "dispatch": { "x": "dim(shapes.queryT, 1)", "y": "attrs.num_heads", "z": "dim(shapes.queryT, 0)" } - }, - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["key_key_t", "value_value_t", "present_key", "present_value", "params"], - "dispatch": { - "x": "min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)", - "z": 1 - } - } - ] - }, - { - "id": "qkv_present", - "priority": 0, - "when": ["fallbackShapeOk", "not causalNoWindow"], - "derive": { - "hasCausal": false, - "hasKeyLimit": false, - "inputScalar": "qkvScalar", - "outputScalar": "qkvScalar", - "presentScalar": "qkvCacheScalar", - "inputElement": "qkvScalar", - "outputElement": "qkvScalar", - "presentElement": "qkvCacheScalar", - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "dim(shapes.queryT, 2) / attrs.num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "kvHidden": "dim(shapes.keyT, 2)", - "workgroupSize": "min(256, pow2ceil(dim(shapes.queryT, 2) / attrs.num_heads))" - }, - "passes": [ - { - "id": "attention", - "name": "GroupQueryAttention.Attention", - "shader": "attn-online-scalar.wgsl.jinja", - "derive": { "layout": "\"bsh\"" }, - "bindings": ["query_query_t", "key_key_t", "value_value_t", "output_output_t", "params_qkv_present"], - "dispatch": { - "x": "min(dim(shapes.queryT, 1), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))", - "y": "attrs.num_heads", - "z": "dim(shapes.queryT, 0)" - } - }, - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["key_key_t", "value_value_t", "present_key", "present_value", "params"], - "dispatch": { - "x": "min(ceilDiv((numel(shapes.presentKeyT)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((numel(shapes.presentKeyT)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - } - ] - }, - { - "id": "qkv_present_causal", - "priority": 0, - "when": ["fallbackShapeOk", "causalNoWindow", "dim(shapes.keyT, 1) == dim(shapes.queryT, 1)"], - "derive": { - "hasCausal": true, - "hasKeyLimit": false, - "inputScalar": "qkvScalar", - "outputScalar": "qkvScalar", - "presentScalar": "qkvCacheScalar", - "inputElement": "qkvScalar", - "outputElement": "qkvScalar", - "presentElement": "qkvCacheScalar", - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "dim(shapes.queryT, 2) / attrs.num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "kvHidden": "dim(shapes.keyT, 2)", - "workgroupSize": "min(256, pow2ceil(dim(shapes.queryT, 2) / attrs.num_heads))" - }, - "passes": [ - { - "id": "attention", - "name": "GroupQueryAttention.Attention", - "shader": "attn-online-scalar.wgsl.jinja", - "derive": { "layout": "\"bsh\"" }, - "bindings": ["query_query_t", "key_key_t", "value_value_t", "output_output_t", "params_qkv_present_causal"], - "dispatch": { - "x": "min(dim(shapes.queryT, 1), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))", - "y": "attrs.num_heads", - "z": "dim(shapes.queryT, 0)" - } - }, - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["key_key_t", "value_value_t", "present_key", "present_value", "params"], - "dispatch": { - "x": "min(ceilDiv((numel(shapes.presentKeyT)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((numel(shapes.presentKeyT)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - } - ] - }, - { - "id": "quant_int8", - "priority": 35, - "when": ["quantizedPromptOk", "gqaScalarDispatchOk", "attrs.kv_cache_bit_width == 8"], - "derive": { - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim / (8 / 8)", - "quantized": true, - "bits": 8, - "mode": "\"build_quant\"", - "qmax": "127 if 8 == 8 else 7", - "qmin": "0 - (128 if 8 == 8 else 8)", - "quantCacheElement": "\"i32\" if 8 == 8 else \"u32\"" - }, - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k_f32", "src_v_f32", "k_scale", "v_scale", "present_key_quant_int8", "present_value_quant_int8", "params_quant_int8"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "bindings": [ - "query", - { - "arg": "presentKeyT", - "name": "kcache", - "buffer": "read-only-storage", - "elementType": "$quantCacheElement" - }, - { - "arg": "presentValueT", - "name": "vcache", - "buffer": "read-only-storage", - "elementType": "$quantCacheElement" - }, - "k_scale", - "v_scale", - "output", - { - "name": "params", - "struct": [ - { "name": "batch", "type": "u32", "value": "dim(shapes.queryT, 0)" }, - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "totalSeq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" }, - { - "name": "windowSize", - "type": "u32", - "value": "attrs.local_window_size if attrs.local_window_size > 0 else 0" - }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { "name": "softcap", "type": "f32", "value": "attrs.softcap" }, - { "name": "smoothSoftmax", "type": "u32", "value": "1 if attrs.smooth_softmax == 1 else 0" }, - { "name": "perChannel", "type": "u32", "value": "1 if dim(shapes.kScaleT, 0) > 1 else 0" } - ] - } - ], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - } - ] - }, - { - "id": "quant_int4", - "priority": 35, - "when": ["quantizedPromptOk", "gqaScalarDispatchOk", "attrs.kv_cache_bit_width == 4"], - "derive": { - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim / (8 / 4)", - "quantized": true, - "bits": 4, - "mode": "\"build_quant\"", - "qmax": "127 if 4 == 8 else 7", - "qmin": "0 - (128 if 4 == 8 else 8)", - "quantCacheElement": "\"i32\" if 4 == 8 else \"u32\"" - }, - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k_f32", "src_v_f32", "k_scale", "v_scale", "present_key_quant_int8", "present_value_quant_int8", "params_quant_int8"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "bindings": [ - "query", - { - "arg": "presentKeyT", - "name": "kcache", - "buffer": "read-only-storage", - "elementType": "$quantCacheElement" - }, - { - "arg": "presentValueT", - "name": "vcache", - "buffer": "read-only-storage", - "elementType": "$quantCacheElement" - }, - "k_scale", - "v_scale", - "output", - { - "name": "params", - "struct": [ - { "name": "batch", "type": "u32", "value": "dim(shapes.queryT, 0)" }, - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "totalSeq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" }, - { - "name": "windowSize", - "type": "u32", - "value": "attrs.local_window_size if attrs.local_window_size > 0 else 0" - }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { "name": "softcap", "type": "f32", "value": "attrs.softcap" }, - { "name": "smoothSoftmax", "type": "u32", "value": "1 if attrs.smooth_softmax == 1 else 0" }, - { "name": "perChannel", "type": "u32", "value": "1 if dim(shapes.kScaleT, 0) > 1 else 0" } - ] - } - ], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - } - ] - }, - { - "id": "quant_int8_decode_splitk", - "priority": 45, - "when": ["quantizedCachedDecodeOk", "decodeFlashShapeOk", "cachedNumSplits >= 2", "cachedSplitScratchFits"], - "derive": { - "useSubgroups": "subgroupSplitK", - "headDim": "gqaHeadDim", - "headDimV4": "gqaHeadDim / 4", - "kvNumHeads": "attrs.kv_num_heads", - "numSplits": "cachedNumSplits", - "usesF16": false, - "scalar": "\"f32\"", - "inputScalar": "\"i32\"", - "inputVec4": "\"vec4\"", - "quantizedCache": true, - "cacheSeqlens": true, - "bits": 8, - "packed": "gqaHeadDim", - "kvHeads": "attrs.kv_num_heads", - "qmax": 127, - "qmin": -128 - }, - "intermediates": [ - { - "id": "partialOut", - "dtype": "float32", - "shape": "[dim(shapes.queryT, 0) * attrs.num_heads * cachedNumSplits * gqaHeadDim]" - }, - { - "id": "partialStats", - "dtype": "float32", - "shape": "[2 * dim(shapes.queryT, 0) * attrs.num_heads * cachedNumSplits]" - } - ], - "passes": [ - { - "id": "copy_past", - "name": "GroupQueryAttention.QuantInt8CopyPast", - "shader": "gqa-present.wgsl.jinja", - "derive": { "modeSpec": "\"copy\"" }, - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - }, - { - "id": "append", - "name": "GroupQueryAttention.QuantInt8Append", - "shader": "gqa-present.wgsl.jinja", - "derive": { "modeSpec": "\"append_quant\"" }, - "bindings": [ - "src_k_f32", - "src_v_f32", - "k_scale", - "v_scale", - "seqlens_k", - { "arg": "presentKeyT", "name": "present_key", "elementType": "i32" }, - { "arg": "presentValueT", "name": "present_value", "elementType": "i32" }, - { - "name": "params", - "struct": [ - { - "name": "count", - "type": "u32", - "value": "dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)" - }, - { "name": "seq", "type": "u32", "value": "dim(shapes.keyT, 1)" }, - { "name": "totalSeq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" }, - { "name": "perChannel", "type": "u32", "value": "1 if dim(shapes.kScaleT, 0) > 1 else 0" } - ] - } - ], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "split_attention", - "name": "GroupQueryAttention.QuantInt8DecodeSplitK", - "shader": "attn-flash-decode-splitk.wgsl.jinja", - "derive": { "layout": "\"bhsd\"" }, - "bindings": [ - { "arg": "queryT", "name": "query", "elementType": "vec4" }, - { "arg": "presentKeyT", "name": "key", "buffer": "read-only-storage", "elementType": "vec4" }, - { "arg": "presentValueT", "name": "value", "buffer": "read-only-storage", "elementType": "vec4" }, - "k_scale", - "v_scale", - "seqlens_k", - "partial_out", - "partial_stats", - { - "name": "params", - "struct": [ - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.presentKeyT, 2)" }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { - "name": "windowSize", - "type": "u32", - "value": "attrs.local_window_size if attrs.local_window_size > 0 else 0" - }, - { "name": "perChannel", "type": "u32", "value": "1 if dim(shapes.kScaleT, 0) > 1 else 0" } - ] - } - ], - "dispatch": { "x": "cachedNumSplits", "y": "attrs.num_heads", "z": "dim(shapes.queryT, 0)" } - }, - { - "id": "merge", - "name": "GroupQueryAttention.QuantInt8DecodeSplitKMerge", - "shader": "attn-flash-decode-splitk-merge.wgsl.jinja", - "derive": { "layout": "\"bhsd\"" }, - "bindings": ["partial_out_merge", "partial_stats_merge", "output_merge"], - "dispatch": { "x": 1, "y": "attrs.num_heads", "z": "dim(shapes.queryT, 0)" } - } - ] - }, - { - "id": "qkv_present_flash_splitk", - "priority": 25, - "when": ["decodeSplitKShapeOk", "qkvSplitScratchFits", "not causalNoWindow"], - "derive": { - "useSubgroups": "device.features.has(\"subgroups\")", - "scalar": "qkvScalar", - "inputVec4": "qkvInputVec4", - "presentScalar": "qkvCacheScalar", - "inputElement": "qkvInputVec4", - "presentElement": "qkvCacheVec4", - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "dim(shapes.queryT, 2) / attrs.num_heads", - "headDimV4": "(dim(shapes.queryT, 2) / attrs.num_heads) / 4", - "qHiddenV4": "dim(shapes.queryT, 2) / 4", - "kvHidden": "dim(shapes.keyT, 2)", - "kvHiddenV4": "dim(shapes.keyT, 2) / 4", - "numSplits": "qkvNumSplits", - "presentVec4": true, - "usesF16": "qkvUsesF16" - }, - "intermediates": [ - { - "id": "partialOut", - "dtype": "float32", - "shape": "[dim(shapes.queryT, 0) * attrs.num_heads * qkvNumSplits * (dim(shapes.queryT, 2) / attrs.num_heads)]" - }, - { - "id": "partialStats", - "dtype": "float32", - "shape": "[2 * dim(shapes.queryT, 0) * attrs.num_heads * qkvNumSplits]" - } - ], - "passes": [ - { - "id": "split_attention", - "name": "GroupQueryAttention.DecodeSplitK", - "shader": "attn-flash-decode-splitk.wgsl.jinja", - "derive": { "usesF16": "tensorDtypes.queryT == \"float16\"", "layout": "\"bsh\"" }, - "bindings": [ - "query_attention", - { "arg": "keyT", "name": "key", "elementType": "$inputVec4" }, - { "arg": "valueT", "name": "value", "elementType": "$inputVec4" }, - "partial_out", - "partial_stats", - { - "name": "params", - "struct": [ - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.keyT, 1)" }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" }, - { - "name": "windowSize", - "type": "u32", - "value": "attrs.local_window_size if attrs.local_window_size > 0 else 0" - } - ] - } - ], - "dispatch": { "x": "qkvNumSplits", "y": "attrs.num_heads", "z": "dim(shapes.queryT, 0)" } - }, - { - "id": "merge", - "name": "GroupQueryAttention.DecodeSplitKMerge", - "shader": "attn-flash-decode-splitk-merge.wgsl.jinja", - "derive": { "layout": "\"bsh\"" }, - "bindings": ["partial_out_merge", "partial_stats_merge", "output_merge"], - "dispatch": { "x": 1, "y": "attrs.num_heads", "z": "dim(shapes.queryT, 0)" } - }, - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["key_key_t", "value_value_t", "present_key", "present_value", "params"], - "dispatch": { - "x": "min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)", - "z": 1 - } - } - ] - }, - { - "id": "qkv_present_flash_cluster", - "priority": 22, - "when": ["flashShapeOk", "qkvSgClusterOk or qkvNoSgClusterStorageOk", "qkvPrefillClusterWorkgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup", "qkvPrefillClusterWorkgroupSize <= device.limits.maxComputeWorkgroupSizeX", "headDimPlan % (4 * qkvPrefillLanesPerQuery) == 0", "dim(shapes.queryT, 1) >= tunables.QKV_PREFILL_MIN_QUERY_TOKENS", "not causalNoWindow"], - "demoteWhen": ["device.features.has(\"subgroups\") and not qkvF32ClusterRegisterGeometry"], - "derive": { - "useSubgroups": "qkvSgClusterOk", - "usesF16": "qkvUsesF16", - "scalar": "qkvScalar", - "presentScalar": "qkvCacheScalar", - "inputElement": "qkvInputVec4", - "outputElement": "qkvInputVec4", - "presentElement": "qkvCacheVec4", - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "dim(shapes.queryT, 2) / attrs.num_heads", - "headDimV4": "(dim(shapes.queryT, 2) / attrs.num_heads) / 4", - "qHiddenV4": "dim(shapes.queryT, 2) / 4", - "kvHidden": "dim(shapes.keyT, 2)", - "kvHiddenV4": "dim(shapes.keyT, 2) / 4", - "presentVec4": true, - "TILE_Q": "qkvPrefillQueryTile", - "TILE_K": "qkvClusterTileK if useSubgroups else qkvNoSgTileK", - "LPQ": "qkvPrefillLanesPerQuery", - "batchNoSgReduction": "not useSubgroups", - "shareNoSgProb": "batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ" - }, - "passes": [ - { - "id": "attention", - "name": "GroupQueryAttention.Flash", - "shader": "attn-flash-prefill-cluster.wgsl.jinja", - "derive": { "usesF16": "tensorDtypes.queryT == \"float16\"", "layout": "\"bsh\"" }, - "bindings": ["query_query_t", "key_key_t", "value_value_t", "output_output_t", "params_qkv_present"], - "dispatch": { - "x": "ceilDiv(dim(shapes.queryT, 1), TILE_Q)", - "y": "attrs.num_heads", - "z": "dim(shapes.queryT, 0)" - } - }, - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["key_key_t", "value_value_t", "present_key", "present_value", "params"], - "dispatch": { - "x": "min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)", - "z": 1 - } - } - ] - }, - { - "id": "past_kv_bias_flash_prefill", - "priority": 35, - "when": ["sharedKvFloatOk", "prefillFlashShapeOk", "cachedMaskSgPrefillOk or cachedNoSgClusterStorageOk", "standardSoftmax", "not present.cosCacheT and not rotaryRequested", "not present.qNormWeightT", "present.attentionBiasT", "not present.headSinkT"], - "derive": { - "useSubgroups": "cachedMaskSgPrefillOk", - "scalar": "gqaScalar", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "hasCausal": true, - "causalRightAlign": true, - "hasMask": true, - "stageMask": "useSubgroups", - "headDim": "gqaHeadDim", - "headDimV4": "gqaHeadDim / 4", - "qHiddenV4": "dim(shapes.queryT, 2) / 4", - "kvNumHeads": "attrs.kv_num_heads", - "TILE_Q": "biasPrefillQueryTile", - "TILE_K": "cachedClusterTileK if useSubgroups else cachedNoSgTileK", - "LPQ": "cachedPrefillLanesPerQuery", - "kvHeads": "attrs.kv_num_heads", - "packed": "gqaHeadDim", - "mode": "\"copy\"", - "inputVec4": "gqaInputVec4", - "inputScalar": "gqaScalar", - "batchNoSgReduction": "not useSubgroups", - "shareNoSgProb": "batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ" - }, - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - }, - { - "id": "attention", - "name": "GroupQueryAttention.FlashPrefill", - "shader": "attn-flash-prefill-cluster.wgsl.jinja", - "derive": { "layout": "\"bsh\"", "qLayout": "\"bsh\"", "kvLayout": "\"bhsd\"" }, - "bindings": ["query_attention", "key_attention", "value_attention", "attn_mask", "output_merge", "params_attn_flash_prefill_cluster"], - "dispatch": { - "x": "ceilDiv(dim(shapes.queryT, 1), TILE_Q)", - "y": "attrs.num_heads", - "z": "dim(shapes.queryT, 0)" - } - } - ] - }, - { - "id": "past_kv_qnorm_rotary_flash_prefill", - "priority": 37, - "when": ["sharedKvFloatOk", "prefillFlashShapeOk", "cachedSgPrefillOk or cachedNoSgClusterStorageOk", "qPrepScratchFits", "standardSoftmax", "present.cosCacheT and rotaryRequested", "present.qNormWeightT", "not present.attentionBiasT", "not present.headSinkT"], - "derive": { - "useSubgroups": "cachedSgPrefillOk", - "scalar": "gqaScalar", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "hasCausal": true, - "causalRightAlign": true, - "headDim": "gqaHeadDim", - "headDimV4": "gqaHeadDim / 4", - "qHiddenV4": "dim(shapes.queryT, 2) / 4", - "kvNumHeads": "attrs.kv_num_heads", - "TILE_Q": "cachedPrefillQueryTile", - "TILE_K": "cachedClusterTileK if useSubgroups else cachedNoSgTileK", - "LPQ": "cachedPrefillLanesPerQuery", - "kvHeads": "attrs.kv_num_heads", - "packed": "gqaHeadDim", - "mode": "\"copy\"", - "hasRotary": true, - "half": "gqaHeadDim / 2", - "qHeads": "attrs.num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "hasQNorm": true, - "qkEps": "attrs.qk_norm_epsilon", - "inputVec4": "gqaInputVec4", - "inputScalar": "gqaScalar", - "cosScalar": "\"f16\" if tensorDtypes.cosCacheT == \"float16\" else \"f32\"", - "qNormScalar": "\"f16\" if tensorDtypes.qNormWeightT == \"float16\" else \"f32\"", - "batchNoSgReduction": "not useSubgroups", - "shareNoSgProb": "batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ" - }, - "intermediates": [ - { - "id": "qPrep", - "dtype": "float32", - "shape": "[dim(shapes.queryT, 0), dim(shapes.queryT, 1), dim(shapes.queryT, 2)]" - } - ], - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - }, - { - "id": "qprep", - "name": "GroupQueryAttention.QPrep", - "shader": "gqa-qprep.wgsl.jinja", - "bindings": ["query_qprep", "cos_cache", "sin_cache", "q_norm_weight", "qout", "params_qprep"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.FlashPrefill", - "shader": "attn-flash-prefill-cluster.wgsl.jinja", - "derive": { "layout": "\"bsh\"", "qLayout": "\"bsh\"", "kvLayout": "\"bhsd\"" }, - "bindings": [ - { "scratch": "qPrep", "name": "query", "buffer": "read-only-storage", "elementType": "vec4" }, - "key_attention", - "value_attention", - "output_merge", - "params_past_kv_flash_prefill" - ], - "dispatch": { - "x": "ceilDiv(dim(shapes.queryT, 1), TILE_Q)", - "y": "attrs.num_heads", - "z": "dim(shapes.queryT, 0)" - } - } - ] - }, - { - "id": "past_kv_decode_splitk", - "priority": 38, - "when": ["sharedKvFloatOk", "decodeFlashShapeOk", "cachedSplitScratchFits", "plainAttentionOptions"], - "derive": { - "useSubgroups": "subgroupSplitK", - "cacheSeqlens": true, - "scalar": "gqaScalar", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "gqaHeadDim", - "headDimV4": "gqaHeadDim / 4", - "numSplits": "cachedNumSplits", - "kvHeads": "attrs.kv_num_heads", - "packed": "gqaHeadDim", - "mode": "\"copy\"", - "inputVec4": "gqaInputVec4", - "inputScalar": "gqaScalar", - "zeroScalar": "gqaScalar" - }, - "intermediates": [ - { - "id": "partialOut", - "dtype": "float32", - "shape": "[dim(shapes.queryT, 0) * attrs.num_heads * (cachedNumSplits) * gqaHeadDim]" - }, - { - "id": "partialStats", - "dtype": "float32", - "shape": "[2 * dim(shapes.queryT, 0) * attrs.num_heads * (cachedNumSplits)]" - } - ], - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - }, - { - "id": "split_attention", - "name": "GroupQueryAttention.DecodeSplitK", - "shader": "attn-flash-decode-splitk.wgsl.jinja", - "derive": { "layout": "\"bhsd\"" }, - "bindings": ["query_attention", "key_attention", "value_attention", "partial_out", "partial_stats", "seqlens_k", "params_split_attention"], - "dispatch": { "x": "cachedNumSplits", "y": "attrs.num_heads", "z": "dim(shapes.queryT, 0)" } - }, - { - "id": "merge", - "name": "GroupQueryAttention.DecodeSplitKMerge", - "shader": "attn-flash-decode-splitk-merge.wgsl.jinja", - "derive": { "layout": "\"bhsd\"" }, - "bindings": ["partial_out_merge", "partial_stats_merge", "output_merge"], - "dispatch": { "x": 1, "y": "attrs.num_heads", "z": "dim(shapes.queryT, 0)" } - } - ] - }, - { - "id": "new_kv_past_decode_splitk", - "priority": 38, - "when": ["newKvPastOk", "decodeFlashShapeOk", "cachedSplitScratchFits", "plainAttentionOptions"], - "derive": { - "useSubgroups": "subgroupSplitK", - "scalar": "gqaScalar", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "gqaHeadDim", - "headDimV4": "gqaHeadDim / 4", - "numSplits": "cachedNumSplits", - "kvHeads": "attrs.kv_num_heads", - "packed": "gqaHeadDim", - "mode": "\"merge\"", - "inputVec4": "gqaInputVec4", - "inputScalar": "gqaScalar", - "zeroScalar": "gqaScalar" - }, - "intermediates": [ - { - "id": "partialOut", - "dtype": "float32", - "shape": "[dim(shapes.queryT, 0) * attrs.num_heads * (cachedNumSplits) * gqaHeadDim]" - }, - { - "id": "partialStats", - "dtype": "float32", - "shape": "[2 * dim(shapes.queryT, 0) * attrs.num_heads * (cachedNumSplits)]" - } - ], - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Merge", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["past_k", "past_v", "new_k", "new_v", "present_key_present", "present_value_present", "params_present"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "split_attention", - "name": "GroupQueryAttention.DecodeSplitK", - "shader": "attn-flash-decode-splitk.wgsl.jinja", - "derive": { "layout": "\"bhsd\"" }, - "bindings": ["query_attention", "key_attention", "value_attention", "partial_out", "partial_stats", "params_split_attention"], - "dispatch": { "x": "cachedNumSplits", "y": "attrs.num_heads", "z": "dim(shapes.queryT, 0)" } - }, - { - "id": "merge", - "name": "GroupQueryAttention.DecodeSplitKMerge", - "shader": "attn-flash-decode-splitk-merge.wgsl.jinja", - "derive": { "layout": "\"bhsd\"" }, - "bindings": ["partial_out_merge", "partial_stats_merge", "output_merge"], - "dispatch": { "x": 1, "y": "attrs.num_heads", "z": "dim(shapes.queryT, 0)" } - } - ] - }, - { - "id": "window_shift_decode_splitk", - "priority": 38, - "when": ["windowShiftOk", "decodeFlashShapeOk", "cachedSplitScratchFits", "plainAttentionOptions"], - "derive": { - "useSubgroups": "subgroupSplitK", - "cacheSeqlens": true, - "scalar": "gqaScalar", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "gqaHeadDim", - "headDimV4": "gqaHeadDim / 4", - "numSplits": "cachedNumSplits", - "kvHeads": "attrs.kv_num_heads", - "packed": "gqaHeadDim", - "mode": "\"window_shift\"", - "inputVec4": "gqaInputVec4", - "inputScalar": "gqaScalar", - "zeroScalar": "gqaScalar" - }, - "intermediates": [ - { - "id": "partialOut", - "dtype": "float32", - "shape": "[dim(shapes.queryT, 0) * attrs.num_heads * (cachedNumSplits) * gqaHeadDim]" - }, - { - "id": "partialStats", - "dtype": "float32", - "shape": "[2 * dim(shapes.queryT, 0) * attrs.num_heads * (cachedNumSplits)]" - } - ], - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.WindowShift", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["past_k", "past_v", "new_k", "new_v", "present_key_present", "present_value_present", "seqlens_k", "params__uniform"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "split_attention", - "name": "GroupQueryAttention.DecodeSplitK", - "shader": "attn-flash-decode-splitk.wgsl.jinja", - "derive": { "layout": "\"bhsd\"" }, - "bindings": ["query_attention", "key_attention", "value_attention", "partial_out", "partial_stats", "seqlens_k", "params_split_attention"], - "dispatch": { "x": "cachedNumSplits", "y": "attrs.num_heads", "z": "dim(shapes.queryT, 0)" } - }, - { - "id": "merge", - "name": "GroupQueryAttention.DecodeSplitKMerge", - "shader": "attn-flash-decode-splitk-merge.wgsl.jinja", - "derive": { "layout": "\"bhsd\"" }, - "bindings": ["partial_out_merge", "partial_stats_merge", "output_merge"], - "dispatch": { "x": 1, "y": "attrs.num_heads", "z": "dim(shapes.queryT, 0)" } - } - ] - }, - { - "id": "past_kv_flash_prefill", - "priority": 34, - "when": ["sharedKvFloatOk", "prefillFlashShapeOk", "cachedSgPrefillOk or cachedNoSgClusterStorageOk", "plainAttentionOptions"], - "derive": { - "useSubgroups": "cachedSgPrefillOk", - "scalar": "gqaScalar", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "hasCausal": true, - "causalRightAlign": true, - "hasMask": false, - "headDim": "gqaHeadDim", - "headDimV4": "gqaHeadDim / 4", - "qHiddenV4": "dim(shapes.queryT, 2) / 4", - "kvNumHeads": "attrs.kv_num_heads", - "TILE_Q": "cachedPrefillQueryTile", - "TILE_K": "cachedClusterTileK if useSubgroups else cachedNoSgTileK", - "LPQ": "cachedPrefillLanesPerQuery", - "kvHeads": "attrs.kv_num_heads", - "packed": "gqaHeadDim", - "mode": "\"copy\"", - "inputVec4": "gqaInputVec4", - "inputScalar": "gqaScalar", - "batchNoSgReduction": "not useSubgroups", - "shareNoSgProb": "batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ" - }, - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - }, - { - "id": "attention", - "name": "GroupQueryAttention.FlashPrefill", - "shader": "attn-flash-prefill-cluster.wgsl.jinja", - "derive": { "layout": "\"bsh\"", "qLayout": "\"bsh\"", "kvLayout": "\"bhsd\"" }, - "bindings": ["query_attention", "key_attention", "value_attention", "output_merge", "params_past_kv_flash_prefill"], - "dispatch": { - "x": "ceilDiv(dim(shapes.queryT, 1), TILE_Q)", - "y": "attrs.num_heads", - "z": "dim(shapes.queryT, 0)" - } - } - ] - }, - { - "id": "new_kv_past_flash_prefill", - "priority": 34, - "when": ["newKvPastOk", "prefillFlashShapeOk", "cachedSgPrefillOk or cachedNoSgClusterStorageOk", "plainAttentionOptions"], - "derive": { - "useSubgroups": "cachedSgPrefillOk", - "scalar": "gqaScalar", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "hasCausal": true, - "causalRightAlign": true, - "hasMask": false, - "headDim": "gqaHeadDim", - "headDimV4": "gqaHeadDim / 4", - "qHiddenV4": "dim(shapes.queryT, 2) / 4", - "kvNumHeads": "attrs.kv_num_heads", - "TILE_Q": "cachedPrefillQueryTile", - "TILE_K": "cachedClusterTileK if useSubgroups else cachedNoSgTileK", - "LPQ": "cachedPrefillLanesPerQuery", - "kvHeads": "attrs.kv_num_heads", - "packed": "gqaHeadDim", - "mode": "\"merge\"", - "inputVec4": "gqaInputVec4", - "inputScalar": "gqaScalar", - "batchNoSgReduction": "not useSubgroups", - "shareNoSgProb": "batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ" - }, - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Merge", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["past_k", "past_v", "new_k", "new_v", "present_key_present", "present_value_present", "params_present"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.FlashPrefill", - "shader": "attn-flash-prefill-cluster.wgsl.jinja", - "derive": { "layout": "\"bsh\"", "qLayout": "\"bsh\"", "kvLayout": "\"bhsd\"" }, - "bindings": ["query_attention", "key_attention", "value_attention", "output_merge", "params_new_kv_past_flash_prefill"], - "dispatch": { - "x": "ceilDiv(dim(shapes.queryT, 1), TILE_Q)", - "y": "attrs.num_heads", - "z": "dim(shapes.queryT, 0)" - } - } - ] - }, - { - "id": "past_kv_rotary_flash_prefill", - "priority": 36, - "when": ["sharedKvFloatOk", "prefillFlashShapeOk", "cachedSgPrefillOk or cachedNoSgClusterStorageOk", "standardSoftmax", "present.cosCacheT and rotaryRequested", "not present.qNormWeightT", "not present.attentionBiasT", "not present.headSinkT"], - "derive": { - "useSubgroups": "cachedSgPrefillOk", - "scalar": "gqaScalar", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "hasCausal": true, - "causalRightAlign": true, - "hasMask": false, - "headDim": "gqaHeadDim", - "headDimV4": "gqaHeadDim / 4", - "qHiddenV4": "dim(shapes.queryT, 2) / 4", - "kvNumHeads": "attrs.kv_num_heads", - "TILE_Q": "cachedPrefillQueryTile", - "TILE_K": "cachedClusterTileK if useSubgroups else cachedNoSgTileK", - "LPQ": "cachedPrefillLanesPerQuery", - "kvHeads": "attrs.kv_num_heads", - "packed": "gqaHeadDim", - "mode": "\"copy\"", - "hasRotary": true, - "fusedRotary": true, - "half": "gqaHeadDim / 2", - "qHidden": "dim(shapes.queryT, 2)", - "inputVec4": "gqaInputVec4", - "inputScalar": "gqaScalar", - "cosScalar": "\"f16\" if tensorDtypes.cosCacheT == \"float16\" else \"f32\"", - "batchNoSgReduction": "not useSubgroups", - "shareNoSgProb": "batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ" - }, - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - }, - { - "id": "attention", - "name": "GroupQueryAttention.FlashPrefill", - "shader": "attn-flash-prefill-cluster.wgsl.jinja", - "derive": { "layout": "\"bsh\"", "qLayout": "\"bsh\"", "kvLayout": "\"bhsd\"" }, - "bindings": ["query_attention", "key_attention", "value_attention", "cos_cache", "sin_cache", "output_merge", "params_past_kv_flash_prefill"], - "dispatch": { - "x": "ceilDiv(dim(shapes.queryT, 1), TILE_Q)", - "y": "attrs.num_heads", - "z": "dim(shapes.queryT, 0)" - } - } - ] - }, - { - "id": "past_kv_softcap_flash_prefill", - "priority": 34, - "when": ["sharedKvFloatOk", "prefillFlashShapeOk", "cachedSgPrefillOk or cachedNoSgClusterStorageOk", "noAuxAttentionInputs", "attrs.softcap > 0", "attrs.smooth_softmax != 1"], - "derive": { - "useSubgroups": "cachedSgPrefillOk", - "scalar": "gqaScalar", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "hasCausal": true, - "causalRightAlign": true, - "hasSoftcap": true, - "hasMask": false, - "headDim": "gqaHeadDim", - "headDimV4": "gqaHeadDim / 4", - "qHiddenV4": "dim(shapes.queryT, 2) / 4", - "kvNumHeads": "attrs.kv_num_heads", - "TILE_Q": "cachedPrefillQueryTile", - "TILE_K": "cachedClusterTileK if useSubgroups else cachedNoSgTileK", - "LPQ": "cachedPrefillLanesPerQuery", - "kvHeads": "attrs.kv_num_heads", - "packed": "gqaHeadDim", - "mode": "\"copy\"", - "inputVec4": "gqaInputVec4", - "inputScalar": "gqaScalar", - "batchNoSgReduction": "not useSubgroups", - "shareNoSgProb": "batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ" - }, - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - }, - { - "id": "attention", - "name": "GroupQueryAttention.FlashPrefill", - "shader": "attn-flash-prefill-cluster.wgsl.jinja", - "derive": { "layout": "\"bsh\"", "qLayout": "\"bsh\"", "kvLayout": "\"bhsd\"" }, - "bindings": ["query_attention", "key_attention", "value_attention", "output_merge", "params_past_kv_softcap_flash_prefill"], - "dispatch": { - "x": "ceilDiv(dim(shapes.queryT, 1), TILE_Q)", - "y": "attrs.num_heads", - "z": "dim(shapes.queryT, 0)" - } - } - ] - }, - { - "id": "past_kv_headsink_flash_prefill", - "priority": 34, - "when": ["sharedKvFloatOk", "prefillFlashShapeOk", "cachedSgPrefillOk or cachedNoSgClusterStorageOk", "not present.cosCacheT and not rotaryRequested", "not present.qNormWeightT", "not present.attentionBiasT", "present.headSinkT", "standardSoftmax"], - "derive": { - "useSubgroups": "cachedSgPrefillOk", - "scalar": "gqaScalar", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "hasCausal": true, - "causalRightAlign": true, - "hasHeadSink": true, - "hasMask": false, - "headDim": "gqaHeadDim", - "headDimV4": "gqaHeadDim / 4", - "qHiddenV4": "dim(shapes.queryT, 2) / 4", - "kvNumHeads": "attrs.kv_num_heads", - "TILE_Q": "cachedPrefillQueryTile", - "TILE_K": "cachedClusterTileK if useSubgroups else cachedNoSgTileK", - "LPQ": "cachedPrefillLanesPerQuery", - "kvHeads": "attrs.kv_num_heads", - "packed": "gqaHeadDim", - "mode": "\"copy\"", - "inputVec4": "gqaInputVec4", - "inputScalar": "gqaScalar", - "batchNoSgReduction": "not useSubgroups", - "shareNoSgProb": "batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ" - }, - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - }, - { - "id": "attention", - "name": "GroupQueryAttention.FlashPrefill", - "shader": "attn-flash-prefill-cluster.wgsl.jinja", - "derive": { "layout": "\"bsh\"", "qLayout": "\"bsh\"", "kvLayout": "\"bhsd\"" }, - "bindings": ["query_attention", "key_attention", "value_attention", "head_sink", "output_merge", "params_past_kv_flash_prefill"], - "dispatch": { - "x": "ceilDiv(dim(shapes.queryT, 1), TILE_Q)", - "y": "attrs.num_heads", - "z": "dim(shapes.queryT, 0)" - } - } - ] - }, - { - "id": "past_kv_bias_headsink_flash_prefill", - "priority": 34, - "when": ["sharedKvFloatOk", "prefillFlashShapeOk", "cachedMaskSgPrefillOk or cachedNoSgClusterStorageOk", "not present.cosCacheT and not rotaryRequested", "not present.qNormWeightT", "present.attentionBiasT", "present.headSinkT", "standardSoftmax"], - "derive": { - "useSubgroups": "cachedMaskSgPrefillOk", - "scalar": "gqaScalar", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "hasCausal": true, - "causalRightAlign": true, - "hasHeadSink": true, - "hasMask": true, - "headDim": "gqaHeadDim", - "headDimV4": "gqaHeadDim / 4", - "qHiddenV4": "dim(shapes.queryT, 2) / 4", - "kvNumHeads": "attrs.kv_num_heads", - "TILE_Q": "cachedPrefillQueryTile", - "TILE_K": "cachedClusterTileK if useSubgroups else cachedNoSgTileK", - "LPQ": "cachedPrefillLanesPerQuery", - "kvHeads": "attrs.kv_num_heads", - "packed": "gqaHeadDim", - "mode": "\"copy\"", - "inputVec4": "gqaInputVec4", - "inputScalar": "gqaScalar", - "batchNoSgReduction": "not useSubgroups", - "shareNoSgProb": "batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ" - }, - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - }, - { - "id": "attention", - "name": "GroupQueryAttention.FlashPrefill", - "shader": "attn-flash-prefill-cluster.wgsl.jinja", - "derive": { "layout": "\"bsh\"", "qLayout": "\"bsh\"", "kvLayout": "\"bhsd\"" }, - "bindings": ["query_attention", "key_attention", "value_attention", "attn_mask", "head_sink", "output_merge", "params_attn_flash_prefill_cluster"], - "dispatch": { - "x": "ceilDiv(dim(shapes.queryT, 1), TILE_Q)", - "y": "attrs.num_heads", - "z": "dim(shapes.queryT, 0)" - } - } - ] - }, - { - "id": "window_shift_flash_prefill", - "priority": 34, - "when": ["windowShiftOk", "prefillFlashShapeOk", "cachedSgPrefillOk or cachedNoSgClusterStorageOk", "plainAttentionOptions"], - "derive": { - "useSubgroups": "cachedSgPrefillOk", - "scalar": "gqaScalar", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "hasCausal": true, - "causalRightAlign": true, - "hasMask": false, - "headDim": "gqaHeadDim", - "headDimV4": "gqaHeadDim / 4", - "qHiddenV4": "dim(shapes.queryT, 2) / 4", - "kvNumHeads": "attrs.kv_num_heads", - "TILE_Q": "cachedPrefillQueryTile", - "TILE_K": "cachedClusterTileK if useSubgroups else cachedNoSgTileK", - "LPQ": "cachedPrefillLanesPerQuery", - "kvHeads": "attrs.kv_num_heads", - "packed": "gqaHeadDim", - "mode": "\"window_shift\"", - "useSeqlens": true, - "zeroScalar": "gqaScalar", - "inputVec4": "gqaInputVec4", - "inputScalar": "gqaScalar", - "batchNoSgReduction": "not useSubgroups", - "shareNoSgProb": "batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ" - }, - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.WindowShift", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["past_k", "past_v", "new_k", "new_v", "present_key_present", "present_value_present", "seqlens_k", "params__uniform"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.FlashPrefill", - "shader": "attn-flash-prefill-cluster.wgsl.jinja", - "derive": { "layout": "\"bsh\"", "qLayout": "\"bsh\"", "kvLayout": "\"bhsd\"" }, - "bindings": ["query_attention", "key_attention", "value_attention", "output_merge", "seqlens_k", "params_new_kv_past_flash_prefill"], - "dispatch": { - "x": "ceilDiv(dim(shapes.queryT, 1), TILE_Q)", - "y": "attrs.num_heads", - "z": "dim(shapes.queryT, 0)" - } - } - ] - }, - { - "id": "qkv_present_flash_q32_broadcast", - "priority": 30, - "when": ["wave32SubgroupsUsable", "device.features.has(\"shader-f16\")", "tensorDtypes.queryT == \"float16\"", "flashShapeOk", "headDimPlan % 32 == 0", "headDimPlan >= 64", "headDimPlan <= 256", "dim(shapes.queryT, 1) >= tunables.QKV_PREFILL_MIN_QUERY_TOKENS", "attrs.local_window_size <= 0", "not causalNoWindow or dim(shapes.queryT, 1) == dim(shapes.keyT, 1)"], - "demoteWhen": ["causalNoWindow and device.features.has(\"subgroups\")"], - "requires": { "features": ["subgroups"] }, - "derive": { - "hasBias": false, - "hasCausal": "causalNoWindow", - "fixedCausal": "causalNoWindow", - "usesF16": true, - "scalar": "\"f16\"", - "presentScalar": "qkvCacheScalar", - "inputElement": "\"vec4\"", - "outputElement": "\"vec4\"", - "presentElement": "qkvCacheVec4", - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "dim(shapes.queryT, 2) / attrs.num_heads", - "headDimV4": "(dim(shapes.queryT, 2) / attrs.num_heads) / 4", - "kvHidden": "dim(shapes.keyT, 2)", - "kvHiddenV4": "dim(shapes.keyT, 2) / 4", - "presentVec4": true, - "kStep": 64, - "qkGroups": 16 - }, - "passes": [ - { - "id": "attention", - "name": "GroupQueryAttention.FlashQ32Broadcast", - "shader": "attn-flash-q32-broadcast.wgsl.jinja", - "derive": { "usesF16": "tensorDtypes.queryT == \"float16\"", "layout": "\"bsh\"" }, - "bindings": [ - "query_query_t", - "key_key_t", - "value_value_t", - "output_output_t", - { - "name": "params", - "struct": [ - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.keyT, 1)" }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" } - ] - } - ], - "dispatch": { - "x": "ceilDiv(dim(shapes.queryT, 1), 32)", - "y": "attrs.num_heads", - "z": "dim(shapes.queryT, 0)" - } - }, - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["key_key_t", "value_value_t", "present_key", "present_value", "params"], - "dispatch": { - "x": "min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)", - "z": 1 - } - } - ] - }, - { - "id": "qkv_present_flash_q32_shared", - "priority": 29, - "when": ["tensorDtypes.queryT == \"float16\"", "flashShapeOk", "headDimPlan % 4 == 0", "headDimPlan >= 64", "headDimPlan <= 256", "dim(shapes.queryT, 1) >= tunables.QKV_PREFILL_MIN_QUERY_TOKENS", "attrs.local_window_size <= 0", "ceilDiv(dim(shapes.queryT, 1), 64) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", "(headDimPlan / 4) * 32 * 16 <= device.limits.maxComputeWorkgroupStorageSize", "not causalNoWindow or dim(shapes.queryT, 1) == dim(shapes.keyT, 1)"], - "demoteWhen": ["causalNoWindow and device.features.has(\"subgroups\")"], - "requires": { "features": ["shader-f16"] }, - "derive": { - "hasBias": false, - "hasCausal": "causalNoWindow", - "fixedCausal": "causalNoWindow", - "usesF16": true, - "scalar": "\"f16\"", - "presentScalar": "qkvCacheScalar", - "inputElement": "\"vec4\"", - "outputElement": "\"vec4\"", - "presentElement": "qkvCacheVec4", - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "dim(shapes.queryT, 2) / attrs.num_heads", - "headDimV4": "(dim(shapes.queryT, 2) / attrs.num_heads) / 4", - "kvHidden": "dim(shapes.keyT, 2)", - "kvHiddenV4": "dim(shapes.keyT, 2) / 4", - "presentVec4": true, - "kStep": 32, - "qkGroups": 8, - "qStep": 64 - }, - "passes": [ - { - "id": "attention", - "name": "GroupQueryAttention.FlashQ32Shared", - "shader": "attn-flash-q32-broadcast.wgsl.jinja", - "derive": { "usesF16": "tensorDtypes.queryT == \"float16\"", "layout": "\"bsh\"", "useSubgroups": "false" }, - "bindings": [ - "query_query_t", - "key_key_t", - "value_value_t", - "output_output_t", - { - "name": "params", - "struct": [ - { "name": "qSeq", "type": "u32", "value": "dim(shapes.queryT, 1)" }, - { "name": "kvSeq", "type": "u32", "value": "dim(shapes.keyT, 1)" }, - { "name": "scale", "type": "f32", "value": "attrs.scale if attrs.scale else 0" } - ] - } - ], - "dispatch": { - "x": "ceilDiv(dim(shapes.queryT, 1), 64)", - "y": "attrs.num_heads", - "z": "dim(shapes.queryT, 0)" - } - }, - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["key_key_t", "value_value_t", "present_key", "present_value", "params"], - "dispatch": { - "x": "min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)", - "z": 1 - } - } - ] - }, - { - "id": "past_kv", - "priority": 30, - "when": ["sharedKvFloatOk", "gqaScalarDispatchOk", "noAuxAttentionInputs", "gqaHeadDim % 2 == 0"], - "derive": { - "useSeqlens": true, - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim", - "mode": "\"copy\"", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "inputScalar": "gqaScalar" - }, - "passes": [ - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "bindings": ["query_qprep", "kcache_past_kv", "vcache_past_kv", "output_past_kv", "seqlens_k", "params_past_kv"], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - }, - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - } - ] - }, - { - "id": "past_kv_rotary", - "priority": 31, - "when": ["sharedKvFloatOk", "gqaScalarDispatchOk", "gqaHeadDim % 2 == 0", "present.cosCacheT and rotaryRequested", "not present.qNormWeightT"], - "derive": { - "useSeqlens": true, - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim", - "half": "gqaHeadDim / 2", - "hasRotary": true, - "mode": "\"copy\"", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "inputScalar": "gqaScalar", - "cosScalar": "\"f16\" if tensorDtypes.cosCacheT == \"float16\" else \"f32\"" - }, - "passes": [ - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "bindings": ["query_qprep", "kcache_past_kv", "vcache_past_kv", "cos_cache", "sin_cache", "output_past_kv", "seqlens_k", "params_past_kv"], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - }, - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - } - ] - }, - { - "id": "past_kv_qnorm_rotary", - "priority": 32, - "when": ["sharedKvFloatOk", "gqaScalarDispatchOk", "gqaHeadDim % 2 == 0", "present.cosCacheT and rotaryRequested", "present.qNormWeightT"], - "derive": { - "useSeqlens": true, - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim", - "half": "gqaHeadDim / 2", - "qkEps": "attrs.qk_norm_epsilon", - "hasRotary": true, - "hasQNorm": true, - "mode": "\"copy\"", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "inputScalar": "gqaScalar", - "cosScalar": "\"f16\" if tensorDtypes.cosCacheT == \"float16\" else \"f32\"", - "qNormScalar": "\"f16\" if tensorDtypes.qNormWeightT == \"float16\" else \"f32\"" - }, - "passes": [ - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "bindings": ["query_qprep", "kcache_past_kv", "vcache_past_kv", "cos_cache", "sin_cache", "q_norm_weight", "output_past_kv", "seqlens_k", "params_past_kv"], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - }, - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - } - ] - }, - { - "id": "window_shift_rotary_append", - "priority": 31, - "when": ["windowShiftRotaryOk", "gqaScalarDispatchOk", "not present.qNormWeightT", "not present.attentionBiasT", "not present.headSinkT"], - "derive": { - "useSeqlens": true, - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim", - "mode": "\"window_shift\"", - "inputScalar": "\"f32\"", - "zeroScalar": "\"f32\"", - "windowOrigin": true - }, - "passes": [ - { - "id": "present_shift", - "name": "GroupQueryAttention.WindowShift", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shiftRegion": "\"shift\"" }, - "bindings": ["past_k", "past_v", "present_key_present", "present_value_present", "seqlens_k", "params__uniform"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "present_append", - "name": "GroupQueryAttention.WindowShiftAppend", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shiftRegion": "\"append\"", "hasRotary": true, "half": "gqaHeadDim / 2" }, - "bindings": ["new_k", "new_v", "cos_cache_f32", "sin_cache_f32", "present_key_present", "present_value_present", "seqlens_k", "params_gqa_present"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "derive": { "hasRotary": true, "half": "gqaHeadDim / 2" }, - "bindings": ["query_qprep", "kcache", "vcache", "cos_cache_f32", "sin_cache_f32", "output_past_kv", "seqlens_k", "params_attention"], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - } - ] - }, - { - "id": "window_shift_rotary_headsink_append", - "priority": 31, - "when": ["windowShiftRotaryOk", "gqaScalarDispatchOk", "not present.qNormWeightT", "not present.attentionBiasT", "present.headSinkT", "tensorDtypes.headSinkT == tensorDtypes.queryT"], - "derive": { - "useSeqlens": true, - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim", - "mode": "\"window_shift\"", - "inputScalar": "\"f32\"", - "zeroScalar": "\"f32\"", - "windowOrigin": true, - "hasHeadSink": true - }, - "passes": [ - { - "id": "present_shift", - "name": "GroupQueryAttention.WindowShift", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shiftRegion": "\"shift\"" }, - "bindings": ["past_k", "past_v", "present_key_present", "present_value_present", "seqlens_k", "params__uniform"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "present_append", - "name": "GroupQueryAttention.WindowShiftAppend", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shiftRegion": "\"append\"", "hasRotary": true, "half": "gqaHeadDim / 2" }, - "bindings": ["new_k", "new_v", "cos_cache_f32", "sin_cache_f32", "present_key_present", "present_value_present", "seqlens_k", "params_gqa_present"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "derive": { "hasRotary": true, "half": "gqaHeadDim / 2" }, - "bindings": ["query_qprep", "kcache", "vcache", "cos_cache_f32", "sin_cache_f32", "head_sink", "output_past_kv", "seqlens_k", "params_gqa_attention"], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - } - ] - }, - { - "id": "window_shift_rotary_bias_append", - "priority": 31, - "when": ["windowShiftRotaryOk", "gqaScalarDispatchOk", "not present.qNormWeightT", "not present.headSinkT", "present.attentionBiasT", "tensorDtypes.attentionBiasT == tensorDtypes.queryT", "dim(shapes.attentionBiasT, 2) == dim(shapes.queryT, 1)", "dim(shapes.attentionBiasT, 0) == dim(shapes.queryT, 0) or dim(shapes.attentionBiasT, 0) == 1", "dim(shapes.attentionBiasT, 1) == attrs.num_heads or dim(shapes.attentionBiasT, 1) == 1"], - "derive": { - "useSeqlens": true, - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim", - "mode": "\"window_shift\"", - "inputScalar": "\"f32\"", - "zeroScalar": "\"f32\"", - "windowOrigin": true, - "hasBias": true - }, - "passes": [ - { - "id": "present_shift", - "name": "GroupQueryAttention.WindowShift", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shiftRegion": "\"shift\"" }, - "bindings": ["past_k", "past_v", "present_key_present", "present_value_present", "seqlens_k", "params__uniform"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "present_append", - "name": "GroupQueryAttention.WindowShiftAppend", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shiftRegion": "\"append\"", "hasRotary": true, "half": "gqaHeadDim / 2" }, - "bindings": ["new_k", "new_v", "cos_cache_f32", "sin_cache_f32", "present_key_present", "present_value_present", "seqlens_k", "params_gqa_present"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "derive": { "hasRotary": true, "half": "gqaHeadDim / 2" }, - "bindings": ["query_qprep", "kcache", "vcache", "cos_cache_f32", "sin_cache_f32", "attn_bias", "output_past_kv", "seqlens_k", "params_window_bias"], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - } - ] - }, - { - "id": "new_kv_past", - "priority": 30, - "when": ["newKvPastOk", "gqaScalarDispatchOk", "noAuxAttentionInputs", "gqaHeadDim % 2 == 0"], - "derive": { - "headDim": "gqaHeadDim", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim", - "mode": "\"merge\"", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "inputScalar": "gqaScalar" - }, - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Merge", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["past_k", "past_v", "new_k", "new_v", "present_key_present", "present_value_present", "params_present"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "bindings": ["query_qprep", "kcache", "vcache", "output_past_kv", "params_attention"], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - } - ] - }, - { - "id": "window_shift_append", - "priority": 30, - "when": ["windowShiftOk", "gqaScalarDispatchOk", "noAuxAttentionInputs", "gqaHeadDim % 2 == 0"], - "derive": { - "useSeqlens": true, - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim", - "mode": "\"window_shift\"", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "inputScalar": "gqaScalar", - "zeroScalar": "gqaScalar" - }, - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.WindowShift", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["past_k", "past_v", "new_k", "new_v", "present_key_present", "present_value_present", "seqlens_k", "params__uniform"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "bindings": ["query_qprep", "kcache", "vcache", "output_past_kv", "seqlens_k", "params_attention"], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - } - ] - }, - { - "id": "window_shift_headsink_append", - "priority": 30, - "when": ["windowShiftOk", "gqaScalarDispatchOk", "gqaHeadDim % 2 == 0", "not present.qNormWeightT", "not present.attentionBiasT", "present.headSinkT", "tensorDtypes.headSinkT == tensorDtypes.queryT"], - "derive": { - "useSeqlens": true, - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim", - "mode": "\"window_shift\"", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "inputScalar": "gqaScalar", - "zeroScalar": "gqaScalar", - "hasHeadSink": true - }, - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.WindowShift", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["past_k", "past_v", "new_k", "new_v", "present_key_present", "present_value_present", "seqlens_k", "params__uniform"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "bindings": ["query_qprep", "kcache", "vcache", "head_sink", "output_past_kv", "seqlens_k", "params_gqa_attention"], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - } - ] - }, - { - "id": "window_shift_bias_append", - "priority": 30, - "when": ["windowShiftOk", "gqaScalarDispatchOk", "gqaHeadDim % 2 == 0", "not present.qNormWeightT", "not present.headSinkT", "present.attentionBiasT", "tensorDtypes.attentionBiasT == tensorDtypes.queryT", "dim(shapes.attentionBiasT, 2) == dim(shapes.queryT, 1)", "dim(shapes.attentionBiasT, 0) == dim(shapes.queryT, 0) or dim(shapes.attentionBiasT, 0) == 1", "dim(shapes.attentionBiasT, 1) == attrs.num_heads or dim(shapes.attentionBiasT, 1) == 1"], - "derive": { - "useSeqlens": true, - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim", - "mode": "\"window_shift\"", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "inputScalar": "gqaScalar", - "zeroScalar": "gqaScalar", - "hasBias": true, - "windowOrigin": true - }, - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.WindowShift", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["past_k", "past_v", "new_k", "new_v", "present_key_present", "present_value_present", "seqlens_k", "params__uniform"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "bindings": ["query_qprep", "kcache", "vcache", "attn_bias", "output_past_kv", "seqlens_k", "params_window_bias"], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - } - ] - }, - { - "id": "new_kv_qnorm_rotary", - "priority": 33, - "when": ["copyWorkgroupOk", "gqaScalarDispatchOk", "present.seqlensKT", "not present.pastKeyT", "dim(shapes.keyT, 1) > 0", "tensorDtypes.queryT == \"float32\"", "not present.kScaleT", "present.cosCacheT and rotaryRequested", "present.qNormWeightT", "dim(shapes.queryT, 2) % attrs.num_heads == 0", "gqaHeadDim % 2 == 0"], - "derive": { - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim", - "half": "gqaHeadDim / 2", - "qkEps": "attrs.qk_norm_epsilon", - "hasRotary": true, - "hasQNorm": true, - "mode": "\"build\"", - "hasKNorm": true - }, - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k_f32", "src_v_f32", "cos_cache_f32", "sin_cache_f32", "k_norm_weight", "present_key_f32", "present_value_f32", "params_count_seq_past_seq"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "bindings": ["query", "kcache_f32", "vcache_f32", "cos_cache_f32", "sin_cache_f32", "q_norm_weight_f32", "output", "params_attention"], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - } - ] - }, - { - "id": "past_kv_bias", - "priority": 30, - "when": ["sharedKvCacheOk", "gqaScalarDispatchOk", "tensorDtypes.queryT == \"float32\"", "gqaHeadDim % 2 == 0", "not present.cosCacheT and not rotaryRequested", "not present.qNormWeightT", "present.attentionBiasT", "not present.headSinkT"], - "derive": { - "useSeqlens": true, - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim", - "hasBias": true, - "mode": "\"copy\"", - "inputScalar": "gqaScalar" - }, - "passes": [ - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "bindings": ["query", "kcache_f32_read", "vcache_f32_read", "attn_bias", "output", "seqlens_k", "params_past_kv_bias"], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - }, - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - } - ] - }, - { - "id": "past_kv_headsink", - "priority": 30, - "when": ["sharedKvCacheOk", "gqaScalarDispatchOk", "tensorDtypes.queryT == \"float32\"", "gqaHeadDim % 2 == 0", "not present.cosCacheT and not rotaryRequested", "not present.qNormWeightT", "not present.attentionBiasT", "present.headSinkT"], - "derive": { - "useSeqlens": true, - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim", - "hasHeadSink": true, - "mode": "\"copy\"", - "inputScalar": "gqaScalar" - }, - "passes": [ - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "bindings": ["query", "kcache_f32_read", "vcache_f32_read", "head_sink", "output", "seqlens_k", "params_gqa_attention"], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - }, - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - } - ] - }, - { - "id": "past_kv_bias_headsink", - "priority": 30, - "when": ["sharedKvCacheOk", "gqaScalarDispatchOk", "tensorDtypes.queryT == \"float32\"", "gqaHeadDim % 2 == 0", "not present.cosCacheT and not rotaryRequested", "not present.qNormWeightT", "present.attentionBiasT", "present.headSinkT"], - "derive": { - "useSeqlens": true, - "headDim": "gqaHeadDim", - "cooperative": "gqaCoop", - "dispatchUnits": "gqaDispatchUnits", - "qHeads": "attrs.num_heads", - "kvHeads": "attrs.kv_num_heads", - "qHidden": "dim(shapes.queryT, 2)", - "packed": "gqaHeadDim", - "hasBias": true, - "hasHeadSink": true, - "mode": "\"copy\"", - "inputScalar": "gqaScalar" - }, - "passes": [ - { - "id": "attention", - "name": "GroupQueryAttention.Attn", - "shader": "gqa-attention.wgsl.jinja", - "bindings": ["query", "kcache_f32_read", "vcache_f32_read", "attn_bias", "head_sink", "output", "seqlens_k", "params_past_kv_bias_headsink"], - "dispatch": { "x": "min(dispatchUnits, 65535)", "y": "ceilDiv(dispatchUnits, 65535)", "z": 1 } - }, - { - "id": "present", - "name": "GroupQueryAttention.Present", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k", "src_v", "present_key_present", "present_value_present", "params_count"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [{ "input": "src_k", "output": "present_key" }, { "input": "src_v", "output": "present_value" }] - } - ] - }, - { - "id": "quant_int8_flash_prefill", - "priority": 37, - "when": ["quantizedPromptOk", "prefillFlashShapeOk", "cachedSgPrefillOk or cachedNoSgClusterStorageOk", "attrs.kv_cache_bit_width == 8", "plainAttentionOptions"], - "derive": { - "useSubgroups": "cachedSgPrefillOk", - "scalar": "gqaScalar", - "usesF16": false, - "hasCausal": true, - "causalRightAlign": true, - "headDim": "gqaHeadDim", - "headDimV4": "gqaHeadDim / 4", - "qHiddenV4": "dim(shapes.queryT, 2) / 4", - "kvNumHeads": "attrs.kv_num_heads", - "TILE_Q": "cachedPrefillQueryTile", - "TILE_K": "cachedClusterTileK if useSubgroups else cachedNoSgTileK", - "LPQ": "cachedPrefillLanesPerQuery", - "kvHeads": "attrs.kv_num_heads", - "inputVec4": "gqaInputVec4", - "inputScalar": "gqaScalar", - "batchNoSgReduction": "not useSubgroups", - "quantCacheFormat": "\"int8\"", - "quantCacheElement": "\"i32\"", - "quantCacheReadElement": "\"vec4\"", - "packed": "gqaHeadDim", - "qHidden": "dim(shapes.queryT, 2)", - "mode": "\"build_quant\"", - "bits": 8, - "qmax": 127, - "qmin": -128, - "shareNoSgProb": "batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ" - }, - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.QuantPresent", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k_f32", "src_v_f32", "k_scale", "v_scale", "present_key_quant_int8", "present_value_quant_int8", "params_quant_int8"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.QuantFlashPrefill", - "shader": "attn-flash-prefill-cluster.wgsl.jinja", - "derive": { "layout": "\"bsh\"", "qLayout": "\"bsh\"", "kvLayout": "\"bhsd\"" }, - "bindings": ["query_attention", "key_present_key_t", "value_present_value_t", "k_scale", "v_scale", "output_merge", "params_quant_int8_flash_prefill"], - "dispatch": { - "x": "ceilDiv(dim(shapes.queryT, 1), cachedPrefillQueryTile)", - "y": "attrs.num_heads", - "z": "dim(shapes.queryT, 0)" - } - } - ] - }, - { - "id": "quant_int4_flash_prefill", - "priority": 37, - "when": ["quantizedPromptOk", "prefillFlashShapeOk", "cachedSgPrefillOk or cachedNoSgClusterStorageOk", "attrs.kv_cache_bit_width == 4", "present.kScaleT", "plainAttentionOptions"], - "derive": { - "useSubgroups": "cachedSgPrefillOk", - "scalar": "gqaScalar", - "usesF16": false, - "hasCausal": true, - "causalRightAlign": true, - "headDim": "gqaHeadDim", - "headDimV4": "gqaHeadDim / 4", - "qHiddenV4": "dim(shapes.queryT, 2) / 4", - "kvNumHeads": "attrs.kv_num_heads", - "TILE_Q": "cachedPrefillQueryTile", - "TILE_K": "cachedClusterTileK if useSubgroups else cachedNoSgTileK", - "LPQ": "cachedPrefillLanesPerQuery", - "kvHeads": "attrs.kv_num_heads", - "inputVec4": "gqaInputVec4", - "inputScalar": "gqaScalar", - "batchNoSgReduction": "not useSubgroups", - "quantCacheFormat": "\"int4\"", - "quantCacheElement": "\"u32\"", - "quantCacheReadElement": "\"u32\"", - "packed": "gqaHeadDim / 2", - "qHidden": "dim(shapes.queryT, 2)", - "mode": "\"build_quant\"", - "bits": 4, - "qmax": 7, - "qmin": -8, - "shareNoSgProb": "batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ" - }, - "passes": [ - { - "id": "present", - "name": "GroupQueryAttention.QuantPresent", - "shader": "gqa-present.wgsl.jinja", - "bindings": ["src_k_f32", "src_v_f32", "k_scale", "v_scale", "present_key_quant_int8", "present_value_quant_int8", "params_quant_int8"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.QuantFlashPrefill", - "shader": "attn-flash-prefill-cluster.wgsl.jinja", - "derive": { "layout": "\"bsh\"", "qLayout": "\"bsh\"", "kvLayout": "\"bhsd\"" }, - "bindings": ["query_attention", "key_present_key_t", "value_present_value_t", "k_scale", "v_scale", "output_merge", "params_quant_int8_flash_prefill"], - "dispatch": { - "x": "ceilDiv(dim(shapes.queryT, 1), cachedPrefillQueryTile)", - "y": "attrs.num_heads", - "z": "dim(shapes.queryT, 0)" - } - } - ] - }, - { - "id": "share_append_split_decode_splitk", - "priority": 39, - "when": ["shareAppendOk", "decodeFlashShapeOk", "cachedSplitScratchFits", "plainAttentionOptions"], - "derive": { - "useSubgroups": "subgroupSplitK", - "cacheSeqlens": "true", - "scalar": "gqaScalar", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "kvNumHeads": "attrs.kv_num_heads", - "headDim": "gqaHeadDim", - "headDimV4": "gqaHeadDim / 4", - "numSplits": "cachedNumSplits", - "kvHeads": "attrs.kv_num_heads", - "packed": "gqaHeadDim", - "mode": "\"merge_share\"", - "inputVec4": "gqaInputVec4", - "inputScalar": "gqaScalar", - "zeroScalar": "gqaScalar" - }, - "intermediates": [ - { - "id": "partialOut", - "dtype": "float32", - "shape": "[dim(shapes.queryT, 0) * attrs.num_heads * (cachedNumSplits) * gqaHeadDim]" - }, - { - "id": "partialStats", - "dtype": "float32", - "shape": "[2 * dim(shapes.queryT, 0) * attrs.num_heads * (cachedNumSplits)]" - } - ], - "passes": [ - { - "id": "present_retain", - "name": "GroupQueryAttention.MergeShareRetain", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shareRegion": "\"retain\"" }, - "bindings": ["past_k", "past_v", "present_key_present", "present_value_present", "seqlens_k", "params__uniform"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [ - { "input": "past_k", "output": "present_key" }, - { "input": "past_v", "output": "present_value" } - ] - }, - { - "id": "present_append", - "name": "GroupQueryAttention.MergeShareAppend", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shareRegion": "\"append\"" }, - "bindings": ["new_k", "new_v", "present_key_present", "present_value_present", "seqlens_k", "params_gqa_present"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "split_attention", - "name": "GroupQueryAttention.DecodeSplitK", - "shader": "attn-flash-decode-splitk.wgsl.jinja", - "derive": { "layout": "\"bhsd\"" }, - "bindings": ["query_attention", "key_attention", "value_attention", "partial_out", "partial_stats", "seqlens_k", "params_split_attention"], - "dispatch": { "x": "cachedNumSplits", "y": "attrs.num_heads", "z": "dim(shapes.queryT, 0)" } - }, - { - "id": "merge", - "name": "GroupQueryAttention.DecodeSplitKMerge", - "shader": "attn-flash-decode-splitk-merge.wgsl.jinja", - "derive": { "layout": "\"bhsd\"" }, - "bindings": ["partial_out_merge", "partial_stats_merge", "output_merge"], - "dispatch": { "x": 1, "y": "attrs.num_heads", "z": "dim(shapes.queryT, 0)" } - } - ] - }, - { - "id": "share_append_split_flash_prefill", - "priority": 35, - "when": ["shareAppendOk", "prefillFlashShapeOk", "cachedSgPrefillOk or cachedNoSgClusterStorageOk", "plainAttentionOptions"], - "derive": { - "useSubgroups": "cachedSgPrefillOk", - "scalar": "gqaScalar", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "hasCausal": true, - "causalRightAlign": true, - "headDim": "gqaHeadDim", - "headDimV4": "gqaHeadDim / 4", - "qHiddenV4": "dim(shapes.queryT, 2) / 4", - "kvNumHeads": "attrs.kv_num_heads", - "TILE_Q": "cachedPrefillQueryTile", - "TILE_K": "cachedClusterTileK if useSubgroups else cachedNoSgTileK", - "LPQ": "cachedPrefillLanesPerQuery", - "kvHeads": "attrs.kv_num_heads", - "packed": "gqaHeadDim", - "mode": "\"merge_share\"", - "useSeqlens": true, - "inputVec4": "gqaInputVec4", - "inputScalar": "gqaScalar", - "batchNoSgReduction": "not useSubgroups", - "shareNoSgProb": "batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ" - }, - "passes": [ - { - "id": "present_retain", - "name": "GroupQueryAttention.MergeShareRetain", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shareRegion": "\"retain\"" }, - "bindings": ["past_k", "past_v", "present_key_present", "present_value_present", "seqlens_k", "params__uniform"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [ - { "input": "past_k", "output": "present_key" }, - { "input": "past_v", "output": "present_value" } - ] - }, - { - "id": "present_append", - "name": "GroupQueryAttention.MergeShareAppend", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shareRegion": "\"append\"" }, - "bindings": ["new_k", "new_v", "present_key_present", "present_value_present", "seqlens_k", "params_gqa_present"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.FlashPrefill", - "shader": "attn-flash-prefill-cluster.wgsl.jinja", - "derive": { "layout": "\"bsh\"", "qLayout": "\"bsh\"", "kvLayout": "\"bhsd\"" }, - "bindings": ["query_attention", "key_attention", "value_attention", "output_merge", "seqlens_k", "params_new_kv_past_flash_prefill"], - "dispatch": { - "x": "ceilDiv(dim(shapes.queryT, 1), TILE_Q)", - "y": "attrs.num_heads", - "z": "dim(shapes.queryT, 0)" - } - } - ] - }, - { - "id": "share_append_bidirectional_flash_prefill", - "priority": 36, - "when": ["shareAppendBidirectionalOk", "prefillFlashShapeOk", "cachedSgPrefillOk or cachedNoSgClusterStorageOk", "plainAttentionOptions"], - "derive": { - "useSubgroups": "cachedSgPrefillOk", - "scalar": "gqaScalar", - "usesF16": "tensorDtypes.queryT == \"float16\"", - "hasCausal": false, - "causalRightAlign": false, - "headDim": "gqaHeadDim", - "headDimV4": "gqaHeadDim / 4", - "qHiddenV4": "dim(shapes.queryT, 2) / 4", - "kvNumHeads": "attrs.kv_num_heads", - "TILE_Q": "cachedPrefillQueryTile", - "TILE_K": "cachedClusterTileK if useSubgroups else cachedNoSgTileK", - "LPQ": "cachedPrefillLanesPerQuery", - "kvHeads": "attrs.kv_num_heads", - "packed": "gqaHeadDim", - "mode": "\"merge_share\"", - "useSeqlens": true, - "inputVec4": "gqaInputVec4", - "inputScalar": "gqaScalar", - "batchNoSgReduction": "not useSubgroups", - "shareNoSgProb": "batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ" - }, - "passes": [ - { - "id": "present_retain", - "name": "GroupQueryAttention.MergeShareRetain", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shareRegion": "\"retain\"" }, - "bindings": ["past_k", "past_v", "present_key_present", "present_value_present", "seqlens_k", "params__uniform"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)", - "z": 1 - }, - "viewAlias": [ - { "input": "past_k", "output": "present_key" }, - { "input": "past_v", "output": "present_value" } - ] - }, - { - "id": "present_append", - "name": "GroupQueryAttention.MergeShareAppend", - "shader": "gqa-present.wgsl.jinja", - "derive": { "shareRegion": "\"append\"" }, - "bindings": ["new_k", "new_v", "present_key_present", "present_value_present", "seqlens_k", "params_gqa_present"], - "dispatch": { - "x": "min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "y": "ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)", - "z": 1 - } - }, - { - "id": "attention", - "name": "GroupQueryAttention.FlashPrefill", - "shader": "attn-flash-prefill-cluster.wgsl.jinja", - "derive": { "layout": "\"bsh\"", "qLayout": "\"bsh\"", "kvLayout": "\"bhsd\"" }, - "bindings": ["query_attention", "key_attention", "value_attention", "output_merge", "seqlens_k", "params_new_kv_past_flash_bidirectional"], - "dispatch": { - "x": "ceilDiv(dim(shapes.queryT, 1), TILE_Q)", - "y": "attrs.num_heads", - "z": "dim(shapes.queryT, 0)" - } - } - ] - } - ] -} +{"domain":"com.microsoft","name":"GroupQueryAttention","sinceVersion":1,"inputs":{"queryT":{"onnx":"query","dtype":"T","rank":3},"keyT":{"onnx":"key","dtype":"T","rank":3},"valueT":{"onnx":"value","dtype":"T","rank":3},"pastKeyT":{"onnx":"past_key","dtype":"T_CACHE","rank":4,"optional":true},"pastValueT":{"onnx":"past_value","dtype":"T_CACHE","rank":4,"optional":true},"seqlensKT":{"onnx":"seqlens_k","dtype":"M","rank":1},"totalSequenceLengthT":{"onnx":"total_sequence_length","dtype":"M","rank":1},"cosCacheT":{"onnx":"cos_cache","dtype":"T","rank":2,"optional":true},"sinCacheT":{"onnx":"sin_cache","dtype":"T","rank":2,"optional":true},"attentionBiasT":{"onnx":"attention_bias","dtype":"T","rank":4,"optional":true},"headSinkT":{"onnx":"head_sink","dtype":"T","rank":1,"optional":true},"kScaleT":{"onnx":"k_scale","dtype":"T_KV_SCALE","rank":1,"optional":true},"vScaleT":{"onnx":"v_scale","dtype":"T_KV_SCALE","rank":1,"optional":true},"qNormWeightT":{"onnx":"q_norm_weight","dtype":"T","rank":1,"optional":true},"kNormWeightT":{"onnx":"k_norm_weight","dtype":"T","rank":1,"optional":true}},"outputs":{"outputT":{"onnx":"output","dtype":"T","rank":3,"shape":"shapes.queryT"},"presentKeyT":{"onnx":"present_key","dtype":"T_CACHE","rank":4},"presentValueT":{"onnx":"present_value","dtype":"T_CACHE","rank":4}},"attributes":{"causal":{"default":1},"do_rotary":{"default":0},"k_quant_type":{"default":"NONE"},"local_window_size":{"default":-1},"qk_norm_epsilon":{"default":0.000001},"sliding_window_cache":{"default":0},"smooth_softmax":{"default":-1},"softcap":{"default":0},"v_quant_type":{"default":"NONE"},"kv_cache_bit_width":{},"kv_num_heads":{},"num_heads":{},"scale":{}},"attributeConstraints":{"causal":{"values":[0,1]},"do_rotary":{"values":[0,1]},"k_quant_type":{"values":["NONE","PER_TENSOR","PER_CHANNEL"]},"kv_cache_bit_width":{"values":[4,8]},"kv_num_heads":{"required":true},"num_heads":{"required":true},"sliding_window_cache":{"values":[0,1]},"v_quant_type":{"values":["NONE","PER_TENSOR","PER_CHANNEL"]}},"typeConstraints":{"T":["float32","float16"],"T_CACHE":["float32","float16","uint8","int8"],"T_KV_SCALE":["float32"],"M":["int32"]},"tunables":{"WORKGROUP_SIZE":{"default":256},"COPY_WORKGROUP_SIZE":{"default":64},"SCALAR_WORKGROUP_SIZE":{"default":64},"COOPERATIVE_QUERY_THRESHOLD":{"default":6144},"MAX_SPLITS":{"default":16},"QKV_SPLIT_TILE_K":{"default":128},"CACHED_SPLIT_TILE_K":{"default":256},"FLASH_MIN_HEAD_DIM":{"default":32},"FLASH_MAX_HEAD_DIM":{"default":256},"PREFILL_QUERY_TILE":{"default":32},"PREFILL_LANES_PER_QUERY":{"default":8},"PREFILL_QUERY_TILE_F16":{"default":16},"PREFILL_LANES_PER_QUERY_F16":{"default":8},"QKV_PREFILL_MIN_QUERY_TOKENS":{"default":31},"QKV_DECODE_MIN_KV_TOKENS":{"default":512},"CACHED_FLASH_MIN_HEAD_DIM":{"default":16},"CACHED_DECODE_MIN_KV_TOKENS":{"default":128},"CLUSTER_TILE_K_F32":{"default":8},"CLUSTER_TILE_K_F16":{"default":8},"NO_SG_TILE_K_MAX":{"default":16},"COOPERATIVE_WORKGROUP_SIZE":{"default":32},"CLUSTER_MAX_SLICE":{"default":8},"MATERIALIZED_SGMAT_QUERY_TILE":{"default":64},"MATERIALIZED_SGMAT_KEY_TILE":{"default":64},"MATERIALIZED_SGMAT_INNER_TILE":{"default":32},"MATERIALIZED_SOFTMAX_WORKGROUP_SIZE":{"default":256},"MATERIALIZED_SGMAT_MIN_SEQ":{"default":256},"MATERIALIZED_SGMAT_PAST_MIN_SEQ":{"default":256},"MATERIALIZED_SGMAT_WINDOW_MIN_QSEQ":{"default":128},"MATERIALIZED_SGMAT_APPEND_MIN_QSEQ":{"default":128}},"derive":{"nvidiaAdapter":"has(device.adapterInfo, \"vendor\") and device.adapterInfo.vendor == \"nvidia\"","deviceWorkgroupCap":"min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX)","wave32Adapter":"has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize == 32 and device.adapterInfo.subgroupMaxSize == 32","subgroupsWave32":"device.features.has(\"subgroups\") and wave32Adapter","narrowSubgroupRange":"has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize < device.adapterInfo.subgroupMaxSize and device.adapterInfo.subgroupMaxSize <= 16","canPinSubgroupSize32":"device.features.has(\"subgroups\") and device.features.has(\"subgroup-size-control\") and has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize <= 32 and device.adapterInfo.subgroupMaxSize >= 32","pinSubgroupSize32":"canPinSubgroupSize32 and not wave32Adapter","wave32Effective":"wave32Adapter or pinSubgroupSize32","wave32SubgroupsUsable":"subgroupsWave32 or pinSubgroupSize32","narrowSimdWithoutSubgroups":"not device.features.has(\"subgroups\") and has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize < 32 and device.adapterInfo.subgroupMaxSize <= 32","variableSubgroup16To32":"device.features.has(\"subgroups\") and has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize == 16 and device.adapterInfo.subgroupMaxSize == 32","subgroupMatrixTopologyBytes":"3 * 16","matrixSubgroupRangeReported":"has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\")","matrixAllowsWidth32":"(not has(device.adapterInfo, \"subgroupMinSize\") and not has(device.adapterInfo, \"subgroupMaxSize\")) or (matrixSubgroupRangeReported and device.adapterInfo.subgroupMinSize <= 32 and device.adapterInfo.subgroupMaxSize >= 32)","matrixAllowsWidth64":"matrixSubgroupRangeReported and device.adapterInfo.subgroupMinSize <= 64 and device.adapterInfo.subgroupMaxSize >= 64","matrixSubgroupWidth":"32 if matrixAllowsWidth32 else (64 if matrixAllowsWidth64 else 0)","boundValueNumerator":"tensorDtypes.queryT == \"float32\" and not device.features.has(\"shader-f16\")","windowCacheRequested":"attrs.sliding_window_cache == 1","headDimPlan":"dim(shapes.queryT, 2) / attrs.num_heads if (ranks.queryT == 3 and attrs.num_heads > 0) else 0","qkvFlashWorkgroupBytes":"16 * ((1 if tensorDtypes.queryT == \"float32\" else 2) * ceilDiv(headDimPlan, 4) + 3 * ceilDiv(tunables.WORKGROUP_SIZE, 4) + ceilDiv(tunables.WORKGROUP_SIZE, 128) + 1)","copyWorkgroupSize":"min(tunables.COPY_WORKGROUP_SIZE, min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX))","scalarWorkgroupSize":"min(tunables.SCALAR_WORKGROUP_SIZE, min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX))","copyWorkgroupOk":"copyWorkgroupSize >= 1","scalarWorkgroupOk":"scalarWorkgroupSize >= 1","metadataInputsOk":"present.seqlensKT and present.totalSequenceLengthT","unquantizedCacheAttrs":"attrs.k_quant_type == \"NONE\" and attrs.v_quant_type == \"NONE\" and not attrs.kv_cache_bit_width and not present.kScaleT and not present.vScaleT","qkNormInputsOk":"present.qNormWeightT == present.kNormWeightT","rotaryRequested":"attrs.do_rotary == 1","gqaRotaryCacheRows":"min(dim(shapes.cosCacheT, 0), dim(shapes.sinCacheT, 0)) if present.cosCacheT and present.sinCacheT else 0","noAuxAttentionInputs":"not present.cosCacheT and not rotaryRequested and not present.qNormWeightT and not present.attentionBiasT and not present.headSinkT","standardSoftmax":"attrs.softcap == 0 and attrs.smooth_softmax != 1","plainAttentionOptions":"noAuxAttentionInputs and standardSoftmax","causalNoWindow":"attrs.causal == 1 and attrs.local_window_size <= 0","qkvCausalQ32Preferred":"variableSubgroup16To32 and causalNoWindow and headDimPlan / 4 <= device.adapterInfo.subgroupMinSize and ceilDiv(dim(shapes.queryT, 1), 32) >= ceilDiv((headDimPlan / 4) * (headDimPlan / 4), device.adapterInfo.subgroupMaxSize)","qkvMaskModeOk":"(attrs.causal == 0 and attrs.local_window_size == -1) or (attrs.causal == 1 and attrs.local_window_size > 0) or causalNoWindow","qkvContractOk":"plainAttentionOptions and not windowCacheRequested and copyWorkgroupOk and metadataInputsOk and unquantizedCacheAttrs and qkNormInputsOk and qkvMaskModeOk and (not present.pastKeyT) and (not present.pastValueT) and ranks.queryT == 3 and ranks.keyT == 3 and ranks.valueT == 3 and ranks.outputT == 3 and ranks.presentKeyT == 4 and ranks.presentValueT == 4 and (tensorDtypes.queryT == \"float32\" or tensorDtypes.queryT == \"float16\") and f16Ok(tensorDtypes.queryT) and tensorDtypes.keyT == tensorDtypes.queryT and tensorDtypes.valueT == tensorDtypes.queryT and tensorDtypes.outputT == tensorDtypes.queryT and (tensorDtypes.presentKeyT == \"float32\" or tensorDtypes.presentKeyT == \"float16\") and f16Ok(tensorDtypes.presentKeyT) and tensorDtypes.presentValueT == tensorDtypes.presentKeyT and attrs.num_heads > 0 and attrs.kv_num_heads > 0 and attrs.num_heads % attrs.kv_num_heads == 0 and dim(shapes.queryT, 2) % attrs.num_heads == 0 and dim(shapes.keyT, 2) == attrs.kv_num_heads * headDimPlan and sameShape(shapes.valueT, shapes.keyT) and dim(shapes.queryT, 0) == dim(shapes.keyT, 0) and sameShape(shapes.outputT, shapes.queryT) and dim(shapes.presentKeyT, 0) == dim(shapes.queryT, 0) and dim(shapes.presentKeyT, 1) == attrs.kv_num_heads and dim(shapes.presentKeyT, 2) == dim(shapes.keyT, 1) and dim(shapes.presentKeyT, 3) == headDimPlan and sameShape(shapes.presentValueT, shapes.presentKeyT)","flashWorkgroupOk":"tunables.WORKGROUP_SIZE <= deviceWorkgroupCap","flashShapeOk":"qkvContractOk and flashWorkgroupOk and headDimPlan % 4 == 0 and headDimPlan >= tunables.FLASH_MIN_HEAD_DIM and headDimPlan <= tunables.FLASH_MAX_HEAD_DIM and (dim(shapes.queryT, 1) * attrs.num_heads >= 248 or (dim(shapes.queryT, 1) == 1 and dim(shapes.keyT, 1) >= tunables.QKV_DECODE_MIN_KV_TOKENS) or (dim(shapes.queryT, 1) > 1 and dim(shapes.keyT, 1) >= 2048)) and dim(shapes.queryT, 0) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 1) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","decodeSplitKShapeOk":"qkvContractOk and flashWorkgroupOk and dim(shapes.queryT, 1) == 1 and dim(shapes.keyT, 1) >= tunables.QKV_DECODE_MIN_KV_TOKENS and headDimPlan % 4 == 0 and headDimPlan >= tunables.FLASH_MIN_HEAD_DIM and headDimPlan <= tunables.FLASH_MAX_HEAD_DIM and dim(shapes.queryT, 0) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","fallbackShapeOk":"qkvContractOk and headDimPlan <= deviceWorkgroupCap and headDimPlan <= tunables.FLASH_MAX_HEAD_DIM","gqaHeadDim":"dim(shapes.queryT, 2) / attrs.num_heads","qkvScalar":"\"f16\" if tensorDtypes.queryT == \"float16\" else \"f32\"","qkvInputVec4":"\"vec4\" if tensorDtypes.queryT == \"float16\" else \"vec4\"","qkvCacheScalar":"\"f16\" if tensorDtypes.presentKeyT == \"float16\" else \"f32\"","qkvCacheVec4":"\"vec4\" if tensorDtypes.presentKeyT == \"float16\" else \"vec4\"","qkvUsesF16":"tensorDtypes.queryT == \"float16\" or tensorDtypes.presentKeyT == \"float16\"","gqaScalar":"\"f16\" if tensorDtypes.queryT == \"float16\" else \"f32\"","gqaInputVec4":"\"vec4\" if tensorDtypes.queryT == \"float16\" else \"vec4\"","qkvNumSplits":"min(tunables.MAX_SPLITS, ceilDiv(dim(shapes.keyT, 1), tunables.QKV_SPLIT_TILE_K))","cachedNumSplits":"min(tunables.MAX_SPLITS, ceilDiv(dim(shapes.presentKeyT, 2), tunables.CACHED_SPLIT_TILE_K))","cachedBaseOk":"attrs.causal == 1 and metadataInputsOk and qkNormInputsOk","sharedKvCacheOk":"cachedBaseOk and unquantizedCacheAttrs and not windowCacheRequested and copyWorkgroupOk and present.pastKeyT and present.pastValueT and dim(shapes.keyT, 1) == 0 and dim(shapes.queryT, 2) % attrs.num_heads == 0 and dim(shapes.pastKeyT, 1) == attrs.kv_num_heads and dim(shapes.pastKeyT, 3) == gqaHeadDim","gqaFlashHd":"gqaHeadDim >= tunables.CACHED_FLASH_MIN_HEAD_DIM and gqaHeadDim <= tunables.FLASH_MAX_HEAD_DIM","f16OrF32":"(tensorDtypes.queryT == \"float32\" or tensorDtypes.queryT == \"float16\") and f16Ok(tensorDtypes.queryT) and tensorDtypes.keyT == tensorDtypes.queryT and tensorDtypes.valueT == tensorDtypes.queryT and tensorDtypes.outputT == tensorDtypes.queryT and tensorDtypes.presentKeyT == tensorDtypes.queryT and tensorDtypes.presentValueT == tensorDtypes.queryT and ((not present.pastKeyT) or tensorDtypes.pastKeyT == tensorDtypes.queryT) and ((not present.pastValueT) or tensorDtypes.pastValueT == tensorDtypes.queryT)","subgroupCluster8":"device.features.has(\"subgroups\") and has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize >= 8 and device.adapterInfo.subgroupMinSize % 8 == 0 and device.adapterInfo.subgroupMaxSize % 8 == 0","qkvPrefillQueryTile":"tunables.PREFILL_QUERY_TILE_F16 if tensorDtypes.queryT == \"float16\" else tunables.PREFILL_QUERY_TILE","f32WidePrefillLanes":"device.features.has(\"subgroups\") and has(device.adapterInfo, \"subgroupMinSize\") and device.adapterInfo.subgroupMinSize >= 2 * tunables.PREFILL_LANES_PER_QUERY and 2 * tunables.PREFILL_QUERY_TILE * tunables.PREFILL_LANES_PER_QUERY <= min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX) and not nvidiaAdapter","qkvPrefillLanesPerQuery":"max(tunables.PREFILL_LANES_PER_QUERY_F16 if tensorDtypes.queryT == \"float16\" else (2 * tunables.PREFILL_LANES_PER_QUERY if f32WidePrefillLanes and headDimPlan % (8 * tunables.PREFILL_LANES_PER_QUERY) == 0 else tunables.PREFILL_LANES_PER_QUERY), ceilDiv(headDimPlan / 4, tunables.CLUSTER_MAX_SLICE))","cachedPrefillQueryTile":"tunables.PREFILL_QUERY_TILE_F16 if tensorDtypes.queryT == \"float16\" else tunables.PREFILL_QUERY_TILE","biasPrefillQueryTile":"min(cachedPrefillQueryTile, 16) if tensorDtypes.queryT == \"float32\" and narrowSimdWithoutSubgroups else cachedPrefillQueryTile","cachedWideLanes":"min(2 * tunables.PREFILL_LANES_PER_QUERY_F16, device.adapterInfo.subgroupMinSize, floor(min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX) / cachedPrefillQueryTile)) if variableSubgroup16To32 else tunables.PREFILL_LANES_PER_QUERY_F16","cachedWideKeyTile":"min(tunables.CLUSTER_TILE_K_F16, max(1, floor(tunables.PREFILL_LANES_PER_QUERY_F16 / 2)))","cachedWideCluster":"variableSubgroup16To32 and tensorDtypes.queryT == \"float16\" and attrs.causal == 0 and present.pastKeyT and present.pastValueT and dim(shapes.keyT, 1) > 0 and dim(shapes.presentKeyT, 2) == dim(shapes.pastKeyT, 2) and gqaHeadDim <= tunables.QKV_SPLIT_TILE_K and cachedWideLanes > tunables.PREFILL_LANES_PER_QUERY_F16 and pow2ceil(cachedWideLanes) == cachedWideLanes and device.adapterInfo.subgroupMinSize % cachedWideLanes == 0 and device.adapterInfo.subgroupMaxSize % cachedWideLanes == 0 and gqaHeadDim % (4 * cachedWideLanes) == 0 and dim(shapes.queryT, 1) % cachedPrefillQueryTile == 0 and dim(shapes.pastKeyT, 2) % cachedWideKeyTile == 0","cachedPrefillLanesPerQuery":"cachedWideLanes if cachedWideCluster else (max(tunables.PREFILL_LANES_PER_QUERY_F16 if tensorDtypes.queryT == \"float16\" else (2 * tunables.PREFILL_LANES_PER_QUERY if f32WidePrefillLanes and gqaHeadDim % (8 * tunables.PREFILL_LANES_PER_QUERY) == 0 else tunables.PREFILL_LANES_PER_QUERY), ceilDiv(gqaHeadDim / 4, tunables.CLUSTER_MAX_SLICE)))","subgroupQkvPrefillCluster":"not narrowSubgroupRange and device.features.has(\"subgroups\") and has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize >= qkvPrefillLanesPerQuery and device.adapterInfo.subgroupMinSize % qkvPrefillLanesPerQuery == 0 and device.adapterInfo.subgroupMaxSize % qkvPrefillLanesPerQuery == 0","subgroupCachedPrefillCluster":"not narrowSubgroupRange and device.features.has(\"subgroups\") and has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize >= cachedPrefillLanesPerQuery and device.adapterInfo.subgroupMinSize % cachedPrefillLanesPerQuery == 0 and device.adapterInfo.subgroupMaxSize % cachedPrefillLanesPerQuery == 0","subgroupSplitK":"subgroupCluster8 and device.adapterInfo.subgroupMaxSize <= tunables.WORKGROUP_SIZE and tunables.WORKGROUP_SIZE % device.adapterInfo.subgroupMinSize == 0 and tunables.WORKGROUP_SIZE % device.adapterInfo.subgroupMaxSize == 0","gqaQueryCount":"dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)","gqaCooperativeLaneCapacity":"floor((floor(device.limits.maxComputeWorkgroupStorageSize / 16) * 4 - gqaHeadDim) / 2)","gqaCooperativeWorkgroupSize":"min(tunables.COOPERATIVE_WORKGROUP_SIZE, deviceWorkgroupCap, max(1, gqaCooperativeLaneCapacity))","cooperativeWorkgroupOk":"gqaCooperativeWorkgroupSize >= 1 and gqaCooperativeWorkgroupSize <= deviceWorkgroupCap","gqaCoopWorkgroupBytes":"ceilDiv((gqaHeadDim + gqaCooperativeWorkgroupSize * 2) * 4, 16) * 16","gqaCoop":"cooperativeWorkgroupOk and gqaQueryCount < tunables.COOPERATIVE_QUERY_THRESHOLD and gqaCoopWorkgroupBytes <= device.limits.maxComputeWorkgroupStorageSize","gqaScalarDispatchOk":"gqaCoop or scalarWorkgroupOk","gqaDispatchUnits":"gqaQueryCount if gqaCoop else ceilDiv(gqaQueryCount, scalarWorkgroupSize)","gqaDispatchFits":"dim(shapes.queryT, 0) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","sharedKvFloatOk":"sharedKvCacheOk and f16OrF32","newKvPastOk":"cachedBaseOk and unquantizedCacheAttrs and not windowCacheRequested and copyWorkgroupOk and present.pastKeyT and present.pastValueT and dim(shapes.keyT, 1) > 0 and f16OrF32 and dim(shapes.queryT, 2) % attrs.num_heads == 0 and dim(shapes.pastKeyT, 1) == attrs.kv_num_heads and dim(shapes.pastKeyT, 3) == gqaHeadDim and dim(shapes.presentKeyT, 2) == dim(shapes.pastKeyT, 2) + dim(shapes.keyT, 1)","windowCapacity":"dim(shapes.pastKeyT, 2) if present.pastKeyT else 0","windowStageCapacity":"windowCapacity + dim(shapes.keyT, 1)","windowStageElements":"dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity * gqaHeadDim","windowStageShapeOk":"ranks.keyT == 3 and ranks.valueT == 3 and ranks.pastKeyT == 4 and ranks.pastValueT == 4 and ranks.presentKeyT == 4 and ranks.presentValueT == 4 and dim(shapes.queryT, 1) == dim(shapes.keyT, 1) and sameShape(shapes.keyT, shapes.valueT) and dim(shapes.keyT, 0) == dim(shapes.queryT, 0) and dim(shapes.keyT, 2) == attrs.kv_num_heads * gqaHeadDim and sameShape(shapes.pastKeyT, shapes.pastValueT) and sameShape(shapes.presentKeyT, shapes.pastKeyT) and sameShape(shapes.presentValueT, shapes.pastKeyT) and dim(shapes.pastKeyT, 0) == dim(shapes.queryT, 0) and dim(shapes.seqlensKT, 0) == dim(shapes.queryT, 0) and dim(shapes.totalSequenceLengthT, 0) == 1 and sameShape(shapes.outputT, shapes.queryT) and attrs.num_heads > 0 and attrs.kv_num_heads > 0 and attrs.num_heads % attrs.kv_num_heads == 0 and windowCapacity > 0 and gqaHeadDim > 0","windowStageFits":"windowStageCapacity <= 2147483647 and windowStageElements <= 4294967295 and windowStageElements * (2 if tensorDtypes.queryT == \"float16\" else 4) <= min(device.limits.maxBufferSize, device.limits.maxStorageBufferBindingSize) and dim(shapes.queryT, 0) * 8 <= min(device.limits.maxBufferSize, device.limits.maxStorageBufferBindingSize) and numel(shapes.queryT) <= 4294967295 and numel(shapes.queryT) * (2 if tensorDtypes.queryT == \"float16\" else 4) <= min(device.limits.maxBufferSize, device.limits.maxStorageBufferBindingSize)","windowFitsCapacity":"attrs.local_window_size > 0 and attrs.local_window_size <= windowCapacity","windowShiftCacheOk":"cachedBaseOk and unquantizedCacheAttrs and copyWorkgroupOk and present.pastKeyT and present.pastValueT and dim(shapes.keyT, 1) > 0 and f16OrF32 and dim(shapes.queryT, 2) % attrs.num_heads == 0 and dim(shapes.pastKeyT, 1) == attrs.kv_num_heads and dim(shapes.pastKeyT, 3) == gqaHeadDim and windowCacheRequested and dim(shapes.presentKeyT, 2) == windowCapacity and windowFitsCapacity and windowStageShapeOk and windowStageFits","windowShiftOk":"windowShiftCacheOk and not present.cosCacheT and not rotaryRequested","windowShiftRotaryOk":"windowShiftCacheOk and present.cosCacheT and present.sinCacheT and rotaryRequested and tensorDtypes.queryT == \"float32\" and gqaHeadDim % 2 == 0 and dim(shapes.keyT, 1) == dim(shapes.queryT, 1)","windowAuxOk":"not present.qNormWeightT and not (present.attentionBiasT and present.headSinkT) and (not present.headSinkT or tensorDtypes.headSinkT == tensorDtypes.queryT) and (not present.attentionBiasT or (tensorDtypes.attentionBiasT == tensorDtypes.queryT and dim(shapes.attentionBiasT, 2) == dim(shapes.queryT, 1) and (dim(shapes.attentionBiasT, 0) == dim(shapes.queryT, 0) or dim(shapes.attentionBiasT, 0) == 1) and (dim(shapes.attentionBiasT, 1) == attrs.num_heads or dim(shapes.attentionBiasT, 1) == 1)))","cacheCopyMode":"dim(shapes.keyT, 1) == 0","shareAppendShapeOk":"unquantizedCacheAttrs and copyWorkgroupOk and present.pastKeyT and present.pastValueT and dim(shapes.keyT, 1) > 0 and f16OrF32 and dim(shapes.queryT, 2) % attrs.num_heads == 0 and dim(shapes.pastKeyT, 1) == attrs.kv_num_heads and dim(shapes.pastKeyT, 3) == gqaHeadDim and not windowCacheRequested and dim(shapes.presentKeyT, 2) == dim(shapes.pastKeyT, 2) and dim(shapes.keyT, 1) <= dim(shapes.pastKeyT, 2)","shareAppendOk":"cachedBaseOk and shareAppendShapeOk","cachedBidirectionalBaseOk":"attrs.causal == 0 and attrs.local_window_size == -1 and metadataInputsOk and qkNormInputsOk","shareAppendBidirectionalOk":"cachedBidirectionalBaseOk and shareAppendShapeOk","decodeFlashShapeOk":"flashWorkgroupOk and dim(shapes.queryT, 1) == 1 and gqaHeadDim % 4 == 0 and gqaFlashHd and dim(shapes.presentKeyT, 2) >= tunables.CACHED_DECODE_MIN_KV_TOKENS and gqaDispatchFits","qkvPrefillClusterWorkgroupSize":"qkvPrefillQueryTile * qkvPrefillLanesPerQuery","cachedPrefillClusterWorkgroupSize":"cachedPrefillQueryTile * cachedPrefillLanesPerQuery","cachedPrefillClusterWorkgroupOk":"cachedPrefillClusterWorkgroupSize <= deviceWorkgroupCap","prefillFlashShapeOk":"cachedPrefillClusterWorkgroupOk and gqaHeadDim % (4 * cachedPrefillLanesPerQuery) == 0 and gqaFlashHd and dim(shapes.queryT, 1) >= cachedPrefillQueryTile and gqaDispatchFits and ceilDiv(dim(shapes.queryT, 1), cachedPrefillQueryTile) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","quantScaleShapeOk":"((attrs.k_quant_type == \"PER_TENSOR\" and numel(shapes.kScaleT) == 1) or (attrs.k_quant_type == \"PER_CHANNEL\" and numel(shapes.kScaleT) == attrs.kv_num_heads * gqaHeadDim)) and ((attrs.v_quant_type == \"PER_TENSOR\" and numel(shapes.vScaleT) == 1) or (attrs.v_quant_type == \"PER_CHANNEL\" and numel(shapes.vScaleT) == attrs.kv_num_heads * gqaHeadDim))","quantizedNewKvOk":"cachedBaseOk and not windowCacheRequested and copyWorkgroupOk and present.kScaleT and present.vScaleT and attrs.k_quant_type == attrs.v_quant_type and attrs.k_quant_type != \"NONE\" and (attrs.kv_cache_bit_width == 4 or attrs.kv_cache_bit_width == 8) and quantScaleShapeOk and tensorDtypes.queryT == \"float32\" and tensorDtypes.keyT == \"float32\" and tensorDtypes.valueT == \"float32\" and tensorDtypes.outputT == \"float32\" and tensorDtypes.presentKeyT == (\"uint8\" if attrs.kv_cache_bit_width == 4 else \"int8\") and tensorDtypes.presentValueT == tensorDtypes.presentKeyT and dim(shapes.presentKeyT, 3) == gqaHeadDim / (8 / attrs.kv_cache_bit_width) and dim(shapes.presentValueT, 3) == dim(shapes.presentKeyT, 3) and dim(shapes.keyT, 1) > 0 and gqaHeadDim % 2 == 0","quantizedPromptOk":"quantizedNewKvOk and dim(shapes.keyT, 1) == dim(shapes.presentKeyT, 2)","quantizedDecodeOptionsOk":"plainAttentionOptions and not present.sinCacheT and not present.kNormWeightT","quantizedCachedDecodeOk":"not windowCacheRequested and quantizedNewKvOk and quantizedDecodeOptionsOk and attrs.kv_cache_bit_width == 8 and present.pastKeyT and present.pastValueT and dim(shapes.queryT, 1) == 1 and dim(shapes.keyT, 1) == 1 and tensorDtypes.pastKeyT == \"int8\" and tensorDtypes.pastValueT == \"int8\" and tensorDtypes.presentKeyT == \"int8\" and tensorDtypes.presentValueT == \"int8\" and dim(shapes.pastKeyT, 0) == dim(shapes.presentKeyT, 0) and dim(shapes.pastKeyT, 1) == dim(shapes.presentKeyT, 1) and dim(shapes.pastKeyT, 2) == dim(shapes.presentKeyT, 2) and dim(shapes.pastKeyT, 3) == dim(shapes.presentKeyT, 3)","qkvSplitScratchBytes":"dim(shapes.queryT, 0) * attrs.num_heads * qkvNumSplits * headDimPlan * 4","qkvSplitStatsBytes":"2 * dim(shapes.queryT, 0) * attrs.num_heads * qkvNumSplits * 4","qkvSplitScratchFits":"qkvSplitScratchBytes <= device.limits.maxStorageBufferBindingSize and qkvSplitScratchBytes <= device.limits.maxBufferSize and qkvSplitStatsBytes <= device.limits.maxStorageBufferBindingSize and qkvSplitStatsBytes <= device.limits.maxBufferSize","cachedSplitScratchBytes":"dim(shapes.queryT, 0) * attrs.num_heads * cachedNumSplits * gqaHeadDim * 4","cachedSplitStatsBytes":"2 * dim(shapes.queryT, 0) * attrs.num_heads * cachedNumSplits * 4","cachedSplitScratchFits":"cachedSplitScratchBytes <= device.limits.maxStorageBufferBindingSize and cachedSplitScratchBytes <= device.limits.maxBufferSize and cachedSplitStatsBytes <= device.limits.maxStorageBufferBindingSize and cachedSplitStatsBytes <= device.limits.maxBufferSize","qPrepScratchBytes":"numel(shapes.queryT) * 4","qPrepScratchFits":"qPrepScratchBytes <= device.limits.maxStorageBufferBindingSize and qPrepScratchBytes <= device.limits.maxBufferSize","qkvTiledWorkgroupBytes":"dim(shapes.valueT, 2) / attrs.kv_num_heads * 32 * 4","qkvTiledStorageOk":"qkvTiledWorkgroupBytes <= device.limits.maxComputeWorkgroupStorageSize","qkvClusterTileK":"tunables.CLUSTER_TILE_K_F32 if tensorDtypes.queryT == \"float32\" and headDimPlan <= tunables.QKV_SPLIT_TILE_K else tunables.CLUSTER_TILE_K_F16","qkvClusterWorkgroupBytes":"qkvClusterTileK * headDimPlan * (8 if tensorDtypes.queryT == \"float32\" else 4)","qkvClusterStorageOk":"qkvClusterWorkgroupBytes <= device.limits.maxComputeWorkgroupStorageSize","qkvF32ClusterRegisterGeometry":"tensorDtypes.queryT != \"float32\" or (headDimPlan % 4 == 0 and headDimPlan / (4 * qkvPrefillLanesPerQuery) <= tunables.CLUSTER_MAX_SLICE)","cachedF32ClusterRegisterGeometry":"tensorDtypes.queryT != \"float32\" or (gqaHeadDim % 4 == 0 and gqaHeadDim / (4 * cachedPrefillLanesPerQuery) <= tunables.CLUSTER_MAX_SLICE)","qkvNoSgReductionBytesPerKey":"qkvPrefillClusterWorkgroupSize * 4","cachedNoSgReductionBytesPerKey":"cachedPrefillClusterWorkgroupSize * 4","qkvNoSgTileBytes":"headDimPlan * (8 if tensorDtypes.queryT == \"float32\" else 4) + qkvNoSgReductionBytesPerKey","qkvNoSgTileK":"min(tunables.NO_SG_TILE_K_MAX, max(1, floor(device.limits.maxComputeWorkgroupStorageSize / qkvNoSgTileBytes)))","qkvNoSgWorkgroupBytes":"qkvNoSgTileK * qkvNoSgTileBytes + max(0, 2 - qkvNoSgTileK) * qkvNoSgReductionBytesPerKey","qkvNoSgClusterStorageOk":"qkvNoSgWorkgroupBytes <= device.limits.maxComputeWorkgroupStorageSize","qkvSgClusterOk":"qkvClusterStorageOk and qkvF32ClusterRegisterGeometry and subgroupQkvPrefillCluster","cachedClusterTileK":"cachedWideKeyTile if cachedWideCluster else (min(tunables.CLUSTER_TILE_K_F32, max(1, floor(cachedPrefillLanesPerQuery / 2))) if variableSubgroup16To32 and tensorDtypes.queryT == \"float32\" and gqaHeadDim <= tunables.QKV_SPLIT_TILE_K and tunables.CLUSTER_TILE_K_F32 <= 16 and gqaHeadDim / (4 * cachedPrefillLanesPerQuery) <= 4 and cachedPrefillQueryTile % 2 == 0 else ((2 * tunables.CLUSTER_TILE_K_F32 if f32WidePrefillLanes and device.adapterInfo.subgroupMinSize >= 32 and dim(shapes.queryT, 1) >= 128 else tunables.CLUSTER_TILE_K_F32) if tensorDtypes.queryT == \"float32\" and gqaHeadDim <= tunables.QKV_SPLIT_TILE_K else tunables.CLUSTER_TILE_K_F16))","cachedClusterWorkgroupBytes":"cachedClusterTileK * gqaHeadDim * (8 if tensorDtypes.queryT == \"float32\" else 4)","cachedClusterStorageOk":"cachedClusterWorkgroupBytes <= device.limits.maxComputeWorkgroupStorageSize","cachedMaskClusterWorkgroupBytes":"cachedClusterWorkgroupBytes + cachedPrefillQueryTile * cachedClusterTileK * 4","cachedMaskClusterStorageOk":"cachedMaskClusterWorkgroupBytes <= device.limits.maxComputeWorkgroupStorageSize","cachedNoSgTileBytes":"gqaHeadDim * (8 if tensorDtypes.queryT == \"float32\" else 4) + cachedNoSgReductionBytesPerKey","cachedNoSgTileK":"min(tunables.NO_SG_TILE_K_MAX, max(1, floor(device.limits.maxComputeWorkgroupStorageSize / cachedNoSgTileBytes)))","cachedNoSgWorkgroupBytes":"cachedNoSgTileK * cachedNoSgTileBytes","cachedNoSgClusterStorageOk":"cachedNoSgWorkgroupBytes <= device.limits.maxComputeWorkgroupStorageSize","cachedSgPrefillOk":"cachedClusterStorageOk and subgroupCachedPrefillCluster and cachedF32ClusterRegisterGeometry","cachedMaskSgPrefillOk":"cachedMaskClusterStorageOk and subgroupCachedPrefillCluster and cachedF32ClusterRegisterGeometry","gqaMatQueryTile":"tunables.MATERIALIZED_SGMAT_QUERY_TILE","gqaMatKeyTile":"tunables.MATERIALIZED_SGMAT_KEY_TILE","gqaMatInnerTile":"tunables.MATERIALIZED_SGMAT_INNER_TILE","gqaMatSubgroupRows":"floor(gqaMatQueryTile / 16)","gqaMatSubgroupCols":"floor(gqaMatKeyTile / 32)","gqaMatWorkgroupSize":"gqaMatSubgroupRows * gqaMatSubgroupCols * 32","gqaMatCompactStorageBytes":"((3 * gqaMatQueryTile + gqaMatKeyTile) * gqaMatInnerTile * 2 if tensorDtypes.queryT == \"float16\" else (gqaMatQueryTile + gqaMatKeyTile) * gqaMatInnerTile * 4) + subgroupMatrixTopologyBytes","gqaMatApplyStorageBytes":"gqaMatCompactStorageBytes + gqaMatQueryTile * 8 + (0 if qkvContractOk else 32)","gqaMatGeometryOk":"gqaMatQueryTile >= 16 and gqaMatQueryTile % 16 == 0 and gqaMatKeyTile >= 32 and gqaMatKeyTile <= 64 and gqaMatKeyTile % 32 == 0 and gqaMatInnerTile == 32 and gqaMatQueryTile >= 64 and gqaMatKeyTile >= 64","gqaMatResourcesFit":"gqaMatGeometryOk and gqaMatWorkgroupSize <= deviceWorkgroupCap and gqaMatApplyStorageBytes <= device.limits.maxComputeWorkgroupStorageSize","gqaMatScoreBytes":"dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.keyT, 1) * 4","gqaMatScoreFits":"gqaMatScoreBytes <= device.limits.maxStorageBufferBindingSize and gqaMatScoreBytes <= device.limits.maxBufferSize","gqaMatBuffersFit":"numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.keyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.valueT) * 4 <= device.limits.maxStorageBufferBindingSize","gqaMatDispatchFits":"ceilDiv(dim(shapes.keyT, 1), gqaMatKeyTile) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","gqaMatRowStatsWg":"min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)","gqaMatRows":"dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)","scoreQueryTiles":"ceilDiv(dim(shapes.queryT, 1), 32)","scoreKeyTiles":"ceilDiv(dim(shapes.keyT, 1), 32)","scoreRangeCount":"dim(shapes.queryT, 0) * (attrs.num_heads * scoreQueryTiles + attrs.kv_num_heads * scoreKeyTiles)","adaptiveScores":"max(scoreQueryTiles, scoreKeyTiles) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and scoreRangeCount * 16 <= min(device.limits.maxBufferSize, device.limits.maxStorageBufferBindingSize)","gqaMatRowDispatchFits":"min(gqaMatRows, DISPATCH_FOLD_WIDTH) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(gqaMatRows, DISPATCH_FOLD_WIDTH) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","gqaMatPastQSeq":"dim(shapes.queryT, 1)","gqaMatPastKvSeq":"dim(shapes.presentKeyT, 2)","gqaMatPastScoreBytes":"dim(shapes.queryT, 0) * attrs.num_heads * gqaMatPastQSeq * gqaMatPastKvSeq * 4","gqaMatPastScoreFits":"gqaMatPastScoreBytes <= device.limits.maxStorageBufferBindingSize and gqaMatPastScoreBytes <= device.limits.maxBufferSize","gqaMatPastBuffersFit":"numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentKeyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentValueT) * 4 <= device.limits.maxStorageBufferBindingSize","gqaMatPastStatSlots":"ceilDiv(gqaMatPastKvSeq, gqaMatKeyTile) * gqaMatSubgroupCols","gqaMatPastRowStatsElements":"dim(shapes.queryT, 0) * attrs.num_heads * gqaMatPastQSeq * 2","gqaMatPastScorePartialElements":"dim(shapes.queryT, 0) * attrs.num_heads * gqaMatPastStatSlots * gqaMatPastQSeq * 2","gqaMatPastDispatchFits":"ceilDiv(gqaMatPastKvSeq, gqaMatKeyTile) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(gqaMatPastQSeq, gqaMatQueryTile) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","gqaMatShareAppendOk":"shareAppendOk and plainAttentionOptions and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and dim(shapes.queryT, 1) == dim(shapes.keyT, 1) and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_APPEND_MIN_QSEQ and dim(shapes.presentKeyT, 2) >= dim(shapes.queryT, 1) and device.features.has(\"subgroups\") and wave32Effective and device.features.has(\"chromium-experimental-subgroup-matrix\") and gqaMatPastScoreFits and gqaMatPastBuffersFit and gqaMatResourcesFit and gqaMatPastDispatchFits","gqaMatWindowOk":"windowShiftOk and plainAttentionOptions and tensorDtypes.queryT == \"float32\" and attrs.local_window_size > 0 and dim(shapes.queryT, 1) == dim(shapes.keyT, 1) and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_WINDOW_MIN_QSEQ and windowCapacity >= dim(shapes.queryT, 1) and attrs.local_window_size + dim(shapes.queryT, 1) >= windowCapacity and device.features.has(\"subgroups\") and wave32Effective and device.features.has(\"chromium-experimental-subgroup-matrix\") and gqaMatPastScoreFits and gqaMatPastBuffersFit and gqaMatResourcesFit and gqaMatPastDispatchFits","gqaMatPastCoreOk":"sharedKvFloatOk and plainAttentionOptions and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and gqaMatPastQSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= gqaMatPastQSeq and device.features.has(\"subgroups\") and wave32Effective and device.features.has(\"chromium-experimental-subgroup-matrix\") and gqaMatPastScoreFits and gqaMatPastBuffersFit and gqaMatResourcesFit and gqaMatPastDispatchFits","gqaMatPastRotaryOk":"sharedKvFloatOk and standardSoftmax and present.cosCacheT and rotaryRequested and not present.qNormWeightT and not present.attentionBiasT and not present.headSinkT and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and gqaHeadDim % 8 == 0 and gqaMatPastQSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= gqaMatPastQSeq and device.features.has(\"subgroups\") and wave32Effective and device.features.has(\"chromium-experimental-subgroup-matrix\") and gqaMatPastScoreFits and gqaMatPastBuffersFit and gqaMatResourcesFit and gqaMatPastDispatchFits","gqaMatNewPastOk":"newKvPastOk and plainAttentionOptions and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and gqaMatPastQSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= gqaMatPastQSeq and device.features.has(\"subgroups\") and wave32Effective and device.features.has(\"chromium-experimental-subgroup-matrix\") and gqaMatPastScoreFits and gqaMatPastBuffersFit and gqaMatResourcesFit and gqaMatPastDispatchFits","gqaMatPastCoreF16Ok":"sharedKvFloatOk and plainAttentionOptions and tensorDtypes.queryT == \"float16\" and device.features.has(\"shader-f16\") and attrs.local_window_size == -1 and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and gqaMatPastQSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= gqaMatPastQSeq and device.features.has(\"subgroups\") and wave32Effective and device.features.has(\"chromium-experimental-subgroup-matrix\") and gqaMatPastScoreFits and gqaMatPastBuffersFit and gqaMatResourcesFit and gqaMatPastDispatchFits","gqaMatPastRotaryF16Ok":"sharedKvFloatOk and standardSoftmax and present.cosCacheT and rotaryRequested and not present.qNormWeightT and not present.attentionBiasT and not present.headSinkT and tensorDtypes.queryT == \"float16\" and device.features.has(\"shader-f16\") and attrs.local_window_size == -1 and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and gqaHeadDim % 8 == 0 and gqaMatPastQSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= gqaMatPastQSeq and device.features.has(\"subgroups\") and wave32Effective and device.features.has(\"chromium-experimental-subgroup-matrix\") and gqaMatPastScoreFits and gqaMatPastBuffersFit and gqaMatResourcesFit and gqaMatPastDispatchFits","gqaMatPastBiasInputsOk":"standardSoftmax and not present.cosCacheT and not rotaryRequested and not present.qNormWeightT and not present.headSinkT and present.attentionBiasT and ranks.attentionBiasT == 4 and tensorDtypes.attentionBiasT == \"float32\" and (dim(shapes.attentionBiasT, 0) == dim(shapes.queryT, 0) or dim(shapes.attentionBiasT, 0) == 1) and (dim(shapes.attentionBiasT, 1) == attrs.num_heads or dim(shapes.attentionBiasT, 1) == 1) and dim(shapes.attentionBiasT, 2) == dim(shapes.queryT, 1) and dim(shapes.attentionBiasT, 3) == dim(shapes.presentKeyT, 2)","gqaMatPastBiasOk":"sharedKvFloatOk and gqaMatPastBiasInputsOk and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and gqaMatPastQSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= gqaMatPastQSeq and device.features.has(\"subgroups\") and wave32Effective and device.features.has(\"chromium-experimental-subgroup-matrix\") and gqaMatPastScoreFits and gqaMatPastBuffersFit and gqaMatResourcesFit and gqaMatPastDispatchFits","qNumHeads":"attrs.num_heads","attentionScaleExpression":"\"select(inverseSqrt(f32(HEAD_DIM)), params.scale, params.scale != 0.0)\"","materializedSgmatQueryTile":"gqaMatQueryTile","materializedSgmatKeyTile":"gqaMatKeyTile","materializedSgmatInnerTile":"gqaMatInnerTile","materializedSgmatDirectApplyStore":false,"materializedSgmatRuntimeDirectStore":false,"materializedRowStatsWg":"gqaMatRowStatsWg","statQuerySeq":"dim(shapes.queryT, 1)","hasWindow":"attrs.local_window_size > 0","windowMatStatSlots":"ceilDiv(windowStageCapacity, gqaMatKeyTile) * gqaMatSubgroupCols","windowMatScorePartialElements":"dim(shapes.queryT, 0) * attrs.num_heads * windowMatStatSlots * dim(shapes.queryT, 1) * 2","windowMatFits":"ceilDiv(windowStageCapacity, gqaMatKeyTile) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * windowStageCapacity * 4 <= min(device.limits.maxBufferSize, device.limits.maxStorageBufferBindingSize) and windowMatScorePartialElements * 4 <= min(device.limits.maxBufferSize, device.limits.maxStorageBufferBindingSize)","clusterPin":"device.adapterInfo.subgroupMinSize if variableSubgroup16To32 and device.features.has(\"subgroup-size-control\") else 0","windowBatchCount":"dim(shapes.queryT, 0)","windowQueryHeads":"attrs.num_heads","windowRotaryRows":"min(dim(shapes.cosCacheT, 0), dim(shapes.sinCacheT, 0)) if present.cosCacheT and present.sinCacheT else 0","windowCooperativeCopy":"has(device.adapterInfo, \"subgroupMinSize\") and windowCapacity >= copyWorkgroupSize * device.adapterInfo.subgroupMinSize and gqaHeadDim >= copyWorkgroupSize and gqaHeadDim % 2 == 0","geometryFixedWidth":"device.features.has(\"subgroups\") and has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize > 0 and device.adapterInfo.subgroupMinSize == device.adapterInfo.subgroupMaxSize and pow2ceil(device.adapterInfo.subgroupMinSize) == device.adapterInfo.subgroupMinSize","geometryLanes":"device.adapterInfo.subgroupMinSize if geometryFixedWidth else cachedPrefillLanesPerQuery","geometryQueryTile":"floor(cachedPrefillClusterWorkgroupSize / geometryLanes)","geometrySharedAppendOk":"not hasWindow and nvidiaAdapter and shareAppendOk and prefillFlashShapeOk and plainAttentionOptions and cachedSgPrefillOk and tensorDtypes.queryT == \"float32\" and geometryFixedWidth and gqaHeadDim / (4 * cachedPrefillLanesPerQuery) > 4 and gqaHeadDim / 4 > device.adapterInfo.subgroupMinSize and dim(shapes.queryT, 0) * attrs.num_heads * ceilDiv(dim(shapes.queryT, 1), cachedPrefillQueryTile) < gqaHeadDim / 4 and geometryLanes > cachedPrefillLanesPerQuery and gqaHeadDim % (4 * geometryLanes) == 0 and cachedPrefillClusterWorkgroupSize % geometryLanes == 0 and geometryQueryTile > 0 and geometryQueryTile < cachedPrefillQueryTile and geometryQueryTile * geometryLanes == cachedPrefillClusterWorkgroupSize and ceilDiv(dim(shapes.queryT, 1), geometryQueryTile) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","gqaDecodeSplits":"max(1, min(256, ceilDiv(dim(shapes.presentKeyT, 2), 32), max(ceilDiv(dim(shapes.presentKeyT, 2), 64), ceilDiv(256, dim(shapes.queryT, 0) * attrs.kv_num_heads))))","gqaDecodeMeasuredTier":"has(device.adapterInfo, \"vendor\") and has(device.adapterInfo, \"architecture\") and device.adapterInfo.vendor == \"nvidia\" and device.adapterInfo.architecture == \"blackwell\"","shareQkNormRotaryOk":"standardSoftmax and present.cosCacheT and rotaryRequested and present.qNormWeightT and not present.attentionBiasT and not present.headSinkT and attrs.local_window_size <= 0 and tensorDtypes.queryT == \"float32\" and tensorDtypes.cosCacheT == \"float32\" and tensorDtypes.sinCacheT == \"float32\" and tensorDtypes.qNormWeightT == \"float32\" and tensorDtypes.kNormWeightT == \"float32\" and dim(shapes.keyT, 1) == dim(shapes.queryT, 1) and dim(shapes.cosCacheT, 1) * 2 == gqaHeadDim and pow2ceil(copyWorkgroupSize) == copyWorkgroupSize","qkSplitWorkgroup":"64 if gqaHeadDim == 128 or gqaHeadDim <= 64 else 128","qkSplits":"max(1, min(32, ceilDiv(dim(shapes.presentKeyT, 2), 8)))","qkSplitSubgroups":"subgroupCluster8 and device.adapterInfo.subgroupMaxSize <= qkSplitWorkgroup and qkSplitWorkgroup % device.adapterInfo.subgroupMinSize == 0 and qkSplitWorkgroup % device.adapterInfo.subgroupMaxSize == 0","qkSplitScratchFits":"dim(shapes.queryT, 0) * attrs.num_heads * qkSplits * (gqaHeadDim + 4) * 4 <= device.limits.maxStorageBufferBindingSize and dim(shapes.queryT, 0) * attrs.num_heads * qkSplits * (gqaHeadDim + 4) * 4 <= device.limits.maxBufferSize","f32PreferCooperativeCachePrefill":"prefillFlashShapeOk and (cachedSgPrefillOk or cachedNoSgClusterStorageOk) and wave32Adapter and not subgroupMatrixConfigAvailable(\"f32\", \"f32\", 8, 8, 8)","qkAppendFusionPreferred":"subgroupsWave32 and device.wgslLanguageFeatures.has(\"subgroup_id\") and not nvidiaAdapter","nativeScoreProductResidual":"has(device.adapterInfo, \"architecture\") and device.adapterInfo.architecture in [\"blackwell\", \"metal-3\"]","dotRecoverProductResidual":"tensorDtypes.queryT == \"float32\" and not nativeScoreProductResidual","qkvSelectorSubgroupWidth":"device.adapterInfo.subgroupMinSize if has(device.adapterInfo, \"subgroupMinSize\") else 1","qkvSelectorQueryGroups":"dim(shapes.queryT, 0) * attrs.num_heads * ceilDiv(dim(shapes.queryT, 1), qkvPrefillQueryTile)","qkvSelectorQueriesPerLane":"2 if tensorDtypes.queryT == \"float32\" and headDimPlan / (4 * qkvPrefillLanesPerQuery) <= 4 and qkvClusterTileK <= 16 and qkvPrefillQueryTile % 2 == 0 else 1","qkvSelectorActualSubgroups":"ceilDiv(qkvPrefillClusterWorkgroupSize / qkvSelectorQueriesPerLane, qkvSelectorSubgroupWidth)","qkvSelectorNominalSubgroups":"ceilDiv(qkvPrefillClusterWorkgroupSize, qkvSelectorSubgroupWidth)","qkvSelectorExtendedTier":"device.features.has(\"shader-f16\") and device.features.has(\"chromium-experimental-subgroup-matrix\") and subgroupMatrixConfigAvailable(\"f16\", \"f32\", 16, 16, 16) and not subgroupMatrixConfigAvailable(\"f32\", \"f32\", 8, 8, 8)","qkvSelectorTargetStorageBytes":"qkvFlashWorkgroupBytes","qkvUnderfilledWideF32PreferQueryGroups":"wave32Adapter and device.features.has(\"subgroups\") and tensorDtypes.queryT == \"float32\" and qkvContractOk and flashShapeOk and qkvSgClusterOk and attrs.causal == 0 and attrs.local_window_size == -1 and ((headDimPlan / (4 * qkvPrefillLanesPerQuery) >= qkvSelectorSubgroupWidth / 4 and qkvSelectorQueryGroups < qkvSelectorSubgroupWidth) or (qkvSelectorExtendedTier and qkvSelectorTargetStorageBytes <= device.limits.maxComputeWorkgroupStorageSize and qkvSelectorQueryGroups * qkvSelectorActualSubgroups < qkvSelectorSubgroupWidth * qkvSelectorNominalSubgroups))","qkvMatrix8WaveWidth":32,"qkvMatrix8Rows":32,"qkvMatrix8Keys":128,"qkvMatrix8ValueKeys":16,"qkvMatrix8QueryTiles":"ceilDiv(dim(shapes.queryT, 1), qkvMatrix8Rows)","qkvMatrix8QueryGroups":"dim(shapes.queryT, 0) * attrs.num_heads * qkvMatrix8QueryTiles","qkvMatrix8StorageBytes":"4 * (qkvMatrix8Rows * qkvMatrix8Keys + qkvMatrix8ValueKeys * headDimPlan + 64 + 3 * qkvMatrix8Rows + 1) + subgroupMatrixTopologyBytes","gqaShapedPastFits":"attrs.local_window_size == -1 and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and gqaMatPastQSeq >= tunables.MATERIALIZED_SGMAT_PAST_MIN_SEQ and gqaMatPastKvSeq >= gqaMatPastQSeq and gqaMatPastScoreFits and gqaMatPastBuffersFit and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","promptAuxOk":"(not present.attentionBiasT or ((dim(shapes.attentionBiasT, 0) == dim(shapes.queryT, 0) or dim(shapes.attentionBiasT, 0) == 1) and (dim(shapes.attentionBiasT, 1) == attrs.num_heads or dim(shapes.attentionBiasT, 1) == 1) and dim(shapes.attentionBiasT, 2) == dim(shapes.queryT, 1) and dim(shapes.attentionBiasT, 3) == dim(shapes.presentKeyT, 2))) and (not present.headSinkT or dim(shapes.headSinkT, 0) == attrs.num_heads)"},"bindings":{"score_ranges_write":{"name":"ranges","scratch":"scoreRanges","elementType":"vec4"},"score_ranges_read":{"name":"ranges","scratch":"scoreRanges","elementType":"vec4","buffer":"read-only-storage"},"score_repair_write":{"name":"repair","scratch":"materializedRowStats","elementType":"u32"},"score_repair_read":{"name":"repair","scratch":"materializedRowStats","elementType":"u32","buffer":"read-only-storage","when":"adaptiveScores"},"query":{"arg":"queryT","elementType":"f32"},"key":{"arg":"keyT","elementType":"f32"},"scores":{"scratch":"materializedScores","elementType":"f32"},"scorePartials":{"scratch":"materializedScorePartials","elementType":"f32"},"scorePartials_f32":{"scratch":"materializedScorePartials","name":"scorePartials","buffer":"read-only-storage","elementType":"f32"},"rowStats":{"scratch":"materializedRowStats","elementType":"f32"},"scores_f32":{"scratch":"materializedScores","name":"scores","buffer":"read-only-storage","elementType":"f32"},"value":{"arg":"valueT","elementType":"f32"},"rowStats_f32":{"scratch":"materializedRowStats","name":"rowStats","buffer":"read-only-storage","elementType":"f32"},"output":{"arg":"outputT","elementType":"f32"},"key_key_t":{"arg":"keyT","name":"key","elementType":"$inputElement"},"value_value_t":{"arg":"valueT","name":"value","elementType":"$inputElement"},"present_key":{"arg":"presentKeyT","elementType":"$presentElement"},"present_value":{"arg":"presentValueT","elementType":"$presentElement"},"params":{"struct":[{"name":"batchSize","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"kvSeq","type":"u32","value":"dim(shapes.keyT, 1)"}]},"src_k":{"arg":"pastKeyT","elementType":"$inputScalar"},"src_v":{"arg":"pastValueT","elementType":"$inputScalar"},"present_key_present":{"arg":"presentKeyT","name":"present_key","elementType":"$inputScalar"},"present_value_present":{"arg":"presentValueT","name":"present_value","elementType":"$inputScalar"},"params_count":{"name":"params","struct":[{"name":"count","type":"u32","value":"dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)"}]},"key_f32":{"arg":"presentKeyT","name":"key","buffer":"read-only-storage","elementType":"f32"},"params_scores":{"name":"params","when":"not present.attentionBiasT","struct":[{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"}]},"params_rows":{"name":"params","struct":[{"name":"rows","type":"u32","value":"dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)"}]},"value_f32":{"arg":"presentValueT","name":"value","buffer":"read-only-storage","elementType":"f32"},"params_apply":{"name":"params","struct":[{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"}]},"key_f16":{"arg":"presentKeyT","name":"key","buffer":"read-only-storage","elementType":"f16"},"value_f16":{"arg":"presentValueT","name":"value","buffer":"read-only-storage","elementType":"f16"},"output_f16":{"arg":"outputT","name":"output","elementType":"f16"},"query_qprep":{"arg":"queryT","name":"query","elementType":"$inputScalar"},"cos_cache":{"arg":"cosCacheT","elementType":"$cosScalar","when":"present.cosCacheT"},"sin_cache":{"arg":"sinCacheT","elementType":"$cosScalar","when":"present.sinCacheT"},"qout":{"scratch":"qPrep","elementType":"vec4"},"params_qprep":{"name":"params","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"dim(shapes.pastKeyT, 2)"}]},"past_k":{"arg":"pastKeyT","elementType":"$inputScalar"},"past_v":{"arg":"pastValueT","elementType":"$inputScalar"},"new_k":{"arg":"keyT","elementType":"$inputScalar"},"new_v":{"arg":"valueT","elementType":"$inputScalar"},"params_present":{"name":"params","struct":[{"name":"count","type":"u32","value":"dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)"},{"name":"seq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"pastSeq","type":"u32","value":"dim(shapes.pastKeyT, 2)"},{"name":"keySeq","type":"u32","value":"dim(shapes.keyT, 1)"}]},"seqlens_k":{"arg":"seqlensKT","elementType":"i32"},"seqlens_k_copy":{"arg":"seqlensKT","name":"seqlens_k","elementType":"i32","when":"cacheCopyMode"},"params__uniform":{"name":"params","struct":[{"name":"count","type":"u32","value":"dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)"},{"name":"seq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"keySeq","type":"u32","value":"dim(shapes.keyT, 1)"}]},"params_gqa_present":{"name":"params","struct":[{"name":"count","type":"u32","value":"dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)"},{"name":"seq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"keySeq","type":"u32","value":"dim(shapes.keyT, 1)"}]},"kcache":{"arg":"presentKeyT","buffer":"read-only-storage","elementType":"$inputScalar"},"vcache":{"arg":"presentValueT","buffer":"read-only-storage","elementType":"$inputScalar"},"output_past_kv":{"arg":"outputT","name":"output","elementType":"$inputScalar"},"params_attention":{"name":"params","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"},{"name":"smoothSoftmax","type":"u32","value":"1 if attrs.smooth_softmax == 1 else 0"}]},"head_sink":{"arg":"headSinkT","elementType":"$inputScalar","when":"present.headSinkT"},"cos_cache_f32":{"arg":"cosCacheT","name":"cos_cache","elementType":"f32","when":"present.cosCacheT"},"sin_cache_f32":{"arg":"sinCacheT","name":"sin_cache","elementType":"f32","when":"present.sinCacheT"},"query_query_t":{"arg":"queryT","name":"query","elementType":"$inputElement"},"output_output_t":{"arg":"outputT","name":"output","elementType":"$outputElement"},"params_qkv_present":{"name":"params","when":"not causalNoWindow","struct":[{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"kvSeq","type":"u32","value":"dim(shapes.keyT, 1)"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"}]},"params_qkv_present_causal":{"name":"params","when":"causalNoWindow","struct":[{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"kvSeq","type":"u32","value":"dim(shapes.keyT, 1)"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"isCausal","type":"u32","value":"attrs.causal"}]},"src_k_f32":{"arg":"keyT","name":"src_k","elementType":"f32"},"src_v_f32":{"arg":"valueT","name":"src_v","elementType":"f32"},"k_scale":{"arg":"kScaleT","elementType":"f32"},"v_scale":{"arg":"vScaleT","elementType":"f32"},"present_key_quant_int8":{"arg":"presentKeyT","name":"present_key","elementType":"$quantCacheElement"},"present_value_quant_int8":{"arg":"presentValueT","name":"present_value","elementType":"$quantCacheElement"},"params_quant_int8":{"name":"params","struct":[{"name":"count","type":"u32","value":"dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)"},{"name":"seq","type":"u32","value":"dim(shapes.keyT, 1)"},{"name":"perChannel","type":"u32","value":"1 if dim(shapes.kScaleT, 0) > 1 else 0"}]},"partial_out":{"scratch":"partialOut","elementType":"vec4"},"partial_stats":{"scratch":"partialStats","elementType":"vec2"},"partial_out_merge":{"scratch":"partialOut","name":"partial_out","buffer":"read-only-storage","elementType":"vec4"},"partial_stats_merge":{"scratch":"partialStats","name":"partial_stats","buffer":"read-only-storage","elementType":"vec2"},"output_merge":{"arg":"outputT","name":"output","elementType":"$inputVec4"},"query_attention":{"arg":"queryT","name":"query","elementType":"$inputVec4"},"key_attention":{"arg":"presentKeyT","name":"key","buffer":"read-only-storage","elementType":"$inputVec4"},"value_attention":{"arg":"presentValueT","name":"value","buffer":"read-only-storage","elementType":"$inputVec4"},"attn_mask":{"arg":"attentionBiasT","elementType":"$inputScalar","when":"present.attentionBiasT"},"params_attn_flash_prefill_cluster":{"name":"params","when":"present.attentionBiasT","struct":[{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"kvSeq","type":"u32","value":"dim(shapes.pastKeyT, 2)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"isCausal","type":"u32","value":1},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"maskBatchStride","type":"u32","value":"0 if dim(shapes.attentionBiasT, 0) == 1 else dim(shapes.attentionBiasT, 1) * dim(shapes.attentionBiasT, 2) * dim(shapes.attentionBiasT, 3)"},{"name":"maskHeadStride","type":"u32","value":"0 if dim(shapes.attentionBiasT, 1) == 1 else dim(shapes.attentionBiasT, 2) * dim(shapes.attentionBiasT, 3)"},{"name":"maskSeqStride","type":"u32","value":"dim(shapes.attentionBiasT, 3)"}]},"q_norm_weight":{"arg":"qNormWeightT","elementType":"$qNormScalar","when":"present.qNormWeightT"},"params_past_kv_flash_prefill":{"name":"params","when":"attrs.softcap == 0 and not present.attentionBiasT and cacheCopyMode","struct":[{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"kvSeq","type":"u32","value":"dim(shapes.pastKeyT, 2)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"isCausal","type":"u32","value":1},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"}]},"params_split_attention":{"name":"params","struct":[{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"}]},"params_new_kv_past_flash_prefill":{"name":"params","when":"not cacheCopyMode and attrs.causal == 1","struct":[{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"isCausal","type":"u32","value":1},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"}]},"params_new_kv_past_flash_bidirectional":{"name":"params","when":"attrs.causal == 0","struct":[{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"}]},"params_past_kv_softcap_flash_prefill":{"name":"params","when":"attrs.softcap > 0","struct":[{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"kvSeq","type":"u32","value":"dim(shapes.pastKeyT, 2)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"isCausal","type":"u32","value":1},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"}]},"kcache_past_kv":{"arg":"pastKeyT","name":"kcache","elementType":"$inputScalar"},"vcache_past_kv":{"arg":"pastValueT","name":"vcache","elementType":"$inputScalar"},"params_past_kv":{"name":"params","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"dim(shapes.pastKeyT, 2)"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"},{"name":"smoothSoftmax","type":"u32","value":"1 if attrs.smooth_softmax == 1 else 0"}]},"k_norm_weight":{"arg":"kNormWeightT","elementType":"f32"},"present_key_f32":{"arg":"presentKeyT","name":"present_key","elementType":"f32"},"present_value_f32":{"arg":"presentValueT","name":"present_value","elementType":"f32"},"params_count_seq_past_seq":{"name":"params","struct":[{"name":"count","type":"u32","value":"dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)"},{"name":"seq","type":"u32","value":"dim(shapes.keyT, 1)"},{"name":"pastSeq","type":"u32","value":0}]},"kcache_f32":{"arg":"presentKeyT","name":"kcache","buffer":"read-only-storage","elementType":"f32"},"vcache_f32":{"arg":"presentValueT","name":"vcache","buffer":"read-only-storage","elementType":"f32"},"q_norm_weight_f32":{"arg":"qNormWeightT","name":"q_norm_weight","elementType":"f32"},"kcache_f32_read":{"arg":"pastKeyT","name":"kcache","elementType":"f32"},"vcache_f32_read":{"arg":"pastValueT","name":"vcache","elementType":"f32"},"attn_bias":{"arg":"attentionBiasT","elementType":"$inputScalar","when":"present.attentionBiasT"},"params_past_kv_bias":{"name":"params","when":"present.attentionBiasT and not present.headSinkT","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"dim(shapes.pastKeyT, 2)"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"},{"name":"smoothSoftmax","type":"u32","value":"1 if attrs.smooth_softmax == 1 else 0"},{"name":"biasBatch","type":"u32","value":"dim(shapes.attentionBiasT, 0)"},{"name":"biasHeads","type":"u32","value":"dim(shapes.attentionBiasT, 1)"}]},"params_gqa_attention":{"name":"params","when":"present.headSinkT and not present.attentionBiasT","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"dim(shapes.pastKeyT, 2)"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"}]},"params_past_kv_bias_headsink":{"name":"params","when":"present.attentionBiasT and present.headSinkT","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"dim(shapes.pastKeyT, 2)"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"},{"name":"biasBatch","type":"u32","value":"dim(shapes.attentionBiasT, 0)"},{"name":"biasHeads","type":"u32","value":"dim(shapes.attentionBiasT, 1)"}]},"key_present_key_t":{"arg":"presentKeyT","name":"key","buffer":"read-only-storage","elementType":"$quantCacheReadElement"},"value_present_value_t":{"arg":"presentValueT","name":"value","buffer":"read-only-storage","elementType":"$quantCacheReadElement"},"params_quant_int8_flash_prefill":{"name":"params","struct":[{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"isCausal","type":"u32","value":1},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"perChannel","type":"u32","value":"1 if dim(shapes.kScaleT, 0) > 1 else 0"}]},"window_key_write":{"name":"present_key","elementType":"$inputScalar","scratch":"windowKey"},"window_value_write":{"name":"present_value","elementType":"$inputScalar","scratch":"windowValue"},"params_window_stage":{"name":"params","struct":[{"name":"count","type":"u32","value":"dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity"},{"name":"seq","type":"u32","value":"windowStageCapacity"},{"name":"keySeq","type":"u32","value":"dim(shapes.keyT, 1)"},{"name":"capacity","type":"u32","value":"windowCapacity"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size"}]},"window_lengths_write":{"name":"stage_seqlens","scratch":"windowLengths","elementType":"i32"},"window_lengths_read":{"elementType":"i32","scratch":"windowLengths","buffer":"read-only-storage","name":"seqlens_k"},"window_key_read":{"name":"stage_k","scratch":"windowKey","elementType":"$inputScalar","buffer":"read-only-storage"},"window_value_read":{"name":"stage_v","scratch":"windowValue","elementType":"$inputScalar","buffer":"read-only-storage"},"params_window_compact":{"name":"params","struct":[{"name":"count","type":"u32","value":"dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity"},{"name":"seq","type":"u32","value":"windowStageCapacity"},{"name":"capacity","type":"u32","value":"windowCapacity"},{"name":"keySeq","type":"u32","value":"dim(shapes.keyT, 1)"},{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size"}]},"window_key_cache":{"buffer":"read-only-storage","elementType":"$inputScalar","scratch":"windowKey","name":"kcache"},"window_value_cache":{"buffer":"read-only-storage","elementType":"$inputScalar","scratch":"windowValue","name":"vcache"},"params_flash_scaled":{"name":"params","struct":[{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"kvSeq","type":"u32","value":"dim(shapes.keyT, 1)"},{"name":"scale","type":"f32","value":"attrs.scale if has(attrs, \"scale\") else 0"}]},"params_flash":{"name":"params","struct":[{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"kvSeq","type":"u32","value":"dim(shapes.keyT, 1)"}]},"params_window_attention_scaled":{"name":"params","struct":[{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"kvSeq","type":"u32","value":"windowStageCapacity"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"}]},"params_window_attention":{"name":"params","struct":[{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"kvSeq","type":"u32","value":"windowStageCapacity"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size"}]},"params_window_cached":{"name":"params","when":"not present.attentionBiasT and not present.headSinkT","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"windowStageCapacity"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"},{"name":"smoothSoftmax","type":"u32","value":"1 if attrs.smooth_softmax == 1 else 0"}]},"params_window_cached_headsink":{"name":"params","when":"present.headSinkT","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"windowStageCapacity"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"}]},"params_window_cached_bias":{"name":"params","when":"present.attentionBiasT","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"windowStageCapacity"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"},{"name":"smoothSoftmax","type":"u32","value":"1 if attrs.smooth_softmax == 1 else 0"},{"name":"biasBatch","type":"u32","value":"dim(shapes.attentionBiasT, 0)"},{"name":"biasHeads","type":"u32","value":"dim(shapes.attentionBiasT, 1)"},{"name":"biasCols","type":"u32","value":"dim(shapes.attentionBiasT, 3)"}]},"window_value_vec4":{"name":"value","buffer":"read-only-storage","elementType":"$inputVec4","scratch":"windowValue"},"params_new_kv_past_flash_prefill_wide":{"name":"params","struct":[{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"isCausal","type":"u32","value":1}]},"params_qprep_share":{"name":"params","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"}]},"qout_rows":{"scratch":"qPrep","name":"qout","elementType":"f32"},"partial_inline":{"scratch":"partial","name":"partial_out","elementType":"vec4"},"partial_inline_merge":{"scratch":"partial","name":"partial_out","buffer":"read-only-storage","elementType":"vec4"},"q_norm_weight_vec4":{"arg":"qNormWeightT","name":"q_norm_weight","elementType":"vec4"},"params_qk_split":{"name":"params","struct":[{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"}]},"params_qk_flash_prefill":{"name":"params","struct":[{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"isCausal","type":"u32","value":1}]},"query_f16":{"arg":"queryT","name":"query","elementType":"f16"},"params_current_kv_scaled":{"name":"params","struct":[{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"kvSeq","type":"u32","value":"dim(shapes.keyT, 1)"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"}]},"prepared_query_write_f32":{"scratch":"q_prepared","name":"prepared_query","buffer":"storage","elementType":"f32"},"prepared_query_read_f32":{"scratch":"q_prepared","name":"query","buffer":"read-only-storage","elementType":"f32"},"qprep_read_vec4_f32":{"scratch":"qPrep","name":"query","buffer":"read-only-storage","elementType":"vec4"},"present_key_read_vec4_u32":{"arg":"presentKeyT","name":"key","buffer":"read-only-storage","elementType":"vec4"},"present_value_read_vec4_u32":{"arg":"presentValueT","name":"value","buffer":"read-only-storage","elementType":"vec4"},"params_present_kv_scaled":{"name":"params","struct":[{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"}]},"qprep_read_f16":{"scratch":"qPrep","name":"query","buffer":"read-only-storage","elementType":"f16"},"qprep_read_f32":{"scratch":"qPrep","name":"query","buffer":"read-only-storage","elementType":"f32"},"window_key_read_f32":{"name":"key","buffer":"read-only-storage","elementType":"f32","scratch":"windowKey"},"window_value_read_f32":{"name":"value","buffer":"read-only-storage","elementType":"f32","scratch":"windowValue"},"window_key_read_vec4":{"name":"key","buffer":"read-only-storage","elementType":"$inputVec4","scratch":"windowKey"},"shaped_key":{"arg":"presentKeyT","name":"key","buffer":"read-only-storage","elementType":"$T"},"shaped_value":{"arg":"presentValueT","name":"value","buffer":"read-only-storage","elementType":"$T"}},"variants":[{"id":"qkv_present_materialized_sgmat_f32","priority":23,"when":["qkvContractOk and attrs.causal == 0 and tensorDtypes.queryT == \"float32\"","headDimPlan >= 64 and headDimPlan <= 256 and headDimPlan % 16 == 0","min(dim(shapes.queryT, 1), dim(shapes.keyT, 1)) >= tunables.MATERIALIZED_SGMAT_MIN_SEQ","wave32Effective and device.limits.maxComputeWorkgroupSizeY >= 16","gqaMatScoreFits and gqaMatBuffersFit and gqaMatResourcesFit and gqaMatDispatchFits and gqaMatRowDispatchFits"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":8,"N":8,"K":8}]},"derive":{"kvNumHeads":"attrs.kv_num_heads","headDim":"dim(shapes.queryT, 2) / attrs.num_heads","qHidden":"dim(shapes.queryT, 2)","kvHidden":"dim(shapes.keyT, 2)","presentScalar":"qkvCacheScalar","presentElement":"qkvCacheVec4","presentVec4":true,"inputElement":"qkvInputVec4","headDimV4":"(dim(shapes.queryT, 2) / attrs.num_heads) / 4","kvHiddenV4":"dim(shapes.keyT, 2) / 4","seqlensQueryFloor":false,"useSeqlens":true},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.keyT, 1)]"},{"id":"materializedRowStats","dtype":"float32","shape":"[max(gqaMatRows * 2, dim(shapes.queryT, 0) * attrs.num_heads * scoreQueryTiles * scoreKeyTiles if adaptiveScores else 0)]"},{"id":"scoreRanges","dtype":"float32","shape":"[4 * scoreRangeCount if adaptiveScores else 1]"}],"passes":[{"repeat":{"index":"adaptivePass","count":"1 if adaptiveScores else 0"},"passes":[{"id":"scoreRange","name":"GroupQueryAttention.ScoreRange","shader":"gqa-score-range.wgsl.jinja","bindings":["query","key","value","score_ranges_write","seqlens_k","params_flash"],"dispatch":{"x":"max(scoreQueryTiles, scoreKeyTiles)","y":2,"z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"scores","name":"GroupQueryAttention.AdaptiveScores","shader":"gqa-score-matrix.wgsl.jinja","bindings":["query","key","scores","score_ranges_read","score_repair_write","seqlens_k","params_flash_scaled"],"dispatch":{"x":"scoreKeyTiles","y":"scoreQueryTiles","z":"dim(shapes.queryT,0)*attrs.num_heads"}}]},{"id":"repair","name":"GroupQueryAttention.CompensatedScores","shader":"attn-materialized-score-f32.wgsl.jinja","derive":{"layout":"\"bsh\"","hasBias":false,"compensatedScoreDot":true,"deferNativeScoreGuard":"nativeScoreProductResidual","materializedQueryTile":"32 if adaptiveScores else gqaMatQueryTile","materializedKeyTile":"32 if adaptiveScores else gqaMatKeyTile","materializedInnerTile":16,"materializedWorkgroupDim":"8 if adaptiveScores else 16","repairScoreTiles":"adaptiveScores","scalarAccumulators":true},"bindings":["query","key","scores","score_repair_read","seqlens_k","params_flash_scaled"],"dispatch":{"x":"ceilDiv(dim(shapes.keyT, 1), materializedKeyTile)","y":"ceilDiv(dim(shapes.queryT, 1), materializedQueryTile)","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.MaterializedRowStats","shader":"attn-materialized-softmax-f32.wgsl.jinja","derive":{"useSubgroups":true,"materializedSoftmaxCols":"dim(shapes.keyT, 1)","materializedSoftmaxWg":"min(32, gqaMatRowStatsWg)","seqlensRowsPerBatch":"qNumHeads * statQuerySeq"},"bindings":["scores_f32","rowStats","seqlens_k","params_rows"],"dispatch":{"x":"min(gqaMatRows, 65535)","y":"ceilDiv(gqaMatRows, 65535)","z":1}},{"id":"apply","name":"GroupQueryAttention.MaterializedApplySgmat","shader":"attn-materialized-sgmat-f32.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\""},"bindings":["scores_f32","value","rowStats_f32","output","seqlens_k","params_flash"],"dispatch":{"x":"ceilDiv(headDim, gqaMatKeyTile)","y":"ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"present","name":"GroupQueryAttention.MaterializedPresent","shader":"gqa-present.wgsl.jinja","bindings":["key_key_t","value_value_t","present_key","present_value","params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"cached_materialized_sgmat_f32","priority":35,"when":["gqaMatPastCoreOk or gqaMatPastBiasOk or gqaMatNewPastOk or gqaMatPastCoreF16Ok","subgroupMatrixConfigAvailable(gqaScalar, \"f32\", 8, 8, 8)"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":8,"N":8,"K":8},{"componentType":"f16","resultComponentType":"f32","M":8,"N":8,"K":8}]},"derive":{"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"gqaMatPastStatSlots","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","operandF16":"tensorDtypes.queryT == \"float16\""},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.presentKeyT, 2)]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatPastRowStatsElements]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[gqaMatPastScorePartialElements]"}],"passes":[{"id":"cache_copy","repeat":{"index":"copyPass","count":"1 if cacheCopyMode else 0"},"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"copy\""},"bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]}]},{"id":"cache_merge","repeat":{"index":"mergePass","count":"0 if cacheCopyMode else 1"},"passes":[{"id":"present","name":"GroupQueryAttention.Merge","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"merge\""},"bindings":["past_k","past_v","new_k","new_v","present_key_present","present_value_present","params_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"scores","name":"GroupQueryAttention.PastMaterializedScores","shader":"attn-materialized-sgmat-f32.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"scoreBias":"present.attentionBiasT"},"bindings":["query_qprep",{"arg":"presentKeyT","name":"key","buffer":"read-only-storage","elementType":"$inputScalar"},{"arg":"attentionBiasT","name":"attention_bias","elementType":"f32","when":"present.attentionBiasT"},"scores","scorePartials","params_scores",{"name":"params","when":"present.attentionBiasT","struct":[{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"biasBatch","type":"u32","value":"dim(shapes.attentionBiasT, 0)"},{"name":"biasHeads","type":"u32","value":"dim(shapes.attentionBiasT, 1)"}]}],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), gqaMatKeyTile)","y":"ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.PastMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (gqaMatRowStatsWg)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.PastMaterializedApply","shader":"attn-materialized-sgmat-f32.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":["scores_f32",{"arg":"presentValueT","name":"value","buffer":"read-only-storage","elementType":"$inputScalar"},"rowStats_f32",{"arg":"outputT","name":"output","elementType":"$inputScalar"},"params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, gqaMatKeyTile)","y":"ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}]},{"id":"past_kv_rotary_materialized_sgmat_f32","priority":37,"when":["gqaMatPastRotaryOk"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":8,"N":8,"K":8}]},"derive":{"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"gqaMatPastStatSlots","mode":"\"copy\"","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","half":"gqaHeadDim / 2","qHeads":"attrs.num_heads","cosScalar":"\"f16\" if tensorDtypes.cosCacheT == \"float16\" else \"f32\"","hasQNorm":false},"intermediates":[{"id":"qPrep","dtype":"float32","shape":"[dim(shapes.queryT, 0), dim(shapes.queryT, 1), dim(shapes.queryT, 2)]"},{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.presentKeyT, 2)]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatPastRowStatsElements]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[gqaMatPastScorePartialElements]"}],"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]},{"id":"qprep","name":"GroupQueryAttention.RotaryQPrep","shader":"gqa-qprep.wgsl.jinja","bindings":["query_qprep","cos_cache","sin_cache","qout","params_qprep"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)","z":1}},{"id":"scores","name":"GroupQueryAttention.PastRotaryMaterializedScores","shader":"attn-materialized-sgmat-f32.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":[{"scratch":"qPrep","name":"query","buffer":"read-only-storage","elementType":"f32"},"key_f32","scores","scorePartials","params_scores"],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), gqaMatKeyTile)","y":"ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.PastRotaryMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (gqaMatRowStatsWg)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.PastRotaryMaterializedApply","shader":"attn-materialized-sgmat-f32.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":["scores_f32","value_f32","rowStats_f32","output","params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, gqaMatKeyTile)","y":"ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}]},{"id":"past_kv_rotary_materialized_sgmat_f16","priority":37,"when":["gqaMatPastRotaryF16Ok"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f16","resultComponentType":"f32","M":8,"N":8,"K":8}]},"derive":{"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"gqaMatPastStatSlots","mode":"\"copy\"","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","half":"gqaHeadDim / 2","qHeads":"attrs.num_heads","cosScalar":"\"f16\" if tensorDtypes.cosCacheT == \"float16\" else \"f32\"","hasQNorm":false,"operandF16":true},"intermediates":[{"id":"qPrep","dtype":"float16","shape":"[dim(shapes.queryT, 0), dim(shapes.queryT, 1), dim(shapes.queryT, 2)]"},{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.presentKeyT, 2)]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatPastRowStatsElements]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[gqaMatPastScorePartialElements]"}],"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]},{"id":"qprep","name":"GroupQueryAttention.RotaryQPrep","shader":"gqa-qprep.wgsl.jinja","bindings":["query_qprep","cos_cache","sin_cache",{"scratch":"qPrep","name":"qout","elementType":"vec4"},"params_qprep"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)","z":1},"derive":{"qPrepF16":true}},{"id":"scores","name":"GroupQueryAttention.PastRotaryMaterializedScores","shader":"attn-materialized-sgmat-f32.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":[{"scratch":"qPrep","name":"query","buffer":"read-only-storage","elementType":"f16"},"key_f16","scores","scorePartials","params_scores"],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), gqaMatKeyTile)","y":"ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.PastRotaryMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (gqaMatRowStatsWg)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.PastRotaryMaterializedApply","shader":"attn-materialized-sgmat-f32.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":["scores_f32","value_f16","rowStats_f32","output_f16","params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, gqaMatKeyTile)","y":"ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}]},{"id":"share_append_materialized_sgmat_f32","priority":36,"when":["gqaMatShareAppendOk"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":8,"N":8,"K":8}]},"derive":{"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"gqaMatPastStatSlots","mode":"\"merge_share\"","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","useSeqlens":true},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.presentKeyT, 2)]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatPastRowStatsElements]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[gqaMatPastScorePartialElements]"}],"passes":[{"id":"present_retain","name":"GroupQueryAttention.MergeShareRetain","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"retain\""},"bindings":["past_k","past_v","present_key_present","present_value_present","seqlens_k","params__uniform"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"past_k","output":"present_key"},{"input":"past_v","output":"present_value"}]},{"id":"present_append","name":"GroupQueryAttention.MergeShareAppend","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"append\""},"bindings":["new_k","new_v","present_key_present","present_value_present","seqlens_k","params_gqa_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","z":1}},{"id":"scores","name":"GroupQueryAttention.ShareAppendMaterializedScores","shader":"attn-materialized-sgmat-f32.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"useSeqlens":true},"bindings":["query","key_f32","scores","scorePartials","seqlens_k","params_scores"],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), gqaMatKeyTile)","y":"ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.ShareAppendMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (gqaMatRowStatsWg)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.ShareAppendMaterializedApply","shader":"attn-materialized-sgmat-f32.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"useSeqlens":true},"bindings":["scores_f32","value_f32","rowStats_f32","output","seqlens_k","params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, gqaMatKeyTile)","y":"ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}]},{"id":"new_kv_share_append_split","priority":32,"when":["shareAppendOk or (shareAppendBidirectionalOk and noAuxAttentionInputs)","gqaScalarDispatchOk","not present.qNormWeightT","not present.kNormWeightT","not present.attentionBiasT","(present.cosCacheT and rotaryRequested and not present.headSinkT and tensorDtypes.queryT == \"float32\") or (not present.cosCacheT and not rotaryRequested)","gqaHeadDim % 2 == 0 or present.cosCacheT"],"derive":{"useSeqlens":true,"headDim":"gqaHeadDim","cooperative":"gqaCoop","dispatchUnits":"gqaDispatchUnits","qHeads":"attrs.num_heads","kvHeads":"attrs.kv_num_heads","qHidden":"dim(shapes.queryT, 2)","packed":"gqaHeadDim","mode":"\"merge_share\"","usesF16":"tensorDtypes.queryT == \"float16\"","inputScalar":"gqaScalar","hasHeadSink":"present.headSinkT","half":"gqaHeadDim / 2","hasRotary":"present.cosCacheT","bidirectional":"attrs.causal == 0"},"passes":[{"id":"present_retain","name":"GroupQueryAttention.MergeShareRetain","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"retain\""},"bindings":["past_k","past_v","present_key_present","present_value_present","seqlens_k","params__uniform"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"past_k","output":"present_key"},{"input":"past_v","output":"present_value"}]},{"id":"present_append","name":"GroupQueryAttention.MergeShareAppend","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"append\""},"bindings":["new_k","new_v","cos_cache_f32","sin_cache_f32","present_key_present","present_value_present","seqlens_k","params_gqa_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","z":1}},{"id":"attention","name":"GroupQueryAttention.Attn","shader":"gqa-attention.wgsl.jinja","bindings":["query_qprep","kcache","vcache","cos_cache_f32","sin_cache_f32","head_sink","output_past_kv","seqlens_k",{"name":"params","when":"not present.headSinkT","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"},{"name":"smoothSoftmax","type":"u32","value":"1 if attrs.smooth_softmax == 1 else 0"}]},{"name":"params","when":"present.headSinkT","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"}]}],"dispatch":{"x":"min(dispatchUnits, 65535)","y":"ceilDiv(dispatchUnits, 65535)","z":1}}]},{"id":"qkv_present_tiled_nosg","priority":19,"when":["plainAttentionOptions","flashShapeOk","qkvTiledStorageOk","headDimPlan % 4 == 0","headDimPlan <= 128","dim(shapes.queryT, 1) >= tunables.QKV_PREFILL_MIN_QUERY_TOKENS","attrs.local_window_size <= 0","not causalNoWindow"],"derive":{"scalar":"qkvScalar","inputScalar":"qkvScalar","presentScalar":"qkvCacheScalar","inputElement":"qkvScalar","presentElement":"qkvCacheScalar","blockM":32,"vHeadCap":"dim(shapes.valueT, 2) / attrs.kv_num_heads","kvNumHeads":"attrs.kv_num_heads","headDim":"dim(shapes.queryT, 2) / attrs.num_heads","kvHidden":"dim(shapes.keyT, 2)","useSeqlens":true,"compensatedScoreDot":"qkvScalar == \"f32\"","compensatedOnlineDenominator":"qkvScalar == \"f32\""},"passes":[{"id":"attention","name":"GroupQueryAttention.PrefillTiledNoSg","shader":"attention-rank4-tiled.wgsl.jinja","derive":{"layout":"\"bsh\""},"bindings":[{"arg":"queryT","name":"q","elementType":"$scalar"},{"arg":"keyT","name":"k","elementType":"$scalar"},{"arg":"valueT","name":"v","elementType":"$scalar"},{"arg":"outputT","name":"y","elementType":"$scalar"},"seqlens_k",{"name":"params","struct":[{"name":"count","type":"u32","value":"numel(shapes.outputT)"},{"name":"qHeads","type":"u32","value":"attrs.num_heads"},{"name":"kvHeads","type":"u32","value":"attrs.kv_num_heads"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"kvSeq","type":"u32","value":"dim(shapes.keyT, 1)"},{"name":"headSize","type":"u32","value":"dim(shapes.queryT, 2) / attrs.num_heads"},{"name":"vHeadSize","type":"u32","value":"dim(shapes.valueT, 2) / attrs.kv_num_heads"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"0"},{"name":"isCausal","type":"u32","value":"0"},{"name":"qHidden","type":"u32","value":"dim(shapes.queryT, 2)"},{"name":"kvHidden","type":"u32","value":"dim(shapes.keyT, 2)"},{"name":"vHidden","type":"u32","value":"dim(shapes.valueT, 2)"}]}],"dispatch":{"x":"min(ceilDiv((dim(shapes.outputT, 0) * attrs.num_heads * ceilDiv(dim(shapes.outputT, 1), blockM) * blockM), (blockM)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.outputT, 0) * attrs.num_heads * ceilDiv(dim(shapes.outputT, 1), blockM) * blockM), (blockM)), 65535)","z":1}},{"id":"present","name":"GroupQueryAttention.PresentTiledNoSg","shader":"gqa-present.wgsl.jinja","bindings":["key_key_t","value_value_t","present_key","present_value","params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.presentKeyT)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.presentKeyT)), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"qkv_stream_matrix8","priority":41,"when":["qkvContractOk","tensorDtypes.queryT == \"float16\"","attrs.causal == 0 and attrs.local_window_size == -1","headDimPlan >= 64 and headDimPlan <= 128 and headDimPlan % 32 == 0","dim(shapes.queryT, 1) >= qkvMatrix8Rows and dim(shapes.queryT, 1) % qkvMatrix8Rows == 0","dim(shapes.keyT, 1) >= qkvMatrix8Keys and dim(shapes.keyT, 1) % qkvMatrix8Keys == 0","wave32Effective","256 <= deviceWorkgroupCap","qkvMatrix8StorageBytes <= device.limits.maxComputeWorkgroupStorageSize","qkvMatrix8QueryTiles <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)"],"requires":{"features":["shader-f16","subgroups","chromium-experimental-subgroup-matrix"],"limits":{"maxComputeInvocationsPerWorkgroup":256,"maxComputeWorkgroupSizeX":256},"subgroupMatrixConfigs":[{"componentType":"f16","resultComponentType":"f32","M":8,"N":8,"K":8},{"componentType":"f32","resultComponentType":"f32","M":8,"N":8,"K":8}]},"derive":{"presentScalar":"qkvCacheScalar","inputElement":"qkvInputVec4","presentElement":"qkvCacheVec4","kvNumHeads":"attrs.kv_num_heads","headDim":"headDimPlan","headDimV4":"headDimPlan / 4","kvHidden":"dim(shapes.keyT, 2)","kvHiddenV4":"dim(shapes.keyT, 2) / 4","presentVec4":true,"attnHeadDim":"headDimPlan","attnQHeads":"attrs.num_heads","attnKvHeads":"attrs.kv_num_heads","streamRows":"qkvMatrix8Rows","streamKeys":"qkvMatrix8Keys","streamValueKeys":"qkvMatrix8ValueKeys"},"passes":[{"id":"attention","name":"GroupQueryAttention.StreamMatrix8","shader":"gqa-stream-matrix8.wgsl.jinja","bindings":["query_f16",{"arg":"keyT","name":"key","elementType":"f16"},{"arg":"valueT","name":"value","elementType":"vec4"},{"arg":"outputT","name":"output","elementType":"vec4"},"seqlens_k","params_current_kv_scaled"],"dispatch":{"x":"qkvMatrix8QueryTiles","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}},{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["key_key_t","value_value_t","present_key","present_value","params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","z":1}}],"demoteWhen":["pinSubgroupSize32","headDimPlan <= 2 * qkvMatrix8WaveWidth","dim(shapes.keyT, 1) < 3 * qkvMatrix8Keys","qkvMatrix8QueryGroups < 2 * qkvMatrix8WaveWidth"]},{"id":"qkv_present_flash_sgmat16_f16","priority":40,"when":["qkvContractOk","tensorDtypes.queryT == \"float16\"","attrs.local_window_size <= 0","attrs.causal == 0 or dim(shapes.keyT, 1) == dim(shapes.queryT, 1)","headDimPlan % 16 == 0 and headDimPlan <= 128","attrs.num_heads % attrs.kv_num_heads == 0","dim(shapes.queryT, 1) >= 64 and dim(shapes.keyT, 1) >= 64","ceilDiv(dim(shapes.queryT, 1), 64) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","256 <= deviceWorkgroupCap","47376 + subgroupMatrixTopologyBytes <= device.limits.maxComputeWorkgroupStorageSize","has(device.adapterInfo, \"subgroupMatrixConfigs\") and subgroupMatrixConfigAvailable(\"f16\", \"f32\", 16, 16, 16)","has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize <= 32 and device.adapterInfo.subgroupMaxSize >= 32"],"requires":{"features":["shader-f16","subgroups","chromium-experimental-subgroup-matrix"],"limits":{"maxComputeInvocationsPerWorkgroup":256,"maxComputeWorkgroupSizeX":256},"subgroupMatrixConfigs":[{"componentType":"f16","resultComponentType":"f32","M":16,"N":16,"K":16}]},"derive":{"presentScalar":"qkvCacheScalar","inputElement":"qkvInputVec4","presentElement":"qkvCacheVec4","kvNumHeads":"attrs.kv_num_heads","headDim":"dim(shapes.queryT, 2) / attrs.num_heads","headDimV4":"(dim(shapes.queryT, 2) / attrs.num_heads) / 4","kvHidden":"dim(shapes.keyT, 2)","kvHiddenV4":"dim(shapes.keyT, 2) / 4","presentVec4":true,"attnHeadDim":"headDimPlan","attnQHeads":"attrs.num_heads","attnKvHeads":"attrs.kv_num_heads","attnCausal":"attrs.causal == 1","attnCausalAtEnd":true,"attnSeqlens":true,"attnSeqlensQueryFloor":"attrs.causal == 1","attnWaves":"8 if dim(shapes.queryT, 0) * attrs.num_heads * ceilDiv(dim(shapes.queryT, 1), 64) < 160 else 4"},"passes":[{"id":"attention","name":"GroupQueryAttention.FlashSgmat16","shader":"attention-flash-sgmat16.wgsl.jinja","bindings":["query_f16",{"arg":"keyT","name":"key","elementType":"vec4"},{"arg":"valueT","name":"value","elementType":"vec4"},"output_f16","seqlens_k","params_current_kv_scaled"],"dispatch":{"x":"ceilDiv(dim(shapes.queryT, 1), 64)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}},{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["key_key_t","value_value_t","present_key","present_value","params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"qkv_present_flash_sgmat16_split_f32","priority":41,"when":["qkvContractOk","tensorDtypes.queryT == \"float32\" and tensorDtypes.keyT == \"float32\"","attrs.local_window_size <= 0","attrs.causal == 0 or dim(shapes.keyT, 1) == dim(shapes.queryT, 1)","headDimPlan % 16 == 0 and headDimPlan <= 128","attrs.num_heads % attrs.kv_num_heads == 0","dim(shapes.queryT, 1) >= 64 and dim(shapes.keyT, 1) >= 64","ceilDiv(dim(shapes.queryT, 1), 64) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","256 <= deviceWorkgroupCap","48672 + subgroupMatrixTopologyBytes <= device.limits.maxComputeWorkgroupStorageSize","has(device.adapterInfo, \"subgroupMatrixConfigs\") and subgroupMatrixConfigAvailable(\"f16\", \"f32\", 16, 16, 16)","has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize <= 32 and device.adapterInfo.subgroupMaxSize >= 32","device.limits.maxStorageBuffersPerShaderStage >= 6","dim(shapes.keyT, 1) >= 1024"],"requires":{"features":["shader-f16","subgroups","chromium-experimental-subgroup-matrix"],"limits":{"maxComputeInvocationsPerWorkgroup":256,"maxComputeWorkgroupSizeX":256},"subgroupMatrixConfigs":[{"componentType":"f16","resultComponentType":"f32","M":16,"N":16,"K":16}]},"derive":{"presentScalar":"qkvCacheScalar","inputElement":"qkvInputVec4","presentElement":"qkvCacheVec4","kvNumHeads":"attrs.kv_num_heads","headDim":"dim(shapes.queryT, 2) / attrs.num_heads","headDimV4":"(dim(shapes.queryT, 2) / attrs.num_heads) / 4","kvHidden":"dim(shapes.keyT, 2)","kvHiddenV4":"dim(shapes.keyT, 2) / 4","presentVec4":true,"attnHeadDim":"headDimPlan","attnQHeads":"attrs.num_heads","attnKvHeads":"attrs.kv_num_heads","attnCausal":"attrs.causal == 1","attnCausalAtEnd":true,"attnSeqlens":true,"attnSeqlensQueryFloor":"attrs.causal == 1","attnWaves":"8 if dim(shapes.queryT, 0) * attrs.num_heads * ceilDiv(dim(shapes.queryT, 1), 64) < 160 else 4","attnFullF32":true,"prepareQElements":"numel(shapes.queryT)"},"passes":[{"id":"split","name":"GroupQueryAttention.PrepareF32","shader":"attention-prepare-f32.wgsl.jinja","bindings":["query","prepared_query_write_f32"],"dispatch":{"x":"min(ceilDiv((prepareQElements), (64)), 65535)","y":"ceilDiv(ceilDiv((prepareQElements), (64)), 65535)","z":1}},{"id":"attention","name":"GroupQueryAttention.OnlineF32","shader":"attention-flash-sgmat16.wgsl.jinja","bindings":["prepared_query_read_f32",{"arg":"keyT","name":"key","elementType":"vec4"},{"arg":"valueT","name":"value","elementType":"vec4"},"output","seqlens_k","params_current_kv_scaled"],"dispatch":{"x":"ceilDiv(dim(shapes.queryT, 1), 64)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}},{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["key_key_t","value_value_t","present_key","present_value","params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","z":1}}],"intermediates":[{"id":"q_prepared","dtype":"float32","shape":"[numel(shapes.queryT)]"}]},{"id":"qkv_present_flash","priority":20,"when":["flashShapeOk","not causalNoWindow or dim(shapes.keyT, 1) == dim(shapes.queryT, 1)","qkvFlashWorkgroupBytes <= device.limits.maxComputeWorkgroupStorageSize"],"requires":{"features":["subgroups"]},"derive":{"hasCausal":"causalNoWindow","combineSubgroups":true,"scalar":"qkvScalar","presentScalar":"qkvCacheScalar","inputElement":"qkvInputVec4","outputElement":"qkvInputVec4","presentElement":"qkvCacheVec4","kvNumHeads":"attrs.kv_num_heads","headDim":"dim(shapes.queryT, 2) / attrs.num_heads","headDimV4":"(dim(shapes.queryT, 2) / attrs.num_heads) / 4","qHiddenV4":"dim(shapes.queryT, 2) / 4","kvHidden":"dim(shapes.keyT, 2)","kvHiddenV4":"dim(shapes.keyT, 2) / 4","presentVec4":true,"seqlensQueryFloor":"attrs.causal == 1","useSeqlens":true,"compensatedScoreDot":"tensorDtypes.queryT == \"float32\""},"passes":[{"id":"attention","name":"GroupQueryAttention.Flash","shader":"attn-flash-online.wgsl.jinja","derive":{"layout":"\"bsh\""},"bindings":["query_query_t","key_key_t","value_value_t","output_output_t","seqlens_k","params_qkv_present","params_qkv_present_causal"],"dispatch":{"x":"dim(shapes.queryT, 1)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}},{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["key_key_t","value_value_t","present_key","present_value","params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"qkv_present","priority":0,"when":["fallbackShapeOk","not causalNoWindow or dim(shapes.keyT, 1) == dim(shapes.queryT, 1)"],"derive":{"hasCausal":"causalNoWindow","inputScalar":"qkvScalar","outputScalar":"qkvScalar","presentScalar":"qkvCacheScalar","inputElement":"qkvScalar","outputElement":"qkvScalar","presentElement":"qkvCacheScalar","kvNumHeads":"attrs.kv_num_heads","headDim":"dim(shapes.queryT, 2) / attrs.num_heads","qHidden":"dim(shapes.queryT, 2)","kvHidden":"dim(shapes.keyT, 2)","workgroupSize":"min(256, pow2ceil(dim(shapes.queryT, 2) / attrs.num_heads))","seqlensQueryFloor":"attrs.causal == 1","useSeqlens":true,"compensateValues":"tensorDtypes.queryT == \"float32\"","compensatedOnlineDenominator":"tensorDtypes.queryT == \"float32\""},"passes":[{"id":"attention","name":"GroupQueryAttention.Attention","shader":"attn-online-scalar.wgsl.jinja","derive":{"layout":"\"bsh\""},"bindings":["query_query_t","key_key_t","value_value_t","output_output_t","seqlens_k","params_qkv_present","params_qkv_present_causal"],"dispatch":{"x":"min(dim(shapes.queryT, 1), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}},{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["key_key_t","value_value_t","present_key","present_value","params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.presentKeyT)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.presentKeyT)), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"quant","priority":35,"when":["quantizedPromptOk","gqaScalarDispatchOk","promptAuxOk","not rotaryRequested or present.cosCacheT and present.sinCacheT"],"derive":{"headDim":"gqaHeadDim","cooperative":"gqaCoop","dispatchUnits":"gqaDispatchUnits","qHeads":"attrs.num_heads","kvHeads":"attrs.kv_num_heads","qHidden":"dim(shapes.queryT, 2)","packed":"gqaHeadDim / (8 / attrs.kv_cache_bit_width)","quantized":true,"bits":"attrs.kv_cache_bit_width","mode":"\"build_quant\"","qmax":"127 if attrs.kv_cache_bit_width == 8 else 7","qmin":"0 - (128 if attrs.kv_cache_bit_width == 8 else 8)","quantCacheElement":"\"i32\" if attrs.kv_cache_bit_width == 8 else \"u32\"","hasRotary":"rotaryRequested","half":"gqaHeadDim / 2","hasQNorm":"present.qNormWeightT","hasKNorm":"present.kNormWeightT","qkEps":"attrs.qk_norm_epsilon","hasBias":"present.attentionBiasT","hasHeadSink":"present.headSinkT","inputScalar":"gqaScalar"},"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["src_k_f32","src_v_f32","k_scale","v_scale","present_key_quant_int8","present_value_quant_int8",{"arg":"cosCacheT","name":"cos_cache","elementType":"f32","when":"rotaryRequested"},{"arg":"sinCacheT","name":"sin_cache","elementType":"f32","when":"rotaryRequested"},{"arg":"kNormWeightT","name":"k_norm_weight","elementType":"f32","when":"present.kNormWeightT"},{"name":"params","when":"not rotaryRequested","struct":[{"name":"count","type":"u32","value":"dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)"},{"name":"seq","type":"u32","value":"dim(shapes.keyT, 1)"},{"name":"perChannel","type":"u32","value":"1 if dim(shapes.kScaleT, 0) > 1 else 0"}]},{"name":"params","when":"rotaryRequested","struct":[{"name":"count","type":"u32","value":"dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)"},{"name":"seq","type":"u32","value":"dim(shapes.keyT, 1)"},{"name":"perChannel","type":"u32","value":"1 if dim(shapes.kScaleT, 0) > 1 else 0"},{"name":"pastSeq","type":"u32","value":0}]}],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","z":1}},{"id":"attention","name":"GroupQueryAttention.Attn","shader":"gqa-attention.wgsl.jinja","bindings":["query",{"arg":"presentKeyT","name":"kcache","buffer":"read-only-storage","elementType":"$quantCacheElement"},{"arg":"presentValueT","name":"vcache","buffer":"read-only-storage","elementType":"$quantCacheElement"},"k_scale","v_scale",{"arg":"cosCacheT","name":"cos_cache","elementType":"f32","when":"rotaryRequested"},{"arg":"sinCacheT","name":"sin_cache","elementType":"f32","when":"rotaryRequested"},{"arg":"qNormWeightT","name":"q_norm_weight","elementType":"f32","when":"present.qNormWeightT"},"attn_bias","head_sink","output",{"name":"params","when":"not present.attentionBiasT and not present.headSinkT","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"},{"name":"smoothSoftmax","type":"u32","value":"1 if attrs.smooth_softmax == 1 else 0"},{"name":"perChannel","type":"u32","value":"1 if dim(shapes.kScaleT, 0) > 1 else 0"}]},{"name":"params","when":"present.attentionBiasT and not present.headSinkT","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"},{"name":"smoothSoftmax","type":"u32","value":"1 if attrs.smooth_softmax == 1 else 0"},{"name":"perChannel","type":"u32","value":"1 if dim(shapes.kScaleT, 0) > 1 else 0"},{"name":"biasBatch","type":"u32","value":"dim(shapes.attentionBiasT, 0)"},{"name":"biasHeads","type":"u32","value":"dim(shapes.attentionBiasT, 1)"}]},{"name":"params","when":"present.headSinkT and not present.attentionBiasT","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"},{"name":"perChannel","type":"u32","value":"1 if dim(shapes.kScaleT, 0) > 1 else 0"}]},{"name":"params","when":"present.attentionBiasT and present.headSinkT","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"},{"name":"perChannel","type":"u32","value":"1 if dim(shapes.kScaleT, 0) > 1 else 0"},{"name":"biasBatch","type":"u32","value":"dim(shapes.attentionBiasT, 0)"},{"name":"biasHeads","type":"u32","value":"dim(shapes.attentionBiasT, 1)"}]}],"dispatch":{"x":"min(dispatchUnits, 65535)","y":"ceilDiv(dispatchUnits, 65535)","z":1}}]},{"id":"append_decode_splitk","priority":45,"when":["quantizedCachedDecodeOk and cachedNumSplits >= 2 or not quantizedCachedDecodeOk and shareAppendOk and plainAttentionOptions","decodeFlashShapeOk","cachedSplitScratchFits","(gqaHeadDim) >= 4 and (tunables.WORKGROUP_SIZE) > 0 and (tunables.WORKGROUP_SIZE) <= deviceWorkgroupCap and (pow2ceil(tunables.WORKGROUP_SIZE) == (tunables.WORKGROUP_SIZE) or (subgroupSplitK)) and ((gqaHeadDim) * 8 + (tunables.WORKGROUP_SIZE) * 12 + (16 * (tunables.WORKGROUP_SIZE) if (tunables.WORKGROUP_SIZE) % ((gqaHeadDim) / 4) == 0 and (tunables.WORKGROUP_SIZE) / ((gqaHeadDim) / 4) >= 2 else 0) + (4 * (tunables.WORKGROUP_SIZE) if (subgroupSplitK) and ((gqaHeadDim) / 4) >= 8 and not ((tensorDtypes.queryT == \"float16\") and ((gqaHeadDim) / 4) <= 32) and (true) else 0) + (ceilDiv((tunables.WORKGROUP_SIZE), 32) * 4 + 8 if (subgroupSplitK) else 0) if (gqaHeadDim) >= 4 and (tunables.WORKGROUP_SIZE) > 0 else 0) <= device.limits.maxComputeWorkgroupStorageSize"],"derive":{"useSubgroups":"subgroupSplitK","cacheSeqlens":true,"scalar":"gqaScalar","usesF16":"tensorDtypes.queryT == \"float16\"","kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","headDimV4":"gqaHeadDim / 4","numSplits":"cachedNumSplits","kvHeads":"attrs.kv_num_heads","packed":"gqaHeadDim","mode":"\"merge_share\"","inputVec4":"gqaInputVec4","inputScalar":"\"i32\" if quantizedCachedDecodeOk else gqaScalar","quantizedCache":"quantizedCachedDecodeOk","bits":"8 if quantizedCachedDecodeOk else 0","qmax":"127 if quantizedCachedDecodeOk else 0","qmin":"-128 if quantizedCachedDecodeOk else 0","splitKvElement":"\"vec4\" if quantizedCachedDecodeOk else gqaInputVec4","normalizedPartialValues":"tensorDtypes.outputT == \"float32\" and ((present.pastValueT and tensorDtypes.pastValueT != \"float16\") or (present.valueT and tensorDtypes.valueT != \"float16\"))"},"intermediates":[{"id":"partialOut","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * cachedNumSplits * gqaHeadDim]"},{"id":"partialStats","dtype":"float32","shape":"[2 * dim(shapes.queryT, 0) * attrs.num_heads * cachedNumSplits]"}],"passes":[{"id":"quantized_append","repeat":{"index":"quantPass","count":"1 if quantizedCachedDecodeOk else 0"},"passes":[{"id":"copy_past","name":"GroupQueryAttention.QuantInt8CopyPast","shader":"gqa-present.wgsl.jinja","derive":{"modeSpec":"\"copy\""},"bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]},{"id":"append","name":"GroupQueryAttention.QuantInt8Append","shader":"gqa-present.wgsl.jinja","derive":{"modeSpec":"\"append_quant\""},"bindings":["src_k_f32","src_v_f32","k_scale","v_scale","seqlens_k",{"arg":"presentKeyT","name":"present_key","elementType":"i32"},{"arg":"presentValueT","name":"present_value","elementType":"i32"},{"name":"params","struct":[{"name":"count","type":"u32","value":"dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)"},{"name":"seq","type":"u32","value":"dim(shapes.keyT, 1)"},{"name":"totalSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"perChannel","type":"u32","value":"1 if dim(shapes.kScaleT, 0) > 1 else 0"}]}],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"share_append","repeat":{"index":"sharePass","count":"0 if quantizedCachedDecodeOk else 1"},"passes":[{"id":"present_retain","name":"GroupQueryAttention.MergeShareRetain","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"retain\""},"bindings":["past_k","past_v","present_key_present","present_value_present","seqlens_k","params__uniform"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"past_k","output":"present_key"},{"input":"past_v","output":"present_value"}]},{"id":"present_append","name":"GroupQueryAttention.MergeShareAppend","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"append\""},"bindings":["new_k","new_v","present_key_present","present_value_present","seqlens_k","params_gqa_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"split_attention","name":"GroupQueryAttention.DecodeSplitK","shader":"attn-flash-decode-splitk.wgsl.jinja","derive":{"layout":"\"bhsd\""},"bindings":["query_attention",{"arg":"presentKeyT","name":"key","buffer":"read-only-storage","elementType":"$splitKvElement"},{"arg":"presentValueT","name":"value","buffer":"read-only-storage","elementType":"$splitKvElement"},{"arg":"kScaleT","name":"k_scale","elementType":"f32","when":"quantizedCachedDecodeOk"},{"arg":"vScaleT","name":"v_scale","elementType":"f32","when":"quantizedCachedDecodeOk"},{"arg":"seqlensKT","name":"seqlens_k","elementType":"i32","when":"quantizedCachedDecodeOk"},"partial_out","partial_stats",{"arg":"seqlensKT","name":"seqlens_k","elementType":"i32","when":"not quantizedCachedDecodeOk"},{"name":"params","struct":[{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"perChannel","type":"u32","value":"1 if dim(shapes.kScaleT, 0) > 1 else 0"}],"when":"quantizedCachedDecodeOk"},{"name":"params","struct":[{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"}],"when":"not quantizedCachedDecodeOk"}],"dispatch":{"x":"cachedNumSplits","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}},{"id":"merge","name":"GroupQueryAttention.DecodeSplitKMerge","shader":"attn-flash-decode-splitk-merge.wgsl.jinja","derive":{"layout":"\"bhsd\""},"bindings":["partial_out_merge","partial_stats_merge","output_merge"],"dispatch":{"x":1,"y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}]},{"id":"qkv_present_flash_splitk","priority":25,"when":["decodeSplitKShapeOk","qkvSplitScratchFits","not causalNoWindow","(dim(shapes.queryT, 2) / attrs.num_heads) >= 4 and (tunables.WORKGROUP_SIZE) > 0 and (tunables.WORKGROUP_SIZE) <= deviceWorkgroupCap and (pow2ceil(tunables.WORKGROUP_SIZE) == (tunables.WORKGROUP_SIZE) or (device.features.has(\"subgroups\"))) and ((dim(shapes.queryT, 2) / attrs.num_heads) * 8 + (tunables.WORKGROUP_SIZE) * 12 + (16 * (tunables.WORKGROUP_SIZE) if (tunables.WORKGROUP_SIZE) % ((dim(shapes.queryT, 2) / attrs.num_heads) / 4) == 0 and (tunables.WORKGROUP_SIZE) / ((dim(shapes.queryT, 2) / attrs.num_heads) / 4) >= 2 else 0) + (4 * (tunables.WORKGROUP_SIZE) if (device.features.has(\"subgroups\")) and ((dim(shapes.queryT, 2) / attrs.num_heads) / 4) >= 8 and not ((qkvUsesF16) and ((dim(shapes.queryT, 2) / attrs.num_heads) / 4) <= 32) and (true) else 0) + (ceilDiv((tunables.WORKGROUP_SIZE), 32) * 4 + 8 if (device.features.has(\"subgroups\")) else 0) if (dim(shapes.queryT, 2) / attrs.num_heads) >= 4 and (tunables.WORKGROUP_SIZE) > 0 else 0) <= device.limits.maxComputeWorkgroupStorageSize"],"derive":{"useSubgroups":"device.features.has(\"subgroups\")","scalar":"qkvScalar","inputVec4":"qkvInputVec4","presentScalar":"qkvCacheScalar","inputElement":"qkvInputVec4","presentElement":"qkvCacheVec4","kvNumHeads":"attrs.kv_num_heads","headDim":"dim(shapes.queryT, 2) / attrs.num_heads","headDimV4":"(dim(shapes.queryT, 2) / attrs.num_heads) / 4","qHiddenV4":"dim(shapes.queryT, 2) / 4","kvHidden":"dim(shapes.keyT, 2)","kvHiddenV4":"dim(shapes.keyT, 2) / 4","numSplits":"qkvNumSplits","presentVec4":true,"usesF16":"qkvUsesF16","seqlensQueryFloor":"attrs.causal == 1","cacheSeqlens":true,"normalizedPartialValues":"tensorDtypes.outputT == \"float32\" and ((present.pastValueT and tensorDtypes.pastValueT != \"float16\") or (present.valueT and tensorDtypes.valueT != \"float16\"))"},"intermediates":[{"id":"partialOut","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * qkvNumSplits * (dim(shapes.queryT, 2) / attrs.num_heads)]"},{"id":"partialStats","dtype":"float32","shape":"[2 * dim(shapes.queryT, 0) * attrs.num_heads * qkvNumSplits]"}],"passes":[{"id":"split_attention","name":"GroupQueryAttention.DecodeSplitK","shader":"attn-flash-decode-splitk.wgsl.jinja","derive":{"usesF16":"tensorDtypes.queryT == \"float16\"","layout":"\"bsh\""},"bindings":["query_attention",{"arg":"keyT","name":"key","elementType":"$inputVec4"},{"arg":"valueT","name":"value","elementType":"$inputVec4"},"partial_out","partial_stats","seqlens_k",{"name":"params","struct":[{"name":"kvSeq","type":"u32","value":"dim(shapes.keyT, 1)"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"}]}],"dispatch":{"x":"qkvNumSplits","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}},{"id":"merge","name":"GroupQueryAttention.DecodeSplitKMerge","shader":"attn-flash-decode-splitk-merge.wgsl.jinja","derive":{"layout":"\"bsh\""},"bindings":["partial_out_merge","partial_stats_merge","output_merge"],"dispatch":{"x":1,"y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}},{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["key_key_t","value_value_t","present_key","present_value","params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"qkv_present_flash_cluster","priority":22,"when":["flashShapeOk","qkvSgClusterOk or qkvNoSgClusterStorageOk","qkvPrefillClusterWorkgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup","qkvPrefillClusterWorkgroupSize <= device.limits.maxComputeWorkgroupSizeX","headDimPlan % (4 * qkvPrefillLanesPerQuery) == 0","dim(shapes.queryT, 1) >= tunables.QKV_PREFILL_MIN_QUERY_TOKENS","not causalNoWindow"],"demoteWhen":["device.features.has(\"subgroups\") and not qkvF32ClusterRegisterGeometry","qkvUnderfilledWideF32PreferQueryGroups"],"derive":{"hasCausal":false,"useSubgroups":"qkvSgClusterOk","usesF16":"qkvUsesF16","scalar":"qkvScalar","presentScalar":"qkvCacheScalar","inputElement":"qkvInputVec4","outputElement":"qkvInputVec4","presentElement":"qkvCacheVec4","kvNumHeads":"attrs.kv_num_heads","headDim":"dim(shapes.queryT, 2) / attrs.num_heads","headDimV4":"(dim(shapes.queryT, 2) / attrs.num_heads) / 4","qHiddenV4":"dim(shapes.queryT, 2) / 4","kvHidden":"dim(shapes.keyT, 2)","kvHiddenV4":"dim(shapes.keyT, 2) / 4","presentVec4":true,"portableLaneScale":"2 if not useSubgroups and dotRecoverProductResidual and headDimV4 > 4 * qkvPrefillLanesPerQuery and headDimV4 % (2 * qkvPrefillLanesPerQuery) == 0 and qkvPrefillQueryTile % 2 == 0 else 1","TILE_Q":"qkvPrefillQueryTile / portableLaneScale","TILE_K":"qkvClusterTileK if useSubgroups else qkvNoSgTileK","LPQ":"qkvPrefillLanesPerQuery * portableLaneScale","batchNoSgReduction":"not useSubgroups","portableScoreKeys":"min(LPQ, max(1, floor(TILE_K / 2))) if headDimV4 <= 4 * LPQ else 1","shareNoSgProb":"batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ","seqlensQueryFloor":"attrs.causal == 1","useSeqlens":true,"compensatedScoreDot":"tensorDtypes.queryT == \"float32\""},"passes":[{"id":"attention_folds","repeat":{"count":"2 if scalar == \"f32\" and not (tensorDtypes.queryT == \"float16\") else 1","index":"foldStep"},"passes":[{"id":"attention","name":"GroupQueryAttention.Flash","shader":"attn-flash-prefill-cluster.wgsl.jinja","derive":{"usesF16":"tensorDtypes.queryT == \"float16\"","layout":"\"bsh\"","foldStep":"repeat.foldStep"},"bindings":["query_query_t","key_key_t","value_value_t","output_output_t","seqlens_k","params_qkv_present"],"dispatch":{"x":"ceilDiv(dim(shapes.queryT, 1), TILE_Q)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}]},{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["key_key_t","value_value_t","present_key","present_value","params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"qkv_present_flash_cluster_causal","priority":31,"when":["flashShapeOk","qkvSgClusterOk or qkvNoSgClusterStorageOk","qkvPrefillClusterWorkgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup","qkvPrefillClusterWorkgroupSize <= device.limits.maxComputeWorkgroupSizeX","headDimPlan % (4 * qkvPrefillLanesPerQuery) == 0","dim(shapes.queryT, 1) >= tunables.QKV_PREFILL_MIN_QUERY_TOKENS","causalNoWindow","dim(shapes.keyT, 1) == dim(shapes.queryT, 1)","tensorDtypes.queryT == \"float16\"","device.features.has(\"subgroups\")","qkvSgClusterOk"],"demoteWhen":["device.features.has(\"subgroups\") and not qkvF32ClusterRegisterGeometry","qkvUnderfilledWideF32PreferQueryGroups"],"derive":{"hasCausal":true,"useSubgroups":"qkvSgClusterOk","usesF16":"qkvUsesF16","scalar":"qkvScalar","presentScalar":"qkvCacheScalar","inputElement":"qkvInputVec4","outputElement":"qkvInputVec4","presentElement":"qkvCacheVec4","kvNumHeads":"attrs.kv_num_heads","headDim":"dim(shapes.queryT, 2) / attrs.num_heads","headDimV4":"(dim(shapes.queryT, 2) / attrs.num_heads) / 4","qHiddenV4":"dim(shapes.queryT, 2) / 4","kvHidden":"dim(shapes.keyT, 2)","kvHiddenV4":"dim(shapes.keyT, 2) / 4","presentVec4":true,"portableLaneScale":"2 if not useSubgroups and dotRecoverProductResidual and headDimV4 > 4 * qkvPrefillLanesPerQuery and headDimV4 % (2 * qkvPrefillLanesPerQuery) == 0 and qkvPrefillQueryTile % 2 == 0 else 1","TILE_Q":"qkvPrefillQueryTile / portableLaneScale","TILE_K":"qkvClusterTileK if useSubgroups else qkvNoSgTileK","LPQ":"qkvPrefillLanesPerQuery * portableLaneScale","batchNoSgReduction":"not useSubgroups","portableScoreKeys":"min(LPQ, max(1, floor(TILE_K / 2))) if headDimV4 <= 4 * LPQ else 1","shareNoSgProb":"batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ","seqlensQueryFloor":"attrs.causal == 1","useSeqlens":true,"compensatedScoreDot":"tensorDtypes.queryT == \"float32\""},"passes":[{"id":"attention_folds","repeat":{"count":"2 if scalar == \"f32\" and not (tensorDtypes.queryT == \"float16\") else 1","index":"foldStep"},"passes":[{"id":"attention","name":"GroupQueryAttention.Flash","shader":"attn-flash-prefill-cluster.wgsl.jinja","derive":{"usesF16":"tensorDtypes.queryT == \"float16\"","layout":"\"bsh\"","foldStep":"repeat.foldStep"},"bindings":["query_query_t","key_key_t","value_value_t","output_output_t","seqlens_k","params_qkv_present_causal"],"dispatch":{"x":"ceilDiv(dim(shapes.queryT, 1), TILE_Q)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}]},{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["key_key_t","value_value_t","present_key","present_value","params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"past_kv_qnorm_rotary_flash_prefill","priority":37,"when":["sharedKvFloatOk","prefillFlashShapeOk","cachedSgPrefillOk or cachedNoSgClusterStorageOk","qPrepScratchFits","standardSoftmax","present.cosCacheT and rotaryRequested","present.qNormWeightT","not present.attentionBiasT","not present.headSinkT"],"derive":{"useSubgroups":"cachedSgPrefillOk","scalar":"gqaScalar","usesF16":"tensorDtypes.queryT == \"float16\"","hasCausal":true,"causalRightAlign":true,"headDim":"gqaHeadDim","headDimV4":"gqaHeadDim / 4","qHiddenV4":"dim(shapes.queryT, 2) / 4","kvNumHeads":"attrs.kv_num_heads","TILE_Q":"cachedPrefillQueryTile","TILE_K":"cachedClusterTileK if useSubgroups else cachedNoSgTileK","LPQ":"cachedPrefillLanesPerQuery","kvHeads":"attrs.kv_num_heads","packed":"gqaHeadDim","mode":"\"copy\"","hasRotary":true,"half":"gqaHeadDim / 2","qHeads":"attrs.num_heads","qHidden":"dim(shapes.queryT, 2)","hasQNorm":true,"qkEps":"attrs.qk_norm_epsilon","inputVec4":"gqaInputVec4","inputScalar":"gqaScalar","cosScalar":"\"f16\" if tensorDtypes.cosCacheT == \"float16\" else \"f32\"","qNormScalar":"\"f16\" if tensorDtypes.qNormWeightT == \"float16\" else \"f32\"","batchNoSgReduction":"not useSubgroups","shareNoSgProb":"batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ"},"intermediates":[{"id":"qPrep","dtype":"float32","shape":"[dim(shapes.queryT, 0), dim(shapes.queryT, 1), dim(shapes.queryT, 2)]"}],"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]},{"id":"qprep","name":"GroupQueryAttention.QPrep","shader":"gqa-qprep.wgsl.jinja","bindings":["query_qprep","cos_cache","sin_cache","q_norm_weight","qout","params_qprep"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)","z":1}},{"id":"attention_folds","repeat":{"count":"2 if scalar == \"f32\" and not usesF16 else 1","index":"foldStep"},"passes":[{"id":"attention","name":"GroupQueryAttention.FlashPrefill","shader":"attn-flash-prefill-cluster.wgsl.jinja","derive":{"layout":"\"bsh\"","qLayout":"\"bsh\"","kvLayout":"\"bhsd\"","foldStep":"repeat.foldStep"},"bindings":["qprep_read_vec4_f32","key_attention","value_attention","output_merge","params_past_kv_flash_prefill"],"dispatch":{"x":"ceilDiv(dim(shapes.queryT, 1), TILE_Q)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}]}]},{"id":"cached_decode_gqa","priority":39,"when":["sharedKvFloatOk or newKvPastOk","decodeFlashShapeOk","cachedSplitScratchFits","plainAttentionOptions","not hasWindow","attrs.num_heads / attrs.kv_num_heads >= 2","gqaHeadDim % 32 == 0 and 256 % (gqaHeadDim / 4) == 0","(attrs.num_heads / attrs.kv_num_heads) * (4 * gqaHeadDim + 5260) <= device.limits.maxComputeWorkgroupStorageSize","256 <= deviceWorkgroupCap","gqaDecodeMeasuredTier"],"derive":{"gqaSeqlens":"cacheCopyMode","headDim":"gqaHeadDim","numKvHeads":"attrs.kv_num_heads","numHeads":"attrs.num_heads","gqaGroup":"attrs.num_heads / attrs.kv_num_heads","numSplits":"gqaDecodeSplits","gqaMinKeys":"32","gqaOutScalar":"gqaScalar","packed":"gqaHeadDim","inputVec4":"gqaInputVec4","inputScalar":"gqaScalar","kvNumHeads":"attrs.kv_num_heads","kvHeads":"attrs.kv_num_heads","gqaNormalizedValues":"tensorDtypes.outputT == \"float32\" and ((present.pastValueT and tensorDtypes.pastValueT != \"float16\") or (present.valueT and tensorDtypes.valueT != \"float16\"))"},"intermediates":[{"id":"partialOut","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * gqaDecodeSplits * gqaHeadDim]"},{"id":"partialStats","dtype":"float32","shape":"[2 * dim(shapes.queryT, 0) * attrs.num_heads * gqaDecodeSplits]"}],"passes":[{"id":"cache_copy","repeat":{"index":"copyPass","count":"1 if cacheCopyMode else 0"},"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"copy\""},"bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]}]},{"id":"cache_merge","repeat":{"index":"mergePass","count":"0 if cacheCopyMode else 1"},"passes":[{"id":"present","name":"GroupQueryAttention.Merge","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"merge\""},"bindings":["past_k","past_v","new_k","new_v","present_key_present","present_value_present","params_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"split_attention","name":"GroupQueryAttention.DecodeGqaSplitK","shader":"attn-decode-gqa-splitk.wgsl.jinja","bindings":["query_attention",{"arg":"presentKeyT","name":"key_cache","buffer":"read-only-storage","elementType":"$inputVec4"},{"arg":"presentValueT","name":"value_cache","buffer":"read-only-storage","elementType":"$inputVec4"},"partial_out","partial_stats","seqlens_k_copy",{"name":"params","struct":[{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"}]}],"dispatch":{"x":"gqaDecodeSplits","y":"attrs.kv_num_heads","z":"dim(shapes.queryT, 0)"}},{"id":"merge","name":"GroupQueryAttention.DecodeGqaSplitKMerge","shader":"attn-decode-gqa-splitk-merge.wgsl.jinja","bindings":["partial_out_merge","partial_stats_merge","output_merge","seqlens_k_copy",{"name":"params","struct":[{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"}]}],"dispatch":{"x":1,"y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}]},{"id":"cached_decode_splitk","priority":38,"when":["sharedKvFloatOk or newKvPastOk","decodeFlashShapeOk","cachedSplitScratchFits","plainAttentionOptions","(gqaHeadDim) >= 4 and (tunables.WORKGROUP_SIZE) > 0 and (tunables.WORKGROUP_SIZE) <= deviceWorkgroupCap and (pow2ceil(tunables.WORKGROUP_SIZE) == (tunables.WORKGROUP_SIZE) or (subgroupSplitK)) and ((gqaHeadDim) * 8 + (tunables.WORKGROUP_SIZE) * 12 + (16 * (tunables.WORKGROUP_SIZE) if (tunables.WORKGROUP_SIZE) % ((gqaHeadDim) / 4) == 0 and (tunables.WORKGROUP_SIZE) / ((gqaHeadDim) / 4) >= 2 else 0) + (4 * (tunables.WORKGROUP_SIZE) if (subgroupSplitK) and ((gqaHeadDim) / 4) >= 8 and not ((tensorDtypes.queryT == \"float16\") and ((gqaHeadDim) / 4) <= 32) and (true) else 0) + (ceilDiv((tunables.WORKGROUP_SIZE), 32) * 4 + 8 if (subgroupSplitK) else 0) if (gqaHeadDim) >= 4 and (tunables.WORKGROUP_SIZE) > 0 else 0) <= device.limits.maxComputeWorkgroupStorageSize"],"derive":{"useSubgroups":"subgroupSplitK","cacheSeqlens":"cacheCopyMode","scalar":"gqaScalar","usesF16":"tensorDtypes.queryT == \"float16\"","kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","headDimV4":"gqaHeadDim / 4","numSplits":"cachedNumSplits","kvHeads":"attrs.kv_num_heads","packed":"gqaHeadDim","inputVec4":"gqaInputVec4","inputScalar":"gqaScalar","normalizedPartialValues":"tensorDtypes.outputT == \"float32\" and ((present.pastValueT and tensorDtypes.pastValueT != \"float16\") or (present.valueT and tensorDtypes.valueT != \"float16\"))"},"intermediates":[{"id":"partialOut","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * (cachedNumSplits) * gqaHeadDim]"},{"id":"partialStats","dtype":"float32","shape":"[2 * dim(shapes.queryT, 0) * attrs.num_heads * (cachedNumSplits)]"}],"passes":[{"id":"cache_copy","repeat":{"index":"copyPass","count":"1 if cacheCopyMode else 0"},"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"copy\""},"bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]}]},{"id":"cache_merge","repeat":{"index":"mergePass","count":"0 if cacheCopyMode else 1"},"passes":[{"id":"present","name":"GroupQueryAttention.Merge","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"merge\""},"bindings":["past_k","past_v","new_k","new_v","present_key_present","present_value_present","params_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"split_attention","name":"GroupQueryAttention.DecodeSplitK","shader":"attn-flash-decode-splitk.wgsl.jinja","derive":{"layout":"\"bhsd\""},"bindings":["query_attention","key_attention","value_attention","partial_out","partial_stats","seqlens_k_copy","params_split_attention"],"dispatch":{"x":"cachedNumSplits","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}},{"id":"merge","name":"GroupQueryAttention.DecodeSplitKMerge","shader":"attn-flash-decode-splitk-merge.wgsl.jinja","derive":{"layout":"\"bhsd\""},"bindings":["partial_out_merge","partial_stats_merge","output_merge"],"dispatch":{"x":1,"y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}]},{"id":"cached_flash_sgmat16_f16","priority":40,"when":["sharedKvFloatOk or newKvPastOk","plainAttentionOptions","tensorDtypes.queryT == \"float16\" and tensorDtypes.presentKeyT == \"float16\"","attrs.local_window_size <= 0","gqaHeadDim % 16 == 0 and gqaHeadDim <= 128","attrs.num_heads % attrs.kv_num_heads == 0","dim(shapes.queryT, 1) >= 64 and dim(shapes.presentKeyT, 2) >= dim(shapes.queryT, 1)","ceilDiv(dim(shapes.queryT, 1), 64) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","256 <= deviceWorkgroupCap","47376 + subgroupMatrixTopologyBytes <= device.limits.maxComputeWorkgroupStorageSize","has(device.adapterInfo, \"subgroupMatrixConfigs\") and subgroupMatrixConfigAvailable(\"f16\", \"f32\", 16, 16, 16)","has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize <= 32 and device.adapterInfo.subgroupMaxSize >= 32"],"requires":{"features":["shader-f16","subgroups","chromium-experimental-subgroup-matrix"],"limits":{"maxComputeInvocationsPerWorkgroup":256,"maxComputeWorkgroupSizeX":256},"subgroupMatrixConfigs":[{"componentType":"f16","resultComponentType":"f32","M":16,"N":16,"K":16}]},"derive":{"headDim":"gqaHeadDim","headDimV4":"gqaHeadDim / 4","kvNumHeads":"attrs.kv_num_heads","kvHeads":"attrs.kv_num_heads","packed":"gqaHeadDim","inputScalar":"gqaScalar","attnHeadDim":"gqaHeadDim","attnQHeads":"attrs.num_heads","attnKvHeads":"attrs.kv_num_heads","attnQLayout":"\"bsh\"","attnKvLayout":"\"bhsd\"","attnCausal":true,"attnCausalAtEnd":true,"attnWaves":"8 if dim(shapes.queryT, 0) * attrs.num_heads * ceilDiv(dim(shapes.queryT, 1), 64) < 160 else 4"},"passes":[{"id":"cache_copy","repeat":{"index":"copyPass","count":"1 if cacheCopyMode else 0"},"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"copy\""},"bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]}]},{"id":"cache_merge","repeat":{"index":"mergePass","count":"0 if cacheCopyMode else 1"},"passes":[{"id":"present","name":"GroupQueryAttention.Merge","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"merge\""},"bindings":["past_k","past_v","new_k","new_v","present_key_present","present_value_present","params_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"attention","name":"GroupQueryAttention.FlashSgmat16","shader":"attention-flash-sgmat16.wgsl.jinja","bindings":["query_f16","present_key_read_vec4_u32","present_value_read_vec4_u32","output_f16","params_present_kv_scaled"],"dispatch":{"x":"ceilDiv(dim(shapes.queryT, 1), 64)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}]},{"id":"past_kv_rotary_flash_sgmat16_f16","priority":40,"when":["sharedKvFloatOk","standardSoftmax","present.cosCacheT and rotaryRequested","not present.qNormWeightT","not present.attentionBiasT","not present.headSinkT","tensorDtypes.queryT == \"float16\" and tensorDtypes.presentKeyT == \"float16\"","attrs.local_window_size <= 0","gqaHeadDim % 16 == 0 and gqaHeadDim <= 128","attrs.num_heads % attrs.kv_num_heads == 0","dim(shapes.queryT, 1) >= 64 and dim(shapes.presentKeyT, 2) >= dim(shapes.queryT, 1)","ceilDiv(dim(shapes.queryT, 1), 64) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","256 <= deviceWorkgroupCap","47376 + subgroupMatrixTopologyBytes <= device.limits.maxComputeWorkgroupStorageSize","has(device.adapterInfo, \"subgroupMatrixConfigs\") and subgroupMatrixConfigAvailable(\"f16\", \"f32\", 16, 16, 16)","has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize <= 32 and device.adapterInfo.subgroupMaxSize >= 32"],"requires":{"features":["shader-f16","subgroups","chromium-experimental-subgroup-matrix"],"limits":{"maxComputeInvocationsPerWorkgroup":256,"maxComputeWorkgroupSizeX":256},"subgroupMatrixConfigs":[{"componentType":"f16","resultComponentType":"f32","M":16,"N":16,"K":16}]},"derive":{"headDim":"gqaHeadDim","headDimV4":"gqaHeadDim / 4","kvNumHeads":"attrs.kv_num_heads","kvHeads":"attrs.kv_num_heads","packed":"gqaHeadDim","mode":"\"copy\"","inputScalar":"gqaScalar","qHidden":"dim(shapes.queryT, 2)","half":"gqaHeadDim / 2","qHeads":"attrs.num_heads","cosScalar":"\"f16\" if tensorDtypes.cosCacheT == \"float16\" else \"f32\"","hasQNorm":false,"qPrepF16":true,"attnHeadDim":"gqaHeadDim","attnQHeads":"attrs.num_heads","attnKvHeads":"attrs.kv_num_heads","attnQLayout":"\"bsh\"","attnKvLayout":"\"bhsd\"","attnCausal":true,"attnCausalAtEnd":true,"attnWaves":"8 if dim(shapes.queryT, 0) * attrs.num_heads * ceilDiv(dim(shapes.queryT, 1), 64) < 160 else 4"},"intermediates":[{"id":"qPrep","dtype":"float16","shape":"[dim(shapes.queryT, 0), dim(shapes.queryT, 1), dim(shapes.queryT, 2)]"}],"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]},{"id":"qprep","name":"GroupQueryAttention.RotaryQPrep","shader":"gqa-qprep.wgsl.jinja","derive":{"qPrepPairs":true},"bindings":["query_qprep","cos_cache","sin_cache",{"scratch":"qPrep","name":"qout","elementType":"vec4"},"params_qprep"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * gqaHeadDim / 8), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * gqaHeadDim / 8), (copyWorkgroupSize)), 65535)","z":1}},{"id":"attention","name":"GroupQueryAttention.FlashSgmat16","shader":"attention-flash-sgmat16.wgsl.jinja","bindings":["qprep_read_f16","present_key_read_vec4_u32","present_value_read_vec4_u32","output_f16","params_present_kv_scaled"],"dispatch":{"x":"ceilDiv(dim(shapes.queryT, 1), 64)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}]},{"id":"past_kv_flash_sgmat16_split_f32","priority":41,"when":["sharedKvFloatOk","plainAttentionOptions","tensorDtypes.queryT == \"float32\" and tensorDtypes.presentKeyT == \"float32\"","attrs.local_window_size <= 0","gqaHeadDim % 16 == 0 and gqaHeadDim <= 128","attrs.num_heads % attrs.kv_num_heads == 0","dim(shapes.queryT, 1) >= 64 and dim(shapes.presentKeyT, 2) >= dim(shapes.queryT, 1)","ceilDiv(dim(shapes.queryT, 1), 64) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","256 <= deviceWorkgroupCap","48672 + subgroupMatrixTopologyBytes <= device.limits.maxComputeWorkgroupStorageSize","has(device.adapterInfo, \"subgroupMatrixConfigs\") and subgroupMatrixConfigAvailable(\"f16\", \"f32\", 16, 16, 16)","has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize <= 32 and device.adapterInfo.subgroupMaxSize >= 32","device.limits.maxStorageBuffersPerShaderStage >= 6","dim(shapes.presentKeyT, 2) >= 1024"],"requires":{"features":["shader-f16","subgroups","chromium-experimental-subgroup-matrix"],"limits":{"maxComputeInvocationsPerWorkgroup":256,"maxComputeWorkgroupSizeX":256},"subgroupMatrixConfigs":[{"componentType":"f16","resultComponentType":"f32","M":16,"N":16,"K":16}]},"derive":{"headDim":"gqaHeadDim","headDimV4":"gqaHeadDim / 4","kvNumHeads":"attrs.kv_num_heads","kvHeads":"attrs.kv_num_heads","packed":"gqaHeadDim","mode":"\"copy\"","inputScalar":"gqaScalar","attnHeadDim":"gqaHeadDim","attnQHeads":"attrs.num_heads","attnKvHeads":"attrs.kv_num_heads","attnQLayout":"\"bsh\"","attnKvLayout":"\"bhsd\"","attnCausal":true,"attnCausalAtEnd":true,"attnWaves":"8 if dim(shapes.queryT, 0) * attrs.num_heads * ceilDiv(dim(shapes.queryT, 1), 64) < 160 else 4","attnFullF32":true,"prepareQElements":"numel(shapes.queryT)"},"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]},{"id":"split","name":"GroupQueryAttention.PrepareF32","shader":"attention-prepare-f32.wgsl.jinja","bindings":["query","prepared_query_write_f32"],"dispatch":{"x":"min(ceilDiv((prepareQElements), (64)), 65535)","y":"ceilDiv(ceilDiv((prepareQElements), (64)), 65535)","z":1}},{"id":"attention","name":"GroupQueryAttention.OnlineF32","shader":"attention-flash-sgmat16.wgsl.jinja","bindings":["prepared_query_read_f32",{"arg":"presentKeyT","name":"key","buffer":"read-only-storage","elementType":"vec4"},{"arg":"presentValueT","name":"value","elementType":"vec4","buffer":"read-only-storage"},"output","params_present_kv_scaled"],"dispatch":{"x":"ceilDiv(dim(shapes.queryT, 1), 64)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}],"intermediates":[{"id":"q_prepared","dtype":"float32","shape":"[numel(shapes.queryT)]"}]},{"id":"new_kv_past_flash_sgmat16_split_f32","priority":41,"when":["newKvPastOk","plainAttentionOptions","tensorDtypes.queryT == \"float32\" and tensorDtypes.presentKeyT == \"float32\"","attrs.local_window_size <= 0","gqaHeadDim % 16 == 0 and gqaHeadDim <= 128","attrs.num_heads % attrs.kv_num_heads == 0","dim(shapes.queryT, 1) >= 64 and dim(shapes.presentKeyT, 2) >= dim(shapes.queryT, 1)","ceilDiv(dim(shapes.queryT, 1), 64) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","256 <= deviceWorkgroupCap","48672 + subgroupMatrixTopologyBytes <= device.limits.maxComputeWorkgroupStorageSize","has(device.adapterInfo, \"subgroupMatrixConfigs\") and subgroupMatrixConfigAvailable(\"f16\", \"f32\", 16, 16, 16)","has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize <= 32 and device.adapterInfo.subgroupMaxSize >= 32","device.limits.maxStorageBuffersPerShaderStage >= 6","dim(shapes.presentKeyT, 2) >= 1024"],"requires":{"features":["shader-f16","subgroups","chromium-experimental-subgroup-matrix"],"limits":{"maxComputeInvocationsPerWorkgroup":256,"maxComputeWorkgroupSizeX":256},"subgroupMatrixConfigs":[{"componentType":"f16","resultComponentType":"f32","M":16,"N":16,"K":16}]},"derive":{"headDim":"gqaHeadDim","headDimV4":"gqaHeadDim / 4","kvNumHeads":"attrs.kv_num_heads","kvHeads":"attrs.kv_num_heads","packed":"gqaHeadDim","mode":"\"merge\"","inputScalar":"gqaScalar","attnHeadDim":"gqaHeadDim","attnQHeads":"attrs.num_heads","attnKvHeads":"attrs.kv_num_heads","attnQLayout":"\"bsh\"","attnKvLayout":"\"bhsd\"","attnCausal":true,"attnCausalAtEnd":true,"attnWaves":"8 if dim(shapes.queryT, 0) * attrs.num_heads * ceilDiv(dim(shapes.queryT, 1), 64) < 160 else 4","attnFullF32":true,"prepareQElements":"numel(shapes.queryT)"},"passes":[{"id":"present","name":"GroupQueryAttention.Merge","shader":"gqa-present.wgsl.jinja","bindings":["past_k","past_v","new_k","new_v","present_key_present","present_value_present","params_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1}},{"id":"split","name":"GroupQueryAttention.PrepareF32","shader":"attention-prepare-f32.wgsl.jinja","bindings":["query","prepared_query_write_f32"],"dispatch":{"x":"min(ceilDiv((prepareQElements), (64)), 65535)","y":"ceilDiv(ceilDiv((prepareQElements), (64)), 65535)","z":1}},{"id":"attention","name":"GroupQueryAttention.OnlineF32","shader":"attention-flash-sgmat16.wgsl.jinja","bindings":["prepared_query_read_f32",{"arg":"presentKeyT","name":"key","buffer":"read-only-storage","elementType":"vec4"},{"arg":"presentValueT","name":"value","elementType":"vec4","buffer":"read-only-storage"},"output","params_present_kv_scaled"],"dispatch":{"x":"ceilDiv(dim(shapes.queryT, 1), 64)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}],"intermediates":[{"id":"q_prepared","dtype":"float32","shape":"[numel(shapes.queryT)]"}],"demoteWhen":["f32PreferCooperativeCachePrefill"]},{"id":"cached_flash_prefill","priority":34,"when":["sharedKvFloatOk or (newKvPastOk and plainAttentionOptions)","prefillFlashShapeOk","(cachedMaskSgPrefillOk if present.attentionBiasT else cachedSgPrefillOk) or cachedNoSgClusterStorageOk","not present.qNormWeightT","attrs.smooth_softmax != 1","attrs.softcap == 0 or (attrs.softcap > 0 and noAuxAttentionInputs)","(present.cosCacheT and rotaryRequested and not present.attentionBiasT and not present.headSinkT) or (not present.cosCacheT and not rotaryRequested)"],"derive":{"useSubgroups":"cachedMaskSgPrefillOk if present.attentionBiasT else cachedSgPrefillOk","scalar":"gqaScalar","usesF16":"tensorDtypes.queryT == \"float16\"","hasCausal":true,"causalRightAlign":true,"hasSoftcap":"attrs.softcap > 0","hasHeadSink":"present.headSinkT","hasMask":"present.attentionBiasT","stageMask":"not present.headSinkT","headDim":"gqaHeadDim","headDimV4":"gqaHeadDim / 4","qHiddenV4":"dim(shapes.queryT, 2) / 4","kvNumHeads":"attrs.kv_num_heads","TILE_Q":"biasPrefillQueryTile if present.attentionBiasT and not present.headSinkT else cachedPrefillQueryTile","TILE_K":"cachedClusterTileK if useSubgroups else cachedNoSgTileK","LPQ":"cachedPrefillLanesPerQuery","kvHeads":"attrs.kv_num_heads","packed":"gqaHeadDim","hasRotary":"present.cosCacheT","fusedRotary":"present.cosCacheT","half":"gqaHeadDim / 2","qHidden":"dim(shapes.queryT, 2)","inputVec4":"gqaInputVec4","inputScalar":"gqaScalar","cosScalar":"\"f16\" if tensorDtypes.cosCacheT == \"float16\" else \"f32\"","batchNoSgReduction":"not useSubgroups","shareNoSgProb":"batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ"},"passes":[{"id":"cache_copy","repeat":{"index":"copyPass","count":"1 if cacheCopyMode else 0"},"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"copy\""},"bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]}]},{"id":"cache_merge","repeat":{"index":"mergePass","count":"0 if cacheCopyMode else 1"},"passes":[{"id":"present","name":"GroupQueryAttention.Merge","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"merge\""},"bindings":["past_k","past_v","new_k","new_v","present_key_present","present_value_present","params_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"attention_folds","repeat":{"count":"2 if scalar == \"f32\" and not usesF16 else 1","index":"foldStep"},"passes":[{"id":"attention","name":"GroupQueryAttention.FlashPrefill","shader":"attn-flash-prefill-cluster.wgsl.jinja","derive":{"layout":"\"bsh\"","qLayout":"\"bsh\"","kvLayout":"\"bhsd\"","foldStep":"repeat.foldStep"},"bindings":["query_attention","key_attention","value_attention","attn_mask","cos_cache","sin_cache","head_sink","output_merge","params_past_kv_flash_prefill","params_past_kv_softcap_flash_prefill","params_attn_flash_prefill_cluster","params_new_kv_past_flash_prefill"],"dispatch":{"x":"ceilDiv(dim(shapes.queryT, 1), TILE_Q)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}]}]},{"id":"qkv_present_flash_q32_broadcast","priority":30,"when":["8 <= device.limits.maxComputeWorkgroupStorageSize","wave32SubgroupsUsable","device.features.has(\"shader-f16\")","tensorDtypes.queryT == \"float16\"","flashShapeOk","headDimPlan % 32 == 0","headDimPlan >= 64","headDimPlan <= 256","dim(shapes.queryT, 1) >= tunables.QKV_PREFILL_MIN_QUERY_TOKENS","attrs.local_window_size <= 0","not causalNoWindow or dim(shapes.queryT, 1) == dim(shapes.keyT, 1)"],"demoteWhen":["causalNoWindow and device.features.has(\"subgroups\") and not qkvCausalQ32Preferred","not causalNoWindow and qkvSgClusterOk and qkvPrefillClusterWorkgroupSize <= deviceWorkgroupCap and headDimPlan % (4 * qkvPrefillLanesPerQuery) == 0","qkvCausalQ32Preferred and (headDimPlan / 4) * 32 * 16 <= device.limits.maxComputeWorkgroupStorageSize"],"requires":{"features":["subgroups"]},"derive":{"hasBias":false,"hasCausal":"causalNoWindow","fixedCausal":"causalNoWindow","usesF16":true,"scalar":"\"f16\"","presentScalar":"qkvCacheScalar","inputElement":"\"vec4\"","outputElement":"\"vec4\"","presentElement":"qkvCacheVec4","kvNumHeads":"attrs.kv_num_heads","headDim":"dim(shapes.queryT, 2) / attrs.num_heads","headDimV4":"(dim(shapes.queryT, 2) / attrs.num_heads) / 4","kvHidden":"dim(shapes.keyT, 2)","kvHiddenV4":"dim(shapes.keyT, 2) / 4","presentVec4":true,"kStep":64,"qkGroups":16,"useSeqlens":true,"seqlensQueryFloor":"attrs.causal == 1","preciseQk":true},"passes":[{"id":"attention","name":"GroupQueryAttention.FlashQ32Broadcast","shader":"attn-flash-q32-broadcast.wgsl.jinja","derive":{"usesF16":"tensorDtypes.queryT == \"float16\"","layout":"\"bsh\""},"bindings":["query_query_t","key_key_t","value_value_t","output_output_t","seqlens_k","params_current_kv_scaled"],"dispatch":{"x":"ceilDiv(dim(shapes.queryT, 1), 32)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}},{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["key_key_t","value_value_t","present_key","present_value","params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"qkv_present_flash_q32_shared","priority":29,"when":["tensorDtypes.queryT == \"float16\"","flashShapeOk","headDimPlan % 4 == 0","headDimPlan >= 64","headDimPlan <= 256","dim(shapes.queryT, 1) >= tunables.QKV_PREFILL_MIN_QUERY_TOKENS","attrs.local_window_size <= 0","ceilDiv(dim(shapes.queryT, 1), 64) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","(headDimPlan / 4) * 32 * 16 <= device.limits.maxComputeWorkgroupStorageSize","not causalNoWindow or dim(shapes.queryT, 1) == dim(shapes.keyT, 1)"],"demoteWhen":["causalNoWindow and device.features.has(\"subgroups\") and not qkvCausalQ32Preferred","not causalNoWindow and qkvSgClusterOk and qkvPrefillClusterWorkgroupSize <= deviceWorkgroupCap and headDimPlan % (4 * qkvPrefillLanesPerQuery) == 0"],"requires":{"features":["shader-f16"]},"derive":{"hasBias":false,"hasCausal":"causalNoWindow","fixedCausal":"causalNoWindow","usesF16":true,"scalar":"\"f16\"","presentScalar":"qkvCacheScalar","inputElement":"\"vec4\"","outputElement":"\"vec4\"","presentElement":"qkvCacheVec4","kvNumHeads":"attrs.kv_num_heads","headDim":"dim(shapes.queryT, 2) / attrs.num_heads","headDimV4":"(dim(shapes.queryT, 2) / attrs.num_heads) / 4","kvHidden":"dim(shapes.keyT, 2)","kvHiddenV4":"dim(shapes.keyT, 2) / 4","presentVec4":true,"kStep":32,"qkGroups":8,"qStep":64,"useSeqlens":true,"seqlensQueryFloor":"attrs.causal == 1","preciseQk":true},"passes":[{"id":"attention","name":"GroupQueryAttention.FlashQ32Shared","shader":"attn-flash-q32-broadcast.wgsl.jinja","derive":{"usesF16":"tensorDtypes.queryT == \"float16\"","layout":"\"bsh\"","useSubgroups":"false"},"bindings":["query_query_t","key_key_t","value_value_t","output_output_t","seqlens_k","params_current_kv_scaled"],"dispatch":{"x":"ceilDiv(dim(shapes.queryT, 1), 64)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}},{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["key_key_t","value_value_t","present_key","present_value","params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"past_kv","priority":30,"when":["sharedKvFloatOk","gqaScalarDispatchOk","gqaHeadDim % 2 == 0","noAuxAttentionInputs or (present.cosCacheT and rotaryRequested)"],"derive":{"useSeqlens":true,"headDim":"gqaHeadDim","cooperative":"gqaCoop","dispatchUnits":"gqaDispatchUnits","qHeads":"attrs.num_heads","kvHeads":"attrs.kv_num_heads","qHidden":"dim(shapes.queryT, 2)","packed":"gqaHeadDim","half":"gqaHeadDim / 2","qkEps":"attrs.qk_norm_epsilon","hasRotary":"present.cosCacheT","hasQNorm":"present.qNormWeightT","mode":"\"copy\"","usesF16":"tensorDtypes.queryT == \"float16\"","inputScalar":"gqaScalar","cosScalar":"\"f16\" if tensorDtypes.cosCacheT == \"float16\" else \"f32\"","qNormScalar":"\"f16\" if tensorDtypes.qNormWeightT == \"float16\" else \"f32\""},"passes":[{"id":"attention","name":"GroupQueryAttention.Attn","shader":"gqa-attention.wgsl.jinja","bindings":["query_qprep","kcache_past_kv","vcache_past_kv","cos_cache","sin_cache","q_norm_weight","output_past_kv","seqlens_k","params_past_kv"],"dispatch":{"x":"min(dispatchUnits, 65535)","y":"ceilDiv(dispatchUnits, 65535)","z":1}},{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]}]},{"id":"new_kv_past","priority":30,"when":["newKvPastOk","gqaScalarDispatchOk","noAuxAttentionInputs","gqaHeadDim % 2 == 0"],"derive":{"headDim":"gqaHeadDim","qHeads":"attrs.num_heads","kvHeads":"attrs.kv_num_heads","qHidden":"dim(shapes.queryT, 2)","packed":"gqaHeadDim","mode":"\"merge\"","cooperative":"gqaCoop","dispatchUnits":"gqaDispatchUnits","usesF16":"tensorDtypes.queryT == \"float16\"","inputScalar":"gqaScalar"},"passes":[{"id":"present","name":"GroupQueryAttention.Merge","shader":"gqa-present.wgsl.jinja","bindings":["past_k","past_v","new_k","new_v","present_key_present","present_value_present","params_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1}},{"id":"attention","name":"GroupQueryAttention.Attn","shader":"gqa-attention.wgsl.jinja","bindings":["query_qprep","kcache","vcache","output_past_kv","params_attention"],"dispatch":{"x":"min(dispatchUnits, 65535)","y":"ceilDiv(dispatchUnits, 65535)","z":1}}]},{"id":"new_kv_qnorm_rotary","priority":33,"when":["copyWorkgroupOk","gqaScalarDispatchOk","present.seqlensKT","not present.pastKeyT","dim(shapes.keyT, 1) > 0","tensorDtypes.queryT == \"float32\"","not present.kScaleT","present.cosCacheT and rotaryRequested","present.qNormWeightT","dim(shapes.queryT, 2) % attrs.num_heads == 0","gqaHeadDim % 2 == 0","promptAuxOk"],"derive":{"headDim":"gqaHeadDim","cooperative":"gqaCoop","dispatchUnits":"gqaDispatchUnits","qHeads":"attrs.num_heads","kvHeads":"attrs.kv_num_heads","qHidden":"dim(shapes.queryT, 2)","packed":"gqaHeadDim","half":"gqaHeadDim / 2","qkEps":"attrs.qk_norm_epsilon","hasRotary":true,"hasQNorm":true,"mode":"\"build\"","hasKNorm":true,"hasBias":"present.attentionBiasT","hasHeadSink":"present.headSinkT","inputScalar":"gqaScalar"},"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["src_k_f32","src_v_f32","cos_cache_f32","sin_cache_f32","k_norm_weight","present_key_f32","present_value_f32","params_count_seq_past_seq"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","z":1}},{"id":"attention","name":"GroupQueryAttention.Attn","shader":"gqa-attention.wgsl.jinja","bindings":["query","kcache_f32","vcache_f32","cos_cache_f32","sin_cache_f32","q_norm_weight_f32","attn_bias","head_sink","output",{"name":"params","when":"not present.attentionBiasT and not present.headSinkT","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"},{"name":"smoothSoftmax","type":"u32","value":"1 if attrs.smooth_softmax == 1 else 0"}]},{"name":"params","when":"present.attentionBiasT and not present.headSinkT","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"},{"name":"smoothSoftmax","type":"u32","value":"1 if attrs.smooth_softmax == 1 else 0"},{"name":"biasBatch","type":"u32","value":"dim(shapes.attentionBiasT, 0)"},{"name":"biasHeads","type":"u32","value":"dim(shapes.attentionBiasT, 1)"}]},{"name":"params","when":"present.headSinkT and not present.attentionBiasT","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"}]},{"name":"params","when":"present.attentionBiasT and present.headSinkT","struct":[{"name":"batch","type":"u32","value":"dim(shapes.queryT, 0)"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"totalSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"softcap","type":"f32","value":"attrs.softcap"},{"name":"biasBatch","type":"u32","value":"dim(shapes.attentionBiasT, 0)"},{"name":"biasHeads","type":"u32","value":"dim(shapes.attentionBiasT, 1)"}]}],"dispatch":{"x":"min(dispatchUnits, 65535)","y":"ceilDiv(dispatchUnits, 65535)","z":1}}]},{"id":"past_kv_bias_or_sink","priority":30,"when":["sharedKvCacheOk","gqaScalarDispatchOk","tensorDtypes.queryT == \"float32\"","gqaHeadDim % 2 == 0","not present.cosCacheT and not rotaryRequested","not present.qNormWeightT","present.attentionBiasT or present.headSinkT"],"derive":{"useSeqlens":true,"headDim":"gqaHeadDim","cooperative":"gqaCoop","dispatchUnits":"gqaDispatchUnits","qHeads":"attrs.num_heads","kvHeads":"attrs.kv_num_heads","qHidden":"dim(shapes.queryT, 2)","packed":"gqaHeadDim","hasBias":"present.attentionBiasT","hasHeadSink":"present.headSinkT","mode":"\"copy\"","inputScalar":"gqaScalar"},"passes":[{"id":"attention","name":"GroupQueryAttention.Attn","shader":"gqa-attention.wgsl.jinja","bindings":["query","kcache_f32_read","vcache_f32_read","attn_bias","head_sink","output","seqlens_k","params_past_kv_bias","params_gqa_attention","params_past_kv_bias_headsink"],"dispatch":{"x":"min(dispatchUnits, 65535)","y":"ceilDiv(dispatchUnits, 65535)","z":1}},{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]}]},{"id":"quant_flash_prefill","priority":37,"when":["quantizedPromptOk","prefillFlashShapeOk","cachedSgPrefillOk or cachedNoSgClusterStorageOk","plainAttentionOptions"],"derive":{"useSubgroups":"cachedSgPrefillOk","scalar":"gqaScalar","usesF16":false,"hasCausal":true,"causalRightAlign":true,"headDim":"gqaHeadDim","headDimV4":"gqaHeadDim / 4","qHiddenV4":"dim(shapes.queryT, 2) / 4","kvNumHeads":"attrs.kv_num_heads","TILE_Q":"cachedPrefillQueryTile","TILE_K":"cachedClusterTileK if useSubgroups else cachedNoSgTileK","LPQ":"cachedPrefillLanesPerQuery","kvHeads":"attrs.kv_num_heads","inputVec4":"gqaInputVec4","inputScalar":"gqaScalar","batchNoSgReduction":"not useSubgroups","quantCacheFormat":"\"int8\" if attrs.kv_cache_bit_width == 8 else \"int4\"","quantCacheElement":"\"i32\" if attrs.kv_cache_bit_width == 8 else \"u32\"","quantCacheReadElement":"\"vec4\" if attrs.kv_cache_bit_width == 8 else \"u32\"","packed":"gqaHeadDim / (8 / attrs.kv_cache_bit_width)","qHidden":"dim(shapes.queryT, 2)","mode":"\"build_quant\"","bits":"attrs.kv_cache_bit_width","qmax":"127 if attrs.kv_cache_bit_width == 8 else 7","qmin":"0 - (128 if attrs.kv_cache_bit_width == 8 else 8)","shareNoSgProb":"batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ"},"passes":[{"id":"present","name":"GroupQueryAttention.QuantPresent","shader":"gqa-present.wgsl.jinja","bindings":["src_k_f32","src_v_f32","k_scale","v_scale","present_key_quant_int8","present_value_quant_int8","params_quant_int8"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","z":1}},{"id":"attention_folds","repeat":{"count":"2 if scalar == \"f32\" and not usesF16 else 1","index":"foldStep"},"passes":[{"id":"attention","name":"GroupQueryAttention.QuantFlashPrefill","shader":"attn-flash-prefill-cluster.wgsl.jinja","derive":{"layout":"\"bsh\"","qLayout":"\"bsh\"","kvLayout":"\"bhsd\"","foldStep":"repeat.foldStep"},"bindings":["query_attention","key_present_key_t","value_present_value_t","k_scale","v_scale","output_merge","params_quant_int8_flash_prefill"],"dispatch":{"x":"ceilDiv(dim(shapes.queryT, 1), cachedPrefillQueryTile)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}]}]},{"id":"share_append_split_flash_prefill","priority":35,"when":["shareAppendOk or shareAppendBidirectionalOk","prefillFlashShapeOk","cachedSgPrefillOk or cachedNoSgClusterStorageOk","plainAttentionOptions"],"derive":{"useSubgroups":"cachedSgPrefillOk","scalar":"gqaScalar","usesF16":"tensorDtypes.queryT == \"float16\"","hasCausal":"attrs.causal == 1","causalRightAlign":"attrs.causal == 1","headDim":"gqaHeadDim","headDimV4":"gqaHeadDim / 4","qHiddenV4":"dim(shapes.queryT, 2) / 4","kvNumHeads":"attrs.kv_num_heads","TILE_Q":"cachedPrefillQueryTile","TILE_K":"cachedClusterTileK if useSubgroups else cachedNoSgTileK","LPQ":"cachedPrefillLanesPerQuery","kvHeads":"attrs.kv_num_heads","packed":"gqaHeadDim","mode":"\"merge_share\"","useSeqlens":true,"inputVec4":"gqaInputVec4","inputScalar":"gqaScalar","batchNoSgReduction":"not useSubgroups","shareNoSgProb":"batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ"},"passes":[{"id":"present_retain","name":"GroupQueryAttention.MergeShareRetain","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"retain\""},"bindings":["past_k","past_v","present_key_present","present_value_present","seqlens_k","params__uniform"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"past_k","output":"present_key"},{"input":"past_v","output":"present_value"}]},{"id":"present_append","name":"GroupQueryAttention.MergeShareAppend","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"append\""},"bindings":["new_k","new_v","present_key_present","present_value_present","seqlens_k","params_gqa_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","z":1}},{"id":"attention_folds","repeat":{"count":"2 if scalar == \"f32\" and not usesF16 else 1","index":"foldStep"},"passes":[{"id":"attention","name":"GroupQueryAttention.FlashPrefill","shader":"attn-flash-prefill-cluster.wgsl.jinja","derive":{"layout":"\"bsh\"","qLayout":"\"bsh\"","kvLayout":"\"bhsd\"","foldStep":"repeat.foldStep"},"bindings":["query_attention","key_attention","value_attention","output_merge","seqlens_k","params_new_kv_past_flash_prefill","params_new_kv_past_flash_bidirectional"],"dispatch":{"x":"ceilDiv(dim(shapes.queryT, 1), TILE_Q)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}]}]},{"id":"share_append_split_flash_prefill_wide_cluster","priority":36,"when":["shareAppendOk","prefillFlashShapeOk","cachedSgPrefillOk or cachedNoSgClusterStorageOk","plainAttentionOptions","geometrySharedAppendOk"],"derive":{"useSubgroups":"cachedSgPrefillOk","scalar":"gqaScalar","usesF16":"tensorDtypes.queryT == \"float16\"","hasCausal":true,"causalRightAlign":true,"headDim":"gqaHeadDim","headDimV4":"gqaHeadDim / 4","qHiddenV4":"dim(shapes.queryT, 2) / 4","kvNumHeads":"attrs.kv_num_heads","TILE_Q":"geometryQueryTile","TILE_K":"cachedClusterTileK if useSubgroups else cachedNoSgTileK","LPQ":"geometryLanes","kvHeads":"attrs.kv_num_heads","packed":"gqaHeadDim","mode":"\"merge_share\"","useSeqlens":true,"inputVec4":"gqaInputVec4","inputScalar":"gqaScalar","batchNoSgReduction":"not useSubgroups","shareNoSgProb":"batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ","singleQueryPerLane":true},"passes":[{"id":"present_retain","name":"GroupQueryAttention.MergeShareRetain","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"retain\""},"bindings":["past_k","past_v","present_key_present","present_value_present","seqlens_k","params__uniform"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"past_k","output":"present_key"},{"input":"past_v","output":"present_value"}]},{"id":"present_append","name":"GroupQueryAttention.MergeShareAppend","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"append\""},"bindings":["new_k","new_v","present_key_present","present_value_present","seqlens_k","params_gqa_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","z":1}},{"id":"attention_folds","repeat":{"count":"2 if scalar == \"f32\" and not usesF16 else 1","index":"foldStep"},"passes":[{"id":"attention","name":"GroupQueryAttention.FlashPrefill","shader":"attn-flash-prefill-cluster.wgsl.jinja","derive":{"layout":"\"bsh\"","qLayout":"\"bsh\"","kvLayout":"\"bhsd\"","foldStep":"repeat.foldStep"},"bindings":["query_attention","key_attention","value_attention","output_merge","seqlens_k","params_new_kv_past_flash_prefill_wide"],"dispatch":{"x":"ceilDiv(dim(shapes.queryT, 1), TILE_Q)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}]}]},{"id":"share_append_qnorm_rotary_decode_splitk","priority":40,"when":["shareAppendOk","shareQkNormRotaryOk","dim(shapes.queryT, 1) == 1","flashWorkgroupOk and gqaHeadDim % 4 == 0 and gqaFlashHd and gqaDispatchFits","qkSplitScratchFits","gqaHeadDim <= qkSplitWorkgroup or gqaHeadDim == qkSplitWorkgroup * 2","(gqaHeadDim) >= 4 and (qkSplitWorkgroup) > 0 and (qkSplitWorkgroup) <= deviceWorkgroupCap and (pow2ceil(qkSplitWorkgroup) == (qkSplitWorkgroup) or (qkSplitSubgroups)) and ((gqaHeadDim) * 8 + (qkSplitWorkgroup) * 12 + (16 * (qkSplitWorkgroup) if (qkSplitWorkgroup) % ((gqaHeadDim) / 4) == 0 and (qkSplitWorkgroup) / ((gqaHeadDim) / 4) >= 2 else 0) + (4 * (qkSplitWorkgroup) if (qkSplitSubgroups) and ((gqaHeadDim) / 4) >= 8 and not ((tensorDtypes.queryT == \"float16\") and ((gqaHeadDim) / 4) <= 32) and (true) else 0) + (ceilDiv((qkSplitWorkgroup), 32) * 4 + 8 if (qkSplitSubgroups) else 0) if (gqaHeadDim) >= 4 and (qkSplitWorkgroup) > 0 else 0) + 4 * (qkSplitWorkgroup) + 4 <= device.limits.maxComputeWorkgroupStorageSize","gqaHeadDim % 8 == 0","dim(shapes.cosCacheT, 0) >= dim(shapes.presentKeyT, 2) and dim(shapes.sinCacheT, 0) >= dim(shapes.presentKeyT, 2)"],"derive":{"useSubgroups":"qkSplitSubgroups","cacheSeqlens":"true","scalar":"gqaScalar","usesF16":"false","kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","headDimV4":"gqaHeadDim / 4","numSplits":"qkSplits","kvHeads":"attrs.kv_num_heads","packed":"gqaHeadDim","mode":"\"merge_share\"","inputVec4":"gqaInputVec4","inputScalar":"gqaScalar","half":"gqaHeadDim / 2","qkEps":"attrs.qk_norm_epsilon","workgroupSizeSpec":"qkSplitWorkgroup","minKeysPerChunk":8,"fusedQNormRope":true,"seqlensQueryFloor":true,"qRopeAtPosition":true,"inlinePartialStats":true,"hasRotary":true,"normalizedPartialValues":"tensorDtypes.outputT == \"float32\" and ((present.pastValueT and tensorDtypes.pastValueT != \"float16\") or (present.valueT and tensorDtypes.valueT != \"float16\"))"},"intermediates":[{"id":"partial","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * qkSplits * (gqaHeadDim + 4)]"}],"passes":[{"id":"present_retain","name":"GroupQueryAttention.MergeShareRetain","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"retain\""},"bindings":["past_k","past_v","present_key_present","present_value_present","seqlens_k","params__uniform"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"past_k","output":"present_key"},{"input":"past_v","output":"present_value"}]},{"id":"append_norm","name":"GroupQueryAttention.ShareAppendNorm","shader":"gqa-norm-rotate-rows.wgsl.jinja","bindings":["new_k","new_v","cos_cache_f32","sin_cache_f32","k_norm_weight","present_key_present","present_value_present","seqlens_k","params_gqa_present"],"dispatch":{"x":"min(dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1), 65535)","y":"ceilDiv(dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1), 65535)","z":1},"derive":{"rowKind":"\"key\"","rowSource":"\"new_k\"","rowDestination":"\"present_key\"","rowNormWeight":"\"k_norm_weight\""}},{"id":"split_attention","name":"GroupQueryAttention.DecodeSplitK","shader":"attn-flash-decode-splitk.wgsl.jinja","derive":{"layout":"\"bhsd\""},"bindings":["query_attention","key_attention","value_attention","partial_inline","q_norm_weight_vec4","cos_cache_f32","sin_cache_f32","seqlens_k","params_qk_split"],"dispatch":{"x":"qkSplits","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}},{"id":"merge","name":"GroupQueryAttention.DecodeSplitKMerge","shader":"attn-flash-decode-splitk-merge.wgsl.jinja","derive":{"layout":"\"bhsd\""},"bindings":["partial_inline_merge","output_merge"],"dispatch":{"x":1,"y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}]},{"id":"share_append_qnorm_rotary_decode_splitk_fused","priority":41,"when":["shareAppendOk","shareQkNormRotaryOk","dim(shapes.queryT, 1) == 1","flashWorkgroupOk and gqaHeadDim % 4 == 0 and gqaFlashHd and gqaDispatchFits","qkSplitScratchFits","gqaHeadDim <= qkSplitWorkgroup or gqaHeadDim == qkSplitWorkgroup * 2","(gqaHeadDim) >= 4 and (qkSplitWorkgroup) > 0 and (qkSplitWorkgroup) <= deviceWorkgroupCap and (pow2ceil(qkSplitWorkgroup) == (qkSplitWorkgroup) or (qkSplitSubgroups)) and ((gqaHeadDim) * 8 + (qkSplitWorkgroup) * 12 + (16 * (qkSplitWorkgroup) if (qkSplitWorkgroup) % ((gqaHeadDim) / 4) == 0 and (qkSplitWorkgroup) / ((gqaHeadDim) / 4) >= 2 else 0) + (4 * (qkSplitWorkgroup) if (qkSplitSubgroups) and ((gqaHeadDim) / 4) >= 8 and not ((tensorDtypes.queryT == \"float16\") and ((gqaHeadDim) / 4) <= 32) and (true) else 0) + (ceilDiv((qkSplitWorkgroup), 32) * 4 + 8 if (qkSplitSubgroups) else 0) if (gqaHeadDim) >= 4 and (qkSplitWorkgroup) > 0 else 0) + 4 * (qkSplitWorkgroup) + 4 <= device.limits.maxComputeWorkgroupStorageSize","gqaHeadDim % 8 == 0","dim(shapes.cosCacheT, 0) >= dim(shapes.presentKeyT, 2) and dim(shapes.sinCacheT, 0) >= dim(shapes.presentKeyT, 2)","device.limits.maxStorageBuffersPerShaderStage >= 10","(dim(shapes.queryT, 0) * attrs.num_heads * qkSplits * (gqaHeadDim + 4) + dim(shapes.queryT, 0) * (attrs.kv_num_heads + 2 * attrs.num_heads) * gqaHeadDim) * 4 <= min(device.limits.maxStorageBufferBindingSize, device.limits.maxBufferSize)","tensorDtypes.pastValueT == \"float32\" and tensorDtypes.outputT == \"float32\"","qkSplitSubgroups"],"derive":{"useSubgroups":"qkSplitSubgroups","cacheSeqlens":"true","scalar":"gqaScalar","usesF16":"false","kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","headDimV4":"gqaHeadDim / 4","numSplits":"qkSplits","kvHeads":"attrs.kv_num_heads","packed":"gqaHeadDim","mode":"\"merge_share\"","inputVec4":"gqaInputVec4","inputScalar":"gqaScalar","half":"gqaHeadDim / 2","qkEps":"attrs.qk_norm_epsilon","workgroupSizeSpec":"qkSplitWorkgroup","minKeysPerChunk":8,"fusedQNormRope":true,"seqlensQueryFloor":true,"qRopeAtPosition":true,"inlinePartialStats":true,"hasRotary":true,"normalizedPartialValues":"tensorDtypes.outputT == \"float32\" and ((present.pastValueT and tensorDtypes.pastValueT != \"float16\") or (present.valueT and tensorDtypes.valueT != \"float16\"))","fusedNormAppend":true,"appendScratchBaseV4":"dim(shapes.queryT, 0) * attrs.num_heads * qkSplits * (gqaHeadDim / 4 + 1)","appendStateBaseV4":"appendScratchBaseV4 + dim(shapes.queryT, 0) * attrs.kv_num_heads * gqaHeadDim / 4"},"intermediates":[{"id":"partial","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * qkSplits * (gqaHeadDim + 4) + dim(shapes.queryT, 0) * (attrs.kv_num_heads + 2 * attrs.num_heads) * gqaHeadDim]"}],"passes":[{"id":"present_retain","name":"GroupQueryAttention.MergeShareRetain","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"retain\""},"bindings":["past_k","past_v","present_key_present","present_value_present","seqlens_k","params__uniform"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"past_k","output":"present_key"},{"input":"past_v","output":"present_value"}]},{"id":"split_attention","name":"GroupQueryAttention.DecodeSplitK","shader":"attn-flash-decode-splitk.wgsl.jinja","derive":{"layout":"\"bhsd\""},"bindings":["query_attention","key_attention","value_attention","partial_inline","q_norm_weight_vec4","cos_cache_f32","sin_cache_f32","seqlens_k","params_qk_split",{"arg":"keyT","name":"new_key","elementType":"vec4"},{"arg":"kNormWeightT","name":"k_norm_weight","elementType":"vec4"}],"dispatch":{"x":"qkSplits","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}},{"id":"merge","name":"GroupQueryAttention.DecodeSplitKMerge","shader":"attn-flash-decode-splitk-merge.wgsl.jinja","derive":{"layout":"\"bhsd\""},"bindings":["partial_inline_merge","output_merge",{"arg":"valueT","name":"new_value","elementType":"vec4"},{"arg":"presentKeyT","name":"key","elementType":"vec4"},{"arg":"presentValueT","name":"value","elementType":"vec4"},"seqlens_k",{"name":"params","struct":[{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"}]}],"dispatch":{"x":1,"y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}],"requires":{"features":["subgroups"]},"demoteWhen":["not qkAppendFusionPreferred"]},{"id":"share_append_qnorm_rotary_flash_prefill","priority":37,"when":["shareAppendOk","shareQkNormRotaryOk","prefillFlashShapeOk","cachedSgPrefillOk or cachedNoSgClusterStorageOk","qPrepScratchFits"],"derive":{"useSubgroups":"cachedSgPrefillOk","scalar":"gqaScalar","usesF16":"false","hasCausal":true,"causalRightAlign":true,"headDim":"gqaHeadDim","headDimV4":"gqaHeadDim / 4","qHiddenV4":"dim(shapes.queryT, 2) / 4","kvNumHeads":"attrs.kv_num_heads","TILE_Q":"cachedPrefillQueryTile","TILE_K":"cachedClusterTileK if useSubgroups else cachedNoSgTileK","LPQ":"cachedPrefillLanesPerQuery","kvHeads":"attrs.kv_num_heads","packed":"gqaHeadDim","mode":"\"merge_share\"","useSeqlens":true,"inputVec4":"gqaInputVec4","inputScalar":"gqaScalar","batchNoSgReduction":"not useSubgroups","shareNoSgProb":"batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ","qHeads":"attrs.num_heads","qHidden":"dim(shapes.queryT, 2)","half":"gqaHeadDim / 2","qkEps":"attrs.qk_norm_epsilon"},"intermediates":[{"id":"qPrep","dtype":"float32","shape":"[dim(shapes.queryT, 0), dim(shapes.queryT, 1), dim(shapes.queryT, 2)]"}],"passes":[{"id":"present_retain","name":"GroupQueryAttention.MergeShareRetain","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"retain\""},"bindings":["past_k","past_v","present_key_present","present_value_present","seqlens_k","params__uniform"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"past_k","output":"present_key"},{"input":"past_v","output":"present_value"}]},{"id":"append_norm","name":"GroupQueryAttention.ShareAppendNorm","shader":"gqa-norm-rotate-rows.wgsl.jinja","bindings":["new_k","new_v","cos_cache_f32","sin_cache_f32","k_norm_weight","present_key_present","present_value_present","seqlens_k","params_gqa_present"],"dispatch":{"x":"min(dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1), 65535)","y":"ceilDiv(dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1), 65535)","z":1},"derive":{"rowKind":"\"key\"","rowSource":"\"new_k\"","rowDestination":"\"present_key\"","rowNormWeight":"\"k_norm_weight\""}},{"id":"qprep","name":"GroupQueryAttention.ShareQueryNorm","shader":"gqa-norm-rotate-rows.wgsl.jinja","bindings":["query_qprep","cos_cache_f32","sin_cache_f32","q_norm_weight_f32","qout_rows","seqlens_k","params_qprep_share"],"dispatch":{"x":"min(dim(shapes.queryT, 0) * dim(shapes.queryT, 1) * attrs.num_heads, 65535)","y":"ceilDiv(dim(shapes.queryT, 0) * dim(shapes.queryT, 1) * attrs.num_heads, 65535)","z":1},"derive":{"rowKind":"\"query\"","rowSource":"\"query\"","rowDestination":"\"qout\"","rowNormWeight":"\"q_norm_weight\""}},{"id":"attention_folds","repeat":{"count":"2 if scalar == \"f32\" and not usesF16 else 1","index":"foldStep"},"passes":[{"id":"attention","name":"GroupQueryAttention.FlashPrefill","shader":"attn-flash-prefill-cluster.wgsl.jinja","derive":{"layout":"\"bsh\"","qLayout":"\"bsh\"","kvLayout":"\"bhsd\"","foldStep":"repeat.foldStep"},"bindings":["qprep_read_vec4_f32","key_attention","value_attention","output_merge","seqlens_k","params_qk_flash_prefill"],"dispatch":{"x":"ceilDiv(dim(shapes.queryT, 1), TILE_Q)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}]}]},{"id":"share_append_qnorm_rotary_split","priority":30,"when":["shareAppendOk","shareQkNormRotaryOk","gqaScalarDispatchOk","qPrepScratchFits"],"derive":{"useSeqlens":true,"headDim":"gqaHeadDim","cooperative":"gqaCoop","dispatchUnits":"gqaDispatchUnits","qHeads":"attrs.num_heads","kvHeads":"attrs.kv_num_heads","qHidden":"dim(shapes.queryT, 2)","packed":"gqaHeadDim","mode":"\"merge_share\"","usesF16":"false","inputScalar":"\"f32\"","half":"gqaHeadDim / 2","qkEps":"attrs.qk_norm_epsilon"},"intermediates":[{"id":"qPrep","dtype":"float32","shape":"[dim(shapes.queryT, 0), dim(shapes.queryT, 1), dim(shapes.queryT, 2)]"}],"passes":[{"id":"present_retain","name":"GroupQueryAttention.MergeShareRetain","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"retain\""},"bindings":["past_k","past_v","present_key_present","present_value_present","seqlens_k","params__uniform"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"past_k","output":"present_key"},{"input":"past_v","output":"present_value"}]},{"id":"append_norm","name":"GroupQueryAttention.ShareAppendNorm","shader":"gqa-norm-rotate-rows.wgsl.jinja","bindings":["new_k","new_v","cos_cache_f32","sin_cache_f32","k_norm_weight","present_key_present","present_value_present","seqlens_k","params_gqa_present"],"dispatch":{"x":"min(dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1), 65535)","y":"ceilDiv(dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1), 65535)","z":1},"derive":{"rowKind":"\"key\"","rowSource":"\"new_k\"","rowDestination":"\"present_key\"","rowNormWeight":"\"k_norm_weight\""}},{"id":"qprep","name":"GroupQueryAttention.ShareQueryNorm","shader":"gqa-norm-rotate-rows.wgsl.jinja","bindings":["query_qprep","cos_cache_f32","sin_cache_f32","q_norm_weight_f32","qout_rows","seqlens_k","params_qprep_share"],"dispatch":{"x":"min(dim(shapes.queryT, 0) * dim(shapes.queryT, 1) * attrs.num_heads, 65535)","y":"ceilDiv(dim(shapes.queryT, 0) * dim(shapes.queryT, 1) * attrs.num_heads, 65535)","z":1},"derive":{"rowKind":"\"query\"","rowSource":"\"query\"","rowDestination":"\"qout\"","rowNormWeight":"\"q_norm_weight\""}},{"id":"attention","name":"GroupQueryAttention.Attn","shader":"gqa-attention.wgsl.jinja","bindings":["qprep_read_f32","kcache","vcache","output_past_kv","seqlens_k","params_attention"],"dispatch":{"x":"min(dispatchUnits, 65535)","y":"ceilDiv(dispatchUnits, 65535)","z":1}}]},{"id":"window_shift_materialized_sgmat_f32","priority":36,"when":["gqaMatWindowOk","tensorDtypes.queryT == \"float32\"","windowMatFits"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":8,"N":8,"K":8}]},"derive":{"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"windowMatStatSlots","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar"},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * windowStageCapacity]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatPastRowStatsElements]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[windowMatScorePartialElements]"},{"id":"windowKey","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowValue","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowLengths","dtype":"int32","shape":"[2 * dim(shapes.queryT, 0)]"}],"passes":[{"id":"present","name":"GroupQueryAttention.WindowShift","shader":"gqa-window-cache.wgsl.jinja","bindings":["past_k","past_v","new_k","new_v","window_key_write","window_value_write","seqlens_k","params_window_stage","window_lengths_write"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","z":1},"derive":{"windowPhase":"\"stage\"","stageRegion":"\"all\""}},{"id":"scores","name":"GroupQueryAttention.WindowMaterializedScores","shader":"attn-materialized-sgmat-f32.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"scoreWindow":true,"useSeqlens":true},"bindings":["query","window_key_read_f32","scores","scorePartials","window_lengths_read","params_window_attention_scaled"],"dispatch":{"x":"ceilDiv(windowStageCapacity, gqaMatKeyTile)","y":"ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.WindowMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (gqaMatRowStatsWg)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.WindowMaterializedApply","shader":"attn-materialized-sgmat-f32.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"scoreWindow":true,"useSeqlens":true},"bindings":["scores_f32","window_value_read_f32","rowStats_f32","output","window_lengths_read","params_window_attention"],"dispatch":{"x":"ceilDiv(gqaHeadDim, gqaMatKeyTile)","y":"ceilDiv(dim(shapes.queryT, 1), gqaMatQueryTile)","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"compact","name":"GroupQueryAttention.WindowCompact","shader":"gqa-window-cache.wgsl.jinja","derive":{"windowPhase":"\"compact\""},"bindings":["window_key_read","window_value_read","window_lengths_read","present_key_present","present_value_present","params_window_compact","output_past_kv"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"window_shift_decode_splitk","priority":38,"when":["windowShiftOk","decodeFlashShapeOk","cachedSplitScratchFits","plainAttentionOptions","tensorDtypes.queryT == \"float32\"","(gqaHeadDim) >= 4 and (tunables.WORKGROUP_SIZE) > 0 and (tunables.WORKGROUP_SIZE) <= deviceWorkgroupCap and (pow2ceil(tunables.WORKGROUP_SIZE) == (tunables.WORKGROUP_SIZE) or (subgroupSplitK)) and ((gqaHeadDim) * 8 + (tunables.WORKGROUP_SIZE) * 12 + (16 * (tunables.WORKGROUP_SIZE) if (tunables.WORKGROUP_SIZE) % ((gqaHeadDim) / 4) == 0 and (tunables.WORKGROUP_SIZE) / ((gqaHeadDim) / 4) >= 2 else 0) + (4 * (tunables.WORKGROUP_SIZE) if (subgroupSplitK) and ((gqaHeadDim) / 4) >= 8 and not ((tensorDtypes.queryT == \"float16\") and ((gqaHeadDim) / 4) <= 32) and (true) else 0) + (ceilDiv((tunables.WORKGROUP_SIZE), 32) * 4 + 8 if (subgroupSplitK) else 0) if (gqaHeadDim) >= 4 and (tunables.WORKGROUP_SIZE) > 0 else 0) <= device.limits.maxComputeWorkgroupStorageSize"],"derive":{"useSubgroups":"subgroupSplitK","cacheSeqlens":true,"scalar":"gqaScalar","usesF16":"tensorDtypes.queryT == \"float16\"","kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","headDimV4":"gqaHeadDim / 4","numSplits":"cachedNumSplits","kvHeads":"attrs.kv_num_heads","inputVec4":"gqaInputVec4","inputScalar":"gqaScalar","normalizedPartialValues":"tensorDtypes.outputT == \"float32\" and ((present.pastValueT and tensorDtypes.pastValueT != \"float16\") or (present.valueT and tensorDtypes.valueT != \"float16\"))"},"intermediates":[{"id":"partialOut","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * (cachedNumSplits) * gqaHeadDim]"},{"id":"partialStats","dtype":"float32","shape":"[2 * dim(shapes.queryT, 0) * attrs.num_heads * (cachedNumSplits)]"},{"id":"windowKey","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowValue","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowLengths","dtype":"int32","shape":"[2 * dim(shapes.queryT, 0)]"}],"passes":[{"id":"present","name":"GroupQueryAttention.WindowShift","shader":"gqa-window-cache.wgsl.jinja","bindings":["past_k","past_v","new_k","new_v","window_key_write","window_value_write","seqlens_k","params_window_stage","window_lengths_write"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","z":1},"derive":{"windowPhase":"\"stage\"","stageRegion":"\"all\""}},{"id":"split_attention","name":"GroupQueryAttention.DecodeSplitK","shader":"attn-flash-decode-splitk.wgsl.jinja","derive":{"layout":"\"bhsd\""},"bindings":["query_attention","window_key_read_vec4","window_value_vec4","partial_out","partial_stats","window_lengths_read",{"name":"params","struct":[{"name":"kvSeq","type":"u32","value":"windowStageCapacity"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"}]}],"dispatch":{"x":"cachedNumSplits","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}},{"id":"merge","name":"GroupQueryAttention.DecodeSplitKMerge","shader":"attn-flash-decode-splitk-merge.wgsl.jinja","derive":{"layout":"\"bhsd\""},"bindings":["partial_out_merge","partial_stats_merge","output_merge"],"dispatch":{"x":1,"y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}},{"id":"compact","name":"GroupQueryAttention.WindowCompact","shader":"gqa-window-cache.wgsl.jinja","derive":{"windowPhase":"\"compact\""},"bindings":["window_key_read","window_value_read","window_lengths_read","present_key_present","present_value_present","params_window_compact","output_past_kv"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"window_shift_decode_splitk_f16","priority":38,"when":["windowShiftOk","decodeFlashShapeOk","cachedSplitScratchFits","plainAttentionOptions","tensorDtypes.queryT == \"float16\"","(gqaHeadDim) >= 4 and (tunables.WORKGROUP_SIZE) > 0 and (tunables.WORKGROUP_SIZE) <= deviceWorkgroupCap and (pow2ceil(tunables.WORKGROUP_SIZE) == (tunables.WORKGROUP_SIZE) or (subgroupSplitK)) and ((gqaHeadDim) * 8 + (tunables.WORKGROUP_SIZE) * 12 + (16 * (tunables.WORKGROUP_SIZE) if (tunables.WORKGROUP_SIZE) % ((gqaHeadDim) / 4) == 0 and (tunables.WORKGROUP_SIZE) / ((gqaHeadDim) / 4) >= 2 else 0) + (4 * (tunables.WORKGROUP_SIZE) if (subgroupSplitK) and ((gqaHeadDim) / 4) >= 8 and not ((tensorDtypes.queryT == \"float16\") and ((gqaHeadDim) / 4) <= 32) and (true) else 0) + (ceilDiv((tunables.WORKGROUP_SIZE), 32) * 4 + 8 if (subgroupSplitK) else 0) if (gqaHeadDim) >= 4 and (tunables.WORKGROUP_SIZE) > 0 else 0) <= device.limits.maxComputeWorkgroupStorageSize"],"derive":{"useSubgroups":"subgroupSplitK","cacheSeqlens":true,"scalar":"gqaScalar","usesF16":"tensorDtypes.queryT == \"float16\"","kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","headDimV4":"gqaHeadDim / 4","numSplits":"cachedNumSplits","kvHeads":"attrs.kv_num_heads","inputVec4":"gqaInputVec4","inputScalar":"gqaScalar","normalizedPartialValues":"tensorDtypes.outputT == \"float32\" and ((present.pastValueT and tensorDtypes.pastValueT != \"float16\") or (present.valueT and tensorDtypes.valueT != \"float16\"))"},"intermediates":[{"id":"partialOut","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * (cachedNumSplits) * gqaHeadDim]"},{"id":"partialStats","dtype":"float32","shape":"[2 * dim(shapes.queryT, 0) * attrs.num_heads * (cachedNumSplits)]"},{"id":"windowKey","dtype":"float16","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowValue","dtype":"float16","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowLengths","dtype":"int32","shape":"[2 * dim(shapes.queryT, 0)]"}],"passes":[{"id":"present","name":"GroupQueryAttention.WindowShift","shader":"gqa-window-cache.wgsl.jinja","bindings":["past_k","past_v","new_k","new_v","window_key_write","window_value_write","seqlens_k","params_window_stage","window_lengths_write"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","z":1},"derive":{"windowPhase":"\"stage\"","stageRegion":"\"all\""}},{"id":"split_attention","name":"GroupQueryAttention.DecodeSplitK","shader":"attn-flash-decode-splitk.wgsl.jinja","derive":{"layout":"\"bhsd\""},"bindings":["query_attention","window_key_read_vec4","window_value_vec4","partial_out","partial_stats","window_lengths_read",{"name":"params","struct":[{"name":"kvSeq","type":"u32","value":"windowStageCapacity"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"}]}],"dispatch":{"x":"cachedNumSplits","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}},{"id":"merge","name":"GroupQueryAttention.DecodeSplitKMerge","shader":"attn-flash-decode-splitk-merge.wgsl.jinja","derive":{"layout":"\"bhsd\""},"bindings":["partial_out_merge","partial_stats_merge","output_merge"],"dispatch":{"x":1,"y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}},{"id":"compact","name":"GroupQueryAttention.WindowCompact","shader":"gqa-window-cache.wgsl.jinja","derive":{"windowPhase":"\"compact\""},"bindings":["window_key_read","window_value_read","window_lengths_read","present_key_present","present_value_present","params_window_compact","output_past_kv"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"window_shift_flash_prefill","priority":34,"when":["windowShiftOk","prefillFlashShapeOk","cachedSgPrefillOk or cachedNoSgClusterStorageOk","plainAttentionOptions","tensorDtypes.queryT == \"float32\""],"derive":{"useSubgroups":"cachedSgPrefillOk","scalar":"gqaScalar","usesF16":"tensorDtypes.queryT == \"float16\"","hasCausal":true,"causalRightAlign":true,"hasMask":false,"headDim":"gqaHeadDim","headDimV4":"gqaHeadDim / 4","qHiddenV4":"dim(shapes.queryT, 2) / 4","kvNumHeads":"attrs.kv_num_heads","TILE_Q":"cachedPrefillQueryTile","TILE_K":"cachedClusterTileK if useSubgroups else cachedNoSgTileK","LPQ":"cachedPrefillLanesPerQuery","kvHeads":"attrs.kv_num_heads","useSeqlens":true,"inputVec4":"gqaInputVec4","inputScalar":"gqaScalar","batchNoSgReduction":"not useSubgroups","shareNoSgProb":"batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ"},"passes":[{"id":"present","name":"GroupQueryAttention.WindowShift","shader":"gqa-window-cache.wgsl.jinja","bindings":["past_k","past_v","new_k","new_v","window_key_write","window_value_write","seqlens_k","params_window_stage","window_lengths_write"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","z":1},"derive":{"windowPhase":"\"stage\"","stageRegion":"\"all\""}},{"id":"attention_folds","repeat":{"count":"2 if scalar == \"f32\" and not usesF16 else 1","index":"foldStep"},"passes":[{"id":"attention","name":"GroupQueryAttention.FlashPrefill","shader":"attn-flash-prefill-cluster.wgsl.jinja","derive":{"layout":"\"bsh\"","qLayout":"\"bsh\"","kvLayout":"\"bhsd\"","foldStep":"repeat.foldStep"},"bindings":["query_attention","window_key_read_vec4","window_value_vec4","output_merge","window_lengths_read",{"name":"params","struct":[{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"kvSeq","type":"u32","value":"windowStageCapacity"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"isCausal","type":"u32","value":1},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"}]}],"dispatch":{"x":"ceilDiv(dim(shapes.queryT, 1), TILE_Q)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}]},{"id":"compact","name":"GroupQueryAttention.WindowCompact","shader":"gqa-window-cache.wgsl.jinja","derive":{"windowPhase":"\"compact\""},"bindings":["window_key_read","window_value_read","window_lengths_read","present_key_present","present_value_present","params_window_compact","output_past_kv"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","z":1}}],"intermediates":[{"id":"windowKey","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowValue","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowLengths","dtype":"int32","shape":"[2 * dim(shapes.queryT, 0)]"}]},{"id":"window_shift_flash_prefill_f16","priority":34,"when":["windowShiftOk","prefillFlashShapeOk","cachedSgPrefillOk or cachedNoSgClusterStorageOk","plainAttentionOptions","tensorDtypes.queryT == \"float16\""],"derive":{"useSubgroups":"cachedSgPrefillOk","scalar":"gqaScalar","usesF16":"tensorDtypes.queryT == \"float16\"","hasCausal":true,"causalRightAlign":true,"hasMask":false,"headDim":"gqaHeadDim","headDimV4":"gqaHeadDim / 4","qHiddenV4":"dim(shapes.queryT, 2) / 4","kvNumHeads":"attrs.kv_num_heads","TILE_Q":"cachedPrefillQueryTile","TILE_K":"cachedClusterTileK if useSubgroups else cachedNoSgTileK","LPQ":"cachedPrefillLanesPerQuery","kvHeads":"attrs.kv_num_heads","useSeqlens":true,"inputVec4":"gqaInputVec4","inputScalar":"gqaScalar","batchNoSgReduction":"not useSubgroups","shareNoSgProb":"batchNoSgReduction and not usesF16 and LPQ >= 4 and TILE_K >= 2 * LPQ"},"passes":[{"id":"present","name":"GroupQueryAttention.WindowShift","shader":"gqa-window-cache.wgsl.jinja","bindings":["past_k","past_v","new_k","new_v","window_key_write","window_value_write","seqlens_k","params_window_stage","window_lengths_write"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","z":1},"derive":{"windowPhase":"\"stage\"","stageRegion":"\"all\""}},{"id":"attention_folds","repeat":{"count":"2 if scalar == \"f32\" and not usesF16 else 1","index":"foldStep"},"passes":[{"id":"attention","name":"GroupQueryAttention.FlashPrefill","shader":"attn-flash-prefill-cluster.wgsl.jinja","derive":{"layout":"\"bsh\"","qLayout":"\"bsh\"","kvLayout":"\"bhsd\"","foldStep":"repeat.foldStep"},"bindings":["query_attention","window_key_read_vec4","window_value_vec4","output_merge","window_lengths_read",{"name":"params","struct":[{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"kvSeq","type":"u32","value":"windowStageCapacity"},{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"isCausal","type":"u32","value":1},{"name":"windowSize","type":"u32","value":"attrs.local_window_size if attrs.local_window_size > 0 else 0"}]}],"dispatch":{"x":"ceilDiv(dim(shapes.queryT, 1), TILE_Q)","y":"attrs.num_heads","z":"dim(shapes.queryT, 0)"}}]},{"id":"compact","name":"GroupQueryAttention.WindowCompact","shader":"gqa-window-cache.wgsl.jinja","derive":{"windowPhase":"\"compact\""},"bindings":["window_key_read","window_value_read","window_lengths_read","present_key_present","present_value_present","params_window_compact","output_past_kv"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","z":1}}],"intermediates":[{"id":"windowKey","dtype":"float16","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowValue","dtype":"float16","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowLengths","dtype":"int32","shape":"[2 * dim(shapes.queryT, 0)]"}]},{"id":"window_shift_rotary_append","priority":31,"when":["windowShiftRotaryOk","gqaScalarDispatchOk","windowAuxOk","tensorDtypes.queryT == \"float32\""],"derive":{"useSeqlens":true,"headDim":"gqaHeadDim","cooperative":"gqaCoop","dispatchUnits":"gqaDispatchUnits","qHeads":"attrs.num_heads","kvHeads":"attrs.kv_num_heads","qHidden":"dim(shapes.queryT, 2)","packed":"gqaHeadDim","inputScalar":"\"f32\"","windowOrigin":true,"hasHeadSink":"present.headSinkT","hasBias":"present.attentionBiasT"},"passes":[{"id":"present_shift","name":"GroupQueryAttention.WindowShift","shader":"gqa-window-cache.wgsl.jinja","derive":{"windowPhase":"\"stage\"","stageRegion":"\"shift\""},"bindings":["past_k","past_v","window_key_write","window_value_write","seqlens_k","params_window_stage","window_lengths_write"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","z":1}},{"id":"present_append","name":"GroupQueryAttention.WindowShiftAppend","shader":"gqa-window-cache.wgsl.jinja","derive":{"hasRotary":true,"half":"gqaHeadDim / 2","windowPhase":"\"stage\"","stageRegion":"\"append\""},"bindings":["new_k","new_v","cos_cache_f32","sin_cache_f32","window_key_write","window_value_write","seqlens_k",{"name":"params","struct":[{"name":"count","type":"u32","value":"dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)"},{"name":"seq","type":"u32","value":"windowStageCapacity"},{"name":"keySeq","type":"u32","value":"dim(shapes.keyT, 1)"},{"name":"capacity","type":"u32","value":"windowCapacity"},{"name":"windowSize","type":"u32","value":"attrs.local_window_size"}]}],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","z":1}},{"id":"attention","name":"GroupQueryAttention.Attn","shader":"gqa-attention.wgsl.jinja","derive":{"hasRotary":true,"half":"gqaHeadDim / 2"},"bindings":["query_qprep","window_key_cache","window_value_cache","cos_cache_f32","sin_cache_f32","head_sink","attn_bias","output_past_kv","window_lengths_read","params_window_cached","params_window_cached_headsink","params_window_cached_bias"],"dispatch":{"x":"min(dispatchUnits, 65535)","y":"ceilDiv(dispatchUnits, 65535)","z":1}},{"id":"compact","name":"GroupQueryAttention.WindowCompact","shader":"gqa-window-cache.wgsl.jinja","derive":{"windowPhase":"\"compact\""},"bindings":["window_key_read","window_value_read","window_lengths_read","present_key_present","present_value_present","params_window_compact","output_past_kv"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","z":1}}],"intermediates":[{"id":"windowKey","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowValue","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowLengths","dtype":"int32","shape":"[2 * dim(shapes.queryT, 0)]"}]},{"id":"window_shift_append","priority":30,"when":["windowShiftOk","gqaScalarDispatchOk","gqaHeadDim % 2 == 0","windowAuxOk","tensorDtypes.queryT == \"float32\""],"derive":{"useSeqlens":true,"headDim":"gqaHeadDim","cooperative":"gqaCoop","dispatchUnits":"gqaDispatchUnits","qHeads":"attrs.num_heads","kvHeads":"attrs.kv_num_heads","qHidden":"dim(shapes.queryT, 2)","packed":"gqaHeadDim","usesF16":"tensorDtypes.queryT == \"float16\"","inputScalar":"gqaScalar","hasHeadSink":"present.headSinkT","hasBias":"present.attentionBiasT","windowOrigin":"present.attentionBiasT"},"passes":[{"id":"present","name":"GroupQueryAttention.WindowShift","shader":"gqa-window-cache.wgsl.jinja","bindings":["past_k","past_v","new_k","new_v","window_key_write","window_value_write","seqlens_k","params_window_stage","window_lengths_write"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","z":1},"derive":{"windowPhase":"\"stage\"","stageRegion":"\"all\""}},{"id":"attention","name":"GroupQueryAttention.Attn","shader":"gqa-attention.wgsl.jinja","bindings":["query_qprep","window_key_cache","window_value_cache","head_sink","attn_bias","output_past_kv","window_lengths_read","params_window_cached","params_window_cached_headsink","params_window_cached_bias"],"dispatch":{"x":"min(dispatchUnits, 65535)","y":"ceilDiv(dispatchUnits, 65535)","z":1}},{"id":"compact","name":"GroupQueryAttention.WindowCompact","shader":"gqa-window-cache.wgsl.jinja","derive":{"windowPhase":"\"compact\""},"bindings":["window_key_read","window_value_read","window_lengths_read","present_key_present","present_value_present","params_window_compact","output_past_kv"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","z":1}}],"intermediates":[{"id":"windowKey","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowValue","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowLengths","dtype":"int32","shape":"[2 * dim(shapes.queryT, 0)]"}]},{"id":"window_shift_append_f16","priority":30,"when":["windowShiftOk","gqaScalarDispatchOk","gqaHeadDim % 2 == 0","windowAuxOk","tensorDtypes.queryT == \"float16\""],"derive":{"useSeqlens":true,"headDim":"gqaHeadDim","cooperative":"gqaCoop","dispatchUnits":"gqaDispatchUnits","qHeads":"attrs.num_heads","kvHeads":"attrs.kv_num_heads","qHidden":"dim(shapes.queryT, 2)","packed":"gqaHeadDim","usesF16":"tensorDtypes.queryT == \"float16\"","inputScalar":"gqaScalar","hasHeadSink":"present.headSinkT","hasBias":"present.attentionBiasT","windowOrigin":"present.attentionBiasT"},"passes":[{"id":"present","name":"GroupQueryAttention.WindowShift","shader":"gqa-window-cache.wgsl.jinja","bindings":["past_k","past_v","new_k","new_v","window_key_write","window_value_write","seqlens_k","params_window_stage","window_lengths_write"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","z":1},"derive":{"windowPhase":"\"stage\"","stageRegion":"\"all\""}},{"id":"attention","name":"GroupQueryAttention.Attn","shader":"gqa-attention.wgsl.jinja","bindings":["query_qprep","window_key_cache","window_value_cache","head_sink","attn_bias","output_past_kv","window_lengths_read","params_window_cached","params_window_cached_headsink","params_window_cached_bias"],"dispatch":{"x":"min(dispatchUnits, 65535)","y":"ceilDiv(dispatchUnits, 65535)","z":1}},{"id":"compact","name":"GroupQueryAttention.WindowCompact","shader":"gqa-window-cache.wgsl.jinja","derive":{"windowPhase":"\"compact\""},"bindings":["window_key_read","window_value_read","window_lengths_read","present_key_present","present_value_present","params_window_compact","output_past_kv"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","z":1}}],"intermediates":[{"id":"windowKey","dtype":"float16","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowValue","dtype":"float16","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowLengths","dtype":"int32","shape":"[2 * dim(shapes.queryT, 0)]"}]},{"id":"matrix_shape_16x16x16_qkv_present_materialized_sgmat_f32","priority":-1000,"when":["(qkvContractOk and attrs.causal == 0 and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and headDimPlan >= 64 and headDimPlan <= 256 and headDimPlan % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_MIN_SEQ and dim(shapes.keyT, 1) >= tunables.MATERIALIZED_SGMAT_MIN_SEQ and matrixSubgroupWidth > 0 and gqaMatScoreFits and (numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.keyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.valueT) * 4 <= device.limits.maxStorageBufferBindingSize) and ((128) <= deviceWorkgroupCap and (((4096 if device.wgslLanguageFeatures.has(\"buffer_view\") else 8192) + 48 + 256 + 0)) <= device.limits.maxComputeWorkgroupStorageSize) and (ceilDiv(dim(shapes.keyT, 1), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(dim(shapes.queryT, 1), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))","has(device.adapterInfo, \"subgroupMatrixConfigs\")","device.limits.maxComputeWorkgroupSizeY >= 8","gqaMatRowDispatchFits"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":16,"K":16}]},"derive":{"matrixM":16,"matrixN":16,"matrixK":16,"kvNumHeads":"attrs.kv_num_heads","headDim":"dim(shapes.queryT, 2) / attrs.num_heads","qHidden":"dim(shapes.queryT, 2)","kvHidden":"dim(shapes.keyT, 2)","presentScalar":"qkvCacheScalar","presentElement":"qkvCacheVec4","presentVec4":true,"inputElement":"qkvInputVec4","headDimV4":"(dim(shapes.queryT, 2) / attrs.num_heads) / 4","kvHiddenV4":"dim(shapes.keyT, 2) / 4","seqlensQueryFloor":"attrs.causal == 1","useSeqlens":true},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.keyT, 1)]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatRows * 2]"}],"passes":[{"id":"scores","name":"GroupQueryAttention.MaterializedScores","shader":"attn-materialized-score-f32.wgsl.jinja","derive":{"layout":"\"bsh\"","hasBias":false,"compensatedScoreDot":true,"deferNativeScoreGuard":"nativeScoreProductResidual","materializedQueryTile":32,"materializedKeyTile":32,"materializedInnerTile":8,"materializedWorkgroupDim":8,"scalarAccumulators":true},"bindings":["query","key","scores","seqlens_k","params_flash_scaled"],"dispatch":{"x":"ceilDiv(dim(shapes.keyT, 1), materializedKeyTile)","y":"ceilDiv(dim(shapes.queryT, 1), materializedQueryTile)","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.MaterializedRowStats","shader":"attn-materialized-softmax-f32.wgsl.jinja","derive":{"useSubgroups":true,"materializedSoftmaxCols":"dim(shapes.keyT, 1)","materializedSoftmaxWg":"min(32, gqaMatRowStatsWg)","seqlensRowsPerBatch":"qNumHeads * statQuerySeq"},"bindings":["scores_f32","rowStats","seqlens_k","params_rows"],"dispatch":{"x":"min(gqaMatRows, 65535)","y":"ceilDiv(gqaMatRows, 65535)","z":1}},{"id":"apply","name":"GroupQueryAttention.MaterializedApplySgmat","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\""},"bindings":["scores_f32","value","rowStats_f32","output","seqlens_k","params_flash"],"dispatch":{"x":"ceilDiv(headDim, (32))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"present","name":"GroupQueryAttention.MaterializedPresent","shader":"gqa-present.wgsl.jinja","bindings":["key_key_t","value_value_t","present_key","present_value","params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","z":1}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x8x16_qkv_present_materialized_sgmat_f32","priority":-1000,"when":["(qkvContractOk and attrs.causal == 0 and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and headDimPlan >= 64 and headDimPlan <= 256 and headDimPlan % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_MIN_SEQ and dim(shapes.keyT, 1) >= tunables.MATERIALIZED_SGMAT_MIN_SEQ and matrixSubgroupWidth > 0 and gqaMatScoreFits and (numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.keyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.valueT) * 4 <= device.limits.maxStorageBufferBindingSize) and ((128) <= deviceWorkgroupCap and (((3072 if device.wgslLanguageFeatures.has(\"buffer_view\") else 5120) + 48 + 256 + 0)) <= device.limits.maxComputeWorkgroupStorageSize) and (ceilDiv(dim(shapes.keyT, 1), (16)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(dim(shapes.queryT, 1), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))","has(device.adapterInfo, \"subgroupMatrixConfigs\")","device.limits.maxComputeWorkgroupSizeY >= 8","gqaMatRowDispatchFits"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":8,"K":16}]},"derive":{"matrixM":16,"matrixN":8,"matrixK":16,"kvNumHeads":"attrs.kv_num_heads","headDim":"dim(shapes.queryT, 2) / attrs.num_heads","qHidden":"dim(shapes.queryT, 2)","kvHidden":"dim(shapes.keyT, 2)","presentScalar":"qkvCacheScalar","presentElement":"qkvCacheVec4","presentVec4":true,"inputElement":"qkvInputVec4","headDimV4":"(dim(shapes.queryT, 2) / attrs.num_heads) / 4","kvHiddenV4":"dim(shapes.keyT, 2) / 4","seqlensQueryFloor":"attrs.causal == 1","useSeqlens":true},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.keyT, 1)]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatRows * 2]"}],"passes":[{"id":"scores","name":"GroupQueryAttention.MaterializedScores","shader":"attn-materialized-score-f32.wgsl.jinja","derive":{"layout":"\"bsh\"","hasBias":false,"compensatedScoreDot":true,"deferNativeScoreGuard":"nativeScoreProductResidual","materializedQueryTile":32,"materializedKeyTile":16,"materializedInnerTile":8,"materializedWorkgroupDim":8,"scalarAccumulators":true},"bindings":["query","key","scores","seqlens_k","params_flash_scaled"],"dispatch":{"x":"ceilDiv(dim(shapes.keyT, 1), materializedKeyTile)","y":"ceilDiv(dim(shapes.queryT, 1), materializedQueryTile)","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.MaterializedRowStats","shader":"attn-materialized-softmax-f32.wgsl.jinja","derive":{"useSubgroups":true,"materializedSoftmaxCols":"dim(shapes.keyT, 1)","materializedSoftmaxWg":"min(32, gqaMatRowStatsWg)","seqlensRowsPerBatch":"qNumHeads * statQuerySeq"},"bindings":["scores_f32","rowStats","seqlens_k","params_rows"],"dispatch":{"x":"min(gqaMatRows, 65535)","y":"ceilDiv(gqaMatRows, 65535)","z":1}},{"id":"apply","name":"GroupQueryAttention.MaterializedApplySgmat","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\""},"bindings":["scores_f32","value","rowStats_f32","output","seqlens_k","params_flash"],"dispatch":{"x":"ceilDiv(headDim, (16))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"present","name":"GroupQueryAttention.MaterializedPresent","shader":"gqa-present.wgsl.jinja","bindings":["key_key_t","value_value_t","present_key","present_value","params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","z":1}}],"demoteWhen":["true"]},{"id":"matrix_shape_8x16x16_qkv_present_materialized_sgmat_f32","priority":-1000,"when":["(qkvContractOk and attrs.causal == 0 and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and headDimPlan >= 64 and headDimPlan <= 256 and headDimPlan % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_MIN_SEQ and dim(shapes.keyT, 1) >= tunables.MATERIALIZED_SGMAT_MIN_SEQ and matrixSubgroupWidth > 0 and gqaMatScoreFits and (numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.keyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.valueT) * 4 <= device.limits.maxStorageBufferBindingSize) and ((128) <= deviceWorkgroupCap and (((3072 if device.wgslLanguageFeatures.has(\"buffer_view\") else 5120) + 48 + 128 + 0)) <= device.limits.maxComputeWorkgroupStorageSize) and (ceilDiv(dim(shapes.keyT, 1), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(dim(shapes.queryT, 1), (16)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))","has(device.adapterInfo, \"subgroupMatrixConfigs\")","device.limits.maxComputeWorkgroupSizeY >= 8","gqaMatRowDispatchFits"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":8,"N":16,"K":16}]},"derive":{"matrixM":8,"matrixN":16,"matrixK":16,"kvNumHeads":"attrs.kv_num_heads","headDim":"dim(shapes.queryT, 2) / attrs.num_heads","qHidden":"dim(shapes.queryT, 2)","kvHidden":"dim(shapes.keyT, 2)","presentScalar":"qkvCacheScalar","presentElement":"qkvCacheVec4","presentVec4":true,"inputElement":"qkvInputVec4","headDimV4":"(dim(shapes.queryT, 2) / attrs.num_heads) / 4","kvHiddenV4":"dim(shapes.keyT, 2) / 4","seqlensQueryFloor":"attrs.causal == 1","useSeqlens":true},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.keyT, 1)]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatRows * 2]"}],"passes":[{"id":"scores","name":"GroupQueryAttention.MaterializedScores","shader":"attn-materialized-score-f32.wgsl.jinja","derive":{"layout":"\"bsh\"","hasBias":false,"compensatedScoreDot":true,"deferNativeScoreGuard":"nativeScoreProductResidual","materializedQueryTile":16,"materializedKeyTile":32,"materializedInnerTile":8,"materializedWorkgroupDim":8,"scalarAccumulators":true},"bindings":["query","key","scores","seqlens_k","params_flash_scaled"],"dispatch":{"x":"ceilDiv(dim(shapes.keyT, 1), materializedKeyTile)","y":"ceilDiv(dim(shapes.queryT, 1), materializedQueryTile)","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.MaterializedRowStats","shader":"attn-materialized-softmax-f32.wgsl.jinja","derive":{"useSubgroups":true,"materializedSoftmaxCols":"dim(shapes.keyT, 1)","materializedSoftmaxWg":"min(32, gqaMatRowStatsWg)","seqlensRowsPerBatch":"qNumHeads * statQuerySeq"},"bindings":["scores_f32","rowStats","seqlens_k","params_rows"],"dispatch":{"x":"min(gqaMatRows, 65535)","y":"ceilDiv(gqaMatRows, 65535)","z":1}},{"id":"apply","name":"GroupQueryAttention.MaterializedApplySgmat","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\""},"bindings":["scores_f32","value","rowStats_f32","output","seqlens_k","params_flash"],"dispatch":{"x":"ceilDiv(headDim, (32))","y":"ceilDiv(dim(shapes.queryT, 1), (16))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"present","name":"GroupQueryAttention.MaterializedPresent","shader":"gqa-present.wgsl.jinja","bindings":["key_key_t","value_value_t","present_key","present_value","params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","z":1}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x16x32_qkv_present_materialized_sgmat_f32","priority":-1000,"when":["(qkvContractOk and attrs.causal == 0 and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and headDimPlan >= 64 and headDimPlan <= 256 and headDimPlan % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_MIN_SEQ and dim(shapes.keyT, 1) >= tunables.MATERIALIZED_SGMAT_MIN_SEQ and matrixSubgroupWidth > 0 and gqaMatScoreFits and (numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.keyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.valueT) * 4 <= device.limits.maxStorageBufferBindingSize) and ((128) <= deviceWorkgroupCap and (((8192 if device.wgslLanguageFeatures.has(\"buffer_view\") else 12288) + 48 + 256 + 0)) <= device.limits.maxComputeWorkgroupStorageSize) and (ceilDiv(dim(shapes.keyT, 1), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(dim(shapes.queryT, 1), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))","has(device.adapterInfo, \"subgroupMatrixConfigs\")","device.limits.maxComputeWorkgroupSizeY >= 8","gqaMatRowDispatchFits"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":16,"K":32}]},"derive":{"matrixM":16,"matrixN":16,"matrixK":32,"kvNumHeads":"attrs.kv_num_heads","headDim":"dim(shapes.queryT, 2) / attrs.num_heads","qHidden":"dim(shapes.queryT, 2)","kvHidden":"dim(shapes.keyT, 2)","presentScalar":"qkvCacheScalar","presentElement":"qkvCacheVec4","presentVec4":true,"inputElement":"qkvInputVec4","headDimV4":"(dim(shapes.queryT, 2) / attrs.num_heads) / 4","kvHiddenV4":"dim(shapes.keyT, 2) / 4","seqlensQueryFloor":"attrs.causal == 1","useSeqlens":true},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.keyT, 1)]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatRows * 2]"}],"passes":[{"id":"scores","name":"GroupQueryAttention.MaterializedScores","shader":"attn-materialized-score-f32.wgsl.jinja","derive":{"layout":"\"bsh\"","hasBias":false,"compensatedScoreDot":true,"deferNativeScoreGuard":"nativeScoreProductResidual","materializedQueryTile":32,"materializedKeyTile":32,"materializedInnerTile":8,"materializedWorkgroupDim":8,"scalarAccumulators":true},"bindings":["query","key","scores","seqlens_k","params_flash_scaled"],"dispatch":{"x":"ceilDiv(dim(shapes.keyT, 1), materializedKeyTile)","y":"ceilDiv(dim(shapes.queryT, 1), materializedQueryTile)","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.MaterializedRowStats","shader":"attn-materialized-softmax-f32.wgsl.jinja","derive":{"useSubgroups":true,"materializedSoftmaxCols":"dim(shapes.keyT, 1)","materializedSoftmaxWg":"min(32, gqaMatRowStatsWg)","seqlensRowsPerBatch":"qNumHeads * statQuerySeq"},"bindings":["scores_f32","rowStats","seqlens_k","params_rows"],"dispatch":{"x":"min(gqaMatRows, 65535)","y":"ceilDiv(gqaMatRows, 65535)","z":1}},{"id":"apply","name":"GroupQueryAttention.MaterializedApplySgmat","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\""},"bindings":["scores_f32","value","rowStats_f32","output","seqlens_k","params_flash"],"dispatch":{"x":"ceilDiv(headDim, (32))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"present","name":"GroupQueryAttention.MaterializedPresent","shader":"gqa-present.wgsl.jinja","bindings":["key_key_t","value_value_t","present_key","present_value","params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","z":1}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x8x32_qkv_present_materialized_sgmat_f32","priority":-1000,"when":["(qkvContractOk and attrs.causal == 0 and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and headDimPlan >= 64 and headDimPlan <= 256 and headDimPlan % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_MIN_SEQ and dim(shapes.keyT, 1) >= tunables.MATERIALIZED_SGMAT_MIN_SEQ and matrixSubgroupWidth > 0 and gqaMatScoreFits and (numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.keyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.valueT) * 4 <= device.limits.maxStorageBufferBindingSize) and ((128) <= deviceWorkgroupCap and (((6144 if device.wgslLanguageFeatures.has(\"buffer_view\") else 8192) + 48 + 256 + 0)) <= device.limits.maxComputeWorkgroupStorageSize) and (ceilDiv(dim(shapes.keyT, 1), (16)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(dim(shapes.queryT, 1), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))","has(device.adapterInfo, \"subgroupMatrixConfigs\")","device.limits.maxComputeWorkgroupSizeY >= 8","gqaMatRowDispatchFits"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":8,"K":32}]},"derive":{"matrixM":16,"matrixN":8,"matrixK":32,"kvNumHeads":"attrs.kv_num_heads","headDim":"dim(shapes.queryT, 2) / attrs.num_heads","qHidden":"dim(shapes.queryT, 2)","kvHidden":"dim(shapes.keyT, 2)","presentScalar":"qkvCacheScalar","presentElement":"qkvCacheVec4","presentVec4":true,"inputElement":"qkvInputVec4","headDimV4":"(dim(shapes.queryT, 2) / attrs.num_heads) / 4","kvHiddenV4":"dim(shapes.keyT, 2) / 4","seqlensQueryFloor":"attrs.causal == 1","useSeqlens":true},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.keyT, 1)]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatRows * 2]"}],"passes":[{"id":"scores","name":"GroupQueryAttention.MaterializedScores","shader":"attn-materialized-score-f32.wgsl.jinja","derive":{"layout":"\"bsh\"","hasBias":false,"compensatedScoreDot":true,"deferNativeScoreGuard":"nativeScoreProductResidual","materializedQueryTile":32,"materializedKeyTile":16,"materializedInnerTile":8,"materializedWorkgroupDim":8,"scalarAccumulators":true},"bindings":["query","key","scores","seqlens_k","params_flash_scaled"],"dispatch":{"x":"ceilDiv(dim(shapes.keyT, 1), materializedKeyTile)","y":"ceilDiv(dim(shapes.queryT, 1), materializedQueryTile)","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.MaterializedRowStats","shader":"attn-materialized-softmax-f32.wgsl.jinja","derive":{"useSubgroups":true,"materializedSoftmaxCols":"dim(shapes.keyT, 1)","materializedSoftmaxWg":"min(32, gqaMatRowStatsWg)","seqlensRowsPerBatch":"qNumHeads * statQuerySeq"},"bindings":["scores_f32","rowStats","seqlens_k","params_rows"],"dispatch":{"x":"min(gqaMatRows, 65535)","y":"ceilDiv(gqaMatRows, 65535)","z":1}},{"id":"apply","name":"GroupQueryAttention.MaterializedApplySgmat","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\""},"bindings":["scores_f32","value","rowStats_f32","output","seqlens_k","params_flash"],"dispatch":{"x":"ceilDiv(headDim, (16))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"present","name":"GroupQueryAttention.MaterializedPresent","shader":"gqa-present.wgsl.jinja","bindings":["key_key_t","value_value_t","present_key","present_value","params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.presentKeyT) / 4), (copyWorkgroupSize)), 65535)","z":1}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x16x16_cached_materialized_sgmat","priority":-1000,"when":["(sharedKvFloatOk and plainAttentionOptions) or (dtypes.T == \"f32\" and ((sharedKvFloatOk and gqaMatPastBiasInputsOk) or (newKvPastOk and plainAttentionOptions)))","gqaShapedPastFits","matrixSubgroupWidth > 0","128 <= deviceWorkgroupCap","has(device.adapterInfo, \"subgroupMatrixConfigs\") and subgroupMatrixConfigAvailable(dtypes.T, \"f32\", 16, 16, 16)","(max(1024 * dtypeBytes(tensorDtypes.queryT), 4096) if device.wgslLanguageFeatures.has(\"buffer_view\") else 1024 * dtypeBytes(tensorDtypes.queryT) + 4096) + 32 * 8 + 80 <= device.limits.maxComputeWorkgroupStorageSize","ceilDiv(gqaMatPastKvSeq, 32) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(gqaMatPastQSeq, 32) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":16,"K":16},{"componentType":"f16","resultComponentType":"f32","M":16,"N":16,"K":16}]},"derive":{"matrixM":16,"matrixN":16,"matrixK":16,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"ceilDiv(gqaMatPastKvSeq, 32)","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","operandF16":"dtypes.T == \"f16\""},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * gqaMatPastQSeq * gqaMatPastKvSeq]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatPastRowStatsElements]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * ceilDiv(gqaMatPastKvSeq, 32) * gqaMatPastQSeq * 2]"}],"passes":[{"id":"cache_copy","repeat":{"index":"copyPass","count":"1 if cacheCopyMode else 0"},"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"copy\""},"bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]}]},{"id":"cache_merge","repeat":{"index":"mergePass","count":"0 if cacheCopyMode else 1"},"passes":[{"id":"present","name":"GroupQueryAttention.Merge","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"merge\""},"bindings":["past_k","past_v","new_k","new_v","present_key_present","present_value_present","params_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"scores","name":"GroupQueryAttention.PastMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"scoreBias":"present.attentionBiasT"},"bindings":["query_qprep","shaped_key",{"arg":"attentionBiasT","name":"attention_bias","elementType":"f32","when":"present.attentionBiasT"},"scores","scorePartials","params_scores",{"name":"params","when":"present.attentionBiasT","struct":[{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"biasBatch","type":"u32","value":"dim(shapes.attentionBiasT, 0)"},{"name":"biasHeads","type":"u32","value":"dim(shapes.attentionBiasT, 1)"}]}],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), (32))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.PastMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.PastMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":["scores_f32","shaped_value","rowStats_f32","output_past_kv","params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (32))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x16x16_past_kv_rotary_materialized_sgmat","priority":-1000,"when":["sharedKvFloatOk and standardSoftmax and present.cosCacheT and rotaryRequested and not present.qNormWeightT and not present.attentionBiasT and not present.headSinkT","gqaShapedPastFits","matrixSubgroupWidth > 0","128 <= deviceWorkgroupCap","has(device.adapterInfo, \"subgroupMatrixConfigs\") and subgroupMatrixConfigAvailable(dtypes.T, \"f32\", 16, 16, 16)","(max(1024 * dtypeBytes(tensorDtypes.queryT), 4096) if device.wgslLanguageFeatures.has(\"buffer_view\") else 1024 * dtypeBytes(tensorDtypes.queryT) + 4096) + 32 * 8 + 80 <= device.limits.maxComputeWorkgroupStorageSize","ceilDiv(gqaMatPastKvSeq, 32) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(gqaMatPastQSeq, 32) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":16,"K":16},{"componentType":"f16","resultComponentType":"f32","M":16,"N":16,"K":16}]},"derive":{"matrixM":16,"matrixN":16,"matrixK":16,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"ceilDiv(gqaMatPastKvSeq, 32)","mode":"\"copy\"","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","half":"gqaHeadDim / 2","qHeads":"attrs.num_heads","cosScalar":"\"f16\" if tensorDtypes.cosCacheT == \"float16\" else \"f32\"","hasQNorm":false,"operandF16":"dtypes.T == \"f16\""},"intermediates":[{"id":"qPrep","dtype":"float32","shape":"shapes.queryT"},{"id":"qPrepF16","dtype":"float16","shape":"shapes.queryT"},{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * gqaMatPastQSeq * gqaMatPastKvSeq]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatPastRowStatsElements]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * ceilDiv(gqaMatPastKvSeq, 32) * gqaMatPastQSeq * 2]"}],"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]},{"id":"qprep","name":"GroupQueryAttention.RotaryQPrep","shader":"gqa-qprep.wgsl.jinja","bindings":["query_qprep","cos_cache","sin_cache",{"name":"qout","scratch":"qPrep","buffer":"storage","elementType":"vec4","when":"dtypes.T == \"f32\""},{"name":"qout","scratch":"qPrepF16","buffer":"storage","elementType":"vec4","when":"dtypes.T == \"f16\""},"params_qprep"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)","z":1},"derive":{"qPrepF16":"dtypes.T == \"f16\""}},{"id":"scores","name":"GroupQueryAttention.PastRotaryMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":[{"name":"query","scratch":"qPrep","buffer":"read-only-storage","elementType":"f32","when":"dtypes.T == \"f32\""},{"name":"query","scratch":"qPrepF16","buffer":"read-only-storage","elementType":"f16","when":"dtypes.T == \"f16\""},"shaped_key","scores","scorePartials","params_scores"],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), (32))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.PastRotaryMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.PastRotaryMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":["scores_f32","shaped_value","rowStats_f32","output_past_kv","params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (32))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x8x16_cached_materialized_sgmat","priority":-1000,"when":["(sharedKvFloatOk and plainAttentionOptions) or (dtypes.T == \"f32\" and ((sharedKvFloatOk and gqaMatPastBiasInputsOk) or (newKvPastOk and plainAttentionOptions)))","gqaShapedPastFits","matrixSubgroupWidth > 0","128 <= deviceWorkgroupCap","has(device.adapterInfo, \"subgroupMatrixConfigs\") and subgroupMatrixConfigAvailable(dtypes.T, \"f32\", 16, 8, 16)","(max(768 * dtypeBytes(tensorDtypes.queryT), 2048) if device.wgslLanguageFeatures.has(\"buffer_view\") else 768 * dtypeBytes(tensorDtypes.queryT) + 2048) + 32 * 8 + 80 <= device.limits.maxComputeWorkgroupStorageSize","ceilDiv(gqaMatPastKvSeq, 16) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(gqaMatPastQSeq, 32) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":8,"K":16},{"componentType":"f16","resultComponentType":"f32","M":16,"N":8,"K":16}]},"derive":{"matrixM":16,"matrixN":8,"matrixK":16,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"ceilDiv(gqaMatPastKvSeq, 16)","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","operandF16":"dtypes.T == \"f16\""},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * gqaMatPastQSeq * gqaMatPastKvSeq]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatPastRowStatsElements]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * ceilDiv(gqaMatPastKvSeq, 16) * gqaMatPastQSeq * 2]"}],"passes":[{"id":"cache_copy","repeat":{"index":"copyPass","count":"1 if cacheCopyMode else 0"},"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"copy\""},"bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]}]},{"id":"cache_merge","repeat":{"index":"mergePass","count":"0 if cacheCopyMode else 1"},"passes":[{"id":"present","name":"GroupQueryAttention.Merge","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"merge\""},"bindings":["past_k","past_v","new_k","new_v","present_key_present","present_value_present","params_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"scores","name":"GroupQueryAttention.PastMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"scoreBias":"present.attentionBiasT"},"bindings":["query_qprep","shaped_key",{"arg":"attentionBiasT","name":"attention_bias","elementType":"f32","when":"present.attentionBiasT"},"scores","scorePartials","params_scores",{"name":"params","when":"present.attentionBiasT","struct":[{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"biasBatch","type":"u32","value":"dim(shapes.attentionBiasT, 0)"},{"name":"biasHeads","type":"u32","value":"dim(shapes.attentionBiasT, 1)"}]}],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), (16))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.PastMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.PastMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":["scores_f32","shaped_value","rowStats_f32","output_past_kv","params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (16))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x8x16_past_kv_rotary_materialized_sgmat","priority":-1000,"when":["sharedKvFloatOk and standardSoftmax and present.cosCacheT and rotaryRequested and not present.qNormWeightT and not present.attentionBiasT and not present.headSinkT","gqaShapedPastFits","matrixSubgroupWidth > 0","128 <= deviceWorkgroupCap","has(device.adapterInfo, \"subgroupMatrixConfigs\") and subgroupMatrixConfigAvailable(dtypes.T, \"f32\", 16, 8, 16)","(max(768 * dtypeBytes(tensorDtypes.queryT), 2048) if device.wgslLanguageFeatures.has(\"buffer_view\") else 768 * dtypeBytes(tensorDtypes.queryT) + 2048) + 32 * 8 + 80 <= device.limits.maxComputeWorkgroupStorageSize","ceilDiv(gqaMatPastKvSeq, 16) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(gqaMatPastQSeq, 32) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":8,"K":16},{"componentType":"f16","resultComponentType":"f32","M":16,"N":8,"K":16}]},"derive":{"matrixM":16,"matrixN":8,"matrixK":16,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"ceilDiv(gqaMatPastKvSeq, 16)","mode":"\"copy\"","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","half":"gqaHeadDim / 2","qHeads":"attrs.num_heads","cosScalar":"\"f16\" if tensorDtypes.cosCacheT == \"float16\" else \"f32\"","hasQNorm":false,"operandF16":"dtypes.T == \"f16\""},"intermediates":[{"id":"qPrep","dtype":"float32","shape":"shapes.queryT"},{"id":"qPrepF16","dtype":"float16","shape":"shapes.queryT"},{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * gqaMatPastQSeq * gqaMatPastKvSeq]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatPastRowStatsElements]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * ceilDiv(gqaMatPastKvSeq, 16) * gqaMatPastQSeq * 2]"}],"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]},{"id":"qprep","name":"GroupQueryAttention.RotaryQPrep","shader":"gqa-qprep.wgsl.jinja","bindings":["query_qprep","cos_cache","sin_cache",{"name":"qout","scratch":"qPrep","buffer":"storage","elementType":"vec4","when":"dtypes.T == \"f32\""},{"name":"qout","scratch":"qPrepF16","buffer":"storage","elementType":"vec4","when":"dtypes.T == \"f16\""},"params_qprep"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)","z":1},"derive":{"qPrepF16":"dtypes.T == \"f16\""}},{"id":"scores","name":"GroupQueryAttention.PastRotaryMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":[{"name":"query","scratch":"qPrep","buffer":"read-only-storage","elementType":"f32","when":"dtypes.T == \"f32\""},{"name":"query","scratch":"qPrepF16","buffer":"read-only-storage","elementType":"f16","when":"dtypes.T == \"f16\""},"shaped_key","scores","scorePartials","params_scores"],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), (16))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.PastRotaryMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.PastRotaryMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":["scores_f32","shaped_value","rowStats_f32","output_past_kv","params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (16))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}],"demoteWhen":["true"]},{"id":"matrix_shape_8x16x16_cached_materialized_sgmat","priority":-1000,"when":["(sharedKvFloatOk and plainAttentionOptions) or (dtypes.T == \"f32\" and ((sharedKvFloatOk and gqaMatPastBiasInputsOk) or (newKvPastOk and plainAttentionOptions)))","gqaShapedPastFits","matrixSubgroupWidth > 0","128 <= deviceWorkgroupCap","has(device.adapterInfo, \"subgroupMatrixConfigs\") and subgroupMatrixConfigAvailable(dtypes.T, \"f32\", 8, 16, 16)","(max(768 * dtypeBytes(tensorDtypes.queryT), 2048) if device.wgslLanguageFeatures.has(\"buffer_view\") else 768 * dtypeBytes(tensorDtypes.queryT) + 2048) + 16 * 8 + 80 <= device.limits.maxComputeWorkgroupStorageSize","ceilDiv(gqaMatPastKvSeq, 32) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(gqaMatPastQSeq, 16) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":8,"N":16,"K":16},{"componentType":"f16","resultComponentType":"f32","M":8,"N":16,"K":16}]},"derive":{"matrixM":8,"matrixN":16,"matrixK":16,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"ceilDiv(gqaMatPastKvSeq, 32)","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","operandF16":"dtypes.T == \"f16\""},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * gqaMatPastQSeq * gqaMatPastKvSeq]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatPastRowStatsElements]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * ceilDiv(gqaMatPastKvSeq, 32) * gqaMatPastQSeq * 2]"}],"passes":[{"id":"cache_copy","repeat":{"index":"copyPass","count":"1 if cacheCopyMode else 0"},"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"copy\""},"bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]}]},{"id":"cache_merge","repeat":{"index":"mergePass","count":"0 if cacheCopyMode else 1"},"passes":[{"id":"present","name":"GroupQueryAttention.Merge","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"merge\""},"bindings":["past_k","past_v","new_k","new_v","present_key_present","present_value_present","params_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"scores","name":"GroupQueryAttention.PastMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"scoreBias":"present.attentionBiasT"},"bindings":["query_qprep","shaped_key",{"arg":"attentionBiasT","name":"attention_bias","elementType":"f32","when":"present.attentionBiasT"},"scores","scorePartials","params_scores",{"name":"params","when":"present.attentionBiasT","struct":[{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"biasBatch","type":"u32","value":"dim(shapes.attentionBiasT, 0)"},{"name":"biasHeads","type":"u32","value":"dim(shapes.attentionBiasT, 1)"}]}],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), (32))","y":"ceilDiv(dim(shapes.queryT, 1), (16))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.PastMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.PastMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":["scores_f32","shaped_value","rowStats_f32","output_past_kv","params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (32))","y":"ceilDiv(dim(shapes.queryT, 1), (16))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}],"demoteWhen":["true"]},{"id":"matrix_shape_8x16x16_past_kv_rotary_materialized_sgmat","priority":-1000,"when":["sharedKvFloatOk and standardSoftmax and present.cosCacheT and rotaryRequested and not present.qNormWeightT and not present.attentionBiasT and not present.headSinkT","gqaShapedPastFits","matrixSubgroupWidth > 0","128 <= deviceWorkgroupCap","has(device.adapterInfo, \"subgroupMatrixConfigs\") and subgroupMatrixConfigAvailable(dtypes.T, \"f32\", 8, 16, 16)","(max(768 * dtypeBytes(tensorDtypes.queryT), 2048) if device.wgslLanguageFeatures.has(\"buffer_view\") else 768 * dtypeBytes(tensorDtypes.queryT) + 2048) + 16 * 8 + 80 <= device.limits.maxComputeWorkgroupStorageSize","ceilDiv(gqaMatPastKvSeq, 32) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(gqaMatPastQSeq, 16) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":8,"N":16,"K":16},{"componentType":"f16","resultComponentType":"f32","M":8,"N":16,"K":16}]},"derive":{"matrixM":8,"matrixN":16,"matrixK":16,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"ceilDiv(gqaMatPastKvSeq, 32)","mode":"\"copy\"","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","half":"gqaHeadDim / 2","qHeads":"attrs.num_heads","cosScalar":"\"f16\" if tensorDtypes.cosCacheT == \"float16\" else \"f32\"","hasQNorm":false,"operandF16":"dtypes.T == \"f16\""},"intermediates":[{"id":"qPrep","dtype":"float32","shape":"shapes.queryT"},{"id":"qPrepF16","dtype":"float16","shape":"shapes.queryT"},{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * gqaMatPastQSeq * gqaMatPastKvSeq]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatPastRowStatsElements]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * ceilDiv(gqaMatPastKvSeq, 32) * gqaMatPastQSeq * 2]"}],"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]},{"id":"qprep","name":"GroupQueryAttention.RotaryQPrep","shader":"gqa-qprep.wgsl.jinja","bindings":["query_qprep","cos_cache","sin_cache",{"name":"qout","scratch":"qPrep","buffer":"storage","elementType":"vec4","when":"dtypes.T == \"f32\""},{"name":"qout","scratch":"qPrepF16","buffer":"storage","elementType":"vec4","when":"dtypes.T == \"f16\""},"params_qprep"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)","z":1},"derive":{"qPrepF16":"dtypes.T == \"f16\""}},{"id":"scores","name":"GroupQueryAttention.PastRotaryMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":[{"name":"query","scratch":"qPrep","buffer":"read-only-storage","elementType":"f32","when":"dtypes.T == \"f32\""},{"name":"query","scratch":"qPrepF16","buffer":"read-only-storage","elementType":"f16","when":"dtypes.T == \"f16\""},"shaped_key","scores","scorePartials","params_scores"],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), (32))","y":"ceilDiv(dim(shapes.queryT, 1), (16))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.PastRotaryMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.PastRotaryMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":["scores_f32","shaped_value","rowStats_f32","output_past_kv","params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (32))","y":"ceilDiv(dim(shapes.queryT, 1), (16))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x16x32_cached_materialized_sgmat","priority":-1000,"when":["(sharedKvFloatOk and plainAttentionOptions) or (dtypes.T == \"f32\" and ((sharedKvFloatOk and gqaMatPastBiasInputsOk) or (newKvPastOk and plainAttentionOptions)))","gqaShapedPastFits","matrixSubgroupWidth > 0","128 <= deviceWorkgroupCap","has(device.adapterInfo, \"subgroupMatrixConfigs\") and subgroupMatrixConfigAvailable(dtypes.T, \"f32\", 16, 16, 32)","(max(2048 * dtypeBytes(tensorDtypes.queryT), 4096) if device.wgslLanguageFeatures.has(\"buffer_view\") else 2048 * dtypeBytes(tensorDtypes.queryT) + 4096) + 32 * 8 + 80 <= device.limits.maxComputeWorkgroupStorageSize","ceilDiv(gqaMatPastKvSeq, 32) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(gqaMatPastQSeq, 32) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":16,"K":32},{"componentType":"f16","resultComponentType":"f32","M":16,"N":16,"K":32}]},"derive":{"matrixM":16,"matrixN":16,"matrixK":32,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"ceilDiv(gqaMatPastKvSeq, 32)","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","operandF16":"dtypes.T == \"f16\""},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * gqaMatPastQSeq * gqaMatPastKvSeq]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatPastRowStatsElements]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * ceilDiv(gqaMatPastKvSeq, 32) * gqaMatPastQSeq * 2]"}],"passes":[{"id":"cache_copy","repeat":{"index":"copyPass","count":"1 if cacheCopyMode else 0"},"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"copy\""},"bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]}]},{"id":"cache_merge","repeat":{"index":"mergePass","count":"0 if cacheCopyMode else 1"},"passes":[{"id":"present","name":"GroupQueryAttention.Merge","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"merge\""},"bindings":["past_k","past_v","new_k","new_v","present_key_present","present_value_present","params_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"scores","name":"GroupQueryAttention.PastMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"scoreBias":"present.attentionBiasT"},"bindings":["query_qprep","shaped_key",{"arg":"attentionBiasT","name":"attention_bias","elementType":"f32","when":"present.attentionBiasT"},"scores","scorePartials","params_scores",{"name":"params","when":"present.attentionBiasT","struct":[{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"biasBatch","type":"u32","value":"dim(shapes.attentionBiasT, 0)"},{"name":"biasHeads","type":"u32","value":"dim(shapes.attentionBiasT, 1)"}]}],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), (32))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.PastMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.PastMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":["scores_f32","shaped_value","rowStats_f32","output_past_kv","params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (32))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x16x32_past_kv_rotary_materialized_sgmat","priority":-1000,"when":["sharedKvFloatOk and standardSoftmax and present.cosCacheT and rotaryRequested and not present.qNormWeightT and not present.attentionBiasT and not present.headSinkT","gqaShapedPastFits","matrixSubgroupWidth > 0","128 <= deviceWorkgroupCap","has(device.adapterInfo, \"subgroupMatrixConfigs\") and subgroupMatrixConfigAvailable(dtypes.T, \"f32\", 16, 16, 32)","(max(2048 * dtypeBytes(tensorDtypes.queryT), 4096) if device.wgslLanguageFeatures.has(\"buffer_view\") else 2048 * dtypeBytes(tensorDtypes.queryT) + 4096) + 32 * 8 + 80 <= device.limits.maxComputeWorkgroupStorageSize","ceilDiv(gqaMatPastKvSeq, 32) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(gqaMatPastQSeq, 32) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":16,"K":32},{"componentType":"f16","resultComponentType":"f32","M":16,"N":16,"K":32}]},"derive":{"matrixM":16,"matrixN":16,"matrixK":32,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"ceilDiv(gqaMatPastKvSeq, 32)","mode":"\"copy\"","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","half":"gqaHeadDim / 2","qHeads":"attrs.num_heads","cosScalar":"\"f16\" if tensorDtypes.cosCacheT == \"float16\" else \"f32\"","hasQNorm":false,"operandF16":"dtypes.T == \"f16\""},"intermediates":[{"id":"qPrep","dtype":"float32","shape":"shapes.queryT"},{"id":"qPrepF16","dtype":"float16","shape":"shapes.queryT"},{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * gqaMatPastQSeq * gqaMatPastKvSeq]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatPastRowStatsElements]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * ceilDiv(gqaMatPastKvSeq, 32) * gqaMatPastQSeq * 2]"}],"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]},{"id":"qprep","name":"GroupQueryAttention.RotaryQPrep","shader":"gqa-qprep.wgsl.jinja","bindings":["query_qprep","cos_cache","sin_cache",{"name":"qout","scratch":"qPrep","buffer":"storage","elementType":"vec4","when":"dtypes.T == \"f32\""},{"name":"qout","scratch":"qPrepF16","buffer":"storage","elementType":"vec4","when":"dtypes.T == \"f16\""},"params_qprep"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)","z":1},"derive":{"qPrepF16":"dtypes.T == \"f16\""}},{"id":"scores","name":"GroupQueryAttention.PastRotaryMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":[{"name":"query","scratch":"qPrep","buffer":"read-only-storage","elementType":"f32","when":"dtypes.T == \"f32\""},{"name":"query","scratch":"qPrepF16","buffer":"read-only-storage","elementType":"f16","when":"dtypes.T == \"f16\""},"shaped_key","scores","scorePartials","params_scores"],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), (32))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.PastRotaryMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.PastRotaryMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":["scores_f32","shaped_value","rowStats_f32","output_past_kv","params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (32))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x8x32_cached_materialized_sgmat","priority":-1000,"when":["(sharedKvFloatOk and plainAttentionOptions) or (dtypes.T == \"f32\" and ((sharedKvFloatOk and gqaMatPastBiasInputsOk) or (newKvPastOk and plainAttentionOptions)))","gqaShapedPastFits","matrixSubgroupWidth > 0","128 <= deviceWorkgroupCap","has(device.adapterInfo, \"subgroupMatrixConfigs\") and subgroupMatrixConfigAvailable(dtypes.T, \"f32\", 16, 8, 32)","(max(1536 * dtypeBytes(tensorDtypes.queryT), 2048) if device.wgslLanguageFeatures.has(\"buffer_view\") else 1536 * dtypeBytes(tensorDtypes.queryT) + 2048) + 32 * 8 + 80 <= device.limits.maxComputeWorkgroupStorageSize","ceilDiv(gqaMatPastKvSeq, 16) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(gqaMatPastQSeq, 32) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":8,"K":32},{"componentType":"f16","resultComponentType":"f32","M":16,"N":8,"K":32}]},"derive":{"matrixM":16,"matrixN":8,"matrixK":32,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"ceilDiv(gqaMatPastKvSeq, 16)","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","operandF16":"dtypes.T == \"f16\""},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * gqaMatPastQSeq * gqaMatPastKvSeq]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatPastRowStatsElements]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * ceilDiv(gqaMatPastKvSeq, 16) * gqaMatPastQSeq * 2]"}],"passes":[{"id":"cache_copy","repeat":{"index":"copyPass","count":"1 if cacheCopyMode else 0"},"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"copy\""},"bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]}]},{"id":"cache_merge","repeat":{"index":"mergePass","count":"0 if cacheCopyMode else 1"},"passes":[{"id":"present","name":"GroupQueryAttention.Merge","shader":"gqa-present.wgsl.jinja","derive":{"mode":"\"merge\""},"bindings":["past_k","past_v","new_k","new_v","present_key_present","present_value_present","params_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1}}]},{"id":"scores","name":"GroupQueryAttention.PastMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"scoreBias":"present.attentionBiasT"},"bindings":["query_qprep","shaped_key",{"arg":"attentionBiasT","name":"attention_bias","elementType":"f32","when":"present.attentionBiasT"},"scores","scorePartials","params_scores",{"name":"params","when":"present.attentionBiasT","struct":[{"name":"qSeq","type":"u32","value":"dim(shapes.queryT, 1)"},{"name":"kvSeq","type":"u32","value":"dim(shapes.presentKeyT, 2)"},{"name":"scale","type":"f32","value":"attrs.scale if attrs.scale else 0"},{"name":"biasBatch","type":"u32","value":"dim(shapes.attentionBiasT, 0)"},{"name":"biasHeads","type":"u32","value":"dim(shapes.attentionBiasT, 1)"}]}],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), (16))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.PastMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.PastMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":["scores_f32","shaped_value","rowStats_f32","output_past_kv","params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (16))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x8x32_past_kv_rotary_materialized_sgmat","priority":-1000,"when":["sharedKvFloatOk and standardSoftmax and present.cosCacheT and rotaryRequested and not present.qNormWeightT and not present.attentionBiasT and not present.headSinkT","gqaShapedPastFits","matrixSubgroupWidth > 0","128 <= deviceWorkgroupCap","has(device.adapterInfo, \"subgroupMatrixConfigs\") and subgroupMatrixConfigAvailable(dtypes.T, \"f32\", 16, 8, 32)","(max(1536 * dtypeBytes(tensorDtypes.queryT), 2048) if device.wgslLanguageFeatures.has(\"buffer_view\") else 1536 * dtypeBytes(tensorDtypes.queryT) + 2048) + 32 * 8 + 80 <= device.limits.maxComputeWorkgroupStorageSize","ceilDiv(gqaMatPastKvSeq, 16) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(gqaMatPastQSeq, 32) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":8,"K":32},{"componentType":"f16","resultComponentType":"f32","M":16,"N":8,"K":32}]},"derive":{"matrixM":16,"matrixN":8,"matrixK":32,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"ceilDiv(gqaMatPastKvSeq, 16)","mode":"\"copy\"","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","half":"gqaHeadDim / 2","qHeads":"attrs.num_heads","cosScalar":"\"f16\" if tensorDtypes.cosCacheT == \"float16\" else \"f32\"","hasQNorm":false,"operandF16":"dtypes.T == \"f16\""},"intermediates":[{"id":"qPrep","dtype":"float32","shape":"shapes.queryT"},{"id":"qPrepF16","dtype":"float16","shape":"shapes.queryT"},{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * gqaMatPastQSeq * gqaMatPastKvSeq]"},{"id":"materializedRowStats","dtype":"float32","shape":"[gqaMatPastRowStatsElements]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * ceilDiv(gqaMatPastKvSeq, 16) * gqaMatPastQSeq * 2]"}],"passes":[{"id":"present","name":"GroupQueryAttention.Present","shader":"gqa-present.wgsl.jinja","bindings":["src_k","src_v","present_key_present","present_value_present","params_count"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.pastKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"src_k","output":"present_key"},{"input":"src_v","output":"present_value"}]},{"id":"qprep","name":"GroupQueryAttention.RotaryQPrep","shader":"gqa-qprep.wgsl.jinja","bindings":["query_qprep","cos_cache","sin_cache",{"name":"qout","scratch":"qPrep","buffer":"storage","elementType":"vec4","when":"dtypes.T == \"f32\""},{"name":"qout","scratch":"qPrepF16","buffer":"storage","elementType":"vec4","when":"dtypes.T == \"f16\""},"params_qprep"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), (copyWorkgroupSize)), 65535)","z":1},"derive":{"qPrepF16":"dtypes.T == \"f16\""}},{"id":"scores","name":"GroupQueryAttention.PastRotaryMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":[{"name":"query","scratch":"qPrep","buffer":"read-only-storage","elementType":"f32","when":"dtypes.T == \"f32\""},{"name":"query","scratch":"qPrepF16","buffer":"read-only-storage","elementType":"f16","when":"dtypes.T == \"f16\""},"shaped_key","scores","scorePartials","params_scores"],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), (16))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.PastRotaryMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.PastRotaryMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true},"bindings":["scores_f32","shaped_value","rowStats_f32","output_past_kv","params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (16))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x16x16_share_append_materialized_sgmat_f32","priority":-1000,"when":["(shareAppendOk and plainAttentionOptions and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and dim(shapes.queryT, 1) == dim(shapes.keyT, 1) and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_APPEND_MIN_QSEQ and dim(shapes.presentKeyT, 2) >= dim(shapes.queryT, 1) and matrixSubgroupWidth > 0 and gqaMatPastScoreFits and (numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentKeyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentValueT) * 4 <= device.limits.maxStorageBufferBindingSize) and ((128) <= deviceWorkgroupCap and (((4096 if device.wgslLanguageFeatures.has(\"buffer_view\") else 8192) + 48 + 256 + 32)) <= device.limits.maxComputeWorkgroupStorageSize) and (ceilDiv((dim(shapes.presentKeyT, 2)), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv((dim(shapes.queryT, 1)), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))","has(device.adapterInfo, \"subgroupMatrixConfigs\")"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":16,"K":16}]},"derive":{"matrixM":16,"matrixN":16,"matrixK":16,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"(ceilDiv((dim(shapes.presentKeyT, 2)), (32)) * (1))","mode":"\"merge_share\"","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","useSeqlens":true},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.presentKeyT, 2)]"},{"id":"materializedRowStats","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (dim(shapes.queryT, 1)) * 2)]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (ceilDiv((dim(shapes.presentKeyT, 2)), (32)) * (1)) * (dim(shapes.queryT, 1)) * 2)]"}],"passes":[{"id":"present_retain","name":"GroupQueryAttention.MergeShareRetain","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"retain\""},"bindings":["past_k","past_v","present_key_present","present_value_present","seqlens_k","params__uniform"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"past_k","output":"present_key"},{"input":"past_v","output":"present_value"}]},{"id":"present_append","name":"GroupQueryAttention.MergeShareAppend","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"append\""},"bindings":["new_k","new_v","present_key_present","present_value_present","seqlens_k","params_gqa_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","z":1}},{"id":"scores","name":"GroupQueryAttention.ShareAppendMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"useSeqlens":true},"bindings":["query","key_f32","scores","scorePartials","seqlens_k","params_scores"],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), (32))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.ShareAppendMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.ShareAppendMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"useSeqlens":true},"bindings":["scores_f32","value_f32","rowStats_f32","output","seqlens_k","params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (32))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x8x16_share_append_materialized_sgmat_f32","priority":-1000,"when":["(shareAppendOk and plainAttentionOptions and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and dim(shapes.queryT, 1) == dim(shapes.keyT, 1) and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_APPEND_MIN_QSEQ and dim(shapes.presentKeyT, 2) >= dim(shapes.queryT, 1) and matrixSubgroupWidth > 0 and gqaMatPastScoreFits and (numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentKeyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentValueT) * 4 <= device.limits.maxStorageBufferBindingSize) and ((128) <= deviceWorkgroupCap and (((3072 if device.wgslLanguageFeatures.has(\"buffer_view\") else 5120) + 48 + 256 + 32)) <= device.limits.maxComputeWorkgroupStorageSize) and (ceilDiv((dim(shapes.presentKeyT, 2)), (16)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv((dim(shapes.queryT, 1)), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))","has(device.adapterInfo, \"subgroupMatrixConfigs\")"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":8,"K":16}]},"derive":{"matrixM":16,"matrixN":8,"matrixK":16,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"(ceilDiv((dim(shapes.presentKeyT, 2)), (16)) * (1))","mode":"\"merge_share\"","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","useSeqlens":true},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.presentKeyT, 2)]"},{"id":"materializedRowStats","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (dim(shapes.queryT, 1)) * 2)]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (ceilDiv((dim(shapes.presentKeyT, 2)), (16)) * (1)) * (dim(shapes.queryT, 1)) * 2)]"}],"passes":[{"id":"present_retain","name":"GroupQueryAttention.MergeShareRetain","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"retain\""},"bindings":["past_k","past_v","present_key_present","present_value_present","seqlens_k","params__uniform"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"past_k","output":"present_key"},{"input":"past_v","output":"present_value"}]},{"id":"present_append","name":"GroupQueryAttention.MergeShareAppend","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"append\""},"bindings":["new_k","new_v","present_key_present","present_value_present","seqlens_k","params_gqa_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","z":1}},{"id":"scores","name":"GroupQueryAttention.ShareAppendMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"useSeqlens":true},"bindings":["query","key_f32","scores","scorePartials","seqlens_k","params_scores"],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), (16))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.ShareAppendMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.ShareAppendMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"useSeqlens":true},"bindings":["scores_f32","value_f32","rowStats_f32","output","seqlens_k","params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (16))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}],"demoteWhen":["true"]},{"id":"matrix_shape_8x16x16_share_append_materialized_sgmat_f32","priority":-1000,"when":["(shareAppendOk and plainAttentionOptions and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and dim(shapes.queryT, 1) == dim(shapes.keyT, 1) and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_APPEND_MIN_QSEQ and dim(shapes.presentKeyT, 2) >= dim(shapes.queryT, 1) and matrixSubgroupWidth > 0 and gqaMatPastScoreFits and (numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentKeyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentValueT) * 4 <= device.limits.maxStorageBufferBindingSize) and ((128) <= deviceWorkgroupCap and (((3072 if device.wgslLanguageFeatures.has(\"buffer_view\") else 5120) + 48 + 128 + 32)) <= device.limits.maxComputeWorkgroupStorageSize) and (ceilDiv((dim(shapes.presentKeyT, 2)), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv((dim(shapes.queryT, 1)), (16)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))","has(device.adapterInfo, \"subgroupMatrixConfigs\")"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":8,"N":16,"K":16}]},"derive":{"matrixM":8,"matrixN":16,"matrixK":16,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"(ceilDiv((dim(shapes.presentKeyT, 2)), (32)) * (1))","mode":"\"merge_share\"","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","useSeqlens":true},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.presentKeyT, 2)]"},{"id":"materializedRowStats","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (dim(shapes.queryT, 1)) * 2)]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (ceilDiv((dim(shapes.presentKeyT, 2)), (32)) * (1)) * (dim(shapes.queryT, 1)) * 2)]"}],"passes":[{"id":"present_retain","name":"GroupQueryAttention.MergeShareRetain","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"retain\""},"bindings":["past_k","past_v","present_key_present","present_value_present","seqlens_k","params__uniform"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"past_k","output":"present_key"},{"input":"past_v","output":"present_value"}]},{"id":"present_append","name":"GroupQueryAttention.MergeShareAppend","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"append\""},"bindings":["new_k","new_v","present_key_present","present_value_present","seqlens_k","params_gqa_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","z":1}},{"id":"scores","name":"GroupQueryAttention.ShareAppendMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"useSeqlens":true},"bindings":["query","key_f32","scores","scorePartials","seqlens_k","params_scores"],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), (32))","y":"ceilDiv(dim(shapes.queryT, 1), (16))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.ShareAppendMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.ShareAppendMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"useSeqlens":true},"bindings":["scores_f32","value_f32","rowStats_f32","output","seqlens_k","params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (32))","y":"ceilDiv(dim(shapes.queryT, 1), (16))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x16x32_share_append_materialized_sgmat_f32","priority":-1000,"when":["(shareAppendOk and plainAttentionOptions and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and dim(shapes.queryT, 1) == dim(shapes.keyT, 1) and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_APPEND_MIN_QSEQ and dim(shapes.presentKeyT, 2) >= dim(shapes.queryT, 1) and matrixSubgroupWidth > 0 and gqaMatPastScoreFits and (numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentKeyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentValueT) * 4 <= device.limits.maxStorageBufferBindingSize) and ((128) <= deviceWorkgroupCap and (((8192 if device.wgslLanguageFeatures.has(\"buffer_view\") else 12288) + 48 + 256 + 32)) <= device.limits.maxComputeWorkgroupStorageSize) and (ceilDiv((dim(shapes.presentKeyT, 2)), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv((dim(shapes.queryT, 1)), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))","has(device.adapterInfo, \"subgroupMatrixConfigs\")"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":16,"K":32}]},"derive":{"matrixM":16,"matrixN":16,"matrixK":32,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"(ceilDiv((dim(shapes.presentKeyT, 2)), (32)) * (1))","mode":"\"merge_share\"","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","useSeqlens":true},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.presentKeyT, 2)]"},{"id":"materializedRowStats","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (dim(shapes.queryT, 1)) * 2)]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (ceilDiv((dim(shapes.presentKeyT, 2)), (32)) * (1)) * (dim(shapes.queryT, 1)) * 2)]"}],"passes":[{"id":"present_retain","name":"GroupQueryAttention.MergeShareRetain","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"retain\""},"bindings":["past_k","past_v","present_key_present","present_value_present","seqlens_k","params__uniform"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"past_k","output":"present_key"},{"input":"past_v","output":"present_value"}]},{"id":"present_append","name":"GroupQueryAttention.MergeShareAppend","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"append\""},"bindings":["new_k","new_v","present_key_present","present_value_present","seqlens_k","params_gqa_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","z":1}},{"id":"scores","name":"GroupQueryAttention.ShareAppendMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"useSeqlens":true},"bindings":["query","key_f32","scores","scorePartials","seqlens_k","params_scores"],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), (32))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.ShareAppendMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.ShareAppendMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"useSeqlens":true},"bindings":["scores_f32","value_f32","rowStats_f32","output","seqlens_k","params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (32))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x8x32_share_append_materialized_sgmat_f32","priority":-1000,"when":["(shareAppendOk and plainAttentionOptions and tensorDtypes.queryT == \"float32\" and attrs.local_window_size == -1 and dim(shapes.queryT, 1) == dim(shapes.keyT, 1) and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_APPEND_MIN_QSEQ and dim(shapes.presentKeyT, 2) >= dim(shapes.queryT, 1) and matrixSubgroupWidth > 0 and gqaMatPastScoreFits and (numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentKeyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentValueT) * 4 <= device.limits.maxStorageBufferBindingSize) and ((128) <= deviceWorkgroupCap and (((6144 if device.wgslLanguageFeatures.has(\"buffer_view\") else 8192) + 48 + 256 + 32)) <= device.limits.maxComputeWorkgroupStorageSize) and (ceilDiv((dim(shapes.presentKeyT, 2)), (16)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv((dim(shapes.queryT, 1)), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))","has(device.adapterInfo, \"subgroupMatrixConfigs\")"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":8,"K":32}]},"derive":{"matrixM":16,"matrixN":8,"matrixK":32,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"(ceilDiv((dim(shapes.presentKeyT, 2)), (16)) * (1))","mode":"\"merge_share\"","packed":"gqaHeadDim","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","useSeqlens":true},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * dim(shapes.presentKeyT, 2)]"},{"id":"materializedRowStats","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (dim(shapes.queryT, 1)) * 2)]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (ceilDiv((dim(shapes.presentKeyT, 2)), (16)) * (1)) * (dim(shapes.queryT, 1)) * 2)]"}],"passes":[{"id":"present_retain","name":"GroupQueryAttention.MergeShareRetain","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"retain\""},"bindings":["past_k","past_v","present_key_present","present_value_present","seqlens_k","params__uniform"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.presentKeyT, 2)), (copyWorkgroupSize)), 65535)","z":1},"viewAlias":[{"input":"past_k","output":"present_key"},{"input":"past_v","output":"present_value"}]},{"id":"present_append","name":"GroupQueryAttention.MergeShareAppend","shader":"gqa-present.wgsl.jinja","derive":{"shareRegion":"\"append\""},"bindings":["new_k","new_v","present_key_present","present_value_present","seqlens_k","params_gqa_present"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * dim(shapes.keyT, 1)), (copyWorkgroupSize)), 65535)","z":1}},{"id":"scores","name":"GroupQueryAttention.ShareAppendMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"useSeqlens":true},"bindings":["query","key_f32","scores","scorePartials","seqlens_k","params_scores"],"dispatch":{"x":"ceilDiv(dim(shapes.presentKeyT, 2), (16))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.ShareAppendMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.ShareAppendMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"useSeqlens":true},"bindings":["scores_f32","value_f32","rowStats_f32","output","seqlens_k","params_apply"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (16))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x16x16_window_shift_materialized_sgmat_f32","priority":-1000,"when":["(windowShiftOk and plainAttentionOptions and tensorDtypes.queryT == \"float32\" and attrs.local_window_size > 0 and dim(shapes.queryT, 1) == dim(shapes.keyT, 1) and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_WINDOW_MIN_QSEQ and windowCapacity >= dim(shapes.queryT, 1) and attrs.local_window_size + dim(shapes.queryT, 1) >= windowCapacity and matrixSubgroupWidth > 0 and gqaMatPastScoreFits and (numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentKeyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentValueT) * 4 <= device.limits.maxStorageBufferBindingSize) and ((128) <= deviceWorkgroupCap and (((4096 if device.wgslLanguageFeatures.has(\"buffer_view\") else 8192) + 48 + 256 + 32)) <= device.limits.maxComputeWorkgroupStorageSize) and (ceilDiv((dim(shapes.presentKeyT, 2)), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv((dim(shapes.queryT, 1)), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))","(ceilDiv(windowStageCapacity, (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * windowStageCapacity * 4 <= min(device.limits.maxBufferSize, device.limits.maxStorageBufferBindingSize) and (dim(shapes.queryT, 0) * attrs.num_heads * (ceilDiv(windowStageCapacity, (32)) * (1)) * dim(shapes.queryT, 1) * 2) * 4 <= min(device.limits.maxBufferSize, device.limits.maxStorageBufferBindingSize))","has(device.adapterInfo, \"subgroupMatrixConfigs\")"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":16,"K":16}]},"derive":{"matrixM":16,"matrixN":16,"matrixK":16,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"(ceilDiv(windowStageCapacity, (32)) * (1))","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","seqlensQueryFloor":false},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * windowStageCapacity]"},{"id":"materializedRowStats","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (dim(shapes.queryT, 1)) * 2)]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (ceilDiv(windowStageCapacity, (32)) * (1)) * dim(shapes.queryT, 1) * 2)]"},{"id":"windowKey","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowValue","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowLengths","dtype":"int32","shape":"[2 * dim(shapes.queryT, 0)]"}],"passes":[{"id":"present","name":"GroupQueryAttention.WindowShift","shader":"gqa-window-cache.wgsl.jinja","bindings":["past_k","past_v","new_k","new_v","window_key_write","window_value_write","seqlens_k","params_window_stage","window_lengths_write"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","z":1},"derive":{"windowPhase":"\"stage\"","stageRegion":"\"all\""}},{"id":"scores","name":"GroupQueryAttention.WindowMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"scoreWindow":true,"useSeqlens":true},"bindings":["query","window_key_read_f32","scores","scorePartials","window_lengths_read","params_window_attention_scaled"],"dispatch":{"x":"ceilDiv(windowStageCapacity, (32))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.WindowMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.WindowMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"scoreWindow":true,"useSeqlens":true},"bindings":["scores_f32","window_value_read_f32","rowStats_f32","output","window_lengths_read","params_window_attention"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (32))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"compact","name":"GroupQueryAttention.WindowCompact","shader":"gqa-window-cache.wgsl.jinja","derive":{"windowPhase":"\"compact\""},"bindings":["window_key_read","window_value_read","window_lengths_read","present_key_present","present_value_present","params_window_compact","output_past_kv"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","z":1}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x8x16_window_shift_materialized_sgmat_f32","priority":-1000,"when":["(windowShiftOk and plainAttentionOptions and tensorDtypes.queryT == \"float32\" and attrs.local_window_size > 0 and dim(shapes.queryT, 1) == dim(shapes.keyT, 1) and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_WINDOW_MIN_QSEQ and windowCapacity >= dim(shapes.queryT, 1) and attrs.local_window_size + dim(shapes.queryT, 1) >= windowCapacity and matrixSubgroupWidth > 0 and gqaMatPastScoreFits and (numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentKeyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentValueT) * 4 <= device.limits.maxStorageBufferBindingSize) and ((128) <= deviceWorkgroupCap and (((3072 if device.wgslLanguageFeatures.has(\"buffer_view\") else 5120) + 48 + 256 + 32)) <= device.limits.maxComputeWorkgroupStorageSize) and (ceilDiv((dim(shapes.presentKeyT, 2)), (16)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv((dim(shapes.queryT, 1)), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))","(ceilDiv(windowStageCapacity, (16)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * windowStageCapacity * 4 <= min(device.limits.maxBufferSize, device.limits.maxStorageBufferBindingSize) and (dim(shapes.queryT, 0) * attrs.num_heads * (ceilDiv(windowStageCapacity, (16)) * (1)) * dim(shapes.queryT, 1) * 2) * 4 <= min(device.limits.maxBufferSize, device.limits.maxStorageBufferBindingSize))","has(device.adapterInfo, \"subgroupMatrixConfigs\")"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":8,"K":16}]},"derive":{"matrixM":16,"matrixN":8,"matrixK":16,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"(ceilDiv(windowStageCapacity, (16)) * (1))","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","seqlensQueryFloor":false},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * windowStageCapacity]"},{"id":"materializedRowStats","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (dim(shapes.queryT, 1)) * 2)]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (ceilDiv(windowStageCapacity, (16)) * (1)) * dim(shapes.queryT, 1) * 2)]"},{"id":"windowKey","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowValue","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowLengths","dtype":"int32","shape":"[2 * dim(shapes.queryT, 0)]"}],"passes":[{"id":"present","name":"GroupQueryAttention.WindowShift","shader":"gqa-window-cache.wgsl.jinja","bindings":["past_k","past_v","new_k","new_v","window_key_write","window_value_write","seqlens_k","params_window_stage","window_lengths_write"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","z":1},"derive":{"windowPhase":"\"stage\"","stageRegion":"\"all\""}},{"id":"scores","name":"GroupQueryAttention.WindowMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"scoreWindow":true,"useSeqlens":true},"bindings":["query","window_key_read_f32","scores","scorePartials","window_lengths_read","params_window_attention_scaled"],"dispatch":{"x":"ceilDiv(windowStageCapacity, (16))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.WindowMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.WindowMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"scoreWindow":true,"useSeqlens":true},"bindings":["scores_f32","window_value_read_f32","rowStats_f32","output","window_lengths_read","params_window_attention"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (16))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"compact","name":"GroupQueryAttention.WindowCompact","shader":"gqa-window-cache.wgsl.jinja","derive":{"windowPhase":"\"compact\""},"bindings":["window_key_read","window_value_read","window_lengths_read","present_key_present","present_value_present","params_window_compact","output_past_kv"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","z":1}}],"demoteWhen":["true"]},{"id":"matrix_shape_8x16x16_window_shift_materialized_sgmat_f32","priority":-1000,"when":["(windowShiftOk and plainAttentionOptions and tensorDtypes.queryT == \"float32\" and attrs.local_window_size > 0 and dim(shapes.queryT, 1) == dim(shapes.keyT, 1) and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_WINDOW_MIN_QSEQ and windowCapacity >= dim(shapes.queryT, 1) and attrs.local_window_size + dim(shapes.queryT, 1) >= windowCapacity and matrixSubgroupWidth > 0 and gqaMatPastScoreFits and (numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentKeyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentValueT) * 4 <= device.limits.maxStorageBufferBindingSize) and ((128) <= deviceWorkgroupCap and (((3072 if device.wgslLanguageFeatures.has(\"buffer_view\") else 5120) + 48 + 128 + 32)) <= device.limits.maxComputeWorkgroupStorageSize) and (ceilDiv((dim(shapes.presentKeyT, 2)), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv((dim(shapes.queryT, 1)), (16)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))","(ceilDiv(windowStageCapacity, (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * windowStageCapacity * 4 <= min(device.limits.maxBufferSize, device.limits.maxStorageBufferBindingSize) and (dim(shapes.queryT, 0) * attrs.num_heads * (ceilDiv(windowStageCapacity, (32)) * (1)) * dim(shapes.queryT, 1) * 2) * 4 <= min(device.limits.maxBufferSize, device.limits.maxStorageBufferBindingSize))","has(device.adapterInfo, \"subgroupMatrixConfigs\")"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":8,"N":16,"K":16}]},"derive":{"matrixM":8,"matrixN":16,"matrixK":16,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"(ceilDiv(windowStageCapacity, (32)) * (1))","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","seqlensQueryFloor":false},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * windowStageCapacity]"},{"id":"materializedRowStats","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (dim(shapes.queryT, 1)) * 2)]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (ceilDiv(windowStageCapacity, (32)) * (1)) * dim(shapes.queryT, 1) * 2)]"},{"id":"windowKey","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowValue","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowLengths","dtype":"int32","shape":"[2 * dim(shapes.queryT, 0)]"}],"passes":[{"id":"present","name":"GroupQueryAttention.WindowShift","shader":"gqa-window-cache.wgsl.jinja","bindings":["past_k","past_v","new_k","new_v","window_key_write","window_value_write","seqlens_k","params_window_stage","window_lengths_write"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","z":1},"derive":{"windowPhase":"\"stage\"","stageRegion":"\"all\""}},{"id":"scores","name":"GroupQueryAttention.WindowMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"scoreWindow":true,"useSeqlens":true},"bindings":["query","window_key_read_f32","scores","scorePartials","window_lengths_read","params_window_attention_scaled"],"dispatch":{"x":"ceilDiv(windowStageCapacity, (32))","y":"ceilDiv(dim(shapes.queryT, 1), (16))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.WindowMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.WindowMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"scoreWindow":true,"useSeqlens":true},"bindings":["scores_f32","window_value_read_f32","rowStats_f32","output","window_lengths_read","params_window_attention"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (32))","y":"ceilDiv(dim(shapes.queryT, 1), (16))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"compact","name":"GroupQueryAttention.WindowCompact","shader":"gqa-window-cache.wgsl.jinja","derive":{"windowPhase":"\"compact\""},"bindings":["window_key_read","window_value_read","window_lengths_read","present_key_present","present_value_present","params_window_compact","output_past_kv"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","z":1}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x16x32_window_shift_materialized_sgmat_f32","priority":-1000,"when":["(windowShiftOk and plainAttentionOptions and tensorDtypes.queryT == \"float32\" and attrs.local_window_size > 0 and dim(shapes.queryT, 1) == dim(shapes.keyT, 1) and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_WINDOW_MIN_QSEQ and windowCapacity >= dim(shapes.queryT, 1) and attrs.local_window_size + dim(shapes.queryT, 1) >= windowCapacity and matrixSubgroupWidth > 0 and gqaMatPastScoreFits and (numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentKeyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentValueT) * 4 <= device.limits.maxStorageBufferBindingSize) and ((128) <= deviceWorkgroupCap and (((8192 if device.wgslLanguageFeatures.has(\"buffer_view\") else 12288) + 48 + 256 + 32)) <= device.limits.maxComputeWorkgroupStorageSize) and (ceilDiv((dim(shapes.presentKeyT, 2)), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv((dim(shapes.queryT, 1)), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))","(ceilDiv(windowStageCapacity, (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * windowStageCapacity * 4 <= min(device.limits.maxBufferSize, device.limits.maxStorageBufferBindingSize) and (dim(shapes.queryT, 0) * attrs.num_heads * (ceilDiv(windowStageCapacity, (32)) * (1)) * dim(shapes.queryT, 1) * 2) * 4 <= min(device.limits.maxBufferSize, device.limits.maxStorageBufferBindingSize))","has(device.adapterInfo, \"subgroupMatrixConfigs\")"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":16,"K":32}]},"derive":{"matrixM":16,"matrixN":16,"matrixK":32,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"(ceilDiv(windowStageCapacity, (32)) * (1))","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","seqlensQueryFloor":false},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * windowStageCapacity]"},{"id":"materializedRowStats","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (dim(shapes.queryT, 1)) * 2)]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (ceilDiv(windowStageCapacity, (32)) * (1)) * dim(shapes.queryT, 1) * 2)]"},{"id":"windowKey","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowValue","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowLengths","dtype":"int32","shape":"[2 * dim(shapes.queryT, 0)]"}],"passes":[{"id":"present","name":"GroupQueryAttention.WindowShift","shader":"gqa-window-cache.wgsl.jinja","bindings":["past_k","past_v","new_k","new_v","window_key_write","window_value_write","seqlens_k","params_window_stage","window_lengths_write"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","z":1},"derive":{"windowPhase":"\"stage\"","stageRegion":"\"all\""}},{"id":"scores","name":"GroupQueryAttention.WindowMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"scoreWindow":true,"useSeqlens":true},"bindings":["query","window_key_read_f32","scores","scorePartials","window_lengths_read","params_window_attention_scaled"],"dispatch":{"x":"ceilDiv(windowStageCapacity, (32))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.WindowMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.WindowMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"scoreWindow":true,"useSeqlens":true},"bindings":["scores_f32","window_value_read_f32","rowStats_f32","output","window_lengths_read","params_window_attention"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (32))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"compact","name":"GroupQueryAttention.WindowCompact","shader":"gqa-window-cache.wgsl.jinja","derive":{"windowPhase":"\"compact\""},"bindings":["window_key_read","window_value_read","window_lengths_read","present_key_present","present_value_present","params_window_compact","output_past_kv"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","z":1}}],"demoteWhen":["true"]},{"id":"matrix_shape_16x8x32_window_shift_materialized_sgmat_f32","priority":-1000,"when":["(windowShiftOk and plainAttentionOptions and tensorDtypes.queryT == \"float32\" and attrs.local_window_size > 0 and dim(shapes.queryT, 1) == dim(shapes.keyT, 1) and gqaHeadDim >= 64 and gqaHeadDim <= 256 and gqaHeadDim % 16 == 0 and dim(shapes.queryT, 1) >= tunables.MATERIALIZED_SGMAT_WINDOW_MIN_QSEQ and windowCapacity >= dim(shapes.queryT, 1) and attrs.local_window_size + dim(shapes.queryT, 1) >= windowCapacity and matrixSubgroupWidth > 0 and gqaMatPastScoreFits and (numel(shapes.queryT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentKeyT) * 4 <= device.limits.maxStorageBufferBindingSize and numel(shapes.presentValueT) * 4 <= device.limits.maxStorageBufferBindingSize) and ((128) <= deviceWorkgroupCap and (((6144 if device.wgslLanguageFeatures.has(\"buffer_view\") else 8192) + 48 + 256 + 32)) <= device.limits.maxComputeWorkgroupStorageSize) and (ceilDiv((dim(shapes.presentKeyT, 2)), (16)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv((dim(shapes.queryT, 1)), (32)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)))","(ceilDiv(windowStageCapacity, (16)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * windowStageCapacity * 4 <= min(device.limits.maxBufferSize, device.limits.maxStorageBufferBindingSize) and (dim(shapes.queryT, 0) * attrs.num_heads * (ceilDiv(windowStageCapacity, (16)) * (1)) * dim(shapes.queryT, 1) * 2) * 4 <= min(device.limits.maxBufferSize, device.limits.maxStorageBufferBindingSize))","has(device.adapterInfo, \"subgroupMatrixConfigs\")"],"requires":{"features":["subgroups","chromium-experimental-subgroup-matrix"],"subgroupMatrixConfigs":[{"componentType":"f32","resultComponentType":"f32","M":16,"N":8,"K":32}]},"derive":{"matrixM":16,"matrixN":8,"matrixK":32,"kvNumHeads":"attrs.kv_num_heads","headDim":"gqaHeadDim","qHidden":"dim(shapes.queryT, 2)","statSlots":"(ceilDiv(windowStageCapacity, (16)) * (1))","kvHeads":"attrs.kv_num_heads","inputScalar":"gqaScalar","seqlensQueryFloor":false},"intermediates":[{"id":"materializedScores","dtype":"float32","shape":"[dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1) * windowStageCapacity]"},{"id":"materializedRowStats","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (dim(shapes.queryT, 1)) * 2)]"},{"id":"materializedScorePartials","dtype":"float32","shape":"[(dim(shapes.queryT, 0) * attrs.num_heads * (ceilDiv(windowStageCapacity, (16)) * (1)) * dim(shapes.queryT, 1) * 2)]"},{"id":"windowKey","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowValue","dtype":"float32","shape":"[dim(shapes.queryT, 0), attrs.kv_num_heads, windowStageCapacity, gqaHeadDim]"},{"id":"windowLengths","dtype":"int32","shape":"[2 * dim(shapes.queryT, 0)]"}],"passes":[{"id":"present","name":"GroupQueryAttention.WindowShift","shader":"gqa-window-cache.wgsl.jinja","bindings":["past_k","past_v","new_k","new_v","window_key_write","window_value_write","seqlens_k","params_window_stage","window_lengths_write"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowStageCapacity), (copyWorkgroupSize)), 65535)","z":1},"derive":{"windowPhase":"\"stage\"","stageRegion":"\"all\""}},{"id":"scores","name":"GroupQueryAttention.WindowMaterializedScores","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"score\"","emitRowStats":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"scoreWindow":true,"useSeqlens":true},"bindings":["query","window_key_read_f32","scores","scorePartials","window_lengths_read","params_window_attention_scaled"],"dispatch":{"x":"ceilDiv(windowStageCapacity, (16))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"rowstats","name":"GroupQueryAttention.WindowMaterializedRowStats","shader":"attn-materialized-rowstats-combine-f32.wgsl.jinja","bindings":["scorePartials_f32","rowStats","params_rows"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.num_heads * dim(shapes.queryT, 1)), ((min(tunables.MATERIALIZED_SOFTMAX_WORKGROUP_SIZE, deviceWorkgroupCap)))), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}},{"id":"apply","name":"GroupQueryAttention.WindowMaterializedApply","shader":"attn-materialized-shaped.wgsl.jinja","derive":{"phase":"\"apply\"","fusedSoftmax":true,"layout":"\"bsh\"","kvLayout":"\"bhsd\"","causalRightAlign":true,"scoreWindow":true,"useSeqlens":true},"bindings":["scores_f32","window_value_read_f32","rowStats_f32","output","window_lengths_read","params_window_attention"],"dispatch":{"x":"ceilDiv(gqaHeadDim, (16))","y":"ceilDiv(dim(shapes.queryT, 1), (32))","z":"dim(shapes.queryT, 0) * attrs.num_heads"}},{"id":"compact","name":"GroupQueryAttention.WindowCompact","shader":"gqa-window-cache.wgsl.jinja","derive":{"windowPhase":"\"compact\""},"bindings":["window_key_read","window_value_read","window_lengths_read","present_key_present","present_value_present","params_window_compact","output_past_kv"],"dispatch":{"x":"min(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.queryT, 0) * attrs.kv_num_heads * windowCapacity), (copyWorkgroupSize)), 65535)","z":1}}],"demoteWhen":["true"]}]}