[PR #3763] [Engine] prefill: per-expert NVFP4 scales on the peer-prefill route (opt-in) #4772

Open
opened 2026-11-07 15:38:56 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3763
Author: @florian862-art
Created: 10/22/2026
Status: 🔄 Open

Base: main ← Head: f-nvfp4-peer


📝 Commits (3)

  • 328b96a prefill: wire per-expert NVFP4 scales through the peer-prefill route (config C)
  • 822c182 prefill: opt-in sums mode on the P2P peer route (STRATA_PF_PEER_SUMS_P2P)
  • a7689c4 docs: generation-path P2P micro-bench - the direct host ring wins at every decode row size (10 KB..2.6 MB), 1.7-3x

📊 Changes

3 files changed (+450 additions, -19 deletions)

View changed files

➕ src/prefill/README-nvfp4-peer.md (+350 -0)
📝 src/prefill/prefill.cpp (+96 -18)
📝 src/program/generate.cpp (+4 -1)

📄 Description

Replaces #2995 (closed in the 0.2.0-beta tracker reset; /reopen was checked OK but GitHub refused to reopen it, per its own message: "open a new pull request and link this one"). Rebased onto main @ cbfd5b92 (v0.2.1.3) at opening; rebased again onto 011c9e60 (v0.2.2) on 2026-10-22 and re-validated on that revision (see the 2026-10-22 comment).

Problem and result

On a --peer-device setup the peer GPU computes its experts' MoE rows for every prompt chunk, but on NVFP4 packs its MMQ products ran without any per-expert scales (grp_tail null, no s_gate/s_up, no s_down, no y_scale) - so every peer-computed row was numerically wrong and set_peer refused the combination. Before: the peer-prefill route was unusable on NVFP4; opening it by env alone recites a long prompt but cannot recall it (silent KV corruption, 0 non-finite). After this change, with STRATA_PF_PEER_NVFP4=1 the route carries the scales end to end: a cold ~25k-token recall prompt finds both needles, 0 non-finite logits, and prefill runs ~2.7k tok/s vs ~2.4k without the peer tier (+12.5 % measured, decode +27 %).

none - focused bug fix, opt-in behind an env gate, no default path touched.

Approach

gather_native carries the tail scales, swiglu_scaled applies s_gate/s_up, scale_down_rows scales Dm rows in place on both GPUs (this also fixes the sums-mode path where s_down was dropped and row_sd read OOB behind the 31 non-finite logits seen earlier), and y_scale feeds the w4a4 dequant. The whole route stays behind STRATA_PF_PEER_NVFP4=1 (prefill.cpp refusal gate + generate.cpp rows==0 skip), so nothing changes unless the env is set. A second, separate and droppable commit adds STRATA_PF_PEER_SUMS_P2P=1 (sums over the P2P link): correct but slower than the host route on this box (5.5 vs 14.3 GB/s), documented in src/prefill/README-nvfp4-peer.md for boxes where P2P beats PCIe. Design + measurement notes live in that README.

Validation

Revision tested: branch head a7689c48, rebased onto main @ 011c9e60 (v0.2.2); the same three commits on the earlier v0.2.1.3 base (e7580cca) were validated identically. Environment: 2x RTX 5070 Ti 16 GB (PCIe, no NVLink), Ubuntu, kernel 7.0.0-38, driver 595.99.02, CUDA build via CMake/Ninja.

Passed:

  • cmake --build build -j4 on v0.2.1.3: 331/331 targets, 0 errors (binary md5 1059259999e587d492da5272e8a840f4).
  • recall-test.py (cold ~25k-token prompt, two needles, greedy): both needles found, 0 non-finite - the gate that the earlier scale-less route failed.
  • pfmeasure.py (unique ~21k-token prompts, max_tokens=1): median ~2.7k tok/s, GPU1 rx ~20 GB/s confirms the peer streams; route banner names "no P2P: through mapped host memory in FP16, one weighted sum per token back". Exact per-run numbers are posted as a comment on this PR.

Failed: none observed on this revision.

Not run: HIP / SYCL / Metal builds (no hardware available); the route is CUDA-only code behind the same env gate. Non-NVFP4 packs: untouched code path, not re-validated. Multi-GPU topologies other than this PCIe pair not tested.

Limits

Opt-in only (STRATA_PF_PEER_NVFP4=1); performance numbers are for this PCIe-only box and will differ on NVLink systems. The sums-P2P commit is independently droppable. The P2P-vs-host route analysis and the generation-path micro-bench in the README apply to consumer GeForce BAR1 P2P.


🔄 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/3763 **Author:** [@florian862-art](https://github.com/florian862-art) **Created:** 10/22/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `f-nvfp4-peer` --- ### 📝 Commits (3) - [`328b96a`](https://github.com/Niko1221/Strata/commit/328b96a330f2a533211d76bcd43c58283b06998f) prefill: wire per-expert NVFP4 scales through the peer-prefill route (config C) - [`822c182`](https://github.com/Niko1221/Strata/commit/822c1827da8366fc0f8cb99904a03ba1f66b989f) prefill: opt-in sums mode on the P2P peer route (STRATA_PF_PEER_SUMS_P2P) - [`a7689c4`](https://github.com/Niko1221/Strata/commit/a7689c48bc211020a794292c8e5d8b5ab8ca9308) docs: generation-path P2P micro-bench - the direct host ring wins at every decode row size (10 KB..2.6 MB), 1.7-3x ### 📊 Changes **3 files changed** (+450 additions, -19 deletions) <details> <summary>View changed files</summary> ➕ `src/prefill/README-nvfp4-peer.md` (+350 -0) 📝 `src/prefill/prefill.cpp` (+96 -18) 📝 `src/program/generate.cpp` (+4 -1) </details> ### 📄 Description Replaces #2995 (closed in the 0.2.0-beta tracker reset; `/reopen` was checked OK but GitHub refused to reopen it, per its own message: "open a new pull request and link this one"). Rebased onto main @ cbfd5b92 (v0.2.1.3) at opening; rebased again onto 011c9e60 (v0.2.2) on 2026-10-22 and re-validated on that revision (see the 2026-10-22 comment). ## Problem and result On a `--peer-device` setup the peer GPU computes its experts' MoE rows for every prompt chunk, but on NVFP4 packs its MMQ products ran **without any per-expert scales** (`grp_tail` null, no `s_gate/s_up`, no `s_down`, no `y_scale`) - so every peer-computed row was numerically wrong and `set_peer` refused the combination. Before: the peer-prefill route was unusable on NVFP4; opening it by env alone recites a long prompt but cannot recall it (silent KV corruption, 0 non-finite). After this change, with `STRATA_PF_PEER_NVFP4=1` the route carries the scales end to end: a cold ~25k-token recall prompt finds both needles, 0 non-finite logits, and prefill runs ~2.7k tok/s vs ~2.4k without the peer tier (+12.5 % measured, decode +27 %). ## Related discussion none - focused bug fix, opt-in behind an env gate, no default path touched. ## Approach `gather_native` carries the tail scales, `swiglu_scaled` applies `s_gate/s_up`, `scale_down_rows` scales Dm rows in place on both GPUs (this also fixes the sums-mode path where `s_down` was dropped and `row_sd` read OOB behind the 31 non-finite logits seen earlier), and `y_scale` feeds the w4a4 dequant. The whole route stays behind `STRATA_PF_PEER_NVFP4=1` (prefill.cpp refusal gate + generate.cpp rows==0 skip), so nothing changes unless the env is set. A second, separate and droppable commit adds `STRATA_PF_PEER_SUMS_P2P=1` (sums over the P2P link): correct but slower than the host route on this box (5.5 vs 14.3 GB/s), documented in `src/prefill/README-nvfp4-peer.md` for boxes where P2P beats PCIe. Design + measurement notes live in that README. ## Validation Revision tested: branch head `a7689c48`, rebased onto main @ `011c9e60` (**v0.2.2**); the same three commits on the earlier v0.2.1.3 base (`e7580cca`) were validated identically. Environment: 2x RTX 5070 Ti 16 GB (PCIe, no NVLink), Ubuntu, kernel 7.0.0-38, driver 595.99.02, CUDA build via CMake/Ninja. **Passed:** - `cmake --build build -j4` on v0.2.1.3: 331/331 targets, 0 errors (binary md5 `1059259999e587d492da5272e8a840f4`). - `recall-test.py` (cold ~25k-token prompt, two needles, greedy): both needles found, 0 non-finite - the gate that the earlier scale-less route failed. - `pfmeasure.py` (unique ~21k-token prompts, max_tokens=1): median ~2.7k tok/s, GPU1 rx ~20 GB/s confirms the peer streams; route banner names "no P2P: through mapped host memory in FP16, one weighted sum per token back". Exact per-run numbers are posted as a comment on this PR. **Failed:** none observed on this revision. **Not run:** HIP / SYCL / Metal builds (no hardware available); the route is CUDA-only code behind the same env gate. Non-NVFP4 packs: untouched code path, not re-validated. Multi-GPU topologies other than this PCIe pair not tested. ## Limits Opt-in only (`STRATA_PF_PEER_NVFP4=1`); performance numbers are for this PCIe-only box and will differ on NVLink systems. The sums-P2P commit is independently droppable. The P2P-vs-host route analysis and the generation-path micro-bench in the README apply to consumer GeForce BAR1 P2P. --- <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#4772
No description provided.