DFlash2 drafter for Qwen3.8-Flash-Next: Q8_0 pack tool, GPU forward (conv, K/V ring, windowed attention, top-16 selector), permanent verify/prefill taps, --draft dflash2 --draft-model (opt-in, MTP stays the fallback)
This commit is contained in:
1 parent
5f426c38cb
commit
7f97c35aca
13 files changed
+1572
-32
No files matched your search
@@ -66,6 +66,9 @@
|
||||
#include "strata/core/native_head.hpp"
|
||||
#include "strata/core/verify.hpp"
|
||||
#include "strata/core/mtp.hpp"
|
||||
#if defined(STRATA_HAVE_DFLASH2)
|
||||
#include "strata/core/dflash2.hpp"
|
||||
#endif
|
||||
#include "strata/prefill/prefill.hpp"
|
||||
#if defined(STRATA_PREFILL_MMQ)
|
||||
#include "strata/prefill/moe_mmq.hpp"
|
||||
@@ -781,6 +784,9 @@ struct Options {
|
||||
std::string mtp_q4; ///< "" (off), all, proj (the projections only) or head (the draft head only)
|
||||
/// --mtp-draft-vocab FILE (opt-in): the draft head's token subset from FILE instead of <mtp>/draft_vocab.bin
|
||||
std::string mtp_draft_vocab;
|
||||
/// --draft dflash2 --draft-model PACK (opt-in, CUDA / HIP): the DFlash2 block drafter for Qwen3.8-Flash-Next (tools/dflash2_pack.py) drafts instead
|
||||
/// of the MTP layer, which stays loaded as the fallback. Needs --mtp, --spec and a native pack; a missing pack falls back to the MTP.
|
||||
std::string draft, draft_model;
|
||||
/// A control vector on the residual stream (strata/kernels/cvec.hpp), with llama.cpp's flags: the
|
||||
/// `experimental-speed-projection` profile passes `--control-vector-scaled FILE:1.0 --control-vector-layer-range
|
||||
/// 4 44 --cvec-mode project --cvec-dir per-layer`. None by default; --serve switches a loaded one per request.
|
||||
@@ -933,6 +939,8 @@ void usage() {
|
||||
" (default) or one per stream (llama.cpp's MTP graph)\n"
|
||||
" --mtp-q4 all|proj|head opt-in: the draft layer's projections and/or draft head as 4-bit copies\n"
|
||||
" --mtp-draft-vocab FILE opt-in: the draft head's token subset (default <mtp>/draft_vocab.bin)\n"
|
||||
" --draft mtp|dflash2 the draft source (default mtp); dflash2 needs --draft-model PACK (tools/dflash2_pack.py)\n"
|
||||
" and keeps the MTP layer loaded as the fallback (opt-in, Flash-Next, CUDA / HIP)\n"
|
||||
" --control-vector-scaled FILE:SCALE[,...] a control vector GGUF on the residual stream (llama.cpp's\n"
|
||||
" format; --control-vector FILE = scale 1). --serve: requests switch it (cvec=0|1)\n"
|
||||
" --control-vector-layer-range A B the layers it follows (inclusive; default 1 .. the last)\n"
|
||||
@@ -2672,6 +2680,14 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
else if (a == "--mtp-draft-vocab") o.mtp_draft_vocab = next("--mtp-draft-vocab");
|
||||
else if (a == "--draft") {
|
||||
o.draft = next("--draft");
|
||||
if (o.draft != "dflash2" && o.draft != "mtp") {
|
||||
std::fprintf(stderr, "strata generate: --draft takes mtp or dflash2\n");
|
||||
std::exit(2);
|
||||
}
|
||||
}
|
||||
else if (a == "--draft-model") o.draft_model = next("--draft-model");
|
||||
else if (a == "--control-vector") o.cvec_files.push_back({next("--control-vector"), 1.0f});
|
||||
else if (a == "--control-vector-scaled") {
|
||||
// FILE:SCALE, comma-separated; the LAST colon splits, so a Windows path (C:\...) keeps its drive
|
||||
@@ -5395,6 +5411,10 @@ int main(int argc, char** argv) {
|
||||
// Secure MTP's CUDA0 allocations before the large host arena is registered with both CUDA contexts.
|
||||
// In particular WDDM can refuse the draft weights after mapping tens of GiB of host pages.
|
||||
strata::core::MtpDrafter mtp;
|
||||
#if defined(STRATA_HAVE_DFLASH2)
|
||||
strata::core::Dflash2Drafter df2; // --draft dflash2 (CLI spec loop only)
|
||||
bool use_df2 = false;
|
||||
#endif
|
||||
// the draft layer's geometry (the canonical model's MTP head), `static` because MtpDrafter keeps a reference; the batch
|
||||
// slots' draft-KV copies use this one too
|
||||
static const strata::core::ModelGeometry draft_geometry{};
|
||||
@@ -5418,6 +5438,23 @@ int main(int argc, char** argv) {
|
||||
if (o.pipeline_windows >= 2) mtp.set_force_capture(true);
|
||||
if (!o.mtp.empty() && !mtp.load(o.mtp, draft_geometry, last_st && !mtp_first ? last_st->ss : ss, mtp_t, err, o.mtp_window)) { std::fprintf(stderr, "strata generate: %s%s\n", err.c_str(), vram_free_note().c_str()); return 1; }
|
||||
mtp.set_ple_session(&ss);
|
||||
#if defined(STRATA_HAVE_DFLASH2)
|
||||
if (o.draft == "dflash2") {
|
||||
const char* why = o.mtp.empty() ? "it needs --mtp (the fallback) and --spec 2 or more"
|
||||
: !native_pack ? "it needs a native pack"
|
||||
: multi_gpu || o.batch > 0 || o.serve ? "it is for one card and the CLI run (not --serve, --batch or a layer split) in this build"
|
||||
: o.draft_model.empty() ? "it needs --draft-model PACK (tools/dflash2_pack.py)" : nullptr;
|
||||
if (why == nullptr) {
|
||||
if (df2.load(o.draft_model, 0, err)) {
|
||||
use_df2 = true;
|
||||
} else {
|
||||
std::fprintf(stderr, "strata generate: --draft dflash2: %s; the MTP drafts instead\n", err.c_str());
|
||||
}
|
||||
} else {
|
||||
std::fprintf(stderr, "strata generate: --draft dflash2 is off: %s; the MTP drafts instead\n", why);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (batch_mtp) {
|
||||
// Slot b's drafter lives where the solo drafter does (the guard above: the last stage's GPU), carved from the
|
||||
// LAST stage's slot-b session (bslot_ss.back(): stage 0's on one GPU): it borrows that session's context
|
||||
@@ -15636,6 +15673,13 @@ int main(int argc, char** argv) {
|
||||
return e.empty() && mtp.prefill(R_rows, nxt.data(), T, p0, e);
|
||||
};
|
||||
}
|
||||
#if defined(STRATA_HAVE_DFLASH2)
|
||||
if (use_df2) { // the drafter's context: the last 2047 prompt rows' taps
|
||||
df2.reset();
|
||||
prefill.set_taps(df2.tap_layers(), std::max<int64_t>(0, n_prompt - 2047), 2048);
|
||||
prefill.on_taps = [&](const float* taps, int64_t rows, int64_t pos0, std::string& e) -> bool { return df2.context(taps, rows, pos0, e); };
|
||||
}
|
||||
#endif
|
||||
if (!kvg_started) { // the elastic K/V: every cell this run can reach (no loan)
|
||||
kvg_started = true;
|
||||
kvg_start(xcache.slots());
|
||||
@@ -15672,6 +15716,9 @@ int main(int argc, char** argv) {
|
||||
std::fprintf(stderr, "strata generate: %zu lent slots refilled in %.1f ms\n", lent.size(),
|
||||
std::chrono::duration<double, std::milli>(Clock::now() - tr).count());
|
||||
}
|
||||
#if defined(STRATA_HAVE_DFLASH2)
|
||||
prefill.clear_taps();
|
||||
#endif
|
||||
prefill_batched_ms = std::chrono::duration<double, std::milli>(Clock::now() - tp0).count();
|
||||
prefill_ms += prefill_batched_ms;
|
||||
pos_start = n_batched;
|
||||
@@ -15959,6 +16006,9 @@ int main(int argc, char** argv) {
|
||||
vh.slot_off = xcache.slot_offsets(); // E-6: the device plan's pointers
|
||||
vh.n_slots = xcache.slots();
|
||||
if (pcie_balance()) ver.set_pcie_balance(&drive.d.pcie_model);
|
||||
#if defined(STRATA_HAVE_DFLASH2)
|
||||
if (use_df2) ver.set_taps(df2.tap_layers());
|
||||
#endif
|
||||
if (!ver.init(wt, g, ss, vh, native_head.loaded() ? &native_head : nullptr, o.spec, err)) {
|
||||
std::fprintf(stderr, "strata generate: %s\n", err.c_str());
|
||||
return 1;
|
||||
@@ -15968,6 +16018,17 @@ int main(int argc, char** argv) {
|
||||
std::fprintf(stderr, "strata generate: %s\n", err.c_str());
|
||||
return 1;
|
||||
}
|
||||
#if defined(STRATA_HAVE_DFLASH2)
|
||||
if (use_df2 && !ver.tapping()) {
|
||||
std::fprintf(stderr, "strata generate: --draft dflash2: the verifier keeps no taps here; the MTP drafts instead\n");
|
||||
use_df2 = false;
|
||||
}
|
||||
if (use_df2 && !df2.bind(wt, &native_head, o.mtp_draft_vocab.empty() ? o.mtp + "/draft_vocab.bin" : o.mtp_draft_vocab, err)) {
|
||||
std::fprintf(stderr, "strata generate: --draft dflash2: %s; the MTP drafts instead\n", err.c_str());
|
||||
use_df2 = false;
|
||||
}
|
||||
if (use_df2) std::fprintf(stderr, "strata generate: DFlash2 drafter on (%s), the MTP layer stays as the fallback\n", o.draft_model.c_str());
|
||||
#endif
|
||||
mem_mark("the verifier and the drafter's binding");
|
||||
ver.set_sampling(sp); // the CLI's own sampling (until 0.1.19 this loop was always greedy); no penalties here
|
||||
if (use_mtp) mtp.set_draft_sampling(sp); // STRATA_SPEC_COUPLED=1: sampled drafts (a no-op otherwise)
|
||||
@@ -16263,6 +16324,19 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}).detach();
|
||||
}
|
||||
// the next round's drafts after a commit: the MTP chain, or the DFlash2 block from the committed rows' taps
|
||||
auto draft_next = [&](int T_, int a_) -> bool {
|
||||
#if defined(STRATA_HAVE_DFLASH2)
|
||||
if (use_df2) {
|
||||
int32_t dd[strata::core::Dflash2Drafter::kDrafts];
|
||||
float pp[strata::core::Dflash2Drafter::kDrafts];
|
||||
if (!df2.draft(ver.tap_dev(), a_ + 1, p, outv[(size_t) a_], dd, pp, err)) return false;
|
||||
for (size_t i = 0; i < drafts.size() && i < (size_t) strata::core::Dflash2Drafter::kDrafts; ++i) { drafts[i] = dd[i]; dprob[i] = pp[i]; }
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return mtp.draft(T_, outv.data(), p, a_, drafts.data(), err, dprob.data(), (float) o.spec_min_p);
|
||||
};
|
||||
while ((int64_t) produced.size() < max_new) {
|
||||
const Clock::time_point t0 = Clock::now();
|
||||
strata::core::progress_at("spec loop: choosing the window", (int64_t) produced.size());
|
||||
@@ -16403,8 +16477,7 @@ int main(int argc, char** argv) {
|
||||
total_ms += std::chrono::duration<double, std::milli>(Clock::now() - t0).count();
|
||||
break;
|
||||
}
|
||||
const bool drafted = !use_mtp || (int64_t) produced.size() >= max_new ||
|
||||
mtp.draft(T, outv.data(), p, a, drafts.data(), err, dprob.data(), (float) o.spec_min_p);
|
||||
const bool drafted = !use_mtp || (int64_t) produced.size() >= max_new || draft_next(T, a);
|
||||
if (adapt_thr.joinable()) adapt_thr.join();
|
||||
if (!adapt_ok) return 1;
|
||||
if (!drafted) {
|
||||
@@ -16528,6 +16601,12 @@ int main(int argc, char** argv) {
|
||||
1000 * pm.g0, 1000 * pm.g);
|
||||
}
|
||||
(void) pool_ms0;
|
||||
#if defined(STRATA_HAVE_DFLASH2)
|
||||
if (use_df2 && df2.rounds > 0)
|
||||
std::printf("%-24s %.3f ms/round drafting (%lld rounds, GPU %.3f), %.0f MiB of VRAM\n", "dflash2", df2.ms_draft / (double) df2.rounds,
|
||||
(long long) df2.rounds, df2.ms_gpu / (double) df2.rounds, (double) df2.vram_bytes() / 1048576.0);
|
||||
else
|
||||
#endif
|
||||
if (use_mtp && rounds > 0)
|
||||
std::printf("%-24s %.3f ms/round drafting (%lld rounds), MTP prompt %.1f ms, %.0f MiB of VRAM\n", "mtp",
|
||||
mtp.ms_draft / (double) mtp.rounds, (long long) mtp.rounds, mtp.ms_prefill,
|
||||
|
||||
Reference in new issue
Block a user