Merge commit '9c282fbc5' into f-027-hip

This commit is contained in:
Niko1221 committed 2026-10-26 12:15:19 +01:00
commit 2d1db1ec6f
13 files changed
+234 -88

No files matched your search

+23 -19
View File
@@ -73,6 +73,7 @@
#include "strata/core/draft_cap.hpp"
#endif
#include "strata/prefill/kva.hpp"
#include "strata/prefill/kva_floor.hpp"
#include "strata/prefill/prefill.hpp"
#if defined(STRATA_PREFILL_MMQ)
#include "strata/prefill/moe_mmq.hpp"
@@ -682,7 +683,6 @@ struct Options {
/// Plan v0.3 P6: the MTP draft layer's runtime directory (tools/mtp_rt.py); drafts come from it.
std::string mtp;
int64_t mtp_window = 32768; ///< the draft layer attends to the last N cells (0 = every cell)
bool mtp_window_given = false; ///< --mtp-window was given (KVA picks the window itself only when it was not)
/// Plan v0.3 P6: the share (0..1) of each layer's distinct missed experts the GPU reads over PCIe from the
/// pinned arena while the CPU computes the rest (verify windows).
double pcie_frac = -1.0; ///< < 0: the model's default (0.2 direct for the Q2_0 pack, 0.55 DMA for native packs)
@@ -2645,7 +2645,7 @@ int main(int argc, char** argv) {
else if (a == "--spec-follow") o.spec_follow = next("--spec-follow");
else if (a == "--window-hashes") o.window_hashes = next("--window-hashes");
else if (a == "--mtp") o.mtp = next("--mtp");
else if (a == "--mtp-window") { o.mtp_window = std::atoll(next("--mtp-window")); o.mtp_window_given = true; }
else if (a == "--mtp-window") o.mtp_window = std::atoll(next("--mtp-window"));
else if (a == "--pcie-frac") o.pcie_frac = std::atof(next("--pcie-frac"));
else if (a == "--adapt-every") { o.adapt_every = std::atoi(next("--adapt-every")); o.adapt_every_given = true; }
else if (a == "--adapt-decay") o.adapt_decay = (float) std::atof(next("--adapt-decay"));
@@ -5532,9 +5532,9 @@ int main(int argc, char** argv) {
// KVA (0.2.7: on by default, STRATA_KVA=0 is the exact 0.2.6 path): what only the engine knows. A layer split and
// the batch slots read their prompts in pieces and in stages, which the one-device, one-cold-read rule of the
// approximate prompt read cannot follow, so they stay on the exact path (and say so here, once). The draft layer
// (MTP) must find exact cells in its window: with no --mtp-window given the window becomes 2048 cells (the 0.2.6
// default, 32768, is every cell of a chat up to that length, which no fully computed tail could cover) and the
// tail 2112; a window the user gave keeps its value and sets the tail (window + 64).
// (MTP) keeps its window, whatever it is: a session KVA approximated tells it the first cell built from a real row
// (the cell floor, set per request below) and every session KVA did not approximate attends exactly as with
// STRATA_KVA=0.
{
const strata::prefill::KvaConfig& kc = strata::prefill::kva_config();
strata::prefill::KvaEngine& ke = strata::prefill::kva_engine();
@@ -5549,15 +5549,8 @@ int main(int argc, char** argv) {
if (kc.explicit_on)
std::fprintf(stderr, "strata generate: KVA (the approximate late-layer prompt read) is off here: %s\n",
ke.blocked.c_str());
} else if (!o.mtp.empty() && o.spec >= 2 && !o.mtp_window_given && kc.suffix_env <= 0) {
if (o.mtp_window != strata::prefill::kKvaDrafterWindow)
std::fprintf(stderr, "strata generate: KVA on (the faster prompt read for long cold prompts): the draft layer "
"attends to the last %lld cells (--mtp-window %lld); STRATA_KVA=0 keeps the "
"exact 0.2.6 prompt read and its %lld-cell window\n",
(long long) strata::prefill::kKvaDrafterWindow, (long long) strata::prefill::kKvaDrafterWindow,
(long long) o.mtp_window);
o.mtp_window = strata::prefill::kKvaDrafterWindow;
}
mtp.enable_cell_floor(kc.wants_cell_floor(ke, !o.mtp.empty() && o.spec >= 2));
}
}
if (!o.mtp.empty()) {
@@ -5579,11 +5572,6 @@ 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 (!o.mtp.empty()) { // KVA: the cells the draft layer attends to now (0 = every cell) set the tail that must be exact
strata::prefill::KvaEngine& ke = strata::prefill::kva_engine();
ke.has_drafter = true;
ke.drafter_window = mtp.window();
}
#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"
@@ -9493,6 +9481,9 @@ int main(int argc, char** argv) {
// a reporter's prompts failed there every time and passed with --short-read 0.
bool nf_prompt_windows = false, short_read_off_once = false;
std::vector<ConvCheckpoint> checks;
// KVA: which prefixes of token ids a KVA read approximated, so the draft layer knows, for whatever state a request
// continues from, the first cell built from a real row (kva_floor.hpp). Empty without KVA.
strata::prefill::KvaFloorRegistry kva_floors;
// STRATA_CKPT_POOL: the dropped checkpoints' storage, reused. STRATA_SLOT_CKPT_MOVE turns it on too: a moved
// checkpoint frees nothing at the next prune, so every save would fault in fresh pages (17 -> 40-60 ms)
CheckpointPool ckpt_pool(ckpt_pool_env() || slot_ckpt_move_env());
@@ -10002,6 +9993,9 @@ int main(int argc, char** argv) {
// come from Q8_1 x Q8_0 MMQ rather than mmvq: drafts may differ, the target's tokens never.
static const bool split_mtp_batch = strata::program::draft_kv::split_env_on(std::getenv("STRATA_SPLIT_MTP_BATCH"));
sp.on_chunk = [&](const float* R_rows, int64_t T, int64_t p0, std::string& e) -> bool {
// KVA: a chunk the late layers did not compute has no real final rows: its draft cells are neither built
// nor read (the floor rises before the cells are built, so they are skipped)
if (use_mtp && mtp.cell_floor_enabled() && sp.kva_floor() > mtp.cell_floor()) mtp.set_cell_floor(sp.kva_floor());
std::vector<int32_t> nxt((size_t) T);
for (int64_t t = 0; t < T; ++t) nxt[(size_t) t] = (int32_t) cur[(size_t) (p0 + t + 1)];
// E-9: batched through the prompt path when it can (a layer split: only with STRATA_SPLIT_MTP_BATCH=1)
@@ -13181,6 +13175,10 @@ int main(int argc, char** argv) {
tr("request", n, geni ? 1 : 0);
req_times = ReqTimes{};
if (use_mtp) mtp.set_prompt_len(n);
// KVA: the draft layer's first real cell for the state this request continues from (0 for a cold read - the
// first segment raises it if KVA approximates it - and for any state no KVA read produced)
if (use_mtp && mtp.cell_floor_enabled())
mtp.set_cell_floor(resume > 0 && reread_to <= 0 ? kva_floors.floor_for(ids.data(), resume) : 0);
const int64_t read_from = reread_to > 0 ? 0 : resume;
conversations.limit_reuse(read_from);
pp_total = n;
@@ -13623,7 +13621,12 @@ int main(int argc, char** argv) {
} seg_plan_scope{seg_plan};
auto run = [&](int64_t q, int64_t r) -> bool {
if (planned) sp.force_chunk(plan.chunk, plan_single, plan.chunked);
return sp.run(ids.data() + q, r - q, q, e);
const bool run_ok = sp.run(ids.data() + q, r - q, q, e);
if (run_ok && q == 0 && sp.kva_floor() > 0) { // KVA approximated the start of this prompt: remember which tokens
kva_floors.note(ids.data(), sp.kva_floor());
if (use_mtp && mtp.cell_floor_enabled()) mtp.set_cell_floor(sp.kva_floor());
}
return run_ok;
};
// (a layer split reads its stages as a pipeline over one run's chunks: beside slots a chunk at a time, with
// none decoding in pieces of STRATA_BATCH_YIELD_CHUNKS chunks (default 8; 0 = one run) so a BYIELD is taken)
@@ -15964,6 +15967,7 @@ int main(int argc, char** argv) {
return 1;
}
prefill.on_chunk = [&](const float* R_rows, int64_t T, int64_t p0, std::string& e) -> bool {
if (mtp.cell_floor_enabled() && prefill.kva_floor() > mtp.cell_floor()) mtp.set_cell_floor(prefill.kva_floor()); // KVA
// cell i pairs R_i with the token at i + 1 (every such token is in the prompt)
std::vector<int32_t> nxt((size_t) T);
for (int64_t t = 0; t < T; ++t) nxt[(size_t) t] = (int32_t) o.tokens[(size_t) (p0 + t + 1)];