Avoid TRTLLM prefill output copy (#33306)

This commit is contained in:
Xingyu Liu
2026-08-04 12:54:04 -07:00
committed by GitHub
parent 38dc2d6cf8
commit aa06433709
3 changed files with 44 additions and 0 deletions
@@ -1302,6 +1302,7 @@ class TRTLLMHAAttnBackend(FlashInferAttnBackend):
*,
cu_seqlens_kv,
use_zigzag_page_table=False,
out=None,
):
block_tables = page_table
if use_zigzag_page_table:
@@ -1327,6 +1328,7 @@ class TRTLLMHAAttnBackend(FlashInferAttnBackend):
window_left=layer.sliding_window_size,
sinks=attention_sink,
skip_softmax_threshold_scale_factor=envs.SGLANG_SKIP_SOFTMAX_PREFILL_THRESHOLD_SCALE_FACTOR.get(),
out=out,
out_dtype=self.q_data_type,
)
@@ -1341,12 +1343,16 @@ class TRTLLMHAAttnBackend(FlashInferAttnBackend):
attention_backend=CPAttentionBackendKind.TRTLLM_MHA,
)
else:
out = forward_batch._attn_output
if out is not None:
out = out.view_as(q)
o = _trtllm_context_attn(
q,
self.forward_metadata.cu_seqlens_q,
self.forward_metadata.cache_seqlens_int32,
self.forward_metadata.max_seq_len_q,
cu_seqlens_kv=self.forward_metadata.cu_seqlens_k,
out=out,
)
return o.view(-1, layer.tp_q_head_num * layer.head_dim)
@@ -553,6 +553,9 @@ class ForwardBatch(ForwardBatchDeepSeekMHAMixin):
num_token_non_padded_cpu: int = None
# === Runtime-filled (set during the forward pass / cuda graph / managers; not at construction) ===
# Preallocated piecewise-graph attention output, set by RadixAttention.
_attn_output: Optional[torch.Tensor] = None
# For logits and logprobs post processing
next_token_logits_buffer: torch.Tensor = None
temperature: torch.Tensor = None