[PR #1637] [CLOSED] batch: the adaptive expert tier keeps adapting in batch windows (--adapt-async 1 beside slots) #3576

Closed
opened 2026-11-07 14:42:27 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1637
Author: @noon-at-cgn
Created: 10/9/2026
Status: ❌ Closed

Base: main ← Head: pr/adapt-async-141


📝 Commits (9)

  • e1e47af batch-mtp: work with a layer split (slot drafters on the last stage's GPU, grouped slot rows through every stage)
  • e46e904 batch-mtp: log the accepted proposals in the batch summary
  • c7b77d8 batch-groups: the 0.1.41 auto default gives way to --batch-mtp (one group, said once)
  • ffc4000 batch-mtp: not with helper expert caches on a layer split (not run); docs say how it meets --batch-groups
  • 2c08077 docs: batch MTP on a layer split - measured on 2x RTX 3080 20 GB (0.1.41 build and the earlier 0.1.40.3 runs), with what was not measured
  • 045219a batch: the adaptive VRAM expert tier keeps adapting in batch windows; per-stage timing in the strata batch line
  • 48f293d batch: tick the asynchronous adaptive tier (--adapt-async 1) between batch windows; --adapt-min-gain
  • 9572dbf batch-groups: --adapt-async 1 also keeps the 0.1.41 auto default at one group (said once)
  • 4dba66a docs: the adaptive tier in batch windows - measured on 2x RTX 3080 20 GB, tier on, blocking, frozen and off

📊 Changes

9 files changed (+601 additions, -75 deletions)

View changed files

📝 CMakeLists.txt (+8 -0)
📝 docs/BATCHING.md (+95 -8)
📝 docs/DETAILS.md (+3 -2)
➕ include/strata/core/batch_rows.hpp (+30 -0)
➕ include/strata/program/batch_groups.hpp (+65 -0)
📝 src/core/verify.cpp (+6 -22)
➕ src/program/batch_groups_test.cpp (+106 -0)
📝 src/program/generate.cpp (+210 -43)
➕ tests/core/batch_rows_test.cpp (+78 -0)

📄 Description

Title

Issue: Related: #876 (the asynchronous tier), #1122 / #905 (pipelined windows with the tier), #1413. Depends on #1636 (--batch-mtp on a layer split, which adds the --batch-groups resolution this uses).

Summary

Why it matters: on upstream main the VRAM expert tier does not adapt in batch windows at all: batch_step never calls it, --adapt-async 1 is switched off with "not with --batch slots", and pipelined groups never adapt. With parallel 2 the cache then follows the routing only while a request is alone. This change counts the routing of batch windows and runs the tier every --adapt-every windows, blocking by default and between the windows with --adapt-async 1, on one GPU and on a layer split (every stage's cache adapts). On 0.1.41 it needs one more thing: a layer split with --batch 2 or more pipelines the slots by default and the pipelined path never adapts, so with --adapt-async 1 and no --batch-groups, auto resolves to one group and the log says why; an explicit --batch-groups N or auto is honoured and turns --adapt-async off.

Measured: 2 concurrent greedy decodes of 300 tokens, layer split 23, parallel 2, --batch-mtp, 2x RTX 3080 20 GB (220 W cap), UD-Q4_K_XL, engine 0.1.41 = our stack on fb58e0d (strata-w10) aggregate tok/s per window routed entries from VRAM
--adapt-async 1 --adapt-every 2 (3 restarts, 60 measurements) 89.2 34.6 ms, adapt wait 0.2 ms 92.1%
blocking tier, --adapt-every 2 (1 restart, 20) 74.7 41.4 ms, adapt wait 8.4 ms 92.3%
no tier, the cache frozen from a profile the tier had learned on the same prompts (1, 20) 69.5 43.6 ms 77.2%
no tier, --adapt-every 0 (2 restarts, 40) 45.2 66-68 ms 52.7%

Read it as the tier as a whole, not as "batch windows only": the switch also changes the solo path (solo decode: 81.7, 66.3, 69.0, 43.1 tok/s in the same order), and no switch turns the tier off in batch windows alone. The prompts are the benchmark's own (eight topics that repeat), which the tier learns quickly, so on a varied workload the gain may be smaller (not measured). The async tier waits 0.2 ms per window, the blocking tier 8.4 ms. Upstream main runs no tier in batch windows and no upstream binary was measured.

What changed

  • src/program/generate.cpp: in batch_step, windows count the routed experts (drive.d.usage); every --adapt-every windows the blocking tier runs on a thread beside the commit and the drafts, and its swaps land (apply_pending) before the window ends; with --adapt-async 1 the round in flight moves on one step per window (table changes and uploads on the main thread, copies on the helper thread and the cards' refill streams). Not between a prompt's chunks (a loan of cache slots), and a request that arrives lands the round in flight first. The --adapt-async gate says "not with --batch-groups (the pipelined slot groups)" instead of "not with --batch slots". The asynchronous round ends at once when its swap list turns out empty. --adapt-min-gain F (default 1.5, the old constant) sets the bar a swap must clear, for both tiers. The strata batch: line shows each stage's GPU-reach wait and pool time, the routed entries served by VRAM, PCIe and CPU, and the rounds and swaps.
  • include/strata/program/batch_groups.hpp, src/program/batch_groups_test.cpp: --adapt-async 1 joins --batch-mtp as a reason the default auto gives way to one group (log: --batch-groups auto: 1 group of 2 slots - --adapt-async 1 does not run in pipelined groups; --batch-groups 2 would pipeline them and turn it off, read in the start log of arm A1, no --batch-mtp). With --batch-groups 2 given, the engine printed --adapt-async 1 is off (not with --batch-groups (the pipelined slot groups)).
  • docs/BATCHING.md (a section and the table above), docs/DETAILS.md.
  • Commits (all by noon-at-cgn): the tier in batch windows, the asynchronous tick with --adapt-min-gain, the groups resolution for --adapt-async 1, the docs with the measurements.

Extra Notes

Behaviour change to know about: the blocking tier now runs in batch windows by default (every 4 windows, --adapt-every), where upstream main runs none; --adapt-every 0 (or 1000000, as in the exactness settings of docs/BATCHING.md) keeps the tier fixed. Swaps move experts between the GPU and the CPU, which round differently, so greedy outputs of a batch can differ from run to run when the tier is on; with it off the exactness statement of docs/BATCHING.md is unchanged. The measured gain above is for a box where most experts are resident in RAM and the VRAM tier is a cache of them (--resident-experts); --adapt-async 1 needs that mode.
Order: #1636 first. This branch applies on top of it without conflicts and was built and tested on top of it (not on main alone). It does not conflict with open #1598, #1599, #1601, #1614 or #1517 (checked with git merge-tree). It touches the same adaptive-tier code as #1517 (evictions reach the residency table before the next window) without a textual conflict; the two have not been run together.
Not tested: HIP, SYCL, three or more stages, more than two slots, images with batch slots, sampled decoding, GPU parity of the swap path in batch windows (no exactness claim: the tier is not bit-exact run to run), --adapt-async 1 with --pipeline-windows 2 beside slots, --peer-device, the helper caches, any upstream-main binary. The numbers come from our build with the rest of our stack (shared KV pool, #1190, aux-cpus, memory guard); the tier arms were run in alternation with the batch-MTP arms between 15:53 and 20:34 on one day, with 1 to 3 restarts per arm.
Tests: batch_groups_test (the 0.1.41 default, --batch-mtp and --adapt-async 1 giving way, explicit values honoured; 16 checks) and batch_rows_test pass; ctest on the whole tree with no GPU: the same 56 failures as #1636 (missing GPU). On GPU 0 with about 1 GiB free: verify_parity, verify_batch_parity, rope_parity, qsa_parity, kv_stream_parity, kv_hybrid_parity pass. python -m unittest discover -s serve: 593 tests OK (11 skipped). The adaptive code path itself ran only in the production engine on strata-w10 (the arms above); there is no CPU test of it.
Context: this change is part of the setup measured in the community benchmark #1640.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/1637 **Author:** [@noon-at-cgn](https://github.com/noon-at-cgn) **Created:** 10/9/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/adapt-async-141` --- ### 📝 Commits (9) - [`e1e47af`](https://github.com/Niko1221/Strata/commit/e1e47afc60321e0a8165a4f425449202f0757770) batch-mtp: work with a layer split (slot drafters on the last stage's GPU, grouped slot rows through every stage) - [`e46e904`](https://github.com/Niko1221/Strata/commit/e46e9044799f12596b89cebfe5026cfe5f786407) batch-mtp: log the accepted proposals in the batch summary - [`c7b77d8`](https://github.com/Niko1221/Strata/commit/c7b77d8d68e203c05ecadd46d05bc56fb201cd99) batch-groups: the 0.1.41 auto default gives way to --batch-mtp (one group, said once) - [`ffc4000`](https://github.com/Niko1221/Strata/commit/ffc40009005cdff42cbed801585e1da90f9e3d1d) batch-mtp: not with helper expert caches on a layer split (not run); docs say how it meets --batch-groups - [`2c08077`](https://github.com/Niko1221/Strata/commit/2c0807762e258b6be7031f77ac19b4b0fa0de262) docs: batch MTP on a layer split - measured on 2x RTX 3080 20 GB (0.1.41 build and the earlier 0.1.40.3 runs), with what was not measured - [`045219a`](https://github.com/Niko1221/Strata/commit/045219a1e5a2d2821b23c14d1dfb809ad4c753ec) batch: the adaptive VRAM expert tier keeps adapting in batch windows; per-stage timing in the strata batch line - [`48f293d`](https://github.com/Niko1221/Strata/commit/48f293d5da4413fe380a727758b17438dc462aee) batch: tick the asynchronous adaptive tier (--adapt-async 1) between batch windows; --adapt-min-gain - [`9572dbf`](https://github.com/Niko1221/Strata/commit/9572dbf60281fbb6ff6c10e19ba3bf3d31b567df) batch-groups: --adapt-async 1 also keeps the 0.1.41 auto default at one group (said once) - [`4dba66a`](https://github.com/Niko1221/Strata/commit/4dba66ac5e721c0d336328b32f8a385e9c487dbf) docs: the adaptive tier in batch windows - measured on 2x RTX 3080 20 GB, tier on, blocking, frozen and off ### 📊 Changes **9 files changed** (+601 additions, -75 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+8 -0) 📝 `docs/BATCHING.md` (+95 -8) 📝 `docs/DETAILS.md` (+3 -2) ➕ `include/strata/core/batch_rows.hpp` (+30 -0) ➕ `include/strata/program/batch_groups.hpp` (+65 -0) 📝 `src/core/verify.cpp` (+6 -22) ➕ `src/program/batch_groups_test.cpp` (+106 -0) 📝 `src/program/generate.cpp` (+210 -43) ➕ `tests/core/batch_rows_test.cpp` (+78 -0) </details> ### 📄 Description ## Title Issue: Related: #876 (the asynchronous tier), #1122 / #905 (pipelined windows with the tier), #1413. Depends on #1636 (`--batch-mtp` on a layer split, which adds the `--batch-groups` resolution this uses). ## Summary **Why it matters:** on upstream main the VRAM expert tier does not adapt in batch windows at all: `batch_step` never calls it, `--adapt-async 1` is switched off with "not with --batch slots", and pipelined groups never adapt. With `parallel 2` the cache then follows the routing only while a request is alone. This change counts the routing of batch windows and runs the tier every `--adapt-every` windows, blocking by default and between the windows with `--adapt-async 1`, on one GPU and on a layer split (every stage's cache adapts). On 0.1.41 it needs one more thing: a layer split with `--batch` 2 or more pipelines the slots by default and the pipelined path never adapts, so with `--adapt-async 1` and no `--batch-groups`, `auto` resolves to one group and the log says why; an explicit `--batch-groups N` or `auto` is honoured and turns `--adapt-async` off. | Measured: 2 concurrent greedy decodes of 300 tokens, layer split `23`, `parallel 2`, `--batch-mtp`, 2x RTX 3080 20 GB (220 W cap), UD-Q4_K_XL, engine 0.1.41 = our stack on fb58e0d (strata-w10) | aggregate tok/s | per window | routed entries from VRAM | |---|---|---|---| | `--adapt-async 1 --adapt-every 2` (3 restarts, 60 measurements) | **89.2** | 34.6 ms, adapt wait 0.2 ms | 92.1% | | blocking tier, `--adapt-every 2` (1 restart, 20) | 74.7 | 41.4 ms, adapt wait 8.4 ms | 92.3% | | no tier, the cache frozen from a profile the tier had learned on the same prompts (1, 20) | 69.5 | 43.6 ms | 77.2% | | no tier, `--adapt-every 0` (2 restarts, 40) | 45.2 | 66-68 ms | 52.7% | Read it as the tier as a whole, not as "batch windows only": the switch also changes the solo path (solo decode: 81.7, 66.3, 69.0, 43.1 tok/s in the same order), and no switch turns the tier off in batch windows alone. The prompts are the benchmark's own (eight topics that repeat), which the tier learns quickly, so on a varied workload the gain may be smaller (not measured). The async tier waits 0.2 ms per window, the blocking tier 8.4 ms. Upstream main runs no tier in batch windows and no upstream binary was measured. ## What changed - `src/program/generate.cpp`: in `batch_step`, windows count the routed experts (`drive.d.usage`); every `--adapt-every` windows the blocking tier runs on a thread beside the commit and the drafts, and its swaps land (`apply_pending`) before the window ends; with `--adapt-async 1` the round in flight moves on one step per window (table changes and uploads on the main thread, copies on the helper thread and the cards' refill streams). Not between a prompt's chunks (a loan of cache slots), and a request that arrives lands the round in flight first. The `--adapt-async` gate says "not with --batch-groups (the pipelined slot groups)" instead of "not with --batch slots". The asynchronous round ends at once when its swap list turns out empty. `--adapt-min-gain F` (default 1.5, the old constant) sets the bar a swap must clear, for both tiers. The `strata batch:` line shows each stage's GPU-reach wait and pool time, the routed entries served by VRAM, PCIe and CPU, and the rounds and swaps. - `include/strata/program/batch_groups.hpp`, `src/program/batch_groups_test.cpp`: `--adapt-async 1` joins `--batch-mtp` as a reason the default `auto` gives way to one group (log: `--batch-groups auto: 1 group of 2 slots - --adapt-async 1 does not run in pipelined groups; --batch-groups 2 would pipeline them and turn it off`, read in the start log of arm A1, no `--batch-mtp`). With `--batch-groups 2` given, the engine printed `--adapt-async 1 is off (not with --batch-groups (the pipelined slot groups))`. - `docs/BATCHING.md` (a section and the table above), `docs/DETAILS.md`. - Commits (all by noon-at-cgn): the tier in batch windows, the asynchronous tick with `--adapt-min-gain`, the groups resolution for `--adapt-async 1`, the docs with the measurements. ## Extra Notes **Behaviour change to know about:** the blocking tier now runs in batch windows by default (every 4 windows, `--adapt-every`), where upstream main runs none; `--adapt-every 0` (or `1000000`, as in the exactness settings of docs/BATCHING.md) keeps the tier fixed. Swaps move experts between the GPU and the CPU, which round differently, so greedy outputs of a batch can differ from run to run when the tier is on; with it off the exactness statement of docs/BATCHING.md is unchanged. The measured gain above is for a box where most experts are resident in RAM and the VRAM tier is a cache of them (`--resident-experts`); `--adapt-async 1` needs that mode. **Order:** #1636 first. This branch applies on top of it without conflicts and was built and tested on top of it (not on main alone). It does not conflict with open #1598, #1599, #1601, #1614 or #1517 (checked with `git merge-tree`). It touches the same adaptive-tier code as #1517 (evictions reach the residency table before the next window) without a textual conflict; the two have not been run together. **Not tested:** HIP, SYCL, three or more stages, more than two slots, images with batch slots, sampled decoding, GPU parity of the swap path in batch windows (no exactness claim: the tier is not bit-exact run to run), `--adapt-async 1` with `--pipeline-windows 2` beside slots, `--peer-device`, the helper caches, any upstream-main binary. The numbers come from our build with the rest of our stack (shared KV pool, #1190, aux-cpus, memory guard); the tier arms were run in alternation with the batch-MTP arms between 15:53 and 20:34 on one day, with 1 to 3 restarts per arm. Tests: `batch_groups_test` (the 0.1.41 default, `--batch-mtp` and `--adapt-async 1` giving way, explicit values honoured; 16 checks) and `batch_rows_test` pass; `ctest` on the whole tree with no GPU: the same 56 failures as #1636 (missing GPU). On GPU 0 with about 1 GiB free: `verify_parity`, `verify_batch_parity`, `rope_parity`, `qsa_parity`, `kv_stream_parity`, `kv_hybrid_parity` pass. `python -m unittest discover -s serve`: 593 tests OK (11 skipped). The adaptive code path itself ran only in the production engine on strata-w10 (the arms above); there is no CPU test of it. Context: this change is part of the setup measured in the community benchmark #1640. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 14:42:27 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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
Niko1221/Strata#3576
No description provided.