mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #5036] [Engine] HIP: --expert-parallel-device N, two gfx1100 cards compute each layer's experts together #5296
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#5296
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/5036
Author: @sky-is-green
Created: 11/2/2026
Status: 🔄 Open
Base:
main← Head:hip-expert-parallel📝 Commits (8)
823e810kernels: expert parallelism over two cards through host-mapped memory (HIP)8db52c4verify: the peer's half of each window as its own graph (--expert-parallel-device)bb32271generate/serve: --expert-parallel-device N, its placement and the peer cache6ae484dbench: the served A/B for HIP expert parallelism (2x 7900 XT)d1f1e0aEP: the RAM copy ranks the experts card 0 does not hold over the whole profilede2c326EP: the prompt on card 0 keeps the fused int8 kernels and the layer-major path0469222EP: auto cache sizing leaves the peer its reserve84e78a1Merge 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 1Related discussion:
#1798 (the SYCL implementation; this HIP port was reported in that thread), where @Gonbatfire asked for the port.
Reviewer guide:
generate.cpp(option, placement, peer cache), thenverify.cpp(two-graph capture and launch), thenep_kernels.cu(the mapped exchange), thenep_parity.cu(plan/row parity).serve/server.pyis only the config exemption; the three original code commits follow that split. The fourth commit only adds the served A/B output underbench/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).--expert-parallel-device; no default path changes.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 ownExpertCache; the assignment of experts to cards is fixed at the start (per-layer slots, no adaptive swaps).resident_plan_epgives 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 isresident_planword for word (ep_parity).invalid device context, so the exchange does not use IPC handles. Each region (inbox, return rows, flag lines) is onecudaHostAlloc(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 withep_send_rows; card 0 copies those rows uncached intoparts_before its single-card combine. The flags live in mapped host memory, carry the window epoch, and every spin is bounded.record_windowpass: 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.--layer-split,--peer-device,--pipeline-windows,--batch,--expert-cache-device1..3or--remote-expert-opt.serve/server.py'slayer_split_of()treats it like--peer-device, so a config with"gpu": [0, 1]can start it.Validation:
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, targetsstrataandep_parity, 0 errors.resident_plan_paritywas built separately../build-hip/ep_parityon 2x RX 7900 XT:ep_parity plans: 151 cases, 0 failuresandep_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 equalsresident_plan), the pushed ids/q8_1 checksum, and the peer rows inparts_bit-exact while card 0's own rows stay untouched../build-hip/resident_plan_parity:resident_plan: 641 cases, 0 failures,resident_plan_parity OK.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).python3 -m unittest serve.test_parallel(37 tests, OK), including the two parallel-args tests the first CI run caught.ep_parity151/0 andresident_plan_parity641/0.--expert-cache auto --expert-parallel-device 1now 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.Minimal serving runtime(full server suite without terminal packages).Minimal serving runtime(full server suite without terminal packages).KeyError: 'args'inlayer_split_of(); fixed withargs = cfg.get("args") or []and the rerun passed.Minimal serving runtimepassed on04692220, 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:
profile_allis 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 from0 of 20.39 GiBto6,213 of 20.39 GiB.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 autonow 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-borrowreserves about 5.6 GiB on card 0, leaves about 103 slots per layer, and the pair cannot hold every expert; a smaller--prefillfits (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, andcapture()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.