mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4175] [Engine] hot-swap the running model at runtime #4934
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4934
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/4175
Author: @jdobson1
Created: 10/26/2026
Status: 🔄 Open
Base:
main← Head:feat/runtime-model-load📝 Commits (3)
14598d5feat(server): runtime model hot-swap + dashboard picker179a43dfix(tokenizer): a non-byte vocab token is its own UTF-8 textd07b812fix(server): a model swap rebuilds every tokenizer-derived cache📊 Changes
4 files changed (+235 additions, -3 deletions)
View changed files
📝
serve/server.py(+173 -0)📝
serve/web/app.js(+46 -1)📝
serve/web/index.html(+11 -0)📝
tools/strata_tokenizer.py(+5 -2)📄 Description
Problem
Strata serves one model per server process. To change the model you stop the
server and start it again on the new one — a full restart that drops the API
and makes every client reload. On a machine that runs several models on one
card (this one switches between Qwen3.8-Flash-Next and DeepSeek V4.1), that
restart is minutes of downtime every time the model is changed.
Result
The server can now swap its engine in place while it keeps running. A new
POST /v1/models/<name>/loadunloads the current engine, builds the target'sfrom its
strata-<name>.jsonrun config, and adopts it atomically. Thedashboard picker lists the switchable models from
serve/strata-*.json(
GET /v1/models/available). Requests answer 503 only for the length of theswap. The swap works for a different engine binary too (DeepSeek's dsv41), not
just variants of the one already running.
Approach
serve/server.py—start_swapruns the work in a background thread andPOST .../loadreturns 202 at once; requests answer 503 while it runs._do_swapfrees VRAM/RAM first, builds the other model with the samehelpers
main()uses — including its ownexefrom the config, so a configcan name a different engine binary — then adopts it under the status lock.
The swap rebuilds every tokenizer-derived cache (
stop_idsand thePromptEncoderinself.prompts), not justself.tok/self.template, soa model with a different vocab is tokenized with its own tokenizer (#537).
tools/strata_tokenizer.py— a literal-token char from a non-byte vocab(DeepSeek's |/▁) is the token's own UTF-8 text, not a byte-alphabet lookup;
token_bytesfalls back to the char's UTF-8 bytes instead of raisingKeyError, so the model's special tokens detokenize.Validation
serve/test_lifecycle.py: 9/9 pass (model discovery, on-demand load, safeunload, streaming reload).
serve/test_detok.py: pass (the five pack-vocab cases skip without a localpack on the test path; the rest pass).
(24560 MiB) with the server's own 60.9 GiB RAM:
iq3_s(Qwen3.8-Flash-Next, engine 0.1.46.2) →deepseek-v4.1-flash→iq3_s. Each side served real responses afterwards.routed experts read mostly from the CPU lane, 5.86 GB weights + 17.59 GB of
the hottest experts on the card (2000 of 15360), the rest in place on CPU.
<|end▁of▁sentence|>rendered correctly in the reply,confirming the
token_bytesfix live.Limits
(seconds when the files are warm on disk, longer for a cold model).
replicas) configs are not hot-swappable yet;the swap refuses one and says to restart the server with that model.
a request is in flight.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.