From 1bb7ad3ef942fc7e2afc96ac1fc77a930065b7fc Mon Sep 17 00:00:00 2001 From: Ashlyn Date: Sun, 18 Oct 2026 09:32:38 -0500 Subject: [PATCH] The series' PR beneath, composed (a copy; it drops out when it lands) #159's tree (a full fence on four-rank prefill-sized all-reduces), which the maintainer will merge by hand in the next release, as the integration branch composed and tested it. Not for review here: review the last commit. Co-Authored-By: Claude Opus 5.5 --- docs/GUIDE.md | 1 + libr4d/r4d_rows.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/docs/GUIDE.md b/docs/GUIDE.md index e2ee6d0c..faa248ca 100644 --- a/docs/GUIDE.md +++ b/docs/GUIDE.md @@ -3085,6 +3085,7 @@ reductions running on fewer blocks: Qwen3.8-27B's 41k-token prefill 9.5 s uncapp | `RADIANCE_CALIB_TOKENS` | with `RADIANCE_CALIB_DIR`, the tokens the calibration tap accumulates before it writes and switches itself off (default 65536) | | `RADIANCE_G3_CALIB_LAYERS` | `lo:hi`: `arch/gemma3`'s calibration tap over layers lo to hi - 1 only, to take a large model's Grams in passes (docs/ARCHITECTURES.md) | | `RADIANCE_PROFILE_EVERY` | with `--profile-ops`, dump the per-op table every N steps (default 32) | +| `RADIANCE_AR_FENCE_FROM` | four-rank all-reduces of at least this many elements take a full fence before their flag (default 131072: prefill chunks, never decode or verify); cures a rare fresh-start divergence on the 31B at tp 4; `0` turns it off | | `RADIANCE_LOG_STEPS` | log one line per step: its phase, sequences, and each one's token count and context (§4.5) | | `RADIANCE_GEMMA4_OVERLAP` | the Gemma 4 31B's prefill overlap (`arch/gemma4_bf16`, two or more ranks, fused junctions, the exact all-reduce wire): a prefill step of 1024 rows or more runs as two slices, each slice's all-reduces on a second stream beside the other's compute. On by default; `0` turns it off and runs every step whole (the startup notes say which) | | `RADIANCE_AR8_SHARD_WEIGHTS`, `RADIANCE_AR8_PIECES` | the eight-rank two-shot's shard weights (`auto`, the default, reads the PCIe links; `off`; or eight integers) and piece count, with `RADIANCE_AR8_SHARD_WEIGHTS_MIN_ELEMS` and `RADIANCE_AR8_PIECES_MIN_ELEMS` for the message size each starts at (§4.7) | diff --git a/libr4d/r4d_rows.cpp b/libr4d/r4d_rows.cpp index 4567168a..9a8ba1d0 100644 --- a/libr4d/r4d_rows.cpp +++ b/libr4d/r4d_rows.cpp @@ -9185,6 +9185,25 @@ extern "C" void r4d_cfg_mxfp4_tiled(const RadArgs* a, R4dMxTileCfg* out) { extern "C" void r4d_cfg_split(const RadArgs* a, R4dSplitCfg* out) { out->splits = TUNE(a, tAttnSplit, "splits"); } +/* A fresh-start divergence (4x R9700 behind an EPYC root complex, 2026-10-17): on a freshly + * started 31B server, a prefill all-reduce now and then reads a peer's scratch before that peer's + * words have landed -- the first reuse of a double-buffered slot, inputs identical on every rank + * (RADIANCE_DEBUG_OPHASH) -- and the first greedy reply flips a near-tie. Every thread's full + * system fence before the flag (drain 1) cures it, as does one after it (acq 1); the per-wave + * store wait (drain 3) and the publisher's one writeback (pub 1) do not, and Relaxed Ordering off + * on every link does not. The mechanism below the fence is not known. Decode heights never showed + * it, and the fence costs them ~0.7 %, so it is taken only from RADIANCE_AR_FENCE_FROM elements + * (default 131072, 24 rows of the 31B's 5376: above any verify height, and every prefill chunk); + * 0 never. Read once. Only at four ranks, where it was seen and cured: at two (Qwen3.8-27B's + * prefill at tp 2) it cost 4.5% of prefill, and no two-rank start ever flipped. */ +static long long ar_fence_from() { + static const long long v = [] { + const char* e = std::getenv("RADIANCE_AR_FENCE_FROM"); + return e && *e ? std::atoll(e) : 131072LL; + }(); + return v; +} + extern "C" void r4d_cfg_ar(const RadArgs* a, R4dArCfg* out) { out->nblocks = TUNE(a, tAr, "nblocks"); out->nthreads = TUNE(a, tAr, "nthreads"); @@ -9192,6 +9211,12 @@ extern "C" void r4d_cfg_ar(const RadArgs* a, R4dArCfg* out) { out->acq = TUNE(a, tAr, "acq"); /* An axis of the four-rank junction only (tArQ84); 1 for every other row, as before. */ out->pub = TUNE(a, tArQ84, "pub"); + /* Operand 0 is the message on every collective that reads this (all_reduce's x, a junction's + * [M, n] input, all_gather's source). */ + const long long from = ar_fence_from(); + if (from > 0 && a && a->t && a->n_t > 0 && rad_tensor_numel(&a->t[0]) >= from && + r4d_geti_or(a, "world_size", 4) == 4) /* the four-rank rows carry no world_size */ + out->drain = 1; } extern "C" int r4d_cfg_ar_tail(const RadArgs* a) { return TUNE(a, tArQ84, "tail");