Swapping model on the fly

Credits to Scicom (MSC) Berhad and Scicom AI Enterprise for the resources.

We had a problem: we retrain often, so the model behind the API keeps changing, but every GPU is already serving and there's no spare one to load the new model on. Swapping meant either downtime or squeezing two models onto the same cards. So we built a way to swap on the fly.

Why the stock rollout doesn't fit

Editing a DynamoGraphDeployment lets Dynamo's operator roll each component with maxSurge. On our cards:

  • No room for a surge. Engines run at 70% of GPU memory. A second 70% doesn't fit.
  • Prefill and decode roll separately. The new prefill must hand off to the new decode.
  • Ready isn't routed. A pod passing its probe doesn't mean the router sends it traffic yet.

Doesn't something already do this?

What each tool decides. Kueue: may this workload start yet. Volcano or KAI: which node its pods land on. HAMi: which card and how much of it. Run:ai: all of the above plus a rolling update per workload. DynamoSwap: in what order prefill and decode slots come and go, and whether the router has sent each one traffic.
They schedule pods. None of them sequences a prefill + decode swap.

Run:ai has rolling updates, but per workload:

Run:ai docs: rolling updates support real-time, disruption-free updates to inference workloads.
From the Run:ai inference overview.

Its GPU memory swap keeps several models on one GPU by paging the idle ones to CPU RAM. That's model multiplexing, not a version swap, and it needs Run:ai's scheduler instead of HAMi:

Run:ai docs: the model in use is loaded into GPU memory and the rest of the models are swapped out to CPU memory.
From Run:ai GPU memory swap.

Kueue decides when a job may start. It doesn't care what replaces what:

Kueue docs: Kueue decides when a job should wait, when a job should be admitted to start, and when it should be preempted.
From the Kueue overview.

Volcano (and KAI) are batch schedulers: gang scheduling, queues, fair share. They'd place the bridge, not retire the old slot:

Volcano docs: Volcano is a cloud native system for high-performance workloads, the CNCF batch scheduling project.
From What is Volcano.

HAMi is what makes two engines fit on one card. It has no idea what a model version is.

So it became a small operator.

The CRD

A DynamoSwap holds spec.model, a served name, and a worker spec. Edit spec.model, push, Argo CD applies it. A Python loop reconciles every 10 s and creates each step as its own workers-only DynamoGraphDeployment.

The swap in five phases, as one card's memory: old at 70%; old 70% plus new 27% bridge; old drained prefill first, leaving the bridge; bridge plus new 70%; new 70% only.
One card's memory through a swap. The new model loads twice: at 27%, then 70%.
  • 70% + 27% fits (about 98% of card memory). 70% + 30% doesn't.
  • "Routed" is checked: every frontend must list the new slot in /health and show traffic to it in /metrics.
  • Fails safe: a bridge that isn't routed in 30 min is removed, the old model keeps serving.

The failed requests

The first run deleted the old slot whole: 0.02% of requests got 503. The decode unregistered a few milliseconds before its prefill.

Fix: scale the old prefill to 0 first. The router drops an incomplete slot immediately, the decode finishes what's in flight (60 s grace), then it goes. Next run: 0% failed.

Request time relative to normal over two swaps: run 1 shows 503s at the delete; run 2, prefill first, has 0% failed.
The bumps are the new engine warming up on shared cards, see resolving the time-slicing issue.

Results

Run Requests served
Lab, old slot deleted whole 99.98%
Lab, prefill first 100%
Production move, one node → two nodes 99.96% (the one failure was a proxy outside the cluster)
Node handed back to training, two nodes → one 100%

Two shortcuts

  • Reload in place. Same architecture, tokenizer and template, new weights? Pause both engines, call Dynamo's update_weights_from_disk, resume. About 99% faster than a bridge swap, 0% failed, outputs identical to a fresh engine.
  • Cache seeding. Reading the weights is under 1% of a cold start; the rest is torch.compile, CUDA graphs and FlashInfer autotune. A Job copies warm caches from NFS to the node before engines start, which cuts startup by roughly 50-65%.

Costs

  • A bridge swap loads the new model twice, so it takes tens of minutes.
  • Latency spikes while two engines share cards. Swap off-peak or use MPS.
  • Streams longer than the 60 s grace get cut.