[3/N] HiSparse: host-resident sparse-MLA decode hot-buffering (#53781)

Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Signed-off-by: Lucas Wilkinson <lwilkinson@neuralmagic.com>
Signed-off-by: Matthew Bonanni <matthew@neuralmagic.com>
Signed-off-by: Nicolò Lucchesi <nicolo.lucchesi@mistral.ai>
Co-authored-by: OpenAI Codex <codex@openai.com>
Co-authored-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: Lucas Wilkinson <lwilkinson@neuralmagic.com>
Co-authored-by: Nicolò Lucchesi <nicolo.lucchesi@mistral.ai>
Co-authored-by: OpenAI Codex <noreply@openai.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Lucas Wilkinson <LucasWilkinson@users.noreply.github.com>
This commit is contained in:
Matthew Bonanni
2026-09-12 00:36:47 -04:00
committed by GitHub
co-authored by OpenAI Codex Lucas Wilkinson Lucas Wilkinson Nicolò Lucchesi OpenAI Codex Claude Opus 5 Lucas Wilkinson
parent 120ec4ebd2
commit d43bb2f37f
124 changed files with 14262 additions and 906 deletions
+52 -1
View File
@@ -661,6 +661,54 @@ void concat_and_cache_mla_grouped(
std::optional<torch::stable::Tensor> kv_scales,
const std::string& kv_cache_dtype);
#ifndef USE_ROCM
// HiSparse kernels use raw PTX in the row copy; CUDA-only.
void hisparse_resolve_residency(
torch::stable::Tensor const& host_cache, torch::stable::Tensor& hot_cache,
torch::stable::Tensor const& hot_block_table,
torch::stable::Tensor const& global_indices,
torch::stable::Tensor& hot_indices,
torch::stable::Tensor& device_global_indices,
torch::stable::Tensor& lru_slots,
std::optional<torch::stable::Tensor> const& request_state_indices,
int64_t region_stride,
std::optional<torch::stable::Tensor> const& miss_mask,
std::optional<torch::stable::Tensor> const& attention_indices,
int64_t attention_block_stride,
std::optional<torch::stable::Tensor> const& request_ids,
std::optional<torch::stable::Tensor> const& source_block_table,
int64_t source_block_size,
std::optional<torch::stable::Tensor> const& resolved_global_indices,
std::optional<torch::stable::Tensor> const& valid_counts,
std::optional<torch::stable::Tensor> const& swap_host_physical_rows,
std::optional<torch::stable::Tensor> const& swap_device_physical_rows,
std::optional<torch::stable::Tensor> const& swap_counts,
std::optional<torch::stable::Tensor> const& resident_block_table,
int64_t resident_block_size, int64_t resident_null_block);
void hisparse_invalidate_written_slots(
torch::stable::Tensor& device_global_indices,
torch::stable::Tensor const& request_state_indices,
torch::stable::Tensor const& req_id_per_token,
torch::stable::Tensor const& written_slots);
void hisparse_gather_plan(
torch::stable::Tensor const& host_cache, torch::stable::Tensor& hot_cache,
torch::stable::Tensor const& global_indices,
torch::stable::Tensor const& hot_indices,
torch::stable::Tensor const& miss_mask,
std::optional<torch::stable::Tensor> const& request_state_indices,
std::optional<torch::stable::Tensor> const& attention_indices,
int64_t attention_block_stride);
void hisparse_gather_compact(torch::stable::Tensor const& host_cache,
torch::stable::Tensor& hot_cache,
torch::stable::Tensor const& miss_global_indices,
torch::stable::Tensor const& miss_hot_indices,
torch::stable::Tensor const& miss_counts);
#endif // !USE_ROCM
// NOTE: k_pe and kv_c order is flipped compared to concat_and_cache_mla
void concat_and_cache_mla_rope_fused(
torch::stable::Tensor& positions, torch::stable::Tensor& q_pe,
@@ -704,7 +752,10 @@ void cp_gather_and_upconvert_fp8_kv_cache(
torch::stable::Tensor const& block_table, // [BATCH, BLOCK_INDICES]
torch::stable::Tensor const& workspace_starts, // [BATCH]
int64_t batch_size,
std::optional<torch::stable::Tensor> seq_starts = std::nullopt);
std::optional<torch::stable::Tensor> seq_starts = std::nullopt,
std::optional<torch::stable::Tensor> host_cache = std::nullopt,
std::optional<torch::stable::Tensor> host_row_ids = std::nullopt,
std::optional<torch::stable::Tensor> device_row_ids = std::nullopt);
// Gather and upconvert an nvfp4_ds_mla KV cache to a BF16 workspace
void cp_gather_and_upconvert_nvfp4_kv_cache(