Skip to content

test(nanbeige): qualify incremental KV allocation on CPU and CUDA - #207

Open
lx6800 wants to merge 1 commit into
InferMatrixLab:mainfrom
lx6800:feat/nanbeige-incremental-kv
Open

lx6800 wants to merge 1 commit into
InferMatrixLab:mainfrom
lx6800:feat/nanbeige-incremental-kv

Conversation

@lx6800

@lx6800 lx6800 commented Nov 23, 2026

Copy link
Copy Markdown

Required human contributor answers

1. What outcome are you trying to achieve?

Qualify CacheConfig(incremental_allocation=True) for Nanbeige4.2 (NanbeigeForCausalLM) as a regression-tested capability—closing the unclaimed Incremental allocation cell in RFC #69—and fix any Nanbeige-specific KV allocation, scheduling, or parity defects uncovered during verification.

2. What is the highest-leverage variable for that outcome?

End-to-end contract verification of Nanbeige's fixed 2-loop (LAST_EXITED, storage_depths=2) KV lifecycle through the real StageEngine / Scheduler / KVCacheManager path—proving that physical pages are actually allocated at the prompt frontier and grown across block boundaries without numerical drift, admission deadlocks, or block leaks, rather than assuming Ouro coverage transfers automatically.

3. How will this work move that variable rather than create busywork?

Instead of a shallow smoke test that merely toggles incremental_allocation=True, this PR adds contract-enforcing tests in tests/test_nanbeige.py (CPU, synthetic CUDA/Triton, and real Nanbeige/Nanbeige4.2-3B BF16 checkpoint on RTX PRO 6000) that explicitly assert: (1) initial allocated_blocks after admission is strictly smaller than full-capacity reservation, (2) decoding across block_size boundaries triggers ensure_capacity growth across intermediate pages, (3) tight-pool admission budgeting (without preemption), watermark headroom, mid-decode abort and request-ID reuse, capacity-pressure preemption/restore with seeded sampling, prefix reuse + WCPB, P->D StageEngine handoff + decode-stage preemption, self-speculative decoding (block and pipeline, sync/async, eager/CUDA Graphs, rollback & mid-speculation abort/reuse), and zero block leaks all hold, and (4) outputs match both non-incremental execution and dense_nanbeige_reference token-for-token.

4. Who is the customer or user, and what do they actually need?

Users serving or evaluating Nanbeige4.2-3B on vllm-rlt under large max_tokens budgets or mixed-length workloads (and maintainers tracking model coverage in RFC #69). They need incremental_allocation=True to avoid upfront over-allocation of physical KV blocks for unused decode capacity, with verified guarantees against deadlocks, KV leaks, and output divergence across ordinary, PD, and speculative paths.

PR necessity and bugfix evidence

Yes, a PR is needed. RFC #69 explicitly requires model-specific validation rather than inheriting Ouro's status, and neither tests/test_nanbeige.py nor open PRs (#138, #139) cover incremental_allocation for Nanbeige. A config tweak or doc note alone cannot provide CI regression protection. This is a qualification/test PR rather than a bugfix; no runtime defects were observed in the tested incremental-allocation paths (including PD handoff and self-speculation on both synthetic models and the real Nanbeige/Nanbeige4.2-3B BF16 checkpoint).

Purpose

Add CPU, synthetic CUDA, and real-checkpoint CUDA qualification tests in tests/test_nanbeige.py covering CacheConfig(incremental_allocation=True) for NanbeigeForCausalLM (part of #69):

  • Initial frontier allocation vs full upfront reservation, monotonic cross-block ensure_capacity growth, fixed 2-loop exit depths, and parity against both non-incremental execution and dense_nanbeige_reference.
  • Tight-pool logical growth budgeting without preemption, mid-decode abort_request + request-ID reuse with a distinct prompt, and watermark_ratio admission headroom.
  • Capacity-pressure preemption and lossless snapshot/restore preserving outputs and seeded sampling RNG (temperature=0.7, seed=17).
  • Combined prefix caching + incremental allocation under ordinary and WCPB prefill, asserting actual prefix cache hits (prefix_hits) and dense oracle parity.
  • StageEngine PD transfer (role="prefill" -> role="decode") under incremental allocation: decode-side growth budgeting, dynamic cross-page expansion, decode-stage tight-pool preemption with seeded sampling (temperature=0.7, seed=31), zero block leaks on both stages, and oracle parity.
  • Self-speculative decoding (draft_loops=1, target_loops=2, K=3, block and pipeline modes) under incremental allocation: initial chunk-only allocation, real draft rejection/rollback (truncate_suffix), mid-speculation abort + request-ID reuse, sync/async and eager/CUDA Graph Triton parity.
  • Real Nanbeige/Nanbeige4.2-3B BF16 GPU qualification (test_nanbeige_gpu_real_checkpoint_incremental_allocation, gated on NANBEIGE_CHECKPOINT or artifacts/models/Nanbeige4.2-3B) covering eager + CUDA Graphs parity, tight-pool preemption/restore, prefix caching, PD handoff, and block/pipeline sync/async/graph self-speculation.

Performance & Refactoring Review (docs/developer-guide.md):

  • rlt-perf-opt: Test-only change; no runtime or kernel execution path was modified, so runtime GPU benchmarking is not applicable and no speedup is claimed.
  • rlt-refactor: Extracted _tiny_gpu_nanbeige() and _copy_prompt_kv() to avoid duplicated test setup across CPU/GPU/PD tests, exercised public engine.step() rather than private scheduler._admit() for watermark verification, and closed all engines in try/finally.

Scope & Disclosed Limitations:

  • PD transfer qualification exercises the in-process StageEngine transfer contract (reserve_transfer, KV copy, accept_import, release_transfer, matching tests/test_stage_engine.py); cross-process multi-GPU NIXL transport was not run because nixl is not installed in the test environment.
  • Real-checkpoint GPU tests cover Nanbeige/Nanbeige4.2-3B BF16 (b82e54bd609793562a75cbf9337970a93369eab5) on RTX PRO 6000 with Triton (block_size=16); full GSM8K accuracy sweeps and throughput benchmarks were not run because no runtime code changed.

Test Plan

vllm-rlt Version / Commit: base main @ ce200f0d2085fb041c66691245e29aef2a9ed714, head 778f40d9283954757e648e41b24adc92ef165ebe
Real Checkpoint: Nanbeige/Nanbeige4.2-3B @ b82e54bd609793562a75cbf9337970a93369eab5 (SHA256 verified)

python -m ruff check .
python -m ruff format --check .
OMP_NUM_THREADS=1 python -m pytest -q tests/test_nanbeige.py -k "not real_checkpoint"
OMP_NUM_THREADS=1 CUDA_VISIBLE_DEVICES=0 python -m pytest -v --run-gpu tests/test_nanbeige.py
OMP_NUM_THREADS=1 python -m pytest -q

Test Result

Environment: Ubuntu Linux, Python 3.10.12, PyTorch 2.7.1+cu128, Triton 3.3.1, ruff 0.13.2, pytest 9.2.0, NVIDIA RTX PRO 6000 Blackwell Server Edition.

  • python -m ruff check .: All checks passed!
  • python -m ruff format --check .: 154 files already formatted
  • OMP_NUM_THREADS=1 python -m pytest -q tests/test_nanbeige.py -k "not real_checkpoint": 19 passed, 10 skipped, 2 deselected in 2.82s
  • OMP_NUM_THREADS=1 CUDA_VISIBLE_DEVICES=0 python -m pytest -v --run-gpu tests/test_nanbeige.py: 30 passed, 1 skipped in 62.40s
    • All CPU, synthetic GPU (Triton/Graphs/async preemption/block & pipeline speculation), and real Nanbeige4.2-3B BF16 GPU checks passed with exact token parity and num_used_blocks == 0 at completion (eager & CUDA Graphs used_after_step1=4 vs 14 full, captures=2, replays=63; tight-pool preemption preemptions=1, resumptions=1; prefix caching hit_tokens=16; PD handoff D_init=2 -> D_peak=4, 24/24 exact match; block & pipeline sync/async/graph speculation u1=2 -> peak=4, 24/24 exact match).
    • Only test_official_nanbeige_tokenizer_contract skipped (checks default HF cache rather than artifacts/models/Nanbeige4.2-3B).
  • OMP_NUM_THREADS=1 python -m pytest -q (full repo CPU suite): 1289 passed, 916 skipped, 12 failed — all 12 failures are unrelated FP8 CPU tests (tests/test_fa4_fp8.py and tests/test_fp8_kv_cache.py) failing with RuntimeError: "index_cpu" not implemented for 'Float8_e4m3fn' on PyTorch 2.7.1.

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