diff --git a/arch/qwen35_fp8/qwen35_fp8.cpp b/arch/qwen35_fp8/qwen35_fp8.cpp index 1f182347..88aac2eb 100644 --- a/arch/qwen35_fp8/qwen35_fp8.cpp +++ b/arch/qwen35_fp8/qwen35_fp8.cpp @@ -424,8 +424,11 @@ static int declare_dflash2(RadBuilder* b, const RadModelMeta* meta, const RadBui /* --draft-coupling (RadBuildCtx::draft_coupling): the walk samples each draft from Q, its * scores' softmax over the best eight candidates, and the sampler couples the target's own draw * to it (abi/rad_spechub.h). The planes are named as the MTP head's, which is how the engine - * finds them. RADIANCE_DFLASH_Q_TEMP sets Q's temperature (default 1); any value keeps the - * output exact and moves only acceptance. */ + * finds them. RADIANCE_DFLASH_Q_TEMP sets Q's temperature; any value keeps the output exact + * and moves only acceptance. The default, 0.6, is where held-out acceptance peaked on + * Qwen3.8-27B MXFP4 + its DFlash2 drafter at request temperature 1 (tokens a step at x4, 32 + * rows: ordinary rule 3.52; Q at 1.0 3.71, 0.7 3.88, 0.5 3.85, 0.35 3.77): the walk's scores + * are flatter than the target's law, and a sharper Q puts its mass where the target's is. */ if (ctx->draft_coupling) { if (dc.steps() > RAD_MTP_COUPLE_MAX_ROUNDS || dc.sel_topk > RAD_DFLASH_COUPLE_MAX_K || dc.sel_rank % RAD_DFLASH_EDGE_PARTS || dc.sel_rank > RAD_DFLASH_COUPLE_MAX_R) { @@ -435,6 +438,7 @@ static int declare_dflash2(RadBuilder* b, const RadModelMeta* meta, const RadBui RAD_DFLASH_COUPLE_MAX_R); return RAD_E_UNSUPPORTED; } + dc.q_temp = 0.6; if (const char* e = std::getenv("RADIANCE_DFLASH_Q_TEMP")) { const double t = std::strtod(e, nullptr); if (!(t > 0.0) || t > 100.0) { diff --git a/docs/GUIDE.md b/docs/GUIDE.md index 57c65e3e..0c417f1f 100644 --- a/docs/GUIDE.md +++ b/docs/GUIDE.md @@ -1943,7 +1943,7 @@ by 0.002-0.003 nats. | `--num-speculative-tokens N` | auto | speculative window; 0 disables. The ceiling under `--draft-window adaptive` | | `--draft-window MODE` | fixed | `fixed` drafts N every step; `adaptive` follows each sequence's acceptance and the measured step cost, serial draft heads only (§4.6) | | `--draft-short-from N` | 0 | a block drafter that declares a shorter block runs it from N decoding sequences on, its own block again two below; 0 never (§4.6) | -| `--draft-coupling MODE` | off | `on`: a linear MTP drafter with a 2-bit candidate head (Qwen3.8-Flash-Next) samples each proposal from its reranked top-8 and the sampler maximally couples the target's draw to it. The output distribution is unchanged and a fixed seed yields other tokens than `off`. The head's law is taken at temperature 1, so it pays at high request temperatures and costs at low ones: on Flash-Next TP2 at 2x R9700, tokens per decode step +18% at temperature 1.0 and c1, +11% at 0.7 and c4, -4% at 0.3. Greedy rows are unchanged. A DFlash2 drafter (Qwen3.5/3.8) couples its candidate walk instead: each position is sampled from the softmax of the walk's own scores over its best eight candidates, at temperature `RADIANCE_DFLASH_Q_TEMP` (default 1). Any other drafter is refused at startup | +| `--draft-coupling MODE` | off | `on`: a linear MTP drafter with a 2-bit candidate head (Qwen3.8-Flash-Next) samples each proposal from its reranked top-8 and the sampler maximally couples the target's draw to it. The output distribution is unchanged and a fixed seed yields other tokens than `off`. The head's law is taken at temperature 1, so it pays at high request temperatures and costs at low ones: on Flash-Next TP2 at 2x R9700, tokens per decode step +18% at temperature 1.0 and c1, +11% at 0.7 and c4, -4% at 0.3. Greedy rows are unchanged. A DFlash2 drafter (Qwen3.5/3.8) couples its candidate walk instead: each position is sampled from the softmax of the walk's own scores over its best eight candidates, at temperature `RADIANCE_DFLASH_Q_TEMP` (default 0.6, where acceptance peaked); on Qwen3.8-27B MXFP4 TP2 at 2x R9700 and request temperature 1, tokens per verify step +8% on held-out prompts at c4 (3.53 to 3.82) and decode +2..8% per stream at c1/c4. Any other drafter is refused at startup | | `--draft-model PATH` | | not implemented: merge the drafter at convert time | **Server** diff --git a/plugin/spechub/spechub.hip b/plugin/spechub/spechub.hip index 300f8db6..5821c7bb 100644 --- a/plugin/spechub/spechub.hip +++ b/plugin/spechub/spechub.hip @@ -199,6 +199,20 @@ __global__ __launch_bounds__(kDfThreads) void dflash_couple( const int c = tid / RAD_DFLASH_EDGE_PARTS, j = tid % RAD_DFLASH_EDGE_PARTS; for (int64_t l = 0; l < steps; ++l) { const int64_t row = s * steps + l; + /* What does not depend on the predecessor is loaded first, so its latency overlaps the + * predecessor's codebook row: the candidate, its successor slice and its unary score. */ + const int32_t id = c < K ? cand[row * ld_cand + c] : -1; + const bool id_ok = id >= 0 && id < vocab; + const bool wide = R == 32 * RAD_DFLASH_EDGE_PARTS; + uint4 v[4] = {}; + if (id_ok && wide) { + /* DFlash2's rank 256: the slice's 32 values in four 16-byte loads issued together. A + * load inside the fmaf chain would wait out one memory latency per element. */ + const uint4* src = reinterpret_cast(succ + (int64_t)id * R + j * 32); +#pragma unroll + for (int i = 0; i < 4; ++i) v[i] = src[i]; + } + const float un = tid < K ? unary[row * ld_unary + tid] : 0.0f; const int32_t pid = spid; const bool ok = pid >= 0 && pid < vocab; for (int64_t r = tid; r < R; r += kDfThreads) @@ -207,24 +221,16 @@ __global__ __launch_bounds__(kDfThreads) void dflash_couple( : 0.0f; __syncthreads(); if (c < K) { - const int32_t id = cand[row * ld_cand + c]; float pv = 0.0f; - if (id >= 0 && id < vocab) { - const uint16_t* srow = succ + (int64_t)id * R; - if (R == 32 * RAD_DFLASH_EDGE_PARTS) { - /* DFlash2's rank 256: the slice's 32 values in four 16-byte loads issued - * together, then rad_dflash_edge_part's fmaf chain over them in its order. A - * load inside the chain would wait out one memory latency per element. */ - const uint4* src = reinterpret_cast(srow + j * 32); - uint4 v[4]; -#pragma unroll - for (int i = 0; i < 4; ++i) v[i] = src[i]; + if (id_ok) { + if (wide) { + /* rad_dflash_edge_part's fmaf chain over the slice, in its order. */ const uint16_t* h = reinterpret_cast(v); const float* a = sa + j * 32; #pragma unroll for (int r = 0; r < 32; ++r) pv = fmaf(a[r], rad_dflash_bf2f(h[r]), pv); } else { - pv = rad_dflash_edge_part(sa, srow, R, j); + pv = rad_dflash_edge_part(sa, succ + (int64_t)id * R, R, j); } } part[tid] = pv; @@ -237,7 +243,7 @@ __global__ __launch_bounds__(kDfThreads) void dflash_couple( if (sid[tid] >= 0 && sid[tid] < vocab) for (int q = 0; q < RAD_DFLASH_EDGE_PARTS; ++q) acc += part[tid * RAD_DFLASH_EDGE_PARTS + q]; - sc[tid] = unary[row * ld_unary + tid] + acc; + sc[tid] = un + acc; } if (tid < 8) slot_id[tid] = -2; __syncthreads();