Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

feat(mtp): add --coupled-draft and --no-coupled-draft CLI options for coupled speculative sampling

Pravesh Khatanab0711943b2c7
diff --git a/include/strata/core/coupled_draft.hpp b/include/strata/core/coupled_draft.hpp
index 4758674b4..d095e3a01 100644
--- a/include/strata/core/coupled_draft.hpp
+++ b/include/strata/core/coupled_draft.hpp
@@ -49,15 +49,23 @@ namespace strata::core {
/// The longest penalty window the coupled drafter mirrors (serve's kPenaltyWindowCap).
inline constexpr int kCoupledHistCap = 4096;
-/// STRATA_SPEC_COUPLED=1 (any value but empty or "0"): read once.
-inline bool coupled_draft_env() {
- static const bool on = [] {
+inline bool& coupled_draft_state() {
+ static bool on = [] {
const char* e = std::getenv("STRATA_SPEC_COUPLED");
return e != nullptr && *e != '\0' && std::strcmp(e, "0") != 0;
}();
return on;
}
+/// Whether coupled draft sampling is enabled (via STRATA_SPEC_COUPLED=1 or --coupled-draft CLI flag).
+inline bool coupled_draft_env() {
+ return coupled_draft_state();
+}
+
+inline void set_coupled_draft(bool on) {
+ coupled_draft_state() = on;
+}
+
/// The MTP cell of chain step j after a window at `p` with `a` drafts accepted (draft() runs step j there).
STRATA_COUPLED_HD inline int64_t coupled_draft_cell(int64_t p, int a, int j) { return p + a + j; }
diff --git a/src/program/generate.cpp b/src/program/generate.cpp
index ce58147e6..ee915d275 100644
--- a/src/program/generate.cpp
+++ b/src/program/generate.cpp
@@ -18,6 +18,7 @@
#include "strata/core/expert_cache.hpp"
#include "strata/core/conversation_snapshot.hpp"
#include "strata/core/conversation_memory.hpp"
+#include "strata/core/coupled_draft.hpp"
#include "strata/core/expert_source.hpp"
#include "strata/core/pinned.hpp"
#include "strata/core/remote_experts.hpp"
@@ -257,6 +258,7 @@ struct Options {
/// pool's own drain: 33.7 GB/s against 5/6 x 44.14 = 36.8 for five workers, on a machine whose sixth core
/// is reserved for a host thread that has nothing to do while the drain runs.
bool no_host_worker = false;
+ bool coupled_draft = strata::core::coupled_draft_env(); ///< Coupled draft sampling for MTP drafter under sampling
bool mmap_experts = false; ///< R2.1: opt OUT of the resident arena, back to MapViewOfFile
std::string shared_expert_arena; ///< Linux: optional file backing for the resident arena shared by processes
bool resident_cpu_experts = false; ///< mmap-backed static-cache misses copied into ordinary RAM
@@ -542,6 +544,8 @@ void usage() {
" --pool-workers N R2.2: CPU expert pool worker count. Default 0 = every physical core\n"
" except the one the host loop spins on. A sweep is how the pool's\n"
" deviation from `cpu_s2` is attributed.\n"
+ " --coupled-draft enable coupled draft sampling for MTP drafter under sampling (STRATA_SPEC_COUPLED)\n"
+ " --no-coupled-draft disable coupled draft sampling (propose argmax drafts)\n"
" --mmap-experts R2.1: opt OUT of the resident expert arena, back to MapViewOfFile.\n"
" The A/B arm: the mmap's rate depends on the OS page cache holding\n"
" 34 GB, and measured 71.97 vs 34.78 ms/token cold vs warm.\n"
@@ -1070,6 +1074,8 @@ int main(int argc, char** argv) {
else if (a == "--pool-workers") o.pool_workers = std::atoi(next("--pool-workers"));
else if (a == "--no-host-worker") o.no_host_worker = true;
else if (a == "--no-ple-prefetch") o.no_ple_prefetch = true;
+ else if (a == "--coupled-draft") o.coupled_draft = true;
+ else if (a == "--no-coupled-draft") o.coupled_draft = false;
else parsed = false;
// The chain continues here in a second statement: one chain of 120+ `else if` passed MSVC's limit of 128
// nested blocks (C1061). The order of the tests and what each does are unchanged.
@@ -1216,6 +1222,7 @@ int main(int argc, char** argv) {
}
}
}
+ strata::core::set_coupled_draft(o.coupled_draft);
if (o.serve && o.conversation_cache_mib > 0 && (o.prompt_cache == 0 || o.conversation_cache_slots == 0))
std::fprintf(stderr, "strata serve: warning: conversation caching is disabled by %s\n",
o.prompt_cache == 0 ? "--prompt-cache 0" : "--conversation-cache-slots 0");