Skip to content

feat(modelexpress): engines pull weight versions themselves - #4822

Open
hallerite wants to merge 3 commits into
mainfrom
feat/mx-pull
Open

hallerite wants to merge 3 commits into
mainfrom
feat/mx-pull

Conversation

@hallerite

@hallerite hallerite commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Builds on #4801 (merged). Rebased onto the reorganized prime-rl-configs package (#4899, #4919). The full-scale DeepSeek-V4-Flash benchmark is below.

Summary

With [weight_broadcast] type = "modelexpress" and pull = true, each inference server moves itself onto every version the trainer publishes to ModelExpress (MX). Today the orchestrator pauses every engine, posts /update_weights_from_modelexpress to each and resumes them. Under pull the orchestrator pauses and pushes nothing: it only reads the version each engine serves, for its dispatch gate, the startup sync and the final evals. The bytes already moved one-sided (engines read the trainer's host copy over NIXL); now the decision to switch is the engine's too. This is the first step towards engines that an orchestrator does not manage one by one, such as engines managed by Kubernetes.

[weight_broadcast]
type = "modelexpress"
pull = true

Design

Config. pull on the ModelExpress [weight_broadcast] section (blocks/weight_broadcast.py), which reaches the trainer and the orchestrator. The engine's EngineWeightBroadcastConfig carries the pull settings: rl builds each engine's transport with the MX host, port, staging settings and timeout, and marks who pulls. The engine config builders take an EngineWeightBroadcastConfig instead of a transport name, so the standalone inference entrypoint passes its whole [weight_broadcast] and a standalone server can pull too. Who pulls:

  • single node: the server itself (weight_broadcast.pull);
  • several nodes: the multi-node template gives the first rank of each DP group --weight-broadcast.pull --weight-broadcast.host $WEIGHT_BROADCAST_HOST --weight-broadcast.group <admin URL of every rank of the group>, and the admin token to call those ranks.

weight_broadcast.group does not require pull: the template gives it to the first rank of every DP group of more than one rank, so anything else that moves a group's weights can find its ranks. weight_broadcast.model_name (default vllm.model) names the model versions are published under.

Where the puller lives. A task in the API server (inference/vllm/weight_pull.py), in API server 0 only under API server scale-out. It needs the engine controls (pause, resume, the weight-version label) that only the engine client reaches; the workers do the data plane. It drives an Engines interface (init, can_stage_live, stage, discard, pause, apply, resume, served):

  • LocalEngine: this server's engines, in process. vLLM fans every call out to all data-parallel engines of an internal-LB server.
  • EngineGroup: the ranks of an external-LB DP group, through admin routes on each rank: /modelexpress/can_stage_live, /modelexpress/stage, /modelexpress/discard, /modelexpress/apply, plus /pause, /resume and /init_broadcaster. The ranks of an expert-parallel DP group share every forward pass, so the group's first rank moves all of them.

Discovery. The puller polls list_weight_versions every 0.2 s (MX 0.8.0 has no watch RPC) and takes the newest READY version published after the one it serves. Publication order decides, not the step, so it also follows a trainer that restarted from a checkpoint back to a lower step. Versions published in between are skipped.

Staging while serving. Every worker stages the version on a background thread, with its own CUDA stream, while the engines serve; the API server polls a cheap status RPC. Staging writes only MX's own buffers, except for the first stage of a trainer's versions: it records how the trainer's tensors map onto the engine's on the live model (layout capture), so it must run paused. Workers therefore refuse to stage live until they have installed a version of the same trainer mesh, and the puller stages that first version after the pause.

  • Without staging_buffer_bytes, the stage reads the whole version into one more copy of the weights on each GPU while serving, so the pause only installs it.
  • With bounded staging, the stage only plans, and the bytes move during the pause, as with push.

The switch. Once every worker of every rank has staged, the puller pauses the engines with the running requests and their KV kept (pause_generation(mode="keep", clear_cache=False), as push does), installs the version on every worker, labels the tokens sampled from then on with its step (weight_versions on every response) and resumes. vLLM's data-parallel pause stops every rank of the group at the same step and its resume is a barrier, so no forward pass mixes versions. Groups switch independently, each as soon as it is ready: there is no global barrier, and a slow group holds up no other.

Orchestrator. ModelExpressPullWeightReceiver initializes, pauses and pushes nothing. It waits until every engine (AdminPlane.served_versions, GET /weight_version) serves the version or a newer one of this trainer, then marks it installed. A newer version counts only if its broadcast finished, so a version from before a trainer restart does not. The watcher keeps dispatching across a swap (on_version_pending is skipped when engines pull). The trainer and orchestrator still share the broadcast dir for its markers; no weights go through it.

Trainer. Each rank publishes from one host copy (MX's COPY_TO_HOST arena), refilled on every publish, so the trainer holds one version, as with push. Before publishing the next version, the master marks the previous one RELEASING, so MX accepts no new lease on it, and every rank waits until the reads still in flight release their leases (bounded by timeout). The trainer waits for no install, except at the end of training, where it keeps the last version available until the orchestrator marks it installed. A new trainer retires a previous trainer's READY versions, so engines do not try to install them. Trainer host memory stays at one copy of the weights.

Failures.

  • A stage that fails leaves the live weights untouched: every worker discards what it staged, the engines go on serving (or resume, if the stage ran paused), and the puller tries the newest version again.
  • An install that fails may leave the weights partly written. The engines stay paused and install the newest version from scratch, staged while paused, until one succeeds; past weight_broadcast.timeout the server exits. It never resumes with mixed weights.
  • MX's own guards apply: a failed install leaves its client uncertain until a full install succeeds, and a bounded refit that leaves a parameter unwritten raises IncompleteRefit.

Also.

  • GET /weight_version returns the label the engine serves; ?uid=true also returns the MX version every worker installed last (modelexpress_served, cleared while an install runs). The plain read, which the orchestrator polls, does not touch the workers.
  • WeightPuller.lock is held through every switch, for anything else that moves the same engines.
  • rl rejects pull with draft swaps, rollout checkpoints, Dynamo and staging_mode = "IN_PLACE" (engines would read weights the trainer is still updating); SFT rejects it.

Fixes pull needs.

  • Tokens newer than the trainer. Batch N trains v{N-1}, the newest version the trainer can have published. An engine that outlived a trainer restart from an earlier checkpoint keeps sampling with the old trainer's weights until it installs the new trainer's first version, and labels those tokens above N-1. The orchestrator's sink and the trainer now mask them like tokens past max_staleness: the sink keeps tokens whose version lies in fresh_versions(step, max_staleness) (orchestrator/utils.py), and transports/payload.py masks versions above trained_version. strict_staleness still drops only traces dispatched too old.
  • P/D decode lease. Groups switch independently, so a decode group can sit paused while prefill keeps serving. A paused decode engine sends no lease heartbeats, and once a lease runs out prefill reuses the blocks it held. monkey_patch_nixl_prefill_lapsed_remote_kv_locally makes decode prefill a request itself when its lease was last renewed more than half of kv_lease_duration ago.

Credit

This builds on the filesystem pull stack and on an earlier MX pull attempt:

Validation

Tiny models on one B200 node (three GPUs per run), the debug algorithm with 8 steps (every step publishes new weights), and a probe that kept long completions in flight with return_weight_versions throughout:

Run Layout Installed Warm switch: staged while serving / time to reach the pause / paused Cold first version (paused) Probe responses spanning a switch (non-monotone) Mismatch KL
Qwen3-MoE, rl one server, internal DP=2 + EP v0-v8 43-63 ms / 46-101 ms / 19-24 ms 33 s 64 (0) 0.0
DeepSeek-V4, online MXFP8, rl one server, internal DP=2 + EP v0-v8 0.13-0.17 s / 0.13-0.39 s / 38-54 ms 0.5 s 40 (0) 5e-4
Qwen3-MoE, group leader two external-LB servers of one DP=2 EP group; rank 0 pulls for both v0-v8 on both ranks 53-65 ms / 55-140 ms / 20-29 ms 29 s 28 per rank (0) 0.0
Qwen3-MoE, P/D 1P1D with NIXL KV transfer, each role pulling for itself, P/D router v0-v8 on both roles 54-93 ms / 21-28 ms / 11-22 ms 27 s 36 (0) 0.0
  • No engine received /pause, /resume, /update_weights_from_modelexpress or /init_broadcaster from the orchestrator. In the group-leader run, each rank received one /modelexpress/stage, /pause and /resume per version, from rank 0. Where the probe read GET /weight_version (both single-server runs, both ranks of the group), it went 0, 1, ..., 8, and both ranks of the group changed version at the same moments.
  • Every probe response's version spans were monotone and covered all its tokens. The only unlabeled tokens (default) were sampled from the checkpoint weights before v0, before the orchestrator dispatched anything; none follows a labeled span.
  • The cold first install is dominated by MX's first NIXL connection setup; push takes as long (28.7 s for its first update in an earlier tiny-model run on the same kind of node).
  • Trainer: each publish took 10-30 ms, of which retiring the previous version took at most 10 ms.

Bit-exactness. #4805's tool, with a mode in which the engine pulls each version itself and the trainer waits until the version was fingerprinted before publishing the next (that mode is not part of this PR). The engine cold-loads W0, and its digests are the oracle; the trainer then publishes W0, W0 + D1, W0, W0 + D2, W0. v0 stages while paused, v1-v4 while serving. All pass: every W0 step equals the cold-load digests, and every floating-point parameter changes at both perturbed steps.

Model Engine Staging Engine tensors
Qwen3-MoE 1 GPU full copy 30
Qwen3-MoE 1 GPU bounded (128 MiB x 2) 30
Qwen3-MoE internal DP=2 + EP full copy 64
DeepSeek-V4, bf16 internal DP=2 + EP full copy 188
DeepSeek-V4, online MXFP8 1 GPU full copy 115

Unit tests. New: the puller's switch protocol (live and cold staging, skipped versions, a restarted trainer, stage and install failures, a failed pause), the worker's background staging, the trainer's retire-before-publish order, the receiver, the config and CLI of a group leader, and pull's config rejections including IN_PLACE. Regression cases, each failing without its fix: a token newer than the trainer (test_partially_stale_trace_ships_fresh_tokens[newer-than-the-trainer], through the sink and the trainer's batch) and the decode lease guard on vLLM's real scheduler. CPU-only, with the pinned verifiers and renderers: the eleven suites this branch touches (pull, ModelExpress boundary, admin clients, Dynamo, train sink and its payloads, payload, batch transport, planner, P/D scheduler, configs) pass, 791 tests.

Launcher. A multi-node rl config with pull renders a SLURM script that passes bash -n, both for one expert-parallel DP group of 16 ranks over two nodes and for 1P1D. Run from the rendered script, weight_group_args gives rank 0 of the group the pull arguments and all 16 admin URLs and the other ranks none, and rank 0's arguments parse with the engine CLI the ranks launch with. Engine configs set pull only on a single node; on several nodes the launcher marks the leaders.

Full-scale benchmark (DeepSeek-V4-Flash, 284B)

Setup:

  • One trainer node, plus two inference nodes, each one aggregated DP8+EP engine (online MXFP8) behind the router, on B200.
  • The launch goes through the multi-node template, so each engine's DP group has 8 single-rank servers and a group leader.
  • RL steps plus 1,024 background sessions keep inference busy during updates.
  • p50 over 17 warm updates per run. All runs use the same code and settings except the weight-update mode.
push pull, bounded staging (2 x 4 GiB) pull, full-copy staging (gpu_memory_utilization 0.45)
Pause per DP group 4.82 s 3.66 s 0.97 s
Client-visible stall per rank 5.46 s 3.91 s 1.36 s
Pause beyond the slowest worker's own work 1.11 s 0.05 s 0.04 s
Stage before the pause (while serving) n/a 1.09 s 5.12 s
Install while paused 4.12 s per rank 3.63 s 0.94 s
Skew between the two engines' switches 0.22 s 0.08 s 0.31 s
Publish to all engines serving 5.71 s 5.40 s 6.75 s
Trainer step 26.79 s 21.59 s 21.88 s
Decode tokens lost per update 86.9k 75.6k 39.8k
Decode tok/s during an update, both engines 1.9k 3.4k 11.5k
Decode tok/s, whole run, both engines 13.9k 13.9k 15.5k
Mismatch KL / loss / entropy / grad norm (means) 0.00282 / -0.04166 / 0.163 / 0.398 0.00270 / -0.04165 / 0.164 / 0.414 0.00273 / -0.04165 / 0.161 / 0.385

What changes with pull:

  • The orchestrator's round trips go. The pause beyond the workers' own install falls from 1.11 s to 0.05 s.
  • The trainer stops waiting for installs (5.5 s per step in push), so its step drops from 26.8 s to 21.6 s.
  • Bounded staging still moves the bytes inside the pause: about 84 GB per GPU at this size.
  • Full-copy staging moves them while serving and leaves only the install in the pause: 0.97 s per DP group. Decode keeps 11.5k tok/s through an update, and each update costs 54% fewer decode tokens than push. It needs a second bf16 copy of each GPU's weights, hence gpu_memory_utilization 0.45. At this load KV usage was 12%.
  • With bounded staging, the faster trainer step means more updates per second. So the whole-run decode throughput stays level even though each update costs less.
  • Numerics are unchanged within run-to-run noise. This is a distributional comparison, since each run samples its own rollouts.

The trainer's pre-broadcast torch.cuda.empty_cache() (#4823) was still in all three runs. Skipping it under ModelExpress saved a further 5.4 s per broadcast plus the next step's memory re-acquisition in a separate push run.

Not yet validated

  • Full-scale DeepSeek-V4-Flash: measured, see "Full-scale benchmark" below. Not yet run at scale: P/D, and a failed install at scale.
  • Execution of the multi-node SLURM template with pull. The same group-leader code ran on one node with servers launched by hand, as the template launches them.
  • P/D at scale, including a decode group paused past half of the NIXL KV lease: the decode lease guard is tested on vLLM's scheduler only.
  • The GPU runs above predate the rebase onto the reorganized config package. The rebase changed how the pull settings reach each process, not the puller, the workers or the trainer.

Known limits

  • Draft swaps (orchestrator.speculative_decoding) are off with pull. Speculative decoding runs with the draft the engines launch with; a drafter that shares the target's embedding or LM head reads the updated ones, since they alias the target's storage and MX installs in place. A draft swap would have to happen at the engine's own switch.
  • Rollout checkpoints, Dynamo, SFT online evals and staging_mode = "IN_PLACE" are rejected with pull.
  • A pulling engine takes the ModelExpress host from its config, which the multi-node template sets at runtime. It does not read PRL_WEIGHT_BROADCAST_HOST, which Kubernetes deployments set for the trainer.
  • MX 0.8.0 never deletes retired versions, so every poll lists one more version per published step. feat(refit): cap concurrent source readers and delete retired versions ai-dynamo/modelexpress#992 deletes them, and would also let the trainer free its copy without waiting for readers.
  • With bounded staging, which large models need (a full copy of a large expert-parallel shard does not fit beside the KV cache), the background stage only plans and the bytes still move during the pause. The pause then stays close to push's transfer time; what pull removes is the orchestrator's barrier and the trainer's wait for every install.

🤖 Generated with Claude Code


Note

High Risk
Changes core weight sync, multi-node admin auth, and training staleness rules; failed installs can pause or exit inference servers past timeout.

Overview
Adds weight_broadcast.pull for ModelExpress so inference engines discover and install new policy versions on their own instead of the orchestrator pausing every engine and pushing each update.

Each API server runs a WeightPuller that polls ModelExpress, stages weights on workers (in the background while serving when safe), then pauses with KV kept, installs, and resumes. Multi-node expert-parallel groups are coordinated by the first rank of each DP group via admin routes (/modelexpress/*, /pause, /resume) and weight_broadcast.group. The orchestrator only polls GET /weight_version through ModelExpressPullWeightReceiver; the trainer publishes without waiting for installs (retiring the previous version when in-flight reads finish).

Configs wire EngineWeightBroadcastConfig, SLURM templates pass pull args and admin tokens to group leaders, and pull is rejected with draft swaps, Dynamo, rollout checkpoints, IN_PLACE staging, and SFT online evals. Supporting fixes include staleness masking for tokens labeled newer than the trainer (fresh_versions) and a NIXL patch so decode prefills locally when KV leases may have lapsed while a rank was paused for a weight switch.

Reviewed by Cursor Bugbot for commit d397d5b. Bugbot is set up for automated code reviews on this repo. Configure here.

@wiz-prime-intellect

wiz-prime-intellect Bot commented Nov 28, 2026 •

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.

With [weight_broadcast] type = "modelexpress" and pull = true, each
inference server (on several nodes, the first rank of each DP group, for
all its ranks) follows the versions the trainer publishes to ModelExpress:
it stages the newest one while serving, then pauses, installs and labels
it, and resumes. The orchestrator only reads the version each engine
serves, and the trainer publishes without waiting for installs.

Rebased onto the reorganized prime-rl-configs package (#4899, #4919):
- pull lives on the ModelExpress section (blocks/weight_broadcast.py) and
  the engine's EngineWeightBroadcastConfig carries the pull settings;
- the engine config builders take an EngineWeightBroadcastConfig, so rl,
  sft and the standalone inference entrypoint pass the full transport;
- rl rejects pull with Dynamo, draft swaps, rollout checkpoints and
  staging_mode = "IN_PLACE" (engines would read weights the trainer is
  still updating); sft rejects pull.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hallerite
hallerite removed this pull request from stack #4830 December 3, 2026 21:54
hallerite and others added 2 commits December 3, 2026 21:58
…iner's

Batch N trains on v{N-1}, the newest version the trainer can have
published. A token labelled with a newer version comes from an engine that
outlived a trainer restart from an earlier checkpoint and still samples
with the old trainer's weights; with engines that pull their weights, such
an engine keeps serving until it installs the new trainer's first version.

The sink now keeps queued tokens whose version lies in fresh_versions(step,
max_staleness), a range from the oldest fresh version to v{step-1}, and
the trainer masks the same tokens when it builds the batch. The sweep no
longer skips traces dispatched with a fresh version, since those can hold
newer tokens; strict_staleness still drops only traces dispatched too old.

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

With engines that pull their weights, P/D groups switch independently, so
a decode engine can sit paused while prefill keeps serving. A paused decode
engine sends no lease heartbeats; once a lease runs out, prefill frees and
reuses the blocks it held, and decode would read another request's KV.
When decode is about to start a read whose lease was last renewed more than
half of kv_lease_duration ago, it now prefills the prompt itself.

From #4779, which needs it for the same reason under filesystem pull.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hallerite
hallerite marked this pull request as ready for review December 3, 2026 22:06

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d397d5b. Configure here.

version_marker = self.step_dir(step) / VERSION_MARKER
pending = installed.with_suffix(".pending")
pending.write_text(version_marker.read_text() if version_marker.exists() else "")
pending.replace(installed)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull receive writes deleted broadcast dir

High Severity

With pull, the trainer no longer waits for the orchestrator, and _clean deletes every broadcast directory older than the previous step. ModelExpressPullWeightReceiver.receive still writes .installed into that directory after engines catch up. If the trainer publishes two further versions first, the directory is already gone and the write raises FileNotFoundError, which kills the weight watcher.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d397d5b. Configure here.

label = await engine_client(request).get_weight_version()
except RuntimeError:
return {"version": None}
return {"version": int(label) if label.isdigit() else None}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weight version endpoint rejects unset label

Medium Severity

GET /weight_version calls label.isdigit() whenever get_weight_version does not raise. Before the first update that label is None, so the handler raises AttributeError instead of returning {"version": null}. The orchestrator polls this route for the dispatch gate and startup sync, and each poll becomes a 500 until an install sets a numeric label.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d397d5b. Configure here.

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