|
4 | 4 | import torch |
5 | 5 |
|
6 | 6 |
|
| 7 | +def test_deepseek_v4_c128a_adaptive_width_has_capture_stable_stride(): |
| 8 | + from vllm.models.deepseek_v4.sparse_mla import build_c128a_topk_metadata |
| 9 | + |
| 10 | + device = torch.device("cuda") |
| 11 | + capacity_width = 512 |
| 12 | + global_decode_buffer = torch.empty( |
| 13 | + (2, capacity_width), dtype=torch.int32, device=device |
| 14 | + ) |
| 15 | + prefill_buffer = torch.empty_like(global_decode_buffer) |
| 16 | + kwargs = dict( |
| 17 | + positions=torch.tensor([255, 511, 383, 639], device=device), |
| 18 | + compress_ratio=128, |
| 19 | + num_decode_tokens=2, |
| 20 | + token_to_req_indices=torch.tensor( |
| 21 | + [0, 1, 0, 1], dtype=torch.int32, device=device |
| 22 | + ), |
| 23 | + block_table=torch.tensor([[3], [5]], dtype=torch.int32, device=device), |
| 24 | + block_size=capacity_width, |
| 25 | + slot_mapping=torch.arange(4, dtype=torch.int64, device=device), |
| 26 | + global_decode_buffer=global_decode_buffer, |
| 27 | + decode_lens_buffer=torch.empty(2, dtype=torch.int32, device=device), |
| 28 | + prefill_buffer=prefill_buffer, |
| 29 | + ) |
| 30 | + captured_decode, _, captured_prefill = build_c128a_topk_metadata( |
| 31 | + max_compressed_tokens=256, |
| 32 | + **kwargs, |
| 33 | + ) |
| 34 | + assert captured_decode.shape == captured_prefill.shape == (2, 256) |
| 35 | + assert captured_decode.stride(0) == captured_prefill.stride(0) == capacity_width |
| 36 | + |
| 37 | + captured_rows = torch.empty((4, 4), dtype=torch.int32, device=device) |
| 38 | + captured_rows[:2].copy_(captured_decode[:, :4]) |
| 39 | + captured_rows[2:].copy_(captured_prefill[:, :4]) |
| 40 | + torch.accelerator.synchronize() |
| 41 | + graph = torch.cuda.CUDAGraph() |
| 42 | + with torch.cuda.graph(graph): |
| 43 | + captured_rows[:2].copy_(captured_decode[:, :4]) |
| 44 | + captured_rows[2:].copy_(captured_prefill[:, :4]) |
| 45 | + |
| 46 | + global_decode_buffer.fill_(-99) |
| 47 | + prefill_buffer.fill_(-99) |
| 48 | + build_c128a_topk_metadata( |
| 49 | + max_compressed_tokens=128, |
| 50 | + **kwargs, |
| 51 | + ) |
| 52 | + graph.replay() |
| 53 | + |
| 54 | + assert captured_rows.cpu().tolist() == [ |
| 55 | + [1536, 1537, -1, -1], |
| 56 | + [2560, 2561, 2562, 2563], |
| 57 | + [0, 1, 2, -1], |
| 58 | + [0, 1, 2, 3], |
| 59 | + ] |
| 60 | + assert torch.all(global_decode_buffer[:, 128:] == -99) |
| 61 | + assert torch.all(prefill_buffer[:, 128:] == -99) |
| 62 | + |
| 63 | + |
7 | 64 | def test_sparse_flashmla_metadata_smoke(): |
8 | 65 | import vllm.v1.attention.ops.flashmla as fm |
9 | 66 |
|
|
0 commit comments