Commit 36a7037
[ROCm][DSv4] Zero prefill-attn KV workspace before gather
``_forward_prefill_attn`` allocates the prefill KV buffer via
``current_workspace_manager().get_simultaneous`` which returns a
``torch.empty`` view -- uninitialized memory shared across requests
and across earlier layers in the same forward pass.
For each chunk row only the compressed-K prefix (rows
[0, seq_len / compress_ratio)) and the SWA window (rows
[N, N + gather_lens)) get written by ``dequantize_and_gather_k_cache``.
The rest of the M dimension stays at whatever bytes the workspace held
last. ``flash_mla_sparse_fwd`` then reads ``kv.view(-1, 1, head_dim)``
using ``combined_indices`` that can address those holes when a query
token's effective context is shorter than M, so the attention output
becomes data-dependent on prior workspace residents.
Concrete symptom: on MI300X with FNUZ FP8 + cudagraphs, the same
temperature=0 deterministic prompt produces 10 distinct first tokens
across 10 back-to-back ``/v1/completions`` calls. Disabling AITER MoE
and MLA did not help; the variance comes from this DSv4-specific
workspace read.
Zero ``kv`` once after ``get_simultaneous`` so any unread slot deterministically
contributes zero. The cost is one bf16 fill of
``PREFILL_CHUNK_SIZE * M * head_dim`` bytes per attention layer call,
which is dwarfed by the FP8 dequant + sparse FlashMLA themselves.
Signed-off-by: Markus Hartikainen <markus.hartikainen@amd.com>
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent b605d0d commit 36a7037
1 file changed
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
961 | 961 | | |
962 | 962 | | |
963 | 963 | | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
964 | 976 | | |
965 | 977 | | |
966 | 978 | | |
| |||
0 commit comments