[PR #5036] [Engine] HIP: --expert-parallel-device N, two gfx1100 cards compute each layer's experts together #5296

Open
opened 2026-11-07 16:34:08 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5036
Author: @sky-is-green
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: hip-expert-parallel


📝 Commits (8)

  • 823e810 kernels: expert parallelism over two cards through host-mapped memory (HIP)
  • 8db52c4 verify: the peer's half of each window as its own graph (--expert-parallel-device)
  • bb32271 generate/serve: --expert-parallel-device N, its placement and the peer cache
  • 6ae484d bench: the served A/B for HIP expert parallelism (2x 7900 XT)
  • d1f1e0a EP: the RAM copy ranks the experts card 0 does not hold over the whole profile
  • de2c326 EP: the prompt on card 0 keeps the fused int8 kernels and the layer-major path
  • 0469222 EP: auto cache sizing leaves the peer its reserve
  • 84e78a1 Merge main (146df3c4): the EP plans beside the 16-row window; the no-MMQ dm16 stubs

📊 Changes

15 files changed (+1370 additions, -31 deletions)

View changed files

📝 CMakeLists.txt (+7 -0)
➕ bench/results/2026-10-15-hip-ep-ab/README.md (+34 -0)
➕ bench/results/2026-10-15-hip-ep-ab/run-clean.txt (+40 -0)
📝 include/strata/core/peer_experts.hpp (+3 -0)
📝 include/strata/core/verify.hpp (+46 -0)
➕ include/strata/kernels/ep_kernels.hpp (+47 -0)
📝 serve/server.py (+24 -4)
📝 serve/test_server.py (+12 -0)
📝 src/core/peer_experts.cpp (+3 -0)
📝 src/core/verify.cpp (+234 -6)
➕ src/kernels/cuda/ep_kernels.cu (+164 -0)
📝 src/kernels/cuda/verify_kernels.cu (+43 -14)
➕ src/kernels/ep_parity.cu (+447 -0)
📝 src/prefill/prefill.cpp (+5 -3)
📝 src/program/generate.cpp (+261 -4)

📄 Description

Problem and result:

This ports the SYCL expert-parallel design from #1798 to the CUDA/HIP tree (src/), so two AMD cards can compute each layer's experts together. It is opt-in (--expert-parallel-device N); without the flag the engine takes the same path as before.

On 2x RX 7900 XT 20 GB (gfx1100, ROCm 7.2.4, Ryzen 7800X3D), serving Qwen3.8-Flash-Next 176B Q6K at 4,096 context with --spec 4 --spec-min-p 0.5:

--layer-split auto --pipeline-windows 2 --expert-parallel-device 1
warm runs 2-4 (tok/s) 60.0 / 74.5 / 85.1 (still climbing) 90.3 / 90.3 / 90.4
400-token decode (tok/s) 59.8 80.4

#1798 (the SYCL implementation; this HIP port was reported in that thread), where @Gonbatfire asked for the port.

Reviewer guide:

  • Suggested review order: generate.cpp (option, placement, peer cache), then verify.cpp (two-graph capture and launch), then ep_kernels.cu (the mapped exchange), then ep_parity.cu (plan/row parity). serve/server.py is only the config exemption; the three original code commits follow that split. The fourth commit only adds the served A/B output under bench/results/. On top: two fixes from @alexanderi96 (the RAM copy ranks the whole profile; the prompt keeps the fused kernels under EP) and an auto-cache sizing fix (the peer keeps its reserve).
  • The feature is off without --expert-parallel-device; no default path changes.
  • Known gaps: the CUDA/NVIDIA build was not run; the served Q6K A/B is from the original branch, not this rebased head (raw output: bench/results/2026-10-15-hip-ep-ab/run-clean.txt); prompt EP (#2205) and batch windows are not ported. The rebased head's parity and server tests pass; a Q2_0 served smoke run is in Validation.

Approach:

  • --expert-parallel-device N: card 0 runs every layer; card N holds the experts card 0 does not and computes their rows of every decode window at the same time. Each layer's experts are dealt hottest first 0,1 / 1,0 (a snake) until card 0's per-layer quota is full. Both cards get their own ExpertCache; the assignment of experts to cards is fixed at the start (per-layer slots, no adaptive swaps).
  • resident_plan_ep gives each card the plan for its own entries only; an expert on neither card is a plan error. The two plans together cover every entry exactly once, and with every expert on card 0 the plan is resident_plan word for word (ep_parity).
  • HIP IPC between these two cards fails with invalid device context, so the exchange does not use IPC handles. Each region (inbox, return rows, flag lines) is one cudaHostAlloc(Mapped | Portable) allocation with a device alias on each card. Card 0 pushes the routed ids and q8_1 rows; card N copies them past its caches, plans and runs its experts, and writes its rows back with ep_send_rows; card 0 copies those rows uncached into parts_ before its single-card combine. The flags live in mapped host memory, carry the window epoch, and every spin is bounded.
  • Both halves of a window are captured in one record_window pass: card 0's graph and the peer's graph on its own stream. The peer's graph is launched just before card 0's; the combine stays the single-card one.
  • The option is refused with --layer-split, --peer-device, --pipeline-windows, --batch, --expert-cache-device1..3 or --remote-expert-opt. serve/server.py's layer_split_of() treats it like --peer-device, so a config with "gpu": [0, 1] can start it.
  • Batch windows are refused for now; prompt expert parallelism (#2205) is not ported, so a prompt reads the peer's experts on card 0 (correct, slower).

Validation:

  • Passed (this rebase): HIP build with cmake -S . -B build-hip -G Ninja -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DCMAKE_HIP_ARCHITECTURES=gfx1100 -DSTRATA_BUILD_TESTS=ON, targets strata and ep_parity, 0 errors. resident_plan_parity was built separately.
  • Passed (this rebase): ./build-hip/ep_parity on 2x RX 7900 XT: ep_parity plans: 151 cases, 0 failures and ep_parity: 0 failures (the 5 plain and 5 captured-graph exchange windows). It checks the two plans against a host replay (each entry exactly once, an expert on neither card sets the plan error, the all-on-card-0 case equals resident_plan), the pushed ids/q8_1 checksum, and the peer rows in parts_ bit-exact while card 0's own rows stay untouched.
  • Passed (this rebase): ./build-hip/resident_plan_parity: resident_plan: 641 cases, 0 failures, resident_plan_parity OK.
  • Passed (this rebase): python3 -m unittest serve.test_server.PeerDevice.test_no_split_with_expert_parallel serve.test_server.PeerDevice.test_no_split_with_helper_caches (2 tests, OK).
  • Passed (this rebase): python3 -m unittest serve.test_parallel (37 tests, OK), including the two parallel-args tests the first CI run caught.
  • Passed (rebased head + the two fixes + the auto-sizing fix): ep_parity 151/0 and resident_plan_parity 641/0.
  • Passed (2x RX 7900 XT 20 GB, Qwen3.8-Flash-Next-GSQ-RCO Q2_0, non-display card as card 0): --expert-cache auto --expert-parallel-device 1 now sizes 239/273 experts per layer and decodes 29.88 tok/s (32 tokens, plain decode, no spec, 4K). Before the auto fix it refused at 203/309; an explicit 246/266 split decodes 29.86 tok/s.
  • Passed (fork CI, before the rebase): Minimal serving runtime (full server suite without terminal packages).
  • Passed (fork CI on the rebased head, run 41879329989): Minimal serving runtime (full server suite without terminal packages).
  • Failed earlier: a CI run before the rebase hit KeyError: 'args' in layer_split_of(); fixed with args = cfg.get("args") or [] and the rerun passed.
  • Not run: full upstream CI on the rebased head (the fork's Minimal serving runtime passed on 04692220, run 41879329989); a served A/B benchmark of this rebased branch (the table above is from the original branch); a CUDA build on NVIDIA hardware; prompt EP (#2205); batch windows.

The A/B above used a fixed four-request sequence; the warm runs are requests 2-4. Card utilization was not saturated: card 0 59 W average / 160 W peak, peer 24 W / 63 W (12 s samples around the 400-token decode, idle included, so lower bounds).

Follow-up fixes:

  • The RAM copy ranks the whole profile in EP mode (from @alexanderi96): profile_all is only filled on the layer-split path, so the complement ranked card 0's set and pinned nothing; the prompt then read the peer's experts from the files every chunk. The RAM-budget line on a 20 GB pair went from 0 of 20.39 GiB to 6,213 of 20.39 GiB.
  • The prompt keeps the fused int8 kernels and the layer-major path under EP (from @alexanderi96): peer_portable() stays for the mapped host allocations, while the prompt-path checks use a --peer-device-only flag. EP has no PeerPrefill, so its prompt should not take the MMQ layout.
  • --expert-cache auto now accounts for the peer's reserve: it gives card 0 the slots the peer cannot hold, instead of sizing card 0 with its own reserve and then refusing the peer's share. On Q2_0 at 4K/1024 prefill, auto now picks 239/273 per layer; card 0 runs with a 256 MiB reserve, the peer/display card keeps its 3 GiB.

Limits:

Only gfx1100 on Linux/ROCm was tested. The host-mapped fallback moves both the inbox and the peer's rows through host memory, so it is not a direct GPU-to-GPU transfer; the gain is that the two cards stop taking turns per window, not that both are saturated. The EP arm's outputs are not byte-identical to the pipelined arm because the arms' resident sets differ (the pipeline computes about 8% on the CPU with different rounding); the plan/row parity above is the contract evidence. On a 20 GB pair, --prefill 8192 --no-prefill-borrow reserves about 5.6 GiB on card 0, leaves about 103 slots per layer, and the pair cannot hold every expert; a smaller --prefill fits (1024: 202/310 per layer on Q6K; Q2_0 with the auto fix: 239/273). With the default prompt loans, card 0 holds 217 per layer and the peer 295, and capture() refuses a window started while a loan is out.


🔄 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/5036 **Author:** [@sky-is-green](https://github.com/sky-is-green) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `hip-expert-parallel` --- ### 📝 Commits (8) - [`823e810`](https://github.com/Niko1221/Strata/commit/823e8100b419afcadb442c4c04464d7ca6910b1a) kernels: expert parallelism over two cards through host-mapped memory (HIP) - [`8db52c4`](https://github.com/Niko1221/Strata/commit/8db52c435659bd8c9cc1e206ef0f19af92776958) verify: the peer's half of each window as its own graph (--expert-parallel-device) - [`bb32271`](https://github.com/Niko1221/Strata/commit/bb322712fd9ee8b460946269560754badee126a3) generate/serve: --expert-parallel-device N, its placement and the peer cache - [`6ae484d`](https://github.com/Niko1221/Strata/commit/6ae484d5273a20141b8a8a6ac65345cfaf0594a3) bench: the served A/B for HIP expert parallelism (2x 7900 XT) - [`d1f1e0a`](https://github.com/Niko1221/Strata/commit/d1f1e0a447119205b1e702bbc5b8604c97226cd7) EP: the RAM copy ranks the experts card 0 does not hold over the whole profile - [`de2c326`](https://github.com/Niko1221/Strata/commit/de2c326dd46f48180f2238b5a62d27dc11d36078) EP: the prompt on card 0 keeps the fused int8 kernels and the layer-major path - [`0469222`](https://github.com/Niko1221/Strata/commit/04692220164b5f06bbc41a897abf58a221d277f1) EP: auto cache sizing leaves the peer its reserve - [`84e78a1`](https://github.com/Niko1221/Strata/commit/84e78a133404fcb68c5a833db4a82d17b2396047) Merge main (146df3c4): the EP plans beside the 16-row window; the no-MMQ dm16 stubs ### 📊 Changes **15 files changed** (+1370 additions, -31 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+7 -0) ➕ `bench/results/2026-10-15-hip-ep-ab/README.md` (+34 -0) ➕ `bench/results/2026-10-15-hip-ep-ab/run-clean.txt` (+40 -0) 📝 `include/strata/core/peer_experts.hpp` (+3 -0) 📝 `include/strata/core/verify.hpp` (+46 -0) ➕ `include/strata/kernels/ep_kernels.hpp` (+47 -0) 📝 `serve/server.py` (+24 -4) 📝 `serve/test_server.py` (+12 -0) 📝 `src/core/peer_experts.cpp` (+3 -0) 📝 `src/core/verify.cpp` (+234 -6) ➕ `src/kernels/cuda/ep_kernels.cu` (+164 -0) 📝 `src/kernels/cuda/verify_kernels.cu` (+43 -14) ➕ `src/kernels/ep_parity.cu` (+447 -0) 📝 `src/prefill/prefill.cpp` (+5 -3) 📝 `src/program/generate.cpp` (+261 -4) </details> ### 📄 Description ## Problem and result: This ports the SYCL expert-parallel design from #1798 to the CUDA/HIP tree (`src/`), so two AMD cards can compute each layer's experts together. It is opt-in (`--expert-parallel-device N`); without the flag the engine takes the same path as before. On 2x RX 7900 XT 20 GB (gfx1100, ROCm 7.2.4, Ryzen 7800X3D), serving Qwen3.8-Flash-Next 176B Q6K at 4,096 context with `--spec 4 --spec-min-p 0.5`: | | `--layer-split auto --pipeline-windows 2` | `--expert-parallel-device 1` | | --- | --- | --- | | warm runs 2-4 (tok/s) | 60.0 / 74.5 / 85.1 (still climbing) | 90.3 / 90.3 / 90.4 | | 400-token decode (tok/s) | 59.8 | 80.4 | ## Related discussion: #1798 (the SYCL implementation; this HIP port was reported in that thread), where @Gonbatfire asked for the port. ## Reviewer guide: - Suggested review order: `generate.cpp` (option, placement, peer cache), then `verify.cpp` (two-graph capture and launch), then `ep_kernels.cu` (the mapped exchange), then `ep_parity.cu` (plan/row parity). `serve/server.py` is only the config exemption; the three original code commits follow that split. The fourth commit only adds the served A/B output under `bench/results/`. On top: two fixes from @alexanderi96 (the RAM copy ranks the whole profile; the prompt keeps the fused kernels under EP) and an auto-cache sizing fix (the peer keeps its reserve). - The feature is off without `--expert-parallel-device`; no default path changes. - Known gaps: the CUDA/NVIDIA build was not run; the served Q6K A/B is from the original branch, not this rebased head (raw output: `bench/results/2026-10-15-hip-ep-ab/run-clean.txt`); prompt EP (#2205) and batch windows are not ported. The rebased head's parity and server tests pass; a Q2_0 served smoke run is in Validation. ## Approach: - `--expert-parallel-device N`: card 0 runs every layer; card N holds the experts card 0 does not and computes their rows of every decode window at the same time. Each layer's experts are dealt hottest first 0,1 / 1,0 (a snake) until card 0's per-layer quota is full. Both cards get their own `ExpertCache`; the assignment of experts to cards is fixed at the start (per-layer slots, no adaptive swaps). - `resident_plan_ep` gives each card the plan for its own entries only; an expert on neither card is a plan error. The two plans together cover every entry exactly once, and with every expert on card 0 the plan is `resident_plan` word for word (`ep_parity`). - HIP IPC between these two cards fails with `invalid device context`, so the exchange does not use IPC handles. Each region (inbox, return rows, flag lines) is one `cudaHostAlloc(Mapped | Portable)` allocation with a device alias on each card. Card 0 pushes the routed ids and q8_1 rows; card N copies them past its caches, plans and runs its experts, and writes its rows back with `ep_send_rows`; card 0 copies those rows uncached into `parts_` before its single-card combine. The flags live in mapped host memory, carry the window epoch, and every spin is bounded. - Both halves of a window are captured in one `record_window` pass: card 0's graph and the peer's graph on its own stream. The peer's graph is launched just before card 0's; the combine stays the single-card one. - The option is refused with `--layer-split`, `--peer-device`, `--pipeline-windows`, `--batch`, `--expert-cache-device1..3` or `--remote-expert-opt`. `serve/server.py`'s `layer_split_of()` treats it like `--peer-device`, so a config with `"gpu": [0, 1]` can start it. - Batch windows are refused for now; prompt expert parallelism (#2205) is not ported, so a prompt reads the peer's experts on card 0 (correct, slower). ## Validation: - Passed (this rebase): HIP build with `cmake -S . -B build-hip -G Ninja -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DCMAKE_HIP_ARCHITECTURES=gfx1100 -DSTRATA_BUILD_TESTS=ON`, targets `strata` and `ep_parity`, 0 errors. `resident_plan_parity` was built separately. - Passed (this rebase): `./build-hip/ep_parity` on 2x RX 7900 XT: `ep_parity plans: 151 cases, 0 failures` and `ep_parity: 0 failures` (the 5 plain and 5 captured-graph exchange windows). It checks the two plans against a host replay (each entry exactly once, an expert on neither card sets the plan error, the all-on-card-0 case equals `resident_plan`), the pushed ids/q8_1 checksum, and the peer rows in `parts_` bit-exact while card 0's own rows stay untouched. - Passed (this rebase): `./build-hip/resident_plan_parity`: `resident_plan: 641 cases, 0 failures`, `resident_plan_parity OK`. - Passed (this rebase): `python3 -m unittest serve.test_server.PeerDevice.test_no_split_with_expert_parallel serve.test_server.PeerDevice.test_no_split_with_helper_caches` (2 tests, OK). - Passed (this rebase): `python3 -m unittest serve.test_parallel` (37 tests, OK), including the two parallel-args tests the first CI run caught. - Passed (rebased head + the two fixes + the auto-sizing fix): `ep_parity` 151/0 and `resident_plan_parity` 641/0. - Passed (2x RX 7900 XT 20 GB, Qwen3.8-Flash-Next-GSQ-RCO Q2_0, non-display card as card 0): `--expert-cache auto --expert-parallel-device 1` now sizes 239/273 experts per layer and decodes 29.88 tok/s (32 tokens, plain decode, no spec, 4K). Before the auto fix it refused at 203/309; an explicit 246/266 split decodes 29.86 tok/s. - Passed (fork CI, before the rebase): `Minimal serving runtime` (full server suite without terminal packages). - Passed (fork CI on the rebased head, run 41879329989): `Minimal serving runtime` (full server suite without terminal packages). - Failed earlier: a CI run before the rebase hit `KeyError: 'args'` in `layer_split_of()`; fixed with `args = cfg.get("args") or []` and the rerun passed. - Not run: full upstream CI on the rebased head (the fork's `Minimal serving runtime` passed on `04692220`, run 41879329989); a served A/B benchmark of this rebased branch (the table above is from the original branch); a CUDA build on NVIDIA hardware; prompt EP (#2205); batch windows. The A/B above used a fixed four-request sequence; the warm runs are requests 2-4. Card utilization was not saturated: card 0 59 W average / 160 W peak, peer 24 W / 63 W (12 s samples around the 400-token decode, idle included, so lower bounds). ## Follow-up fixes: - The RAM copy ranks the whole profile in EP mode (from @alexanderi96): `profile_all` is only filled on the layer-split path, so the complement ranked card 0's set and pinned nothing; the prompt then read the peer's experts from the files every chunk. The RAM-budget line on a 20 GB pair went from `0 of 20.39 GiB` to `6,213 of 20.39 GiB`. - The prompt keeps the fused int8 kernels and the layer-major path under EP (from @alexanderi96): `peer_portable()` stays for the mapped host allocations, while the prompt-path checks use a `--peer-device`-only flag. EP has no PeerPrefill, so its prompt should not take the MMQ layout. - `--expert-cache auto` now accounts for the peer's reserve: it gives card 0 the slots the peer cannot hold, instead of sizing card 0 with its own reserve and then refusing the peer's share. On Q2_0 at 4K/1024 prefill, auto now picks 239/273 per layer; card 0 runs with a 256 MiB reserve, the peer/display card keeps its 3 GiB. ## Limits: Only gfx1100 on Linux/ROCm was tested. The host-mapped fallback moves both the inbox and the peer's rows through host memory, so it is not a direct GPU-to-GPU transfer; the gain is that the two cards stop taking turns per window, not that both are saturated. The EP arm's outputs are not byte-identical to the pipelined arm because the arms' resident sets differ (the pipeline computes about 8% on the CPU with different rounding); the plan/row parity above is the contract evidence. On a 20 GB pair, `--prefill 8192 --no-prefill-borrow` reserves about 5.6 GiB on card 0, leaves about 103 slots per layer, and the pair cannot hold every expert; a smaller `--prefill` fits (1024: 202/310 per layer on Q6K; Q2_0 with the auto fix: 239/273). With the default prompt loans, card 0 holds 217 per layer and the peer 295, and `capture()` refuses a window started while a loan is out. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#5296
No description provided.