From 34228249774a307438108412f1679708b722e443 Mon Sep 17 00:00:00 2001 From: zihaomu Date: Fri, 27 Nov 2026 11:57:33 +0800 Subject: [PATCH] perf(attention): read fp8 kv as fp16 bit patterns in rdna3 decode gfx11 has no fp8 converts and lowers fp32 -> bf16 to integer RNE code, so the generic E4M3 decode dominates grouped decode, repeated for every dot-operand replica. On gfx11 the decode stage reads each E4M3 code as the fp16 bit pattern of value/256 (exact for every finite code), pins it to the load layout, restores the 256 in kv_row_scale and runs fp16 WMMA. It uses 16-key single-stage tiles, a minimum split length of 32 and up to eight programs per SM. --- python/freetoken/attention/triton.py | 5 +- python/freetoken/kernel/triton/attention.py | 63 ++++++++++++++++----- python/freetoken/kernel/triton/kv_rows.py | 16 +++++- tests/kernels/test_triton_attention.py | 55 +++++++++++++----- 4 files changed, 109 insertions(+), 30 deletions(-) diff --git a/python/freetoken/attention/triton.py b/python/freetoken/attention/triton.py index bd92f3ee1f..a336634849 100644 --- a/python/freetoken/attention/triton.py +++ b/python/freetoken/attention/triton.py @@ -86,7 +86,10 @@ def __init__(self, config: ModelConfig): def _split_cap(self, bs: int) -> int: """The most decode KV splits any layer group takes at this batch size.""" - return max(decode_kv_split_cap(bs, max(1, self.num_q_heads), heads, self.device.index) for heads in self.kv_heads) + return max( + decode_kv_split_cap(bs, max(1, self.num_q_heads), heads, self.device.index, self.kvcache.kv_format) + for heads in self.kv_heads + ) def _ensure_decode_scratch( self, diff --git a/python/freetoken/kernel/triton/attention.py b/python/freetoken/kernel/triton/attention.py index 70232dbf6a..1e0d990335 100644 --- a/python/freetoken/kernel/triton/attention.py +++ b/python/freetoken/kernel/triton/attention.py @@ -7,7 +7,9 @@ import triton.language as tl from freetoken.kernel.triton.e4m3_compat import FORCE_EMU -from freetoken.kernel.triton.kv_rows import kv_row_scale, kv_scale_args, kv_tile, kv_tile_rows, kv_tile_staged +from freetoken.kernel.triton.kv_rows import ( + _kv_tile_gfx11_f16, kv_row_scale, kv_scale_args, kv_tile, kv_tile_rows, kv_tile_staged, +) from freetoken.kvcache.format import NONE, KVFormat from freetoken.utils.arch import get_rocm_gfx_arch, is_rocm @@ -20,6 +22,9 @@ # a short request still takes up to this many splits of _MIN_BLOCK_KV keys, so tiny requests stay parallel _MIN_SPLITS = 8 _MAX_KV_SPLITS = 64 +# the gfx11 fp8 reader runs 16-key single-stage tiles: shorter splits and more programs hide its latency +_GFX11_F16_MIN_SPLIT_LEN = 32 +_GFX11_F16_MAX_KV_SPLITS = 256 # requests with more query rows take the extend kernel MAX_DECODE_ROWS = 8 # stage 2 merges at most this many fp32 partial elements per step @@ -66,6 +71,14 @@ def _use_gfx12_fp8_reader(kv_format: KVFormat, q: torch.Tensor, k_cache: torch.T ) +def _use_gfx11_f16_reader(kv_format: KVFormat) -> bool: + # RDNA3 has neither fp8 nor fp32 -> bf16 converts; E4M3 read as fp16 bit patterns needs neither + return ( + kv_format.name == "fp8_per_token_head" and not FORCE_EMU + and (get_rocm_gfx_arch() or "").startswith("gfx11") + ) + + def _multi_row_decode_launch(m: int, block_d: int, quantized: bool, q_bytes: int, kv_bytes: int, smem: int) -> tuple[int, int, int]: """(block_n, num_stages, num_warps) of stage 1 for ``m`` > 1 query rows x heads per program. @@ -81,6 +94,11 @@ def _multi_row_decode_launch(m: int, block_d: int, quantized: bool, q_bytes: int return block_n, 3, num_warps +def _gfx11_f16_decode_launch(m: int) -> tuple[int, int, int]: + """(block_n, num_stages, num_warps) of stage 1 for the gfx11 fp8 reader with ``m`` query rows x heads per program.""" + return 16, 1, (2 if m <= 16 else 4) + + def _decode_heads_per_program(group: int, rows: int, head_dim: int) -> int: """Query heads per decode program: the whole GQA group within the cap, else its largest power-of-two divisor within the cap. @@ -95,8 +113,8 @@ def _decode_heads_per_program(group: int, rows: int, head_dim: int) -> int: return max(h for h in (1, 2, 4, 8, 16) if h <= cap and group % h == 0) -def _max_request_splits(keys: int) -> int: - return max(triton.cdiv(keys, _MIN_SPLIT_LEN), min(_MIN_SPLITS, triton.cdiv(keys, _MIN_BLOCK_KV)), 1) +def _max_request_splits(keys: int, min_split_len: int = _MIN_SPLIT_LEN) -> int: + return max(triton.cdiv(keys, min_split_len), min(_MIN_SPLITS, triton.cdiv(keys, _MIN_BLOCK_KV)), 1) @functools.lru_cache(maxsize=None) @@ -116,10 +134,14 @@ def _num_sms(device_index: int) -> int: return int(torch.cuda.get_device_properties(device_index).multi_processor_count) -def decode_kv_split_cap(batch: int, num_q_heads: int, num_kv_heads: int, device_index: int) -> int: - """Most KV splits per request for a decode batch: about four programs per SM, within [_MIN_SPLITS, _MAX_KV_SPLITS].""" +def decode_kv_split_cap( + batch: int, num_q_heads: int, num_kv_heads: int, device_index: int, kv_format: KVFormat = NONE, +) -> int: + """Most KV splits per request for a decode batch: about four programs per SM, within [_MIN_SPLITS, _MAX_KV_SPLITS]; + eight, within [_MIN_SPLITS, _GFX11_F16_MAX_KV_SPLITS], for the gfx11 fp8 reader.""" head_blocks = triton.cdiv(num_q_heads, min(16, max(1, num_q_heads // num_kv_heads))) - return max(_MIN_SPLITS, min(_MAX_KV_SPLITS, triton.cdiv(4 * _num_sms(device_index), batch * head_blocks))) + per_sm, max_splits = (8, _GFX11_F16_MAX_KV_SPLITS) if _use_gfx11_f16_reader(kv_format) else (4, _MAX_KV_SPLITS) + return max(_MIN_SPLITS, min(max_splits, triton.cdiv(per_sm * _num_sms(device_index), batch * head_blocks))) def _select_extend_tile(head_dim: int, block_d: int, smem_optin: int) -> tuple[int, int]: @@ -265,7 +287,7 @@ def _paged_attention_kernel( @triton.jit def _decode_num_splits(effective_len, max_kv_splits, MIN_SPLIT_LEN: tl.constexpr, MIN_SPLITS: tl.constexpr, MIN_BLOCK_KV: tl.constexpr): - # same rule as _max_request_splits: long requests split by length, short ones still take up to MIN_SPLITS small splits + # same rule as _max_request_splits(keys, MIN_SPLIT_LEN): long requests split by length, short ones still take up to MIN_SPLITS small splits by_len = tl.maximum(tl.cdiv(effective_len, MIN_SPLIT_LEN), tl.minimum(MIN_SPLITS, tl.cdiv(effective_len, MIN_BLOCK_KV))) return tl.minimum(tl.maximum(by_len, 1), max_kv_splits) @@ -316,6 +338,7 @@ def _decode_grouped_stage1_kernel( KV_OFFSET_DTYPE: tl.constexpr, KV_FMT: tl.constexpr, KV_PACK: tl.constexpr, + F16_KV: tl.constexpr, ): batch_id = tl.program_id(0) head_block_id = tl.program_id(1) @@ -387,6 +410,8 @@ def _decode_grouped_stage1_kernel( q = tl.load(q_ptr + q_offsets, mask=mask_h[:, None] & mask_d[None, :], other=0.0) if KV_FMT == "none": q = q.to(k_ptr.dtype.element_ty) + elif F16_KV: + q = q.to(tl.float16) for rel_start in tl.range(split_start, split_end, BLOCK_N): rel_offs = rel_start + tl.arange(0, BLOCK_N) @@ -398,9 +423,11 @@ def _decode_grouped_stage1_kernel( if KV_PACK == 4: k = kv_tile_rows(k_ptr, slots, kv_head, stride_ks, stride_kh, mask_n, D, BLOCK_D, True) + elif F16_KV: + k = _kv_tile_gfx11_f16(k_ptr + slots[None, :] * stride_ks + k_base_offsets, mask_n[None, :] & mask_d[:, None]) else: k = kv_tile(k_ptr + slots[None, :] * stride_ks + k_base_offsets, mask_n[None, :] & mask_d[:, None], KV_FMT) - scale_k = kv_row_scale(k_scale_ptr + slots * stride_kss + kv_head, mask_n, KV_FMT) + scale_k = kv_row_scale(k_scale_ptr + slots * stride_kss + kv_head, mask_n, KV_FMT, F16_KV) scores = tl.dot(q, k) * sm_scale * scale_k[None, :] mask = mask_h[:, None] & mask_n[None, :] if ROWS > 1: @@ -413,9 +440,11 @@ def _decode_grouped_stage1_kernel( if KV_PACK == 4: v = kv_tile_rows(v_ptr, slots, kv_head, stride_vs, stride_vh, mask_n, DV, BLOCK_DV, False) + elif F16_KV: + v = _kv_tile_gfx11_f16(v_ptr + slots[:, None] * stride_vs + v_base_offsets, mask_n[:, None] & mask_dv[None, :]) else: v = kv_tile(v_ptr + slots[:, None] * stride_vs + v_base_offsets, mask_n[:, None] & mask_dv[None, :], KV_FMT) - scale_v = kv_row_scale(v_scale_ptr + slots * stride_vss + kv_head, mask_n, KV_FMT) + scale_v = kv_row_scale(v_scale_ptr + slots * stride_vss + kv_head, mask_n, KV_FMT, F16_KV) row_max = tl.max(scores, axis=1) if ROWS > 1: @@ -569,7 +598,7 @@ def decode_paged_attention( """SGLang-style split-k grouped decode attention for up to MAX_DECODE_ROWS causal query rows per request. Request ``i`` owns query rows ``qo_indptr[i]:qo_indptr[i + 1]`` (one row each when ``qo_indptr`` is None); ``q_positions`` holds each row's key position. - Each request takes ``max(ceil(keys / 128), min(8, ceil(keys / 32)))`` splits, capped by ``max_kv_splits`` (default :func:`decode_kv_split_cap`) and by the split dim of ``attn_logits`` / ``attn_lse``, which hold one entry per query row. + Each request takes ``max(ceil(keys / L), min(8, ceil(keys / 32)))`` splits, with ``L`` 128 (32 for the gfx11 fp8 reader), capped by ``max_kv_splits`` (default :func:`decode_kv_split_cap`) and by the split dim of ``attn_logits`` / ``attn_lse``, which hold one entry per query row. The kernels compute the split count on the device, so a captured graph serves any context length. """ @@ -594,12 +623,14 @@ def decode_paged_attention( if sliding_window is not None and sliding_window <= 0: # the kernels treat a window <= 0 as no window sliding_window = None + f16_kv = _use_gfx11_f16_reader(kv_format) + min_split_len = _GFX11_F16_MIN_SPLIT_LEN if f16_kv else _MIN_SPLIT_LEN if max_kv_splits is None: - max_kv_splits = decode_kv_split_cap(batch, num_q_heads, num_kv_heads, q.device.index) + max_kv_splits = decode_kv_split_cap(batch, num_q_heads, num_kv_heads, q.device.index, kv_format) if sliding_window: # no request attends more than the window plus its later rows, so programs past its splits would only exit span = sliding_window + max_q_len - 1 - max_kv_splits = min(max_kv_splits, _max_request_splits(span)) + max_kv_splits = min(max_kv_splits, _max_request_splits(span, min_split_len)) max_kv_splits = min(max_kv_splits, attn_logits.shape[2], attn_lse.shape[2]) if sinks is not None: assert sinks.is_cuda @@ -650,6 +681,9 @@ def decode_paged_attention( kv_pack = 1 if is_rocm() and rows == 1 and _use_gfx12_fp8_reader(kv_format, q, k_cache, v_cache): kv_pack, block_n, num_stages, num_warps = 4, 64, 1, 4 + if f16_kv: + # one stage: the pipeliner cannot predicate the gfx11 tile's asm pin + block_n, num_stages, num_warps = _gfx11_f16_decode_launch(rows * block_h) k_scale_arg, v_scale_arg, stride_kss, stride_vss = kv_scale_args(kv_format, k_cache, v_cache, k_scale, v_scale, q) _decode_grouped_stage1_kernel[grid]( @@ -683,6 +717,7 @@ def decode_paged_attention( KV_OFFSET_DTYPE=_kv_offset_dtype(k_cache, v_cache), KV_FMT=kv_format.name, KV_PACK=kv_pack, + F16_KV=f16_kv, GROUP=group, NUM_Q_HEADS=num_q_heads, ROWS=rows, @@ -692,7 +727,7 @@ def decode_paged_attention( BLOCK_H=block_h, VALID_BLOCK_H=valid_block_h, MIN_BLOCK_KV=_MIN_BLOCK_KV, - MIN_SPLIT_LEN=_MIN_SPLIT_LEN, + MIN_SPLIT_LEN=min_split_len, MIN_SPLITS=_MIN_SPLITS, D=head_dim, DV=head_dim, @@ -722,7 +757,7 @@ def decode_paged_attention( o.stride(1), ROWS=rows, MIN_BLOCK_KV=_MIN_BLOCK_KV, - MIN_SPLIT_LEN=_MIN_SPLIT_LEN, + MIN_SPLIT_LEN=min_split_len, MIN_SPLITS=_MIN_SPLITS, BLOCK_DV=block_dv, DV=head_dim, diff --git a/python/freetoken/kernel/triton/kv_rows.py b/python/freetoken/kernel/triton/kv_rows.py index c0e9aa20f0..6ce72a0cb4 100644 --- a/python/freetoken/kernel/triton/kv_rows.py +++ b/python/freetoken/kernel/triton/kv_rows.py @@ -39,6 +39,16 @@ def _kv_tile_gfx12_bf16(ptrs, mask, TRANSPOSE: tl.constexpr): return values +@triton.jit +def _kv_tile_gfx11_f16(ptrs, mask): + """E4M3FN codes as fp16 holding ``value / 256``, exact for every finite code; ``kv_row_scale(F16=True)`` restores the 256.""" + codes = tl.load(ptrs, mask=mask, other=0).to(tl.uint16) + bits = ((codes & 0x80) << 8) | ((codes & 0x7F) << 7) + # keep the decode in the load layout: Triton otherwise repeats it for every dot-operand replica + bits = tl.inline_asm_elementwise("v_mov_b32 $0, $1", "=v,v", [bits], dtype=tl.uint16, is_pure=False, pack=2) + return bits.to(tl.float16, bitcast=True) + + @triton.jit def kv_tile(ptrs, mask, FMT: tl.constexpr): """One K or V tile in the dtype ``tl.dot`` takes.""" @@ -101,12 +111,14 @@ def kv_tile_staged(ptrs, mask, FMT: tl.constexpr): @triton.jit -def kv_row_scale(ptrs, mask, FMT: tl.constexpr): - """Row scales of a tile; all ones without scales, so the caller's multiply folds away.""" +def kv_row_scale(ptrs, mask, FMT: tl.constexpr, F16: tl.constexpr = False): + """Row scales of a tile; all ones without scales, so the caller's multiply folds away. ``F16`` pairs with ``_kv_tile_gfx11_f16``.""" if FMT == "none": scale = tl.full(mask.shape, 1.0, tl.float32) else: scale = tl.load(ptrs, mask=mask, other=0.0) + if F16: + scale = scale * 256.0 return scale diff --git a/tests/kernels/test_triton_attention.py b/tests/kernels/test_triton_attention.py index 679efce9c5..eb1d2e0847 100644 --- a/tests/kernels/test_triton_attention.py +++ b/tests/kernels/test_triton_attention.py @@ -146,6 +146,18 @@ def _quantized_pool(fmt_name: str, k, v, slots, capacity: int, num_kv_heads: int return k_cache, v_cache, k_scale, v_scale +def _decode_kv(fmt_name: str | None, k_cache: torch.Tensor, v_cache: torch.Tensor): + """The caches a decode test passes, the values its reference reads, and the kernel's KV arguments.""" + if fmt_name is None: + return k_cache, v_cache, k_cache, v_cache, {} + total, heads, head_dim = k_cache.shape + slots = torch.arange(total, device=k_cache.device, dtype=torch.int32) + k_codes, v_codes, k_scale, v_scale = _quantized_pool( + fmt_name, k_cache.view(total, -1), v_cache.view(total, -1), slots, total, heads, head_dim + ) + kv_args = {"kv_format": KV_FORMATS[fmt_name], "k_scale": k_scale, "v_scale": v_scale} + return k_codes, v_codes, _dequantize(fmt_name, k_codes, k_scale), _dequantize(fmt_name, v_codes, v_scale), kv_args + def _attend(path: str, q, k_cache, v_cache, indices, kv_args: dict, k_extend=None, v_extend=None): from freetoken.kernel.triton.attention import ( decode_paged_attention, @@ -264,16 +276,16 @@ def test_quantized_kv_attention_matches_dequantized_reference(fmt_name: str, pat @pytest.mark.skipif(not torch.cuda.is_available() or torch.version.hip is None, reason="needs ROCm") -@pytest.mark.parametrize("transpose", [False, True]) -def test_rdna4_kv_decode_preserves_every_finite_fp8_code(transpose: bool): +@pytest.mark.parametrize(("arch", "transpose"), [("gfx1201", False), ("gfx1201", True), ("gfx11", False)]) +def test_rocm_kv_decode_preserves_every_finite_fp8_code(arch: str, transpose: bool): import triton import triton.language as tl - from freetoken.kernel.triton.kv_rows import kv_tile_rows + from freetoken.kernel.triton.kv_rows import _kv_tile_gfx11_f16, kv_tile_rows from freetoken.utils.arch import get_rocm_gfx_arch - if get_rocm_gfx_arch() != "gfx1201": - pytest.skip("packed KV conversion requires gfx1201") + if not (get_rocm_gfx_arch() or "").startswith(arch): + pytest.skip(f"this fp8 KV reader requires {arch}") @triton.jit def decode_codes(x, y, TRANSPOSE: tl.constexpr): @@ -284,10 +296,21 @@ def decode_codes(x, y, TRANSPOSE: tl.constexpr): values = tl.trans(values) tl.store(y + rows[:, None] * 128 + tl.arange(0, 128)[None, :], values) + @triton.jit + def decode_codes_f16(x, y): + offs = tl.arange(0, 64)[:, None] * 128 + tl.arange(0, 128)[None, :] + tl.store(y + offs, _kv_tile_gfx11_f16(x + offs, tl.full((64, 128), True, tl.int1))) + codes = torch.arange(256, dtype=torch.uint8).repeat(32) - expected = codes.view(torch.float8_e4m3fn).bfloat16().cuda() - actual = torch.empty_like(expected) - decode_codes[(1,)](codes.cuda(), actual, transpose, num_warps=4) + if arch == "gfx1201": + expected = codes.view(torch.float8_e4m3fn).bfloat16().cuda() + actual = torch.empty_like(expected) + decode_codes[(1,)](codes.cuda(), actual, transpose, num_warps=4) + else: + # value / 256 is exact in fp16, E4M3 subnormals included + expected = (codes.view(torch.float8_e4m3fn).float() / 256).half().cuda() + actual = torch.empty_like(expected) + decode_codes_f16[(1,)](codes.cuda(), actual, num_warps=4) finite = expected.isfinite() # Integer comparison also checks signed zero and the byte order in each word. assert torch.equal(actual.view(torch.int16)[finite], expected.view(torch.int16)[finite]) @@ -707,6 +730,7 @@ def test_decode_triton_attention_with_sinks_matches_reference(): @pytest.mark.skipif(not torch.cuda.is_available(), reason="Triton attention needs CUDA") +@pytest.mark.parametrize("fmt_name", [None, *KV_QUANT_FORMATS]) @pytest.mark.parametrize( ("seq_lens", "num_kv_heads", "sliding_window", "scratch_splits", "use_sinks"), [ @@ -721,6 +745,7 @@ def test_decode_triton_attention_splits_long_requests( sliding_window: int | None, scratch_splits: int, use_sinks: bool, + fmt_name: str | None, ): """Requests of many splits next to short ones, a scratch smaller than the split cap, and windows that span several splits.""" from freetoken.kernel.triton.attention import decode_paged_attention @@ -734,6 +759,7 @@ def test_decode_triton_attention_splits_long_requests( q = torch.randn(batch, num_q_heads, head_dim, device=device, dtype=torch.bfloat16) k_cache = torch.randn(total_kv, num_kv_heads, head_dim, device=device, dtype=torch.bfloat16) v_cache = torch.randn(total_kv, num_kv_heads, head_dim, device=device, dtype=torch.bfloat16) + k_cache, v_cache, k_ref, v_ref, kv_args = _decode_kv(fmt_name, k_cache, v_cache) indptr = torch.tensor([0, *seq_lens], dtype=torch.int32, device=device).cumsum(0).to(torch.int32) indices = torch.randperm(total_kv, device=device).to(torch.int32) q_positions = torch.tensor([n - 1 for n in seq_lens], dtype=torch.int64, device=device) @@ -746,15 +772,16 @@ def test_decode_triton_attention_splits_long_requests( actual = decode_paged_attention( q, k_cache, v_cache, indptr, indices, q_positions, attn_logits, attn_lse, sm_scale, - sliding_window=sliding_window, sinks=sinks, + sliding_window=sliding_window, sinks=sinks, **kv_args, ) expected = _reference_paged_attention( - q, k_cache, v_cache, indptr, indices, q_to_req, q_positions, sm_scale, sliding_window, sinks=sinks, + q, k_ref, v_ref, indptr, indices, q_to_req, q_positions, sm_scale, sliding_window, sinks=sinks, ) torch.testing.assert_close(actual.float(), expected.float(), atol=2e-2, rtol=2e-2) @pytest.mark.skipif(not torch.cuda.is_available(), reason="Triton attention needs CUDA") +@pytest.mark.parametrize("fmt_name", [None, *KV_QUANT_FORMATS]) @pytest.mark.parametrize( ("num_q_heads", "num_kv_heads", "head_dim", "cached_lens", "q_lens", "sliding_window", "scratch_splits", "use_sinks"), [ @@ -774,6 +801,7 @@ def test_decode_triton_attention_multi_row_matches_reference( sliding_window: int | None, scratch_splits: int, use_sinks: bool, + fmt_name: str | None, ): """Several causal query rows per request: rows that see no key of a split (1017 + 8 keys leave one key in the last split), a window shorter than the rows, short requests next to many-split ones, and fewer heads per program at head_dim 512.""" from freetoken.kernel.triton.attention import decode_paged_attention @@ -786,6 +814,7 @@ def test_decode_triton_attention_multi_row_matches_reference( q = torch.randn(num_rows, num_q_heads, head_dim, device=device, dtype=torch.bfloat16) k_cache = torch.randn(total_kv, num_kv_heads, head_dim, device=device, dtype=torch.bfloat16) v_cache = torch.randn(total_kv, num_kv_heads, head_dim, device=device, dtype=torch.bfloat16) + k_cache, v_cache, k_ref, v_ref, kv_args = _decode_kv(fmt_name, k_cache, v_cache) indptr = torch.tensor([0, *kv_lens], device=device).cumsum(0).to(torch.int32) qo_indptr = torch.tensor([0, *q_lens], device=device).cumsum(0).to(torch.int32) indices = torch.randperm(total_kv, device=device).to(torch.int32) @@ -798,10 +827,10 @@ def test_decode_triton_attention_multi_row_matches_reference( actual = decode_paged_attention( q, k_cache, v_cache, indptr, indices, q_positions, attn_logits, attn_lse, sm_scale, - sliding_window=sliding_window, sinks=sinks, qo_indptr=qo_indptr, max_q_len=max(q_lens), + sliding_window=sliding_window, sinks=sinks, qo_indptr=qo_indptr, max_q_len=max(q_lens), **kv_args, ) expected = _reference_paged_attention( - q, k_cache, v_cache, indptr, indices, q_to_req, q_positions, sm_scale, sliding_window, sinks=sinks, + q, k_ref, v_ref, indptr, indices, q_to_req, q_positions, sm_scale, sliding_window, sinks=sinks, ) assert torch.isfinite(actual).all() torch.testing.assert_close(actual.float(), expected.float(), atol=2e-2, rtol=2e-2) @@ -1186,7 +1215,7 @@ def v_cache(self, layer_id): def test_triton_backend_replay_metadata_uses_capture_buffers(monkeypatch): from freetoken.attention.triton import TritonAttentionBackend, TritonMetadata - class FakeKVCache: + class FakeKVCache(_PlainKVStorage): def __init__(self, device: torch.device): self.device = device