dflash2: reserve the drafter's head before the expert cache is sized, loud fallback lines naming the VRAM needed, Blackwell window cap 6 (draft_cap_test)

This commit is contained in:
Niko1221 committed 2026-10-22 12:44:45 +02:00
1 parent 3ae2123bce
commit eebb870922
4 files changed
+69 -5

No files matched your search

+23 -5
View File
@@ -68,6 +68,7 @@
#include "strata/core/mtp.hpp"
#if defined(STRATA_HAVE_DFLASH2)
#include "strata/core/dflash2.hpp"
#include "strata/core/draft_cap.hpp"
#endif
#include "strata/prefill/prefill.hpp"
#if defined(STRATA_PREFILL_MMQ)
@@ -5463,20 +5464,27 @@ int main(int argc, char** argv) {
#else
const bool uma = false;
#endif
const int cap = o.draft_cap > 0 ? o.draft_cap : (uma ? 5 : 0);
#if defined(STRATA_USE_HIP)
const int cc_major = 0;
#else
const int cc_major = dp.major;
#endif
const int cap = o.draft_cap > 0 ? o.draft_cap : strata::core::dflash2_auto_cap(uma, cc_major);
if (cap > 0 && o.spec > cap) {
std::fprintf(stderr, "strata generate: --draft dflash2: windows capped at %d tokens (%s; --draft-cap N changes it)\n", cap,
o.draft_cap > 0 ? "as asked" : "the width measured best on this card");
o.spec = cap;
}
#if !defined(STRATA_USE_HIP)
if (o.draft_cap == 0 && dp.totalGlobalMem < (size_t) 13 << 30)
if (o.draft_cap == 0 && strata::core::dflash2_small_nvidia(true, dp.totalGlobalMem))
std::fprintf(stderr, "strata generate: --draft dflash2: on a 12 GB NVIDIA card the MTP drafter was faster in most measurements "
"(code prompts at a window of 6 gained 3%%); continuing as asked\n");
#endif
}
} else {
std::fprintf(stderr, "strata generate: --draft dflash2: %s; the MTP drafts instead\n", err.c_str());
std::fprintf(stderr, "strata generate: --draft dflash2: %s. DFlash2 needs about 1.2 GiB of VRAM (the pack 0.76 GiB, its buffers and K/V ring "
"0.25 GiB, a draft head 0.2 GiB); start with --vram-reserve-mib 1900 to keep it (the expert cache then gives up about 2.5%% "
"of its experts to the CPU), or a smaller --max-context. 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);
@@ -5826,6 +5834,9 @@ int main(int argc, char** argv) {
const int64_t pf_mib = (o.prefill_chunk > 0 && !pf_borrow) ? 160 + (o.prefill_chunk * 680) / 1024 : 0;
int64_t mtp_b = (!o.mtp.empty() && native_head.loaded())
? (int64_t) mtp.bind_bytes(native_head.row_bytes(), n_vocab) : 0;
#if defined(STRATA_HAVE_DFLASH2)
if (use_df2 && native_head.loaded()) mtp_b += (int64_t) mtp.bind_bytes(native_head.row_bytes(), n_vocab) + (48 << 20); // DFlash2's own draft head and logits
#endif
if (stages.empty())
for (const auto& d : slot_mtp) mtp_b += (int64_t) d->bind_bytes(native_head.row_bytes(), n_vocab);
const int64_t pipe_b = o.pipeline_windows <= 0 ? 0
@@ -6070,6 +6081,9 @@ int main(int argc, char** argv) {
if (stages.empty())
for (const auto& d : slot_mtp)
mtp_bind += (int64_t) d->bind_bytes(native_head.row_bytes(), n_vocab);
#if defined(STRATA_HAVE_DFLASH2)
if (use_df2 && native_head.loaded()) mtp_bind += (int64_t) mtp.bind_bytes(native_head.row_bytes(), n_vocab) + (48 << 20); // DFlash2's own draft head and logits, bound after this
#endif
const int64_t reserve = (((int64_t) o.vram_reserve_mib + prefill_mib) << 20) + mtp_bind + pipe_first;
const int64_t blob = (int64_t) strata::kernels::cpu::expert_layout().max_blob;
int64_t slots = ((int64_t) free_b - reserve) / blob;
@@ -16052,11 +16066,15 @@ int main(int argc, char** argv) {
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());
std::fprintf(stderr, "strata generate: --draft dflash2: %s. It needs about 1.2 GiB of VRAM in all (the pack 0.76 GiB, buffers and K/V ring "
"0.25 GiB, a draft head 0.2 GiB); --vram-reserve-mib 1900 keeps it (the expert cache gives up about 2.5%% of its experts "
"to the CPU). The MTP drafts instead.\n", err.c_str());
use_df2 = false;
}
if (use_df2 && !df2.prepare(ver.tap_dev(), err)) {
std::fprintf(stderr, "strata generate: --draft dflash2: %s; the MTP drafts instead\n", err.c_str());
std::fprintf(stderr, "strata generate: --draft dflash2: %s. It needs about 1.2 GiB of VRAM in all (the pack 0.76 GiB, buffers and K/V ring "
"0.25 GiB, a draft head 0.2 GiB); --vram-reserve-mib 1900 keeps it (the expert cache gives up about 2.5%% of its experts "
"to the CPU). The MTP drafts instead.\n", err.c_str());
use_df2 = false;
}
if (use_df2) std::fprintf(stderr, "strata generate: DFlash2 drafter on (%s, graphs captured in %.0f ms), the MTP layer stays as the fallback\n", o.draft_model.c_str(), df2.ms_capture);