← Back to Pull requests

perf(sampler): replace MRV2 O(B) seeded multinomial with batched Gumbel and add Qwen2.5 152064 hints #380

Closed
unknown closed this pull request without merging on Dec 01, 2026 00:44 UTC
View on GitHub
unknown unknown commented on Nov 27, 2026 12:05 UTC
Author

Summary

1. Replace MRV2's O(B) sequential torch.multinomial loop with batched stateless gumbel_sample (vllm_musa/v1/sample/topk_topp_sampler.py):
- sample_worker_logits_seeded_multinomial was introduced as a v0.22 workaround when upstream gumbel_sample unconditionally cast to tl.float64 (unsupported on MUSA). Upstream v0.32.0 gumbel_sample uses 32-bit Murmur3 (murmur3_uniform32 + _log1p_neg_stable, use_fp64=False), and SamplingStates already populates seeds.gpu and pos for every request.
- Adds can_use_worker_seeded_gumbel + sample_worker_logits_seeded_gumbel ahead of can_use_worker_seeded_multinomial in _worker_sample so all MRV2 user-seeded batches (not use_fp64_gumbel, logprobs_mode not in ("processed_logits", "processed_logprobs"), temperature > 1e-5) across all model vocabularies and dtypes run a single batched stateless gumbel_sample launch instead of materializing a full [B, V] FP32 softmax tensor and launching B sequential torch.multinomial kernels in Python.
- Includes a zero-copy bf16 fast path when not np.any(needs_logits_processing[idx_mapping_np]), single-copy in-place filtering (preserve_processed_logits=False) otherwise, and evicts stale musa_generators on _sampling_states_add_request without eagerly allocating torch.Generator(device="musa") unless the legacy fallback is entered.
2. Add Qwen2.5 152064 vocabulary to CPU-side gpu_input_batch.py hints (series/0082):
- Aligns uniform_top_k and uniform_temperature vocab gates in vllm/v1/worker/gpu_input_batch.py from (151936, 248320) to (151936, 152064, 248320), matching _MUSA_QWEN_SAMPLER_VOCAB_SIZES and vllm_musa/optimization_contract/qwen.py.

S5000 Hardware Evidence

  • Environment: 2 × MTT S5000 (80 GiB, mp_count=64, driver 5.2.0-server), image sh-harbor.mthreads.com/mcctest/vllm:v0.32.0-ph1-5.2.0-torch2.13.0.post1-20261126 (torch 2.13.0.post1+musa5.2.0, torchada 0.1.111, mate 0.2.8.post1).

  • Cold-Cache Sampler Microbenchmark (256 MiB L2 flush, 46/46 bit-exact deterministic):
  • | Vocab | Mode | B=1 Base -> Cand (Speedup) | B=16 Base -> Cand (Speedup) | B=64 Base -> Cand (Speedup) | B=128 Base -> Cand (Speedup) |
    |---|---|---:|---:|---:|---:|
    | Qwen3-151936 | filtered (T=0.7, top_k=50, top_p=0.95) | 0.80 -> 0.47 ms (1.72x) | 6.93 -> 0.76 ms (9.12x) | 25.70 -> 1.01 ms (25.45x) | 51.91 -> 1.61 ms (32.31x) |
    | Qwen3-151936 | unfiltered (T=1.0) | 0.46 -> 0.036 ms (12.93x) | 6.20 -> 0.069 ms (89.81x) | 25.06 -> 0.24 ms (104.77x) | 50.79 -> 0.47 ms (108.53x) |
    | Qwen2.5-152064 | filtered | 0.78 -> 0.47 ms (1.67x) | 6.97 -> 0.76 ms (9.18x) | 25.91 -> 1.00 ms (25.81x) | 52.61 -> 1.60 ms (32.81x) |
    | Qwen2.5-152064 | unfiltered | 0.46 -> 0.036 ms (12.96x) | 6.20 -> 0.068 ms (90.68x) | 25.08 -> 0.24 ms (104.14x) | 50.83 -> 0.47 ms (108.65x) |
    | Qwen3.5-248320 | filtered | 1.11 -> 0.48 ms (2.31x) | 11.21 -> 1.20 ms (9.33x) | 41.26 -> 1.69 ms (24.42x) | 84.45 -> 2.71 ms (31.21x) |
    | Qwen3.5-248320 | unfiltered | 0.73 -> 0.036 ms (20.05x) | 9.98 -> 0.10 ms (98.13x) | 41.01 -> 0.38 ms (107.19x) | 82.69 -> 0.76 ms (109.45x) |
    | Llama3-128256 | filtered / unfiltered | 0.73 -> 0.47 ms (1.56x) / 0.40 -> 0.036 ms (11.01x) | 7.35 -> 2.32 ms (3.17x) / 5.26 -> 0.060 ms (87.22x) | 26.34 -> 5.84 ms (4.51x) / 21.17 -> 0.20 ms (103.99x) | 53.19 -> 10.78 ms (4.93x) / 42.98 -> 0.40 ms (108.68x) |
    | DeepSeekV2-102400 | filtered / unfiltered | 0.66 -> 0.47 ms (1.41x) / 0.33 -> 0.036 ms (9.04x) | 6.19 -> 1.95 ms (3.18x) / 4.25 -> 0.052 ms (81.19x) | 21.70 -> 4.75 ms (4.57x) / 16.99 -> 0.17 ms (102.70x) | 43.18 -> 8.74 ms (4.94x) / 34.55 -> 0.32 ms (108.04x) |

  • Compiled End-to-End MRV2 vllm serve A/B (Qwen3-8B BF16, TP=2, CUDAGraphMode.FULL_AND_PIECEWISE, max_tokens=192, user seed on every request):
  • | Mode | Concurrency | Baseline (O(B) Multinomial) | Candidate (Batched Stateless Gumbel) | Throughput Gain | Mean TPOT (Base -> Cand) |
    |---|---:|---:|---:|---:|---:|
    | filtered (T=0.7, top_k=50, top_p=0.95) | 1 | 107.06 tok/s | 108.84 tok/s | +1.66% | 9.29 -> 9.14 ms |
    | filtered | 16 | 1298.35 tok/s | 1483.46 tok/s | +14.26% | 12.11 -> 10.57 ms |
    | filtered | 32 | 2198.37 tok/s | 2759.57 tok/s | +25.53% | 14.21 -> 11.26 ms |
    | filtered | 64 | 3311.23 tok/s | 4846.32 tok/s | +46.36% | 18.79 -> 12.66 ms |
    | filtered | 128 | 3986.68 tok/s | 7022.86 tok/s | +76.16% | 31.18 -> 17.35 ms |
    | unfiltered (T=1.0) | 32 | 2292.49 tok/s | 2933.73 tok/s | +27.97% | 13.59 -> 10.58 ms |
    | unfiltered | 64 | 3394.24 tok/s | 5147.17 tok/s | +51.64% | 18.27 -> 11.93 ms |
    | unfiltered | 128 | 4065.01 tok/s | 7260.24 tok/s | +78.60% | 30.57 -> 16.75 ms |

    Validation & Regression Matrix

  • musa_sync check-series, check-series --replay, verify (219/219 series clean), ruff check, ruff format --check, and git diff --check: PASS

  • Unit tests: 40 passed offline + 62 passed on S5000 (test_mrv2_batched_seeded_gumbel.py, test_sampler_cpu_state_fast_paths.py, test_qwen_unit_temperature_source.py, test_qwen_sampler_model_traits_source.py, test_default_on_dispatch_parity.py): PASS

  • Subsystem regression smokes (TP=2 compiled MRV2, greedy semantic + seeded sampling):

  • - Qwen3-8B (Dense, FLASH_ATTN): PASS (4/4 seeded exact)
    - Qwen3.5-35B-A3B-FP8 (Hybrid GDN + FP8 MoE, FLASH_ATTN + DEEPGEMM): PASS
    - DeepSeek-V2-Lite-Chat (MLA + MoE): PASS (4/4 seeded exact)

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: yeahdongcn Review duration: 5079m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.57) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #380"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%