rc1 merge pf-small-df2-split (dcad09339): generate.cpp conflicted at the DFlash2 serve on_taps line; kept the layer-split install and added the branch's df2_tap_dump (env-gated diagnostic) to the single-card lambda

This commit is contained in:
Niko1221 committed 2026-11-02 09:58:43 +01:00
commit df642fbf77
7 files changed
+210 -19

No files matched your search

+66 -2
View File
@@ -84,6 +84,8 @@
#include "strata/prefill/kva.hpp"
#include "strata/prefill/kva_floor.hpp"
#include "strata/prefill/prefill.hpp"
#include "strata/prefill/pf_fused_override.hpp"
#include "strata/core/sm120_series.hpp"
#if defined(STRATA_PREFILL_MMQ)
#include "strata/prefill/moe_mmq.hpp"
#endif
@@ -183,6 +185,22 @@ bool window_slot_copy_main(bool into_slot, int slot, int64_t upto, bool kv_only,
#include <unordered_map>
#include <vector>
// STRATA_DF2_TAP_DUMP=FILE (research, off by default): every prompt tap batch the DFlash2 context takes is appended to FILE as
// int64 pos0, int64 rows, then rows x floats_per_row float32 (the tap rows [rows][taps][n_embd]), for the layer-major / chunk-major
// equivalence test (DF-08). Nothing runs without the variable.
static void df2_tap_dump(const float* dev, int64_t rows, int64_t pos0, int64_t floats_per_row) {
static const char* path = std::getenv("STRATA_DF2_TAP_DUMP");
if (path == nullptr || path[0] == '\0' || rows <= 0) return;
std::vector<float> h((size_t) (rows * floats_per_row));
if (cudaMemcpy(h.data(), dev, h.size() * sizeof(float), cudaMemcpyDeviceToHost) != cudaSuccess) return;
if (std::FILE* f = std::fopen(path, "ab")) {
std::fwrite(&pos0, 8, 1, f);
std::fwrite(&rows, 8, 1, f);
std::fwrite(h.data(), sizeof(float), h.size(), f);
std::fclose(f);
}
}
// logprobs=K / allowed=...: one `LP` line for the token just emitted, from `ver`'s head
// logits for the window row it came from (before sampling, penalties and temperature).
// Format matches the SYCL port's LP line so one server-side reader serves both.
@@ -10104,6 +10122,52 @@ int main(int argc, char** argv) {
return std::max(c, small); // never a smaller chunk than 0.1.39's
};
int64_t chunk = scan(nullptr);
// The small-card prompt path (strata::small_card_prompt_path; owner's yes 2026-11-02): this chunk is what the DEFAULT prompt path got from the cache.
// Below 8,192 tokens the default streams every expert again for every chunk, and the unfused experts plus (from two chunks) the layer-major walk
// read the same prompt 9-50% sooner (RESULTS-DF2MEM.md); the chunk is then sized again for that layout. One CUDA card, a native pack, an auto
// chunk; STRATA_PF_FUSED / STRATA_PREFILL_LAYER_MAJOR set by the user win; STRATA_PF_SMALL=0 turns the rule off.
if (chunk > 0 && o.prefill_auto && !multi_gpu && stages.empty() && !(std::getenv("STRATA_PF_SMALL") != nullptr && std::getenv("STRATA_PF_SMALL")[0] == '0')) {
#if defined(STRATA_USE_HIP)
constexpr bool pf_small_hip = true;
#else
constexpr bool pf_small_hip = false;
#endif
const char* fe = std::getenv("STRATA_PF_FUSED");
const char* le = std::getenv("STRATA_PREFILL_LAYER_MAJOR");
const strata::SmallCardPromptPath pp = strata::small_card_prompt_path(
chunk, pf_small_hip, 1, strata::kernels::cpu::expert_layout().native, strata::qwen_defaults_026(),
fe != nullptr && fe[0] != '\0', le != nullptr && le[0] != '\0');
if (pp.any()) {
const int64_t chunk_default = chunk;
if (pp.fused_off) strata::prefill::pf_fused_override().store(0);
if (pp.layer_major) {
#if defined(_WIN32)
_putenv_s("STRATA_PREFILL_LAYER_MAJOR", "1");
#else
setenv("STRATA_PREFILL_LAYER_MAJOR", "1", 0);
#endif
}
chunk = scan(nullptr);
if (chunk <= 0) { // the unfused layout's buffers do not fit anywhere: keep the default path as it was
strata::prefill::pf_fused_override().store(-1);
if (pp.layer_major) {
#if defined(_WIN32)
_putenv_s("STRATA_PREFILL_LAYER_MAJOR", "");
#else
unsetenv("STRATA_PREFILL_LAYER_MAJOR");
#endif
}
chunk = scan(nullptr);
std::fprintf(stderr, "strata serve: small expert cache: the unfused prompt path does not fit here; the default path stays (chunk %lld tokens)\n",
(long long) chunk);
} else
std::fprintf(stderr, "strata serve: small expert cache: the default prompt path would read in chunks of %lld tokens (under %lld), "
"so prompts read with the unfused experts%s (chunk %lld tokens); STRATA_PF_SMALL=0 keeps the default path, "
"STRATA_PF_FUSED / STRATA_PREFILL_LAYER_MAJOR set by hand win\n",
(long long) chunk_default, (long long) strata::kSmallCardChunkBelow,
pp.layer_major ? " and, from two chunks, the layer-major walk" : "", (long long) chunk);
}
}
// #448: a small card in a layer split caps every stage's chunk (an RTX 3080's 512-slot cache held a
// 32 GB card's split to 512 tokens: prompts 6.2x slower, decode the same). Named when it bites, so the
// regression is one log line: each stage that cannot fund the chunk CUDA0 alone would read in.
@@ -10940,7 +11004,7 @@ int main(int argc, char** argv) {
if (o.draft_mtp_spec_set && o.spec > o.draft_mtp_spec) o.spec = o.draft_mtp_spec; // the MTP drafts with its own window, not DFlash2's
} else {
if (multi_gpu) df2_stage_prompt_taps_install();
else sp.on_taps = [&](const float* taps, int64_t rows, int64_t pos0, std::string& e) -> bool { return df2.context(taps, rows, pos0, e); };
else sp.on_taps = [&](const float* taps, int64_t rows, int64_t pos0, std::string& e) -> bool { df2_tap_dump(taps, rows, pos0, (int64_t) df2.tap_layers().size() * g.n_embd); return df2.context(taps, rows, pos0, e); };
std::fprintf(stderr, "strata serve: DFlash2 drafter on (%s, graphs captured in %.0f ms); windows up to %d tokens; %s%s\n",
o.draft_model.c_str(), df2.ms_capture, o.spec, df2_solo ? "no MTP layer is loaded (--draft-fallback none)" : "the MTP layer stays as the fallback",
df2_chain ? (std::string("; layer split: the drafter is on CUDA") + std::to_string(df2.device()) + " (" + (df2_on_last ? "last" : "first") +
@@ -19126,7 +19190,7 @@ int main(int argc, char** argv) {
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); };
prefill.on_taps = [&](const float* taps, int64_t rows, int64_t pos0, std::string& e) -> bool { df2_tap_dump(taps, rows, pos0, (int64_t) df2.tap_layers().size() * g.n_embd); return df2.context(taps, rows, pos0, e); };
}
#endif
if (!kvg_started) { // the elastic K/V: every cell this run can reach (no loan)