Skip to content

feat: AutoFlipController + heal path + bvar metrics for CP<->DP switching.#1969

Open
cchh05 wants to merge 2 commits into
xLLM-AI:mainfrom
cchh05:pr2-cp-dp-autoflip-heal-on-pr1
Open

feat: AutoFlipController + heal path + bvar metrics for CP<->DP switching.#1969
cchh05 wants to merge 2 commits into
xLLM-AI:mainfrom
cchh05:pr2-cp-dp-autoflip-heal-on-pr1

Conversation

@cchh05

@cchh05 cchh05 commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Description

Follow-on to #1968. Adds autonomous flipping and post-flip drain safety on top of the runtime CP<->DP switching feature.

  1. AutoFlipController — scheduler-side controller that watches traffic stats and issues SwitchMode RPCs autonomously. Config knobs: minimum inter-flip interval, stat window, hysteresis.

  2. Heal path — after a flip, if a small tail of in-flight requests fails to converge (long-prefill sequences straddling the flip), a bounded heal window (default 4 rounds) drains them safely instead of holding the whole cluster.

  3. CP -> DP pending gate — refuses a CP -> DP flip while the CP side still has queued long-prefill sequences that would be silently split apart by the DP layout.

  4. 7 bvar metrics on /vars:

    Metric Meaning
    xllm_mode_flip_total flip attempts (count)
    xllm_mode_flip_success_total flips that completed cleanly
    xllm_mode_flip_target_cp_total flips into CP layout
    xllm_mode_flip_target_dp_total flips into DP layout
    xllm_mode_flip_latency_ms latency histogram (bvar)
    xllm_mode_flip_heal_rounds heal rounds consumed per flip
    xllm_mode_flip_pending_gate_reject_total flips rejected by the CP->DP pending gate

Fully gated by the same --enable_runtime_cp_dp_switch flag introduced in #1968.

Related Issues

Part of #1967. Depends on #1968 — please merge that first.

Change Type

  • Bug fix
  • New feature
  • Performance improvement
  • Refactor
  • Documentation
  • Test
  • Build or CI

Pull Request Checklist

PR Title and Commit Messages

  • The PR title and each commit message follow the xLLM commit format: <type>: <subject>.

Pre-commit Checks

  • clang-format was run against all touched C++ files (verified via --dry-run --Werror, 0 violations).
  • Full pre-commit run --all-files — not run locally due to environment gap on my dev machine; happy to run whatever the CI does and iterate on any reported issue.

Self Review

Build and Test Coverage

  • Tests have been added: auto_flip_decide_target_test (278 lines, covers stat window, min flip interval, target selection, hysteresis).
  • CUDA python setup.py build test: not run — feature is NPU-only in this PR. Behavior on CUDA is unchanged (feature gated off).
  • NPU: E2E verify_switch extended with a long-prefill injection straddling the flip; 842 ms average tail drain, 18/18 flips still convergent. 10-min soak @ 32 procs with periodic auto-flips, HBM watermark stable.
  • MLU: not run — feature is NPU-only in this PR. Behavior on MLU is unchanged (feature gated off).

Reviewer Notes

cchh05 added 2 commits July 17, 2026 21:20
Add support for flipping worker layout between CP_PREFILL (cp=N, dp=1)
and DP_DECODE (cp=1, dp=N) on a live instance in ~500 ms, without a
service restart. Traffic patterns rarely stay in one regime forever;
this lets a single deployment adapt across the day rather than being
statically sized for either lane.

Design
------

* Startup builds BOTH ATB graphs (dual-mode) when
  `--enable_runtime_cp_dp_switch=true`, so a flip is a graph handle
  swap, not a rebuild.
* Flip flow: scheduler drains in-flight requests -> pause workers ->
  swap the active `ParallelArgs` (cp/dp) and block-manager pool
  atomically -> resume. The block-manager pool is guarded by a
  shared-ptr for lockless reads on the hot path.
* Worker-side call sites read the live `parallel_args_.cp_size()` (not
  the immutable `options_.cp_size()`), so already-scheduled requests
  observe the new layout after resume.

New surfaces
------------

* `mode_switch.proto` + `ModeSwitchService`: RPC surface for flipping,
  exposed via the xLLM server.
* `AutoFlipController` scaffolding for autoscaling callers.
* `docs/en/features/runtime_cp_dp_switch.md`: user-facing design doc.

Testing
-------

* Unit: `dual_parallel_args_test`, `atomic_pool_handle_test`,
  `lopsided_defer_gate_test`.
* E2E on 8*A3: `verify_switch` regression, 18/18 flips stable across
  61 model layers; lm_eval CP == DP within tolerance;
  10-min soak on 32-proc load did not regress HBM watermark.

Related issue: xLLM-AI#1967
…hing.

Follow-on to the runtime CP<->DP mode switching feature. Adds:

1. AutoFlipController — a scheduler-facing controller that watches
   traffic stats and issues SwitchMode RPCs, so an instance can flip
   layout autonomously instead of relying on an external caller.
2. Heal path — after a switch, if a small tail of in-flight requests
   fails to converge (e.g. long-prefill sequences straddling the flip),
   a bounded heal window (default 4 rounds) drains them safely without
   holding the whole cluster.
3. CP -> DP pending gate — refuses a CP -> DP flip while
   the CP side still has queued long-prefill sequences that would be
   silently split apart by the DP layout.
4. 7 bvar metrics on `/vars`:
     xllm_mode_flip_total
     xllm_mode_flip_success_total
     xllm_mode_flip_target_cp_total
     xllm_mode_flip_target_dp_total
     xllm_mode_flip_latency_ms
     xllm_mode_flip_heal_rounds
     xllm_mode_flip_pending_gate_reject_total

Testing
-------

* Unit: `auto_flip_decide_target_test` (278 lines, covers stat window,
  minimum flip interval, target selection, hysteresis).
* E2E: heal path exercised by the same `verify_switch` regression,
  which was extended to inject a long prefill straddling the flip;
  842 ms average tail drain, 18/18 flips still convergent.
* Soak: 10 min @ 32 procs with periodic auto-flips, HBM stable.

Depends on xLLM-AI#1968 (feat: runtime CP<->DP mode switching).
@cchh05
cchh05 force-pushed the pr2-cp-dp-autoflip-heal-on-pr1 branch from a22f815 to c4b45a9 Compare July 17, 2026 13:23
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