Skip to content

Prefix caching | Coordinator scheduling. - #3665

Merged
lmcafee-nvidia merged 9 commits into
NVIDIA:mainfrom
lmcafee-nvidia:prefix-caching-coordinator
Mar 3, 2026
Merged

lmcafee-nvidia merged 9 commits into
NVIDIA:mainfrom
lmcafee-nvidia:prefix-caching-coordinator

Conversation

@lmcafee-nvidia

@lmcafee-nvidia lmcafee-nvidia commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The DP inference coordinator now computes block hashes from prompt tokens and routes each request to the rank with the longest consecutive prefix match, with recency tie-breaking. Falls back to round-robin when prefix caching is disabled or no rank has matching hashes.
  • Adds block_size_tokens and enable_prefix_caching parameters to DataParallelInferenceCoordinator, with per-rank shadow state (rank_cached_hashes, rank_hash_timestamps) for tracking which hashes each rank owns.
  • Engine reports INCREMENT_STALENESS header to coordinator for bookkeeping.
  • Includes 509-line test suite (test_dynamic_prefix_caching_coordinator.py) covering hash computation, affinity routing, recency tie-breaking, round-robin fallback, and multi-rank scenarios.

Test plan

  • Run test_dynamic_prefix_caching_coordinator.py unit tests
  • Run test_dynamic_prefix_caching.py to verify no regressions in base prefix caching

🤖 Generated with Claude Code

@lmcafee-nvidia
lmcafee-nvidia requested review from a team as code owners March 3, 2026 02:32
@copy-pr-bot

copy-pr-bot Bot commented Mar 3, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@svcnvidia-nemo-ci
svcnvidia-nemo-ci requested a review from a team March 3, 2026 02:32
@lmcafee-nvidia lmcafee-nvidia changed the title Inference | Prefix-cache-aware DP coordinator routing Prefix caching | Coordinator. Mar 3, 2026
@lmcafee-nvidia lmcafee-nvidia changed the title Prefix caching | Coordinator. Prefix caching | Coordinator scheduling. Mar 3, 2026
@lmcafee-nvidia
lmcafee-nvidia marked this pull request as draft March 3, 2026 02:53
@lmcafee-nvidia lmcafee-nvidia self-assigned this Mar 3, 2026
lmcafee-nvidia and others added 2 commits March 2, 2026 19:59
The DP inference coordinator now computes block hashes from prompt tokens
and routes each request to the rank with the longest consecutive prefix
match, with recency tie-breaking. Falls back to round-robin when prefix
caching is disabled or no rank has matching hashes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…routing.

Adds a `PrefixCachingCoordinatorPolicy` enum with `LONGEST_PREFIX` (default)
and `ROUND_ROBIN` options, wired through CLI, InferenceConfig, context, engine,
and coordinator. When `ROUND_ROBIN` is selected, the coordinator skips prefix
matching and cycles through ranks, enabling baseline benchmarking.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lmcafee-nvidia
lmcafee-nvidia force-pushed the prefix-caching-coordinator branch from 1223fad to 0312044 Compare March 3, 2026 04:00
Thread a --coordinator-schedule-output-path CLI arg through the coordinator
entry script, dynamic engine, and coordinator process. The coordinator records
each routing decision (request_id, rank_index, num_hashes) and writes a JSON
file at shutdown, enabling verification that LONGEST_PREFIX consolidates
duplicate prompts on the same rank while ROUND_ROBIN spreads them.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lmcafee-nvidia
lmcafee-nvidia requested a review from kvareddy March 3, 2026 15:40
@lmcafee-nvidia
lmcafee-nvidia marked this pull request as ready for review March 3, 2026 15:40
@lmcafee-nvidia
lmcafee-nvidia force-pushed the prefix-caching-coordinator branch 3 times, most recently from faa5027 to 84679e0 Compare March 3, 2026 17:39
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lmcafee-nvidia
lmcafee-nvidia force-pushed the prefix-caching-coordinator branch from 84679e0 to ab3c6ca Compare March 3, 2026 17:54
lmcafee-nvidia and others added 5 commits March 3, 2026 10:54
Consolidate rank_cached_hashes and rank_hash_timestamps into a single
hash_to_rank_info dict (hash → {rank → timestamp}), and use a reverse
scan over parent-chained hashes for O(hashes) routing instead of
O(ranks × hashes).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…o start().

Ensures both get_best_data_parallel_rank and _update_rank_hashes see the
same truncated request_hashes, so the coordinator only stores the first
block hash rather than all hashes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lmcafee-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test eefe32f

@svcnvidia-nemo-ci svcnvidia-nemo-ci added this to the Core 0.16 milestone Mar 3, 2026
@lmcafee-nvidia
lmcafee-nvidia enabled auto-merge March 3, 2026 19:28
@lmcafee-nvidia
lmcafee-nvidia added this pull request to the merge queue Mar 3, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/22645872157

Merged via the queue into NVIDIA:main with commit 9b18de4 Mar 3, 2026
78 of 89 checks passed
@lmcafee-nvidia
lmcafee-nvidia deleted the prefix-caching-coordinator branch March 3, 2026 23:37
ilml added a commit to ilml/Megatron-LM that referenced this pull request Mar 20, 2026
…VIDIA#3665)

New files:
  - tests/unit_tests/inference/test_dynamic_prefix_caching_coordinator.py
yangbofun pushed a commit to xlm-research/Megatron-LM that referenced this pull request May 22, 2026
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
terminator123 pushed a commit to 021ai/Megatron-LM that referenced this pull request Aug 3, 2026
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

This branch was previously deployed

1 inactive deployment
test — eefe32ff Deployed Mar 3, 2026 by copy-pr-bot[bot] via cicd-wait-in-queue #9051
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants