Repository navigation
perf(attention): copy triton metadata without blocking the host - #726
Merged
Merged
Conversation
pretor
pushed a commit
to pretor/FreeToken
that referenced
this pull request
Oct 17, 2026
…r RTX), PR FlashML-org#729 (split decode attention), PR FlashML-org#726, PR FlashML-org#700 and GGUF updates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TritonAttentionBackend.prepare_metadatabuildsindptr,prefix_lensand, for an extend with a cached prefix,cu_seqlens_qwithtorch.tensor(list, device=cuda). That copy blocks the host: torch issuescudaMemcpyAsyncand thencudaStreamSynchronize. In the overlap scheduler (Scheduler.overlap_loop), the scheduler stream already waits on the engine stream before the next batch is prepared, so this sync waits for the previous forward to finish. The host then builds and launches the next batch while the GPU sits idle.This PR builds the three tensors in pinned host memory and copies them with
non_blocking=True, as the fa and trtllm backends already do. Batch-1 decode gets 0.3 to 0.35 ms per token faster on Gemma 4, gpt-oss and Qwen3.6 with--attention-backend triton. The same code runs for every model on the triton backend, which includes all sliding-window models (no other backend serves them) and every model on ROCm.Changes
attention/triton.py,TritonAttentionBackend.prepare_metadata: the three host lists become pinned int32 tensors (cumsum on the host) copied with.to(device, non_blocking=True). Memory is pinned only on CUDA devices, so the CPU-only tests still run.Tested on
NVIDIA H100 80GB HBM3, Intel Xeon Platinum 8480+, driver 580.95.05, CUDA 13.0, torch 2.14.1+cu130, Triton 3.8.0.
mainis 9b68e00, the base of this branch.End-to-end results
Models: nvidia/Gemma-4-26B-A4B-NVFP4, openai/gpt-oss-20b and nvidia/Qwen3.6-35B-A3B-NVFP4 with
--attention-backend triton.Long prompts: one streamed
/v1/chat/completionsrequest at a time, a prompt of about 1k to 192k tokens (source code, cut with each model's tokenizer), 256 output tokens withignore_eos, temperature 1.0, top_p 0.95, top_k 64. Decode tok/s is (output tokens - 1) / (last token time - first token time). Median of 3 runs. TTFT is unchanged.For reference, Qwen3.6 with the flashinfer backend decodes at 244.9 tok/s at 1k on the same machine. At long context the triton backend is still far behind it (49.0 vs 183.2 tok/s at 192k). That gap is in the decode kernel, which splits every request's keys into a fixed 8 parts, and a separate PR fixes it.
AIME25 problem 1: the model's recommended sampling (Gemma 4: temperature 1.0, top_p 0.95, top_k 64; gpt-oss: temperature 1.0, top_p 1.0, no top_k), natural end, 3 runs per side.
Other checks
PYTHONPATH=python pytest tests/kernels/test_triton_attention.py: 38 passed; withCUDA_VISIBLE_DEVICES=, 11 passed and 27 skipped, the same as main.