Skip to content

Weight updates ​

Use this reference to coordinate checkpoint and distributed weight updates, weight versions, and GPU memory release during reinforcement learning (RL) workflows. For the initial API flags, see API parameters.

Weight versions ​

The weight loads (see RL weight updates) take an optional weight_version. With L3 storage on, it names the namespace that new pages publish under (--weight-version names the first one), and it changes only after the load succeeds on every rank. A new weight_version requires flush_cache=True, and a flushed load must name its version, so independent checkpoints cannot share a namespace. Intermediate loads pass None to keep the current one until the last load flushes. Without L3 storage the engine keeps no version.

RL weight updates ​

An RL trainer's operations are control operations on the engine's wire (zmq_wire.CONTROL_REQUESTS). The frontend that drives the engine sends each to every engine of the replica and gets every engine's reply, through the engine's client library (ts-client, or its Python binding, tokenspeed_engine.FrontendListener):

  • update coordination: PauseSchedulerReqInput, ResumeSchedulerReqInput, and FlushCacheReqInput;
  • NCCL weight sync: InitWeightsUpdateGroupReqInput, UpdateWeightsFromDistributedReqInput, and DestroyWeightsUpdateGroupReqInput;
  • checkpoint loads: UpdateWeightsFromMooncakeReqInput and UpdateWeightFromDiskReqInput;
  • memory control: ReleaseMemoryOccupationReqInput and ResumeMemoryOccupationReqInput.

TokenSpeed serves no HTTP route for them. ts serve's gateway (SMG's direct lane) serves them under its /v1/rl routes (--enable-rl), with the SGLang-compatible route names and bodies: each POST route is a control call of the same name on every engine of the worker, its JSON body the call's argument, read with the route's field names and defaults (ts-control/src/calls.rs): pause_generation, continue_generation, init_weights_update_group, destroy_weights_update_group, update_weights_from_distributed, update_weights_from_disk, update_weights_from_mooncake, release_memory_occupation, resume_memory_occupation, rebalance_experts, and flush_cache. The GET routes, such as get_weight_version, have no call, and a response's weight_version stays the one the engine registered with. Attention data parallelism (DP) of any size is supported: the scheduler completes an operation only in a round where every DP rank holds it (see Weight updates under attention DP). Real rollout log probabilities require --enable-output-logprobs.

A one-rank world (TP1, no DP) defaults NCCL_BUFFSIZE to 64 KiB for its process, since its own communicators move no data between peers. NCCL reads the size once per process, so the NCCL group that init_weights_update_group joins inherits it, and weight broadcasts stage through those small buffers; the engine warns when it joins. For RL weight sync on a single-GPU engine, set NCCL_BUFFSIZE in the server environment (for example 4194304, NCCL's default); an explicit setting is never overridden.

GPU memory release with the --enable-memory-saver flag ​

When you use --enable-memory-saver, set --weight-memory-policy cpu_backup|discard explicitly. The host Python package, native host, and kernel package must be built from matching sources; an older native host is rejected before device initialization. See weight memory policies for the update contract and validation procedure.

ReleaseMemoryOccupationReqInput frees GPU memory between rollouts so a trainer colocated on the same GPUs can use it; ResumeMemoryOccupationReqInput maps it back. Both take optional tags. A release without tags frees every region the engine has, and a resume without tags restores whatever is released. The following table describes the memory that each tag controls and its resume behavior:

TagMemoryOn resume
kv_cachethe cache arena's device regionszeroed; a PD engine registers it with the transfer engine again
weightsmodel and draft parameters, persistent attention/runtime buffers, and shared workspacesparameters use CPU backup or remain invalid until a complete update; frozen drafts and attention/runtime buffers retain CPU backup
cuda_graphthe decode CUDA graphs' memory pooldiscarded; replays rewrite it
acl_graphAscend decode graph private pools--acl-graph-memory-policy selects discard (default) or cpu_backup; see Ascend Memory Saver for eligibility, dependencies, and wake order
ncclNCCL communicator buffers (ProcessGroupNCCL.suspend); requires a PyTorch build with suspend support and NCCL 2.29.7 or laterresumed in place

A release waits until the scheduler is drained, and on a disaggregated (--disaggregation-mode prefill|decode) engine also until no request is bootstrapping, no pages are pinned for a transfer, and the transfer peer holds no sender or receiver. While a release is draining or memory is released, a disaggregated engine finishes new requests with an abort. Weight updates are refused while weights or nccl is released. To release memory, train, and push new weights, follow this order:

  1. Release every memory region.
  2. Train the model.
  3. Resume ["nccl", "cuda_graph", "weights"] (without nccl on an older NCCL).
  4. Push the new weights with UpdateWeightsFromMooncakeReqInput.
  5. Resume ["kv_cache"].

With discard, KV must be released before the weight update and cannot resume until every rank has loaded and committed the complete version. Under either policy, a weight load that fails after it started requires a restart; an update that any rank refuses before loading runs on no rank and can be retried. A bare resume of all tags immediately after discard is therefore invalid. Sparse KV offload keeps its pinned Host history mapped across a release and zeroes it on resume. Persistent attention/runtime buffers and shared workspaces are backed up with the weights tag, retaining their addresses and contents. Other device memory, including communication workspaces such as symmetric memory or DeepEP buffers and prefill CUDA graph capture pools, stays resident.

With attention DP, every rank must stop admissions and drain before any rank releases memory. Send the release to every DP engine concurrently; a release itself stops admissions, so a separate pause is unnecessary. A peer explicitly paused with wait or abort may also satisfy the drain. An idle engine that has not paused prevents release. After a partial or staggered resume, no DP rank forwards until every region released on every rank has been restored.

Queued weight operations finish before a release frees memory. If a PD engine is paused with buffered requests, release is refused: resume and drain those requests first. While any region is released, a pause is refused; resume the memory first.

With memory saver enabled, startup skips the disposable CUDA-graph memory probe and captures the serving graphs once. The installed memory saver cannot destroy a tagged probe pool and then capture again. Graph memory is therefore not reserved by that probe; leave headroom in --gpu-memory-utilization.

Disk checkpoint updates ​

UpdateWeightFromDiskReqInput reloads the weights in place from a checkpoint directory (model_path, and load_format, which defaults to the server's). It takes the same scheduler path as the distributed and Mooncake updates: the weight_version checks, the attention-DP same-round gate, a cache flush before the load, and the replica-wide result. The reply counts the checkpoint tensors actually read, and a checkpoint that yields none is a failure. Load formats that do not read checkpoint files (for example dummy) are refused. The checkpoint is streamed the way the startup load streams it, so a model that reads tables from its checkpoint directory (DeepSeek-V4.1's Engram tables) reads them from the new one.

The request is refused, with nothing written, when the startup loader transformed the model's weights after loading them, because a checkpoint holds those weights untransformed: quantized checkpoints (FP8, MXFP4, NVFP4, compressed-tensors), and MoE layers whose kernel repacks the experts, which includes the FlashInfer TRT-LLM and CUTLASS kernels for unquantized experts. Restart the engine with the new checkpoint instead. Unquantized dense models, and unquantized MoE on a kernel that keeps the checkpoint layout (the Triton kernel, or the Gluon kernel on gfx950), reload in place.

For a safetensors checkpoint the shard headers are read before the first write. A shard shorter than its header declares (for example, one still being written) or a tensor whose shape differs from the same name in the checkpoint the model holds fails the request with the weights unchanged. The held shapes are captured from the files selected at startup, so this check survives removal of the original source. A dummy/config-only startup snapshots already-local safetensors headers if readable; it does not download weights for this check. Unreadable optional dummy headers produce a warning and an empty snapshot. Without a snapshot (including object-store streams and loaders that do not provide canonical checkpoint shapes), only the new shards' header validity is checked, without a held-source shape comparison. A failure after the load has started says that the worker's weights may now mix the two checkpoints: reload a complete checkpoint or restart the engine before relying on its output. The weight version does not advance on any failure.

Unsupported CUDA-IPC updates ​

UpdateWeightsFromTensorReqInput (colocated CUDA-IPC updates) fails before anything reaches the scheduler: TokenSpeed's scheduler does not implement the CUDA-IPC receive path. Use the distributed or disk update, or the Mooncake weight update.

Weight updates under attention DP ​

With --data-parallel-size > 1, the frontend sends every weight operation to every attention-DP engine and combines their replies. Each scheduler queues the op and completes it only in a round where every DP rank holds the same kind of op at the head of its queue, decided on the per-round DP all-reduce that already carries flush intent. One op completes per round. TokenSpeed then MIN-reduces the device result across the replica before it publishes the L3 weight version, so a failure on one rank fails the update everywhere. A rank whose peer never receives the op waits indefinitely, as with a cache flush. For the design rationale, see Event loop: design principles.

The engine does not wait for running requests before a load: a request that runs across one generates under both weights. When that matters, pause first (see the Trainer-side contract section of this page).

Mooncake weight updates ​

Install a Model Updater SDK provider in every scheduler environment and select its import path with --model-update-sdk-module. TokenSpeed supplies the update session and control-plane coordination; the provider owns store access, model support, and publication metadata. The standalone WeightStore receiver is supplied by an external plugin rather than bundled with the runtime. Follow that provider's documentation for its module path, dependencies, and configuration.

UpdateWeightsFromMooncakeReqInput loads one committed checkpoint version that the RL trainer published to a Mooncake weight store through the Model Updater SDK. Fields: version (an integer), flush_cache (default true), weight_version (optional), and snapshot (optional SDK publication metadata passed unchanged to the provider). Every scheduler process reads its own shard with its global rank as the SDK reader rank, on the forward thread, ordered against forwards like the distributed update. The reply arrives only after every worker finished its read.

Start the server with the four --model-update-* flags in the API parameter reference: the engine imports the SDK module lazily on the first update, and a missing module fails that update with a clear message rather than failing startup. --model-update-draft-weights retain updates the target model only. refresh streams the target and the speculative draft model (every pipeline stage that holds draft weights). Both policies notify the drafter afterwards like the distributed update does.

flush_cache and weight_version follow the distributed update's rules with one default: a flushed Mooncake update publishes weight_version = str(version) when none is given (an explicit value wins). An unflushed update keeps the current namespace unless one is given, and with L3 storage a new weight_version still requires flush_cache=true. A successful update stamps the version into generation metadata.

Trainer-side contract ​

  • Pause dispatch at the router, or the engine (PauseSchedulerReqInput), before calling and resume after the reply: requests that run across the load generate under both weights. The scheduler's control thread blocks for the duration of the SDK read, so load reporting, PD transfer polling, and health responses stall on every worker.
  • While PD transfers or Host write-backs are in flight on any replica rank, the engine rejects flush_cache=true (and skips the load). Retry after they drain, or send intermediate updates with flush_cache=false and flush on the last one.
  • Model update session: the SDK streams (name, tensor) pairs into each model's load_weights in many partial calls. The runtime brackets the models in a weight-update session (begin_weight_update / end_weight_update on BaseCausalLM) so a model derives its post-load state once, after the last chunk: BaseCausalLM defers every post_load_weights call made while the session is active and runs it once at the end, so a model's loader needs no session awareness of its own. The update rewrites the absorbed MLA w_kc/w_vc and the KDA conv banks in their existing storage (captured CUDA graphs keep valid addresses; a geometry change is an error). In-place one-shot transforms such as the LoRA norm scale fold apply only to the parameters this update reloaded, and fused parameters assembled from several checkpoint tensors (the NextN drafts' q_a_proj/kv_a_proj_with_mqa, GLM's FP8 indexer wk weight and scale) may straddle chunks. When the session ends, it rejects an update that streamed one half without the other. The session also screens every chunk for KV-cache scales other than one (the runtime writes and reads KV caches at unit scale): it loads such an update to completion and then rejects it, like the distributed update's. Models outside BaseCausalLM take no session hooks. The distributed update uses the same session.
  • The engine does not roll back a failed update (success: false): the SDK may already have rewritten part of the parameters on some ranks, so the engine may be serving a mix of old and new weights, and replicas may disagree. The engine keeps the current weight version. Re-issue the update (a successful retry streams the whole checkpoint and restores consistency) or restart the engine before resuming dispatch. The same holds for the distributed update.

TokenSpeed documentation