Skip to content

feat: add opt-in bounded-hash routing for TP1 and TP2 replicas - #616

Open
chengcuiping wants to merge 5 commits into
InfiniTensor:mainfrom
chengcuiping:feat/bounded-hash-v3-upstream-20261112T030118Z
Open

chengcuiping wants to merge 5 commits into
InfiniTensor:mainfrom
chengcuiping:feat/bounded-hash-v3-upstream-20261112T030118Z

Conversation

@chengcuiping

@chengcuiping chengcuiping commented Nov 12, 2026 •

Copy link
Copy Markdown

Summary

  • Start each complete-model replica with --bounded-hash-backend-key-env INFINILM_REPLICA_KEY and --bounded-hash-cache-policy prefix_lru. Build a cost file on a separate replica from the same deployment, then start the gateway with enabled: true and routing_policy: bounded_hash_v3. A TP1 or TP2 replica runs both prefill and decode. Build, calibration, gateway and request commands
  • Select round_robin to compare placement policies with the same model, prefix LRU, KV budget and in-flight limit. V3 checks every replica's authenticated token contract. RR checks the replica it reserved. Each admitted request sends one generation POST and holds its full KV reservation until completion or cleanup.
  • The ordinary service keeps the native allocator, sampler, graph configuration, mixed batching and chunked prefill. The optional contract, build measurement and cache observer are installed only on a routing backend. TP2 checks both ranks' BF16 model shards and physical KV tensors. NVIDIA and MetaX use explicit device providers. Other supported TP1 deployments supply their hardware identity.

Motivation

Long shared prompts can benefit from cache locality while demand can exceed a hot replica's slots. V3 weighs a reusable prefix against serving cost and the wait for capacity. The same-cache RR control isolates the effect of placement. Both policies reserve the entire prompt and output envelope. The original PR ported the frozen V3 experiment and verified the 98 source-file digests. Its source attribution, vendored hash ring and Apache-2.0 notice are retained. Original V3 source

Type of Change

  • feat — new feature / new model
  • fix — bug fix
  • perf — performance improvement (no behavioral change)
  • refactor — code restructuring without behavior change
  • test — adding or fixing tests only
  • docs — documentation only
  • build / ci — build system or CI configuration
  • chore — tooling, formatting, or other non-code changes
  • Breaking change

Test Results of Involved Models on Supported Platforms (Please attach screenshots)

Final rebased PR head d0a095f345fe0747ffa12fed80615a2a1809aa67 on upstream 3a630d18. We rebuilt the final checkout and ran the following checks on eight NVIDIA A100-SXM4-80GB GPUs. Build, cost calibration, B/D startup and request commands · Regression and workload commands

Scope Result on this head
Build and runtime identity Built the pinned SDK and SM80 extension in a clean recursive checkout and repeated the build at the final SHA. The running Python extension, LM runtime, InfiniRT, InfiniOps, InfiniCCL, FlashInfer sampler and TVM-FFI library all mapped from that checkout.
Host regressions 267 tests passed across seven modules, including test/runtime/test_chunked_prefill_sched.py and test/service/test_agent_protocol.py. A separate CPython 3.10.12 run passed 29 routing, cancellation, cache and TP-layout tests. Nine device-selection tests passed. Native topology passed 540 mappings and 18,576 ranges. The repository format check passed.
Qwen3-32B BF16, TP2 All 8,192 prompt IDs matched. Each call produced 32 IDs. Cold, warm and restarted-cold cache hits were 0 → 7,936 → 0. The restarted process had a fresh instance ID and reproduced the previous request's generated IDs. The first prefill wrote the K page on each rank. Each rank owned 4 GiB of KV.
Independent calibration A disposable TP2 replica served 55 calibration requests with 1,120 synchronized forwards, 16 prefill samples and decode batches of 1, 2 and 3. All four new B replicas and all four new D replicas matched the calibrated identity.
Four complete TP2 replicas per pool Each policy served one diagnostic probe, 64 learning requests and 32 measured requests at C16 after direct warmups. B queried four contracts per request (388 contracts, 97 generation POSTs). D queried one (97 contracts, 97 generation POSTs). Each admitted request generated once. Each diagnostic reserved 8,448 positions. All four replicas ended both the probe and the workload with zero in-flight requests and zero reserved KV positions.
TP1 and ordinary TP2 service TP1 cold/warm hits were 0/7,936. With routing disabled, TP2 served an 8,192/32 request with native mixed batching and 2,048-token prefill chunks. The contract endpoint returned HTTP 404 and responses carried no routing metadata. The stock streaming client completed 64/64 at C20, and the stock single-request example completed. Repeating a prompt four times at temperature 1.25, top-k 64, top-p 0.95 produced 4 distinct 32-token completions.
MetaX W64 and MUSA This NVIDIA server had no hardware from either platform. Their historical evidence appears below.

The hardware checks used Qwen3-32B BF16. The two stock entry points were examples/test_infer.py and scripts/test_perf.py. We skipped the offline engine microbenchmark in examples/bench.py because it bypasses HTTP routing. Task accuracy, including C-Eval and MMLU in test/bench/test_benchmark.py, was outside this validation.

The screenshot records the earlier rebased checkout 98a3a6c5. The table above records the repeat on the final head.

Rebased A100 validation at 98a3a6c5

Previously published A100 checkout b3269ad4b88a1a148d05fbe552cefad585bfeb1a separately passed 19 service tests, real TP2 cold/warm and dual-rank checks, independent calibration, and four-TP2 B/D contract and release checks. Release validation · Source correspondence · Release build and run instructions

Benchmark / Performance Impact

Original platform experiments. Both platforms used 8 GPUs, Qwen3-32B BF16, four TP2 replicas and closed-loop concurrency 16. Requests had 8,192 input tokens, a page-aligned 7,936-token shared prefix and 32 actual output tokens. Each cell ran 64 cache-learning requests then 128 measured requests. Throughput divides actual output tokens by total elapsed time for the phase. Deployment, unrelated warmup and independent calibration are outside the timed windows.

A100-SXM4-80GB arm Cache learning (output tok/s) Measured (output tok/s) Including learning (output tok/s)
A · native InfiniLM with capacity RR 80.30 91.70 87.56
D · same-cache RR 85.92 103.87 97.11
B · bounded hash V3 97.85 143.73 124.30
C · NVIDIA vLLM 0.11.0 104.75 127.83 119.09
  • A100 B's measured throughput was +56.75% vs A, +38.38% vs D and +12.44% vs C. B vs C during cache learning was −6.59%. Including learning, B gained 4.38% in throughput and had 4.30% higher TTFT P99 and 22.71% higher E2E P99. Three rounds yielded 12 valid cells and 2,304 successful executions with zero automatic generation retries. Report · Per-round metrics · Paired comparisons
  • This historical A100 build used greedy generation. InfiniLM used PyTorch 2.8.0+cu126 with whole prefills and CUDA graphs off after concurrent serving stalled. vLLM used PyTorch 2.8.0+cu128 with graphs and chunked prefill. All arms returned token IDs. The prompt IDs were attached to vLLM's first role event and InfiniLM's final event, which can affect TTFT. The cache-hit field was available on 53.1% of measured vLLM responses. Of 576 matched inputs, generated ID sequences differed in 3 B/D and 121 B/C pairs. Task accuracy was not evaluated. Measurement limitations
MetaX W64, 8×C550, independent batches Measured baseline → B (output tok/s) Measured gain Gain including learning
D/B · same-cache round robin → V3 98.086 → 124.265 +26.69% +21.25%
B/C · vLLM-MetaX → V3 109.517 → 125.056 +14.19% +10.76%

B was run independently in each W64 batch. vLLM-MetaX had shorter combined TTFT and E2E P99 in B/C. The historical public W64 +48.52% is an 8B/TP1 measurement. The reduced B/D run above checks behavior on this head. The historical throughput percentages apply to their original builds. W64 32B per-round receipts and source digests · Public W64 8B/TP1 validation

Earlier MUSA experiment. A separate, single-round run used eight MTT S5000 GPUs and eight TP1 Qwen3-32B replicas. All 1,728 requests across three methods and three output lengths completed. Original TP1 scope and results

Notes for Reviewers

  • Review the post-batch cache publication in the scheduler alongside main's paused decode queue, decode cap and chunked-prefill transitions. Only the routing backend forbids mixed/chunked prefill. The native request sampler and SDK gitlinks come from current main.
  • Each participating replica has 32,768 KV positions (256-token pages), up to three requests in flight and an 8,448-position reservation per 8,192 + 32 request. V3 uses 128 virtual nodes, at most two persistent hot owners, skew 1.25 and a five-second hint TTL. A deliberate wait is capped at the smaller of 1,000 ms and one quarter of estimated prefill savings.
  • Calibration and ordinary serving load the native runtime in the same order. Real libraries and sources, model, tokenizer, hardware and geometry bind the cost file. A changed backend instance invalidates old hints. Read the tests for cancellation, failed streams, quarantine and single release. Keep the internal endpoints and deployment key private. Runbook

CI / ChatOps

At the November 30 push of d0a095f3, GitHub created two upstream pull-request workflow runs. Both reported action_required with zero jobs. An upstream maintainer can review and approve the runs. CI run · Ruff run

Host behavior and format have automatic PR triggers. The separate upstream device workflow uses manual dispatch. The A100 results above were obtained on the final checkout. The protected main branch also requires an approving review from its designated team. PR checks


Checklist

Every contributor must verify every item below before requesting
review. Tick each box only after the check has actually been performed —
do not tick speculatively. If an item truly does not apply, replace the
checkbox with N/A and briefly explain why in an inline comment.

Title, Branch, and Commits

  • PR title follows Conventional Commits (e.g. feat(nvidia): …, fix(cuda/gemm): …).
  • Branch name follows <type>/xxx-yyyy-zzzz where <type> matches the PR title's Conventional Commits type and words are joined with hyphens (see CONTRIBUTING.md §Branches).
  • Each commit message follows Conventional Commits.
  • Small PR is a single squashable commit; or, for a large PR, every commit is meaningful, well-formed, and independently reviewable (see CONTRIBUTING.md §Pull Requests).
  • No stray merge commits from main — the branch is rebased cleanly on top of the current main.
  • No fixup! / squash! / wip commits remain.
  • N/A Existing PR/branch/commit that followed the legacy issue format.

Scope and Design

  • Changes are minimal — nothing unrelated to the stated motivation was added (CONTRIBUTING.md §Code/General).
  • No dead code, commented-out blocks, debug prints, printf/std::cout/print(...) left behind, or TODO without an owner and issue link.
  • No unrelated formatting churn that would obscure the diff.
  • Public API changes (if any) are intentional, documented, and reflected in affected callers/tests.

General Code Hygiene (applies to all languages)

  • The code is self-explanatory; comments were added only where the why is non-obvious (CONTRIBUTING.md §Code/General).
  • Every modified or added file ends with a single trailing newline (CONTRIBUTING.md §Code/General).
  • No trailing whitespace, tab/space mixing, or stray BOMs.
  • Identifiers in comments and error messages are wrapped in backticks (e.g. the `seqlens_k` tensor) (CONTRIBUTING.md §Code/General).
  • All comments and error messages are in English (CONTRIBUTING.md §Code/General).
  • Comments and error messages are complete sentences — capitalized first letter, terminal punctuation — unless the language/framework convention says otherwise (CONTRIBUTING.md §Code/General; §Python).

C++ Specific (if C++ files changed)

  • N/A Code follows the Google C++ Style Guide strictly.
  • N/A Error and warning message wording follows the LLVM Coding Standards (CONTRIBUTING.md §C++).
  • N/A Constructor initializer list order matches member declaration order (CONTRIBUTING.md §C++).
  • N/A No raw new/delete; RAII / smart pointers / existing allocators are used.
  • N/A Changed files are formatted by scripts/format.py.
  • N/A No changes/reference to csrc/models/llama_legacy/.

Python Specific (if Python files changed)

  • Code is PEP 8 compliant.
  • Comments are complete English sentences, starting with a capital letter and ending with punctuation; Markdown backticks are used for code references (CONTRIBUTING.md §Python).
  • Docstrings (if any) follow PEP 257 (CONTRIBUTING.md §Python).
  • Changed files are formatted by scripts/format.py.
  • No changes/reference to python/infinilm/auto_config.py.

Testing

  • For any platform that could not be tested, an explicit reason is given in the table and a reviewer with access has been tagged.
  • Passed single request test (examples/test_infer.py), or specify the reason for skipping.
  • Passed offline performance test (examples/bench.py), or specify the reason for skipping.
  • Passed sanity test (test/bench/test_benchmark.py), or specify the reason for skipping.
  • Passed service test (python/infinilm/server/inference_server.py + scripts/test_perf.py), or specify the reason for skipping.

Build, CI, and Tooling

  • The project builds cleanly from a fresh directory on at least one affected platform.
  • CI has been triggered manually (Actions → CI on this branch), or /retest was requested.

Documentation

  • README.md, CONTRIBUTING.md, or inline docs updated when behavior, build flags, or developer workflow changed.
  • N/A Any user-visible breaking change is called out explicitly under "Motivation" and in the commit/PR title with a ! or BREAKING CHANGE: footer.

Security and Safety

  • No secrets, access tokens, internal URLs, customer data, or personal hardware identifiers have been committed.
  • Third-party code is license-compatible and attributed.
  • No unsafe pointer arithmetic, uninitialized reads, or missing bounds checks were introduced.

The original experiment modules retain their attributed comments. Individual prose, docstring and backtick style items above await review. The platform table identifies the unavailable devices. No additional hardware reviewer was requested. The manual device workflow remains a maintainer action. The testing entries for offline performance and task accuracy refer to the explicit skip reasons above.

@chengcuiping
chengcuiping marked this pull request as ready for review November 12, 2026 04:29
@chengcuiping
chengcuiping requested a review from a team November 12, 2026 04:29
@chengcuiping
chengcuiping force-pushed the feat/bounded-hash-v3-upstream-20261112T030118Z branch from 581eeaa to d0a095f Compare November 30, 2026 09:58
@chengcuiping chengcuiping changed the title feat: add opt-in bounded-hash routing for full-model replicas feat: add opt-in bounded-hash routing for TP1 and TP2 replicas Nov 30, 2026
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.

1 participant