ttx sweep-resident: one boot per B, arms re-armed in place (weights stay on the cards) #113

Closed
Grok wants to merge 1 commit from resident-rearm into master
Owner

Why

A sweep32k arm costs one boot per B, about 340 s:

Boot phase (c72 T2 equiv boot, 2026-09-27, boot_s 337.9) Time
Container and Python start ~34 s
Mesh open and weight load ~118 s
Engine init, including 70 s of compile 135 s

A queue step with two boots takes ~1050–1100 s, of which ~680 s is booting (c70 and c72 r1). Most of our A/Bs differ only in QWEN36_* flags that load the same tensors.

Upstream has no support for keeping device buffers after the process exits. What it does instead is keep the process running:

  • tt-metal#57574 keeps MiniMax-M3 resident across measurements;
  • tt-metal#50139 keeps one persistent mesh per job.

This PR does the same for our vLLM server: the server, mesh and weights stay up, and only the model is rebuilt.

What

  • tools/ttx/clients/ttx_rearm_ext.py, a vLLM --worker-extension-cls. It needs no plugin or vLLM patch.
    • Weight registry: it wraps ttnn.as_tensor(cache_file_name=...), so a rebuild gets the same device tensors back instead of re-reading the tensorbins.
    • ttx_rearm, called through VLLM_SERVER_DEV_MODE=1 → POST /collective_rpc. It releases traces, KV and the model, reloads the qwen36 package under the new env, rebuilds through initialize_vllm_model, re-allocates KV and warms up.
    • It refuses without touching anything when:
      • a changed key is read outside the qwen36 package (a grep of the served sources);
      • the engine's boot-time sizing would move (KV block count or KV spec, checked under the new env);
      • the engine has requests in flight.
    • It stops if teardown leaves more DRAM allocated than the old model's post-build figure.
  • ttxlib/resident.py and ttx sweep-resident A B C --seqs 8 1.
    • One boot per B; each compatible arm is re-armed, and the rest are booted as usual.
    • Records are ordinary sweep32k records plus a resident section (boot_kind, re-arm timings, registry hits and misses, DRAM).
    • Identity is re-read from the log after the TTX_REARM_BEGIN marker. A banner from the original boot counts only if its flag did not change.
  • --validate B, the fidelity gate. It boots A and captures equiv, re-arms to B and captures, re-arms back to A and compares with A cold, then boots B cold and compares with B re-armed. Both compares must be BIT_EXACT.
  • Docs: DEV-LOOP §2a and the tt-bench skill.

Checked (no cards)

  • 10 new unit tests covering the registry, env classification, the re-arm flow, the DRAM-leak stop, the sizing refusal, the ttx compatibility and identity rules, and the client. The full ttx suite passes.
  • In the vllm-tt:k2-mr-pk4 image, run without --device:
    • the extension imports and wraps as_tensor and load_model;
    • it clashes with no TTWorker attribute;
    • vLLM 0.26 has --worker-extension-cls.
  • With the prod overlays mounted:
    • QWEN36_DEVICE_RESIDENT, QWEN36_FABRIC_PAYLOAD and QWEN36_MTP_BATCH classify as boot-level;
    • MR, SDPA GQA mcast, GDN fused and QWEN36_PREFILL_RS_CFG classify as model-level.

There has been no hardware run, so there is no speed number yet.

To queue once this is on the tree the queue runs

timeout=90m ttx sweep-resident prod-g2-EFS-c70 prod-g2-c72-T2 --validate 8
reboot_if_leak
timeout=80m ttx sweep-resident prod-g2-EFS-c70 prod-g2-c72-T2 --seqs 8 1

The second line is quotable only if the first passes. Its cells should also match the existing cold c70/c72 r1 records within noise.

Our boot log shows 130 Pinned source memory ... must be aligned 64 B fallbacks. That is the slow path described in tt-metal#56146, and tt-metal#57758 measured TT_METAL_PINNED_MEMORY_CACHE_LIMIT_BYTES=0 loading 10× faster (1.41 → 15.0 GB/s). A one-boot check, e.g. ttx run prod-g2-c72-T2 --env TT_METAL_PINNED_MEMORY_CACHE_LIMIT_BYTES=0 --suite smoke, compares its load time against the ~118 s above.

🤖 Generated with Claude Code

## Why A sweep32k arm costs one boot per B, about 340 s: | Boot phase (c72 T2 equiv boot, 2026-09-27, boot_s 337.9) | Time | |---|---| | Container and Python start | ~34 s | | Mesh open and weight load | ~118 s | | Engine init, including 70 s of compile | 135 s | A queue step with two boots takes ~1050–1100 s, of which ~680 s is booting (c70 and c72 r1). Most of our A/Bs differ only in `QWEN36_*` flags that load the same tensors. Upstream has no support for keeping device buffers after the process exits. What it does instead is keep the process running: - tt-metal#57574 keeps MiniMax-M3 resident across measurements; - tt-metal#50139 keeps one persistent mesh per job. This PR does the same for our vLLM server: the server, mesh and weights stay up, and only the model is rebuilt. ## What - **`tools/ttx/clients/ttx_rearm_ext.py`**, a vLLM `--worker-extension-cls`. It needs no plugin or vLLM patch. - **Weight registry:** it wraps `ttnn.as_tensor(cache_file_name=...)`, so a rebuild gets the same device tensors back instead of re-reading the tensorbins. - **`ttx_rearm`**, called through `VLLM_SERVER_DEV_MODE=1` → `POST /collective_rpc`. It releases traces, KV and the model, reloads the qwen36 package under the new env, rebuilds through `initialize_vllm_model`, re-allocates KV and warms up. - **It refuses without touching anything when:** - a changed key is read outside the qwen36 package (a grep of the served sources); - the engine's boot-time sizing would move (KV block count or KV spec, checked under the new env); - the engine has requests in flight. - **It stops if teardown leaves more DRAM** allocated than the old model's post-build figure. - **`ttxlib/resident.py`** and **`ttx sweep-resident A B C --seqs 8 1`**. - One boot per B; each compatible arm is re-armed, and the rest are booted as usual. - Records are ordinary sweep32k records plus a `resident` section (`boot_kind`, re-arm timings, registry hits and misses, DRAM). - Identity is re-read from the log after the `TTX_REARM_BEGIN` marker. A banner from the original boot counts only if its flag did not change. - **`--validate B`**, the fidelity gate. It boots A and captures equiv, re-arms to B and captures, re-arms back to A and compares with A cold, then boots B cold and compares with B re-armed. Both compares must be BIT_EXACT. - Docs: DEV-LOOP §2a and the tt-bench skill. ## Checked (no cards) - 10 new unit tests covering the registry, env classification, the re-arm flow, the DRAM-leak stop, the sizing refusal, the ttx compatibility and identity rules, and the client. The full ttx suite passes. - In the `vllm-tt:k2-mr-pk4` image, run without `--device`: - the extension imports and wraps `as_tensor` and `load_model`; - it clashes with no `TTWorker` attribute; - vLLM 0.26 has `--worker-extension-cls`. - With the prod overlays mounted: - `QWEN36_DEVICE_RESIDENT`, `QWEN36_FABRIC_PAYLOAD` and `QWEN36_MTP_BATCH` classify as boot-level; - MR, SDPA GQA mcast, GDN fused and `QWEN36_PREFILL_RS_CFG` classify as model-level. **There has been no hardware run, so there is no speed number yet.** ## To queue once this is on the tree the queue runs ``` timeout=90m ttx sweep-resident prod-g2-EFS-c70 prod-g2-c72-T2 --validate 8 reboot_if_leak timeout=80m ttx sweep-resident prod-g2-EFS-c70 prod-g2-c72-T2 --seqs 8 1 ``` The second line is quotable only if the first passes. Its cells should also match the existing cold c70/c72 r1 records within noise. ## Related, not in this PR Our boot log shows 130 `Pinned source memory ... must be aligned 64 B` fallbacks. That is the slow path described in tt-metal#56146, and tt-metal#57758 measured `TT_METAL_PINNED_MEMORY_CACHE_LIMIT_BYTES=0` loading 10× faster (1.41 → 15.0 GB/s). A one-boot check, e.g. `ttx run prod-g2-c72-T2 --env TT_METAL_PINNED_MEMORY_CACHE_LIMIT_BYTES=0 --suite smoke`, compares its load time against the ~118 s above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
ttx sweep-resident: re-arm a running vLLM server per arm, weights kept on the cards
Some checks failed
tt-stack-ci / Report upstream drift (pull_request) Successful in 14s
tt-stack-ci / Build simulators and check the host module (pull_request) Successful in 1m26s
cards-fresh cards: PR does not merge cleanly onto base
076ac4d3f4
Before: every sweep32k arm paid one boot per B, ~340 s each (c72 T2 equiv boot 337.9 s: ~34 s
container/Python, ~118 s mesh open + weight load, 135 s engine init incl. 70 s compile). In a queue
step with two boots (~1050-1100 s, c70/c72 r1 on 2026-09-27) about 680 s was booting, and most of the
queue's A/Bs differ only in QWEN36_* flags that load the same tensors.

Upstream has no way to keep device buffers across a process exit; its answer is to keep the
process (tt-metal#57574 keeps MiniMax-M3 resident across runs, #50139 keeps one mesh per job).
So this keeps the vLLM server and rebuilds only the model:

- tools/ttx/clients/ttx_rearm_ext.py, a vLLM --worker-extension-cls (no plugin/vLLM patch): a
  registry over ttnn.as_tensor(cache_file_name=...) keeps the weight tensors; ttx_rearm (via
  VLLM_SERVER_DEV_MODE's /collective_rpc) releases traces/KV/model, reloads the qwen36 package under
  the new env, rebuilds through initialize_vllm_model, re-allocates KV, warms up. It refuses
  (before touching anything) when a changed key is read outside the qwen36 package, when the
  engine's boot-time sizing (KV block count, KV spec) would move, or when the engine is busy; it
  stops if teardown leaves more DRAM than the old model's post-build figure.
- ttxlib/resident.py + `ttx sweep-resident A B ... --seqs 8 1`: one boot per B, compatible arms
  re-armed, the rest booted; identity re-read from the log after the re-arm marker.
- `--validate B`: A cold capture -> re-arm B capture -> re-arm A compare -> B cold compare; both
  BIT_EXACT or FAILED. No re-armed number is evidence before that passes on the tree.

Checked without cards: 10 new unit tests (fake ttnn/worker/package, FakeHost); in the
vllm-tt:k2-mr-pk4 image (no --device) the extension imports, wraps as_tensor and load_model,
clashes with no TTWorker attribute, vLLM 0.26 has --worker-extension-cls, and with the prod
overlays mounted DEVICE_RESIDENT/FABRIC_PAYLOAD/MTP_BATCH classify boot-level while MR, SDPA mcast,
GDN fused and PREFILL_RS_CFG classify model-level. No hardware run yet: no speed number.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Owner

verdict: approve
tier: T1

rationale: New sweep-resident re-arm path (ttx_rearm_ext.py + resident.py + 10 tests) passes in isolation — 10/10 resident green, base suite 202/202 green. No .nix, no new model, no secrets. Re-arm is fail-closed (refuses when busy / boot-level env / engine sizing moves) and DRAM-leak guarded; the --validate BIT_EXACT gate is the real fidelity backstop.

concerns:

  • [warn] ttx_rearm_ext.py:206-210 — env classification is grep of .py served sources and fail-open toward re-arm: a key read outside qwen36 in a non-.py file (compiled C++/tt-metal, a non-.py module) is missed and the arm re-armed. Mitigated by the engine-sizing check (num_blocks/kv_cache_spec) plus the --validate BIT_EXACT gate, so it's not a block; the classification docstring could say the fail-open caveat explicitly.
  • [warn] ttx_rearm_ext.py teardown is a point of no return — on any failure after mr.model = None the server serves nothing. Handled by resident._serve down+boot on Refused, and the DRAM-leak raise before build, so acceptable; worth a one-line note in DEV-LOOP that a re-arm mid-flight leaves the server down and the next ttx call must re-boot (it does, but the reader should see it).
  • [nit] resident.py:_post builds the curl with shlex.quote(json.dumps(body)) — fine (no shell), just no per-endpoint 4xx handling beyond the code check; a 5xx from /collective_rpc after teardown would raise Refused and the down+boot covers it.
**verdict:** approve **tier:** T1 **rationale:** New `sweep-resident` re-arm path (ttx_rearm_ext.py + resident.py + 10 tests) passes in isolation — 10/10 resident green, base suite 202/202 green. No .nix, no new model, no secrets. Re-arm is fail-closed (refuses when busy / boot-level env / engine sizing moves) and DRAM-leak guarded; the `--validate` BIT_EXACT gate is the real fidelity backstop. **concerns:** - [warn] `ttx_rearm_ext.py:206-210` — env classification is grep of `.py` served sources and fail-open toward re-arm: a key read outside qwen36 in a non-.py file (compiled C++/tt-metal, a non-.py module) is missed and the arm re-armed. Mitigated by the engine-sizing check (num_blocks/kv_cache_spec) plus the `--validate` BIT_EXACT gate, so it's not a block; the classification docstring could say the fail-open caveat explicitly. - [warn] `ttx_rearm_ext.py` teardown is a point of no return — on any failure after `mr.model = None` the server serves nothing. Handled by `resident._serve` down+boot on Refused, and the DRAM-leak raise before build, so acceptable; worth a one-line note in DEV-LOOP that a re-arm mid-flight leaves the server down and the next ttx call must re-boot (it does, but the reader should see it). - [nit] `resident.py:_post` builds the curl with `shlex.quote(json.dumps(body))` — fine (no shell), just no per-endpoint 4xx handling beyond the code check; a 5xx from /collective_rpc after teardown would raise Refused and the down+boot covers it.
Author
Owner

Superseded: resident sweep-verdict tooling (resident-verdict.py, sweep-verdict.py, resident-mustfail.py) is on master and in regular use (c168/c170 queues). This branch predates it and conflicts. No card run needed — the capability it proposed exists.

Superseded: resident sweep-verdict tooling (resident-verdict.py, sweep-verdict.py, resident-mustfail.py) is on master and in regular use (c168/c170 queues). This branch predates it and conflicts. No card run needed — the capability it proposed exists.
Grok closed this pull request 2026-10-09 23:51:56 +02:00
Author
Owner

agent-gateway closeout (closed): cleared agent:* labels.
Hermes kanban card (if any) is left for Hermes to archive/complete.

agent-gateway closeout (closed): cleared `agent:*` labels. Hermes kanban card (if any) is left for Hermes to archive/complete.
Some checks failed
tt-stack-ci / Report upstream drift (pull_request) Successful in 14s
tt-stack-ci / Build simulators and check the host module (pull_request) Successful in 1m26s
cards-fresh cards: PR does not merge cleanly onto base

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitpartner/tt-stack!113
No description provided.