Repository navigation
perf(inference): persist decode scheduling metadata - #643
Merged
Merged
Conversation
7 of 13 tasks
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.
What does this PR do?
Ordinary one-token decode currently reads request IDs and lengths back to the host and recreates block/slot tensors each iteration. Keep scheduler-owned logical lengths and persistent device tables, updating mappings on admission, compaction or KV-page growth. Skip the empty cache-invalidation reduction for adapters without cache invalidation.
EOS uses a bounded pinned flag transfer and an explicit CUDA event. CPU length bookkeeping runs before waiting, and the event guards buffer reuse. Shared CPU cancellation flags are checked using cached CPU request IDs. Completion delivery, stop/length handling, recurrent-slot reset and graph scratch-row handling retain their existing semantics. Speculative decode and NPU retain their legacy metadata path.
Related issue
Fixes #633
Type of change
How was it tested?
Baseline: latest main
0de39d1b8e507110b6b622d373f71d06729004b5(includes #635). Compare its isolated inference module against this change with the same resident model, KV cache and graph buckets. The main matrix scripts token choice to keep workloads identical; model forward and TP-selected-token logprob computation remain real. It bypasses greedy argmax, so production greedy measurements are reported separately. GPU: H20-3e, BF16, PyTorch2.8.0a0+34c6371d24.nv25.08, CUDA 13. Prompt lengths 254–257, 32 output tokens; batch sizes 1/8/64. Graph buckets include 1/2/4/8/64; compilation disabled. Each case warms baseline and candidate once, then alternates ordering for 3 measurements per variant (5 for the seeded 4-layer Qwen3 model); tables show medians from rank 0.atol=rtol=1e-5; observed differences are exactly zero.PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 ARENO_CHECK_TOKEN_IDS=1 python -m pytest -q tests/ examples/agentic/pi/ -k cpu. Local macOS C++ compilation required replacing a stale SDK path in the compiler invocation; repository sources were unchanged for this environment fix.pre-commit run --all-files --hook-stage manualpassed.Measured CUDA Graph performance
steadyignores EOS and reaches the fixed length limit.tail_refillruns twice the active capacity with output lengths 4/8/16/32, EOS, refill, compaction and a shrinking tail. TPOT is decode-window wall time / actual decode iterations; the window includes interleaved refill and final delivery.host wallis time outside model/sample enqueue, including completion waits and delivery, not pure CPU compute. Throughput includes prefill and delivery. All arrows are main → candidate; total speedup is main wall time / candidate wall time.Real greedy sampling, Ling TP4, CUDA Graph, 32 output tokens, batches 1/8/64, 3 repeats per variant (the normal sharded argmax is enabled):
These greedy runs also have exactly matching outputs, finish reasons and logprobs (mean/max abs diff = 0).
Additional Ling TP4 batch-8 scenarios, 3 repeats per variant:
The improvement is workload-dependent: Ling graph steady decode improves, while the TP4 batch-8 tail has a 0.980× total speedup. Cancellation/live-refill eager cases have 0.958×/0.975× speedup; these regressions are included above. Eager matrix speedups range 0.972×–1.131×. Peak allocated GPU memory on rank 0, graph batch-64 steady (all graph buckets preallocated): Qwen3 tiny / TP1: 344.730 → 344.731 MiB (Δ +1024 bytes); Ling / TP1: 51784.167 → 51784.168 MiB (Δ +1024 bytes); Ling / TP4: 13507.204 → 13507.205 MiB (Δ +1024 bytes).
Bounded Nsight evidence
Nsight Systems 2025.4.1, Qwen3 TP1, graph batch 8, 64 output tokens; capture starts after both variants' warmup/parity checks. In the interior metadata window of a 63-decode-iteration steady trace:
cudaStreamSynchronize: 496 → 2 in that window.Reproduction (with an editable install of the candidate checkout and a local model):
Checklist