Skip to content

feat: swap the checkpoint a deployment serves without a restart - #4824

Draft
hallerite wants to merge 16 commits into
feat/mx-pullfrom
feat/mx-swap-checkpoint
Draft

hallerite wants to merge 16 commits into
feat/mx-pullfrom
feat/mx-swap-checkpoint

Conversation

@hallerite

Copy link
Copy Markdown
Member

A deployment that serves exported checkpoints (offline evals of an RL run) can move to another checkpoint in seconds instead of a full teardown and restart. Two parts:

  • Checkpoint publisher (tools/publish_checkpoint.py, transports/weights/checkpoint_publisher.py). Offers an HF safetensors export as a ModelExpress version, numbered with its step, and rolls from checkpoint to checkpoint.
  • POST /swap-checkpoint on the engines, plus tools/swap_checkpoint.py for a whole deployment. A DP group's first rank installs a version on every rank of the group.

Builds on the Engines interface of the pull branch (stage / pause / apply / resume). It adds a few general primitives to it: hold, release, in_flight, abort, reset_prefix_cache, set_health, integer_tables and update_draft, with per-rank admin routes.

Publisher

uv run python tools/publish_checkpoint.py /exports/step-300 300 --model-name my-run --ranks 8 --serve-modelexpress /tmp/mx
curl -X POST http://<host>:8090/publish -d '{"model_dir": "/exports/step-400", "step": 400}'   # roll
curl -X POST http://<host>:8090/release                                                     # or SIGTERM
  • Loading and serving.
    • Ranks split the tensors into runs of about equal bytes.
    • Each rank reads its share with O_DIRECT reads, round-robin over files, into page-locked host buffers.
    • It binds them IN_PLACE through ModelExpressTrainerClient, so the host holds a single copy.
    • Each tensor sits on pages of its own, so UCX's registration cache never merges two registrations.
    • Tensors keep their checkpoint names and layout. The engine converts a version only when its names are PrimeRL's, detected with the model class's is_hf_state_dict.
  • Rails (default when the host has as many GPUs as ranks). Rank r uses GPU r, its nearest RDMA port (from UCX_NET_DEVICES) and that port's NUMA node. Each rank then registers with one port instead of all of them.
  • One version at a time. A roll first checks that the new checkpoint has the same tensors. It then marks the current version RELEASING, waits for leases to drain, re-reads into the same buffers and republishes.
  • Integer tensors. ModelExpress publishes floating-point tensors only. The version uid carries a digest of the checkpoint's integer tables (DeepSeek-V4 tid2eid). An engine refuses a version whose tables differ from its own (409, needs a restart).
  • Host memory floor. The publisher refuses to start, and a publish fails, below max(200 GiB, 15%) of host memory available.

POST /swap-checkpoint {step | version_uid, mode, drain_timeout_s, draft_dir}

The swap runs these steps in order:

  1. Resolve the target. A missing one gets 404; one already served returns unchanged.
  2. Check the integer tables.
  3. Stage while serving. A failed stage changes nothing (502).
  4. Hold new requests at the API servers; they are not rejected. Then handle the requests in flight by mode:
    • fail: 409 if there are any.
    • drain: wait up to the timeout, else 409.
    • abort: abort them; they finish with reason abort.
  5. Pause the group (vLLM's DP-aware pause).
  6. Apply.
  7. Load the optional matching draft.
  8. Reset the prefix cache.
  9. Label the step.
  10. Resume and release the held requests.

The response includes timings (stage, drain, pause, apply, total).

Further behavior:

  • Cold first version. The first version of a publisher process stages while paused (cold, stage_paused).
  • Concurrency. One swap runs at a time per group. A duplicate request shares the result; another target gets 409.
  • Failed install. The group stays paused, /health answers 503 on every rank, the request gets 500, and the group retries the install while paused. It never resumes on mixed weights, even when a later stage fails. A new swap takes over.
  • GET /weight_version?uid=true returns {version, uid}, and completions carry per-token weight_versions labels.

Results

Tiny models, 4 GPUs:

  • DeepSeek-V4 tiny (online MXFP8) with internal DP2+EP and as a 2-server external-LB group behind vllm-router; dense Qwen3 with internal DP2 and 2 independent servers.
  • Everything passes:
    • all three modes, idempotence, the concurrent duplicate and the different-target 409;
    • bad targets (missing, other integer tables, unstageable cold version);
    • bit-exact after swapping back to the startup checkpoint, and warm vs cold stage, with buffers included;
    • prefix cache 256 → 0 → 256, labels;
    • the CLI, including --rolling;
    • a real install failure: publisher killed mid-drain with bounded staging → 500, 503 health, held requests, recovery by a swap to another version.

Full size. A DeepSeek-V4-architecture model, 530 GiB bf16, served as one DEP8 replica with online MXFP8, DSpark speculative decoding and bounded staging. The publisher runs on a second node with 8 ranks. 32 sessions of load ran through the router throughout.

Swap Publisher Mode Stage Drain Pause Apply Total
step A → B (new publisher, cold) 8 ranks, all ports drain paused 43.2 s 1.9 s 53.6 s 10.3 s 57.2 s
B → C (warm) same drain 0.11 s 1.7 s 10.4 s 10.3 s 12.5 s
C → C + draft reload same drain 0.15 s 1.9 s 14.1 s 10.3 s + draft 3.8 s 16.4 s
C → A (warm) same abort (32 aborted) 0.08 s 0.04 s 10.3 s 10.3 s 10.8 s
A → B' (new publisher, cold) rails drain paused 1.9 s 1.9 s 12.1 s 10.1 s 14.2 s
B' → C' (warm) rails drain 0.12 s 1.9 s 9.9 s 9.9 s 12.3 s
→ (warm), 4 GiB × 2 staging rails drain 0.07 s 1.9 s 9.0 s 9.0 s 11.3 s
  • The prefix reset, labeling and resume take ~0.05 s of each pause.
  • After the swap back to the startup checkpoint, every rank matched the cold-loaded fingerprints bit for bit.
  • Load during the four swaps: 1,131 requests, all 200, none with mixed weight labels; 32 aborted in the abort swap.
  • Publisher, full model, 8 ranks.
    • Without rails: pin 36 s, O_DIRECT read 14-17 s per rank (~32 GiB/s aggregate), registration + publish 76-80 s; the publish took 98 s.
    • With rails: read 11.8 s, registration 9.5 s; VmPin per rank 2× the buffer instead of 16×.
    • A roll takes 16-18 s, all of it re-reading.
    • Host memory peak: 530 GiB pinned plus ~20 GiB.

Known limits and follow-ups

  • UCX environment. NIXL ships its own UCX. Engines that swap must not point LD_LIBRARY_PATH or UCX_MODULE_DIR at another UCX build. Mixing them aborts every worker as soon as its NIXL agent starts (undefined symbol: uct_ib_mlx5_ext_register).
  • Wire speed. The wire runs at 8.4-14 GB/s per GPU, and the apply is all wire plus install.
    • Checkpoint tensors are per expert: 5,324 reads of ~15.8 MB per GPU through vLLM's per-expert loader. Trainer tensors are stacked per layer; pulling those reached 25 GB/s per GPU on the same engine config.
    • A publisher that publishes the stacked native layout (the inverse conversion chain) would take that path.
    • DP rank 0 is consistently the slowest rank, and every DP pause waits for it.
  • Registration. One NIXL registration per buffer instead of per tensor would cut registration further. It needs ModelExpress to register a slab and describe tensors as offsets into it.
  • JIT build on the first stage. A worker's first stage builds ModelExpress's receive-buffer allocator, a JIT extension cached under TORCH_EXTENSIONS_DIR. That costs ~20 s of pause when the cache is cold, for example after another environment rebuilt it. Give each environment its own TORCH_EXTENSIONS_DIR.
  • Restart after a streamed install failure. When an install fails while moving bytes under bounded staging, ModelExpress refuses further stages in that process. The group stays out of service until it restarts.
  • Integer tensors cannot be swapped until ModelExpress publishes them; a different table needs a restart.
  • API servers. Swaps need one API server per engine (api_server_count = 1).

Stacked on #4822 (engines pull ModelExpress versions); review that first.

🤖 Generated with Claude Code

hallerite and others added 16 commits November 27, 2026 10:21
…opies

- The MX worker id named the generator's registration, version leases and NIXL
  agent after `rank_offset + self.rank`. vLLM's worker rank restarts at 0 in
  every data-parallel engine, so all engines of a DP>1 server registered under
  the same id, shared one version lease, and the first engine to finish
  released it for all. The id now uses the device index, as the NCCL worker
  does.
- The sender keeps the state dict it publishes from. Packed parameters' splits
  are copies (full q/k/v per layer), so they stayed allocated through every
  training step. The sender now drops the dict after each release; the next
  broadcast refreshes it.

Trainer and inference layouts need not match; the docs list the combinations
covered (FSDP, EP, CP, HSDP and uneven shards on the trainer; TP, DP and DP+EP
on inference), each checked bit-exact against the weights loaded from disk.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MX uses the worker id only as an opaque key: the worker's registration, its
version lease (the server derives the lease id from the version and worker
id, one lease per worker and version) and its NIXL agent name. It needs the
id to be unique; nothing in MX expects dense ranks or a worker count.

The id was the device index plus a `rank_offset` the orchestrator assigned
(`index * workers_per_server`). That needed the inference layout
(`inference_world_size`, the same number of GPUs on every server) and assumed
one worker per GPU on visible devices 0..N-1.

Each worker now names itself `{session}:{GPU UUID}:{pid}`. The GPU UUID is
unique across data-parallel engines, external-LB servers, P/D roles and
replicas without any global knowledge. The process id keeps ids unique when
engines share a GPU, and fresh after an engine restarts. The id is stable
within a process, so a repeated `init_broadcaster` (the Dynamo admin plane
sends one before every update) keeps the running client.

- The orchestrator and the Dynamo admin plane send every engine the same
  initialization, without `rank_offset` or `inference_world_size`. Dynamo no
  longer adds the instance id to the session.
- `/init_broadcaster` passes its body to the worker extension as keyword
  arguments, so each transport's extension takes its own fields. The NCCL
  request and worker are unchanged and keep `rank_offset`.
- MX no longer reads `weight_broadcast.inference_world_size`; the field stays
  for NCCL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With `[weight_broadcast] type = "modelexpress"` and `pull = true`, each inference server moves itself onto every
version the trainer publishes, instead of the orchestrator pausing every engine and pushing each update.

- Engine (`inference/vllm/weight_pull.py`). A task in the API server polls ModelExpress for the newest READY
  version published after the one it serves. Every worker stages it on a background thread while the engine
  serves; once all have, the engines pause with the running requests kept, install it, label the tokens sampled
  from then on with its step and resume. The first version of a trainer stages while paused: that stage records
  the layout on the live model.
- Groups. `Engines` is the interface (init, can_stage_live, stage, discard, pause, apply, resume). `LocalEngine`
  moves this server's engines in process, every data-parallel engine of an internal-LB server included.
  `EngineGroup` moves the ranks of an external-LB DP group through new admin routes
  (`/modelexpress/{can_stage_live,stage,discard,apply}`, `/pause`, `/resume`), so its first rank pulls for the
  group (`weight_broadcast.pull_group`, set by the multi-node template). vLLM's data-parallel pause stops every
  rank at the same step. Groups switch independently.
- Failures. A failed stage leaves the live weights untouched and the engines keep serving. A failed install keeps
  the engines paused and installs the newest version from scratch until one succeeds; past `timeout` the server
  exits.
- `GET /weight_version` returns the label the engine serves.
- Trainer. Each rank publishes from one host copy, so it holds one version. Before publishing the next, the
  master marks the previous one RELEASING (no new leases) and every rank waits until the reads in flight end. No
  install is awaited, except for the last version at close. A new trainer retires a previous trainer's READY
  versions.
- Orchestrator. `ModelExpressPullWeightReceiver` initializes, pauses and pushes nothing: it waits until every
  engine serves the version or a newer one of this trainer, then marks it installed. The watcher keeps
  dispatching across a swap.
- `rl` rejects pull with Dynamo, draft swaps and rollout checkpoints; SFT rejects it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… to ModelExpress

- docs/model-express.md: how pull stages, switches and fails, and what the trainer and the orchestrator still do.
- The puller retries connecting the engines to ModelExpress until the server answers, so engines may start before
  it. Its log line now separates reaching the pause from the time paused.
- Config tests: pull reaches the engines, the trainer and the orchestrator; the arguments a group leader gets
  parse; pull rejects rollout checkpoints and transports other than ModelExpress.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…served version ids; model name override

- `weight_broadcast.pull_group` becomes `weight_broadcast.group`, which no longer needs `pull`: it is the admin URL
  of every rank of the server's DP group, and the multi-node launcher gives it to the first rank of each group
  whether or not the engines pull, so anything that moves a group's weights can find its ranks.
- `GET /weight_version?uid=true` also returns the ModelExpress version every worker installed last
  (`modelexpress_served`, cleared while an install runs); `Engines.served()` reads it. The plain route, which the
  orchestrator polls, stays a label read.
- `weight_broadcast.model_name` names the model versions are published under, defaulting to `vllm.model`, and
  reaches `init_broadcaster`.
- `WeightPuller.lock` is held through every switch, for anything else that moves the same engines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An install that failed keeps the engines paused and retries with the newest version. A failure to list the versions
then retries the same version instead of leaving the switch while paused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hed engines

The first version of a trainer stages after the pause. When that stage fails, no install started, so the live
weights are untouched: discard, resume and let the puller retry later, instead of keeping the engines paused as
after a failed install, which may leave the weights partly written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…versions

`tools/publish_checkpoint.py MODEL_DIR STEP --model-name NAME` offers an exported HF safetensors checkpoint to running
engines as an MX version, numbered with its step, so that a deployment can move to it without a restart.

- Ranks (one process each, joined by a gloo group) split the checkpoint's tensors into runs of about equal bytes,
  read their share into page-locked host buffers (cudaHostRegister, exact size) with reader threads, and bind them
  IN_PLACE through ModelExpressTrainerClient: MX serves the buffers themselves, so the publisher holds one copy.
- Tensors keep the checkpoint's names, layout and dtypes (bf16, fp16 or fp32), which is what vLLM's loader reads.
- One trainer mesh for the publisher's lifetime, so engines stage only its first version while paused.
- One version at a time. Publishing the next checkpoint (HTTP `POST /publish` on rank 0) checks that it holds the same
  tensors, marks the current version RELEASING, waits until its leases drain, reads the new checkpoint into the same
  buffers and publishes it. `POST /release` or SIGTERM retires the version and exits; `GET /status` reports it.
- MX publishes floating-point tensors only. The version's uid carries a digest of the checkpoint's integer tensors
  (by value and shape, independent of names and integer width), so engines can refuse a checkpoint whose integer
  tables differ from the ones they keep.
- `--serve-modelexpress` runs an MX server beside the publisher.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… restart

`POST /swap-checkpoint {step | version_uid, mode, drain_timeout_s}` (admin) moves every rank of a DP group onto a
ModelExpress version, such as one a checkpoint publisher offers, through the group's first rank
(`weight_broadcast.group`) or a server that holds all of its engines.

- Order: resolve the target (newest READY version of the step; 404 if none), return `unchanged` if every rank serves
  it, refuse a version whose integer tables differ from the engines' (409, needs a restart), stage it while serving
  (a failed stage changes nothing, 502), stop admitting requests and handle the ones in flight by `mode` (`fail`: 409
  if any; `drain`: wait up to `drain_timeout_s`, else 409; `abort`: abort them, finish reason `abort`), pause the group,
  install, reset the prefix cache, label the tokens with the step, resume, and answer with timings (stage, drain,
  pause, apply, total). The first version of a mesh stages while paused (`cold`, `stage_paused` counts toward
  `pause`).
- Requests that arrive during a swap wait at the API server (an admission gate on the engine client's `add_request`)
  and then run on the new weights; they are never rejected. vLLM's own wait and abort pauses reject them, and a
  data-parallel wait pause cannot be cancelled on a drain timeout.
- One swap at a time per group: a request for the version being installed shares that swap's result, one for another
  version gets 409. The swap continues if its client disconnects.
- A failed install keeps the group paused, reports every rank unhealthy (`/health` 503, so the router drops it),
  answers 500 and retries the install while paused until it succeeds or `weight_broadcast.timeout` passes. A new swap
  to any version takes over. It never resumes on mixed weights.
- Engines interface: `hold`, `release`, `in_flight`, `abort`, `reset_prefix_cache`, `set_health`, `integer_tables`,
  with per-rank admin routes for EngineGroup (`/admission/{close,open}`, `/in_flight`, `/abort_in_flight`,
  `/reset_prefix_cache_paused`, `/set_health`, `/modelexpress/integer_tables`).
- Worker: a version's tensors convert from PrimeRL to the checkpoint layout only when their names are PrimeRL's (the
  model class's `is_hf_state_dict`, as when the trainer loads a checkpoint), so checkpoint publishers need no
  conversion. `modelexpress_integer_tables` digests the integer parameters vLLM loaded from the checkpoint (not those
  it derives after loading, such as MXFP8 scales).
- `tools/swap_checkpoint.py --router URL --step N --mode drain` discovers every DP group behind a router (or
  `--servers`) and swaps all of them, or one at a time out of the router's rotation with `--rolling`.
- The multi-node inference template passes every EP group's first rank its group's admin URLs when the engines use
  ModelExpress, and the admin token from `$ADMIN_TOKEN_SEND_ENV`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and keeps a host memory floor

Reading a 530 GiB checkpoint from Lustre into pinned buffers let the Lustre client cache grow beside the pinned copy
until the host ran out of memory. The publisher now reads with O_DIRECT through a page-aligned bounce buffer per
reader thread (buffered reads that drop their pages on filesystems without O_DIRECT), and refuses to start, or fails a
publish, rather than leave less host memory available than max(200 GiB, 15% of the total)
(`--min-available-gib`, `--min-available-fraction`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ils; swap phase and group URLs

- A swap that takes over from a failed install stages while the group is paused with partly written weights. If that
  stage fails, the group stays paused and unhealthy and retries the new version, instead of resuming as a group
  with intact weights does: a dense engine resumed that way ran a step on meta tensors and died.
- `GET /swap-checkpoint` reports where a running swap is (`phase`: staging, draining, paused). A failed ModelExpress
  lookup answers 502.
- The swapping server connects its group to ModelExpress at startup, best effort, so the first swap does not.
- A server that pulls from a trainer builds no swapper: its generator clients follow the trainer.
- The multi-node inference template names a group's ranks by host name, as the router does, so
  `tools/swap_checkpoint.py` matches the router's workers to their groups.
- Docs: the publisher's O_DIRECT reads and memory floor, bounded staging needs a buffer of the largest tensor,
  the JIT-compiled receive-buffer allocator on a first stage, and the failure cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-decoding draft

`POST /swap-checkpoint` takes an optional `draft_dir` (a directory, or a Hub id in the local cache). The route checks
it against the served draft before anything changes (422 if it does not match), and the group loads it on every rank
in the same pause, after the version and before the prefix cache reset (`timings.draft`). A failed draft load counts
as a failed install. Without `draft_dir` the draft keeps its weights, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…bin, copying without the GIL

A Lustre file's bandwidth is bounded by its storage targets, so readers that drain one file after another stall on
it: each rank now interleaves its chunks over its files, and copies from its O_DIRECT bounce buffers with torch, which
releases the GIL. One process read 63 GiB of an export at 8 GiB/s instead of 1.6 GiB/s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pages of its own

ModelExpress registers each tensor with NIXL separately, and UCX's registration cache merges registrations whose
pages overlap and registers the union anew. With a rank's tensors packed back to back in one buffer, every
registration re-registered everything before it: for 4,300 tensors (one rank of a 530 GiB checkpoint) pinned memory
accounting grew past 21 TB and host memory drained at 2.5 GiB/s. Each tensor now starts on a page boundary (at most
4 KiB of padding per tensor), so registrations never overlap: one rank registers in ~78 s with VmPin at 16x its
buffer (8 NICs, two registrations each).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…NIXL's UCX in the docs

With at least as many GPUs as ranks (and CUDA_VISIBLE_DEVICES unset), rank r of the checkpoint publisher now uses GPU
r, the RDMA port nearest it among UCX_NET_DEVICES and the CPUs of that port's NUMA node, so its buffers land there
(`--rails`/`--no-rails` to choose). Each rank then registers its tensors with one port instead of every port: for a
530 GiB checkpoint over 8 ranks, registration drops from ~78 s to ~9.5 s and VmPin from 16x to 2x a rank's buffer, and
an engine connects to a new publisher in ~0.1 s instead of ~34 s, so a cold swap pauses ~12 s instead of ~54 s.

Docs: engines that swap must not point LD_LIBRARY_PATH or UCX_MODULE_DIR at another UCX build; NIXL ships its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wiz-prime-intellect

Copy link
Copy Markdown

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities -
Data Finding Sensitive Data -
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings 1 Medium
Software Management Finding Software Management Findings -
Total 1 Medium

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try the Wiz Code extension for VS Code, JetBrains, or Visual Studio.

@hallerite
hallerite added this pull request to stack #4830 November 29, 2026 11:20
@hallerite
hallerite removed this pull request from stack #4830 December 3, 2026 21:54

This branch has not been deployed

No deployments
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