Repository navigation
[rl] per-step session-KV metrics (7/7) - #5338
Closed
felipemello1 wants to merge 20 commits into
Closed
felipemello1 wants to merge 20 commits into
felipemello1 wants to merge 20 commits into
Conversation
…urce, CPU tier
Every hold, eviction and CPU-offload signal was stdout-only, and vLLM's kv_offload_cpu_cache_usage_perc
counts only chunks pinned by in-flight transfers, so it reads ~0 on a full CPU tier.
The controller logs, at each step's metrics_log, generator/session_kv/<name>:
- per generator (its rank-0 engine), as mean and max over generators:
- levels: gpu_used_fraction, held_sessions, held_blocks (distinct), cpu_used_fraction (chunks that
hold KV over the tier's chunks);
- counts this step: evicted_sessions, stall_evicted_sessions, cpu_store_bytes, and a session's later
turns' prompt tokens split into gpu_hit_prefix_tokens, cpu_hit_prefix_tokens and
recomputed_prefix_tokens (tokens its previous request computed that this turn computed again);
- from the router, as one sum: repinned_sessions, sessions moved to another generator, whose turn
re-prefills there.
SessionKVHolder keeps plain-int running totals on the engine thread; get_session_kv_metrics reads them
and logs the change since its last call. CPU store bytes come from a vLLM StatLoggerBase on rank 0.
The "Session KV at step N" log line is gone.
added 19 commits
October 13, 2026 00:32
# Conflicts: # tests/rl/unit_tests/cpu/test_session_kv_holder.py # torchtitan/rl/generator.py # torchtitan/rl/session_kv_holder.py
…fload Both CPU-tier metrics now come from CPUKVOffload: used_fraction() and store_bytes, which its stat_logger factory adds up on rank 0's engine. KVOffloadStoreBytesStatLogger leaves observability/vllm.py and the generator drops its _kv_offload_store_bytes attribute.
# Conflicts: # tests/rl/unit_tests/cpu/test_inter_generator_router.py # torchtitan/rl/actors/monarch/generator.py # torchtitan/rl/routing/inter_generator.py
…ep) into 7/7 # Conflicts: # torchtitan/rl/generator/generator.py # torchtitan/rl/generator/vllm/session_kv_holder.py
# Conflicts: # torchtitan/rl/generator/vllm/session_kv_holder.py
# Conflicts: # torchtitan/rl/generator/vllm/session_kv_holder.py
The base PR now carries main's split of the generator (service, engine loop, engine) and of the router (plain class plus actor endpoints). The metrics move with it: - VLLMEngine.session_kv_metrics holds the levels and counts and their totals; rank 0 adds the CPU offload stat logger. - EngineLoop.session_kv_metrics (rank 0) -> Generator.get_session_kv_metrics -> the actor endpoint; InterGeneratorRouter.get_session_kv_metrics plus its actor endpoint. - The per-step "Session KV" log line goes, as before; the metrics replace it.
…s run (7/7) - VLLMEngine.log_stats stays: it is the only implementer of the engine loop's log hook, so removing it would leave the hook unused. - GenerationEngine.session_kv_metrics runs on the actor thread, as log_stats does: one docstring line says to read only single values. - Generator.get_session_kv_metrics: rank 0's metrics; [] on other ranks.
Contributor
Author
|
Reply from claude: superseded by #5919, which deletes the session KV holder and evicts an ended rollout's KV from vLLM's prefix cache instead. Closing. |
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.
TLDR: every hold and CPU-offload signal of the session-KV stack was stdout-only. This logs 11 per-step metrics: 10 per generator (mean and max over generators) and the router's re-pins. The key one,
recomputed_prefix_tokens, counts the tokens a session's earlier turns computed that its next turn computed again: on a churned Qwen3.5-4B run it is 0 per round with an 8 GiB CPU tier and 67-76k without it.Problem
session_kv_holder(5/5) and itscpu_kv_offload(6/6) report only through vLLM's periodic stdout lines and one "Session KV at step N" log.kv_offload_cpu_cache_usage_percis(allocated - free - evictable) / num_chunks: it counts only chunks pinned by in-flight stores and loads, so it reads ~0 on a full CPU tier.Solution
VLLMSessionKVHolderkeeps plain-int running totals on the engine thread: held sessions, distinct held blocks (GRPO siblings hold their shared prompt blocks once), evictions and their stall subset.reusable 64 tokens = GPU hit 48 + CPU hit 0 + recomputed 16.CPUKVOffload(6/6) reports the CPU tier's fill (used_fraction()), and itsstat_logger(a vLLM stat logger on rank 0) sums the CPU store bytes vLLM reports each engine step.VLLMGenerator.get_session_kv_metricslogs levels as they are and counts since its last call. The router gathers every generator's rank 0 and addsrepinned_sessions; the controller logs them at each step'smetrics_log.Metrics (
generator/session_kv/<name>)cpu_used_fractionis ours: chunks that hold KV (stored or being stored) over the tier's chunks.Results
cpu_store_bytessums to 59,794,391,040, the connector's store bytes as counted by the replay script;evicted_sessionssums to the holder's total (315).You may ask:
generator/num_preemptionsandgenerator/queue_time_msalready log them per request.cpu_hit_prefix_tokenscounts the same event, in tokens.sync_log_step? That one sets the step on every rank; this reads rank 0 when the step's metrics are logged.NOTE:
recomputed_prefix_tokens;repinned_sessionscounts those moves.Request.prefill_stats(kept fromtrack: vLLM detaches it at the first output), the offload connector's stats payload,LRUCachePolicy.chunks.Test plan
pytest tests/rl/unit_tests/cpu: 514 passed, 5 skipped.test_session_kv_holder.py: a later turn's prefix split on vLLM's real KV cache manager (GPU 48 / recomputed 16; with a CPU hit, 16 / 0); siblings' shared blocks count once inheld_blocks; stall evictions;cpu_used_fraction0.25 where vLLM's gauge reads 0.test_generator.py: levels as they are, counts since the last call, each feature's keys only when it is on.test_cpu_kv_offload.py: the stat logger sums each step's store bytes.test_inter_generator_router.py: the router gathers every generator and logs re-pins once.