serve: --mtp is optional
Without --mtp, serve drafts with the suffix/prompt-lookup drafter only (or one token per round), as the plain generate command already does; every token is still verified against the model. The draft layer's VRAM goes to the expert cache instead (1,000 -> 1,678 slots in an A/B on an RTX 2060 SUPER 8 GB). The bind, the prompt path's draft prefill (batched and per token), the draft-KV restore, prompt length, max drafts, draft sampling, coupled-draft history and the draft call itself are skipped without it. The conversation cache is off without it: a parked conversation always carries the draft layer's K/V.
This commit is contained in:
1 parent
028cb234a4
commit
3216d27118
3 files changed
+47
-31
No files matched your search
@@ -117,6 +117,11 @@ RTX 5090 (IQ3_S, the reporter's measurement).
|
||||
smaller subset fits, and the server's start error repeats it; setup suggests `--draft-vocab en` on cards under
|
||||
14 GB (only a suggestion: nothing changes unless you pass it).
|
||||
|
||||
**Serving without the draft layer (`--mtp` is optional):** `serve` runs without `--mtp`. Drafts then come from the
|
||||
suffix/prompt-lookup drafter only (or one token per round), every token is still verified against the model, and the
|
||||
draft layer's VRAM (~0.7-1 GiB with its head) goes to the expert cache: 1,000 -> 1,678 slots in one A/B on an 8 GB
|
||||
card. The conversation cache (`--conversation-cache-mib`) stays on: a parked conversation then carries no draft K/V.
|
||||
|
||||
**Low-RAM mode (engine 0.1.26, chosen by setup):** normally all of a model's experts are copied into RAM (23-50 GB,
|
||||
pinned) and the GPU holds a copy of the most-used ones. On a PC whose RAM cannot hold them beside the system (the
|
||||
experts plus ~10 GB), setup instead maps them from one file in the model's folder (`--mmap-experts`, the pack's
|
||||
|
||||
+2
-1
@@ -30,7 +30,8 @@ from that dependency (`STRATA_GGUF_PY` can point to its `gguf-py` directory).
|
||||
Use this model's own tokenizer exported into the pack. Do not share another model's `dense.bin`,
|
||||
and do not rename the Orca files to impersonate one of setup's GSQ-RCO models.
|
||||
|
||||
Strata's persistent server also requires the MTP runtime, prepared by the existing tools:
|
||||
Strata's persistent server also uses the MTP runtime (optional: without `--mtp` it drafts by lookup only), prepared by
|
||||
the existing tools:
|
||||
|
||||
```sh
|
||||
.venv/bin/python tools/mtp_fetch.py fetch --out mtp
|
||||
|
||||
+40
-30
@@ -4941,12 +4941,18 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
if (o.adapt_async && !src.complement_ready()) adapt_async_off("the resident RAM mode is not running");
|
||||
if (o.serve) {
|
||||
if (o.spec < 2 || o.mtp.empty() || o.prefill_chunk <= 0 ||
|
||||
if (o.spec < 2 || o.prefill_chunk <= 0 ||
|
||||
(graph_hits && (thits.d_res == nullptr || host_res.empty()))) {
|
||||
std::fprintf(stderr, "strata serve: needs --spec T, --mtp DIR and --prefill CHUNK (and a fillable "
|
||||
std::fprintf(stderr, "strata serve: needs --spec T and --prefill CHUNK (and a fillable "
|
||||
"--expert-cache; the graphed hit path additionally needs --expert-profile P)\n");
|
||||
return 2;
|
||||
}
|
||||
// STRATA_VOLTA_BUILD backport (see docs/ and ninfer-flash-next-v100-backport): --mtp is optional here,
|
||||
// mirroring the plain `generate` command's own use_mtp handling below. Without it, drafting falls back
|
||||
// to the suffix/prompt-lookup drafter (DraftPolicy still picks Lookup vs plain per round) or, when
|
||||
// neither fires, plain one-token-per-round decoding - slower, never wrong: the verify window still
|
||||
// confirms every emitted token against the real model regardless of where the draft came from.
|
||||
const bool use_mtp = !o.mtp.empty();
|
||||
strata::prefill::Prefill sp;
|
||||
void* borrow = nullptr;
|
||||
uint64_t borrow_bytes = 0;
|
||||
@@ -5537,8 +5543,8 @@ int main(int argc, char** argv) {
|
||||
if (batch_mtp) ver.set_batch_graph_limit(64); // --batch-mtp only: slot rotation makes many layouts (LRU); 0.1.39 keeps all
|
||||
if (!ver.init(wt, g, ss, vh, native_head.loaded() ? &native_head : nullptr,
|
||||
batch_mtp ? strata::kernels::kVerifyMaxT : std::max(o.spec, o.batch), err) ||
|
||||
!mtp.bind(last_st ? last_st->wt : wt, last_st ? &last_st->head : &native_head,
|
||||
pipe ? pl_mtp_R : ver.final_R_all(), err)) {
|
||||
(use_mtp && !mtp.bind(last_st ? last_st->wt : wt, last_st ? &last_st->head : &native_head,
|
||||
pipe ? pl_mtp_R : ver.final_R_all(), err))) {
|
||||
std::fprintf(stderr, "strata serve: %s\n", err.c_str());
|
||||
return 1;
|
||||
}
|
||||
@@ -5695,6 +5701,8 @@ int main(int argc, char** argv) {
|
||||
std::vector<ConvCheckpoint> checks;
|
||||
uint64_t check_clock = 0; // the checkpoints' LRU clock; creation and every use advance it
|
||||
bool cvec_cached = true; // the control vector's state the live session and the checkpoints were read with
|
||||
// without --mtp the conversation cache stays on: a parked image carries the draft layer's K/V only when there is one
|
||||
// (the snapshots accept a null draft)
|
||||
strata::core::ConversationCache conversations(
|
||||
o.prompt_cache > 0 ? (size_t) o.conversation_cache_mib * 1024 * 1024 : 0,
|
||||
(size_t) o.conversation_cache_slots);
|
||||
@@ -5713,8 +5721,8 @@ int main(int argc, char** argv) {
|
||||
const size_t n_st = stages.size();
|
||||
// the draft layer's K/V lives on the last stage's GPU (the drafter is loaded there): with a split it is
|
||||
// saved with that stage's image, under its device; stage 0's image holds none
|
||||
const strata::core::QsaState* draft0 = n_st > 0 ? nullptr : &mtp.kv_state();
|
||||
auto draft_of = [&](size_t k) -> const strata::core::QsaState* { return k + 1 == n_st ? &mtp.kv_state() : nullptr; };
|
||||
const strata::core::QsaState* draft0 = n_st > 0 || !use_mtp ? nullptr : &mtp.kv_state(); // no --mtp: no draft K/V (snapshots accept null)
|
||||
auto draft_of = [&](size_t k) -> const strata::core::QsaState* { return use_mtp && k + 1 == n_st ? &mtp.kv_state() : nullptr; };
|
||||
strata::core::ConversationCheckpointSplit cs;
|
||||
if (n_st > 0) cs = strata::core::conversation_checkpoints_split(std::move(checks), n_st); // #752: two-phase; a bad_alloc leaves `checks` whole
|
||||
struct MergeBack {
|
||||
@@ -5900,9 +5908,9 @@ int main(int argc, char** argv) {
|
||||
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 (one GPU: a layer split's drafter is on the last stage)
|
||||
const bool batched = !multi_gpu && sp.draft_kv(mtp, R_rows, nxt.data(), T, p0, e);
|
||||
if (!e.empty() || (!batched && !mtp.prefill(R_rows, nxt.data(), T, p0, e))) return false;
|
||||
if (std::getenv("STRATA_SNAPSHOT_VERIFY") != nullptr)
|
||||
const bool batched = use_mtp && !multi_gpu && sp.draft_kv(mtp, R_rows, nxt.data(), T, p0, e);
|
||||
if (!e.empty() || (use_mtp && !batched && !mtp.prefill(R_rows, nxt.data(), T, p0, e))) return false;
|
||||
if (use_mtp && std::getenv("STRATA_SNAPSHOT_VERIFY") != nullptr)
|
||||
std::fprintf(stderr, "strata serve: DRAFT_PREFILL path=%s mode=%d cells=%lld\n",
|
||||
batched ? "batched" : "token", mtp.kv_state().kv_mode, (long long) T);
|
||||
// progress for the server window: PP <position reached> <prompt tokens> <ms> <fresh tokens/s>
|
||||
@@ -6502,9 +6510,9 @@ int main(int argc, char** argv) {
|
||||
int64_t rounds = 0;
|
||||
const int S = o.spec;
|
||||
const int S_mtp = o.mtp_max_t > 0 ? std::min(o.mtp_max_t, S) : S; // the MTP's windows; suffixes go up to S
|
||||
if (S_mtp < S) mtp.set_max_drafts(S_mtp - 1);
|
||||
if (use_mtp && S_mtp < S) mtp.set_max_drafts(S_mtp - 1);
|
||||
// --pipeline-windows 2 loads the drafter with 8 rows: the serial loop's chain keeps its own length
|
||||
else if (mtp.max_t() > S_mtp) mtp.set_max_drafts(S_mtp - 1);
|
||||
else if (use_mtp && mtp.max_t() > S_mtp) mtp.set_max_drafts(S_mtp - 1);
|
||||
strata::spec::SuffixDrafter sfx(std::max(1, o.suffix_draft), 64, (size_t) o.max_context + 4096);
|
||||
strata::spec::DraftPolicy policy(S); // MTP or lookup window, learned over the whole process
|
||||
// The vision path (--vision): GENI <max_new> <embeddings file> <id,id,...> carries images. The file is one
|
||||
@@ -7304,7 +7312,7 @@ int main(int argc, char** argv) {
|
||||
if (incoming) for (size_t i = 0; i < stages.size(); ++i) {
|
||||
const strata::core::OnDevice on(stages[i]->dev);
|
||||
if (!strata::core::conversation_snapshot_validate(incoming->stage_images[i], stages[i]->ss, g,
|
||||
i + 1 == stages.size() ? &mtp.kv_state() : nullptr, err)) { // the draft: the last stage's
|
||||
use_mtp && i + 1 == stages.size() ? &mtp.kv_state() : nullptr, err)) { // the draft: the last stage's
|
||||
std::fprintf(stderr, "strata serve: conversation cache: discard invalid stage snapshot (%s)\n",
|
||||
err.c_str());
|
||||
incoming.reset();
|
||||
@@ -7313,7 +7321,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
if (incoming && !strata::core::conversation_snapshot_validate(*incoming, ss, g,
|
||||
stages.empty() ? &mtp.kv_state() : nullptr, err)) {
|
||||
use_mtp && stages.empty() ? &mtp.kv_state() : nullptr, err)) {
|
||||
std::fprintf(stderr, "strata serve: conversation cache: discard invalid snapshot (%s)\n", err.c_str());
|
||||
incoming.reset();
|
||||
err.clear();
|
||||
@@ -7364,7 +7372,7 @@ int main(int argc, char** argv) {
|
||||
if (incoming) {
|
||||
const auto t0 = Clock::now();
|
||||
if (strata::core::conversation_snapshot_restore(*incoming, ss, g,
|
||||
stages.empty() ? &mtp.kv_state() : nullptr, err) !=
|
||||
use_mtp && stages.empty() ? &mtp.kv_state() : nullptr, err) !=
|
||||
strata::core::ConversationRestore::restored) {
|
||||
// Already prevalidated above: a failure here is fatal, never
|
||||
// permission to decode from a partially restored session.
|
||||
@@ -7374,7 +7382,7 @@ int main(int argc, char** argv) {
|
||||
for (size_t i = 0; i < stages.size(); ++i) { // the later stages' parts
|
||||
const strata::core::OnDevice on(stages[i]->dev);
|
||||
if (strata::core::conversation_snapshot_restore(incoming->stage_images[i], stages[i]->ss, g,
|
||||
i + 1 == stages.size() ? &mtp.kv_state() : nullptr, err) !=
|
||||
use_mtp && i + 1 == stages.size() ? &mtp.kv_state() : nullptr, err) !=
|
||||
strata::core::ConversationRestore::restored) {
|
||||
std::printf("ERR restoring parked conversation (stage CUDA%d): %s\n", stages[i]->dev,
|
||||
err.c_str());
|
||||
@@ -7382,7 +7390,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
if (cudaDeviceSynchronize() != cudaSuccess) { std::printf("ERR stage sync\n"); return 1; }
|
||||
}
|
||||
if (std::getenv("STRATA_SNAPSHOT_VERIFY") != nullptr) {
|
||||
if (use_mtp && std::getenv("STRATA_SNAPSHOT_VERIFY") != nullptr) {
|
||||
uint64_t draft_hash = 0;
|
||||
const auto& draft_kv = stages.empty() ? incoming->kv.back() : incoming->stage_images.back().kv.back();
|
||||
const strata::core::OnDevice on_d(stages.empty() ? 0 : stages.back()->dev);
|
||||
@@ -7477,9 +7485,9 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
// KV streaming: the drafter's ring may hold cells past `resume` from a longer turn; the main layers'
|
||||
// host copies and slots are always current (every writer writes both), so they need nothing
|
||||
if (resume > 0 && reread_to <= 0) mtp.kv_restore(resume);
|
||||
if (use_mtp && resume > 0 && reread_to <= 0) mtp.kv_restore(resume);
|
||||
tr("request", n, geni ? 1 : 0);
|
||||
mtp.set_prompt_len(n);
|
||||
if (use_mtp) mtp.set_prompt_len(n);
|
||||
const int64_t read_from = reread_to > 0 ? 0 : resume;
|
||||
conversations.limit_reuse(read_from);
|
||||
pp_total = n;
|
||||
@@ -7665,7 +7673,7 @@ int main(int argc, char** argv) {
|
||||
}();
|
||||
if (logpos != nullptr && !ver.window_logprobs(nxt.data(), T, q, logpos_extra, logpos, e))
|
||||
return false;
|
||||
if (!ver.commit(T, e) || !mtp.prefill(ver.final_R_all(), nxt.data(), T, q, e)) return false;
|
||||
if (!ver.commit(T, e) || (use_mtp && !mtp.prefill(ver.final_R_all(), nxt.data(), T, q, e))) return false;
|
||||
q += T;
|
||||
pp_reached = q; // #471
|
||||
}
|
||||
@@ -7903,7 +7911,7 @@ int main(int argc, char** argv) {
|
||||
req_sp.counter = 0;
|
||||
ver.set_sampling(req_sp);
|
||||
if (pipe) ver_b.set_sampling(req_sp); // (reaches the later stage's odd verifier)
|
||||
mtp.set_draft_sampling(req_sp); // STRATA_SPEC_COUPLED=1: sampled drafts (a no-op otherwise)
|
||||
if (use_mtp) mtp.set_draft_sampling(req_sp); // STRATA_SPEC_COUPLED=1: sampled drafts (a no-op otherwise)
|
||||
drive.d.pcie_num = std::max(0, std::min(256, (int) (req_pcie_frac * 256.0 + 0.5)));
|
||||
// a layer split: CUDA0's share as asked; a later GPU keeps its own (its link) unless the request sets one
|
||||
for (int st = 0; st < split_drive.n; ++st)
|
||||
@@ -8004,7 +8012,7 @@ int main(int argc, char** argv) {
|
||||
int64_t p = n - 1;
|
||||
int32_t x = (int32_t) ids[(size_t) (n - 1)];
|
||||
// (the drafter writes max_t - 1 drafts: 8 rows with --pipeline-windows 2)
|
||||
const size_t DS = (size_t) std::max(S, mtp.max_t());
|
||||
const size_t DS = (size_t) std::max(S, use_mtp ? mtp.max_t() : 0);
|
||||
std::vector<int32_t> drafts(DS, 0), window((size_t) S), outv((size_t) S);
|
||||
std::vector<float> dprob(DS, 0.0f);
|
||||
std::vector<int32_t> sbuf((size_t) S, 0);
|
||||
@@ -8631,8 +8639,8 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
while (!pl_ran && !cancelled && produced_n < max_new) {
|
||||
int T = S_mtp;
|
||||
if (req_spec_min_p > 0.0) {
|
||||
int T = use_mtp ? S_mtp : 1; // no --mtp: one token a round unless a lookup draft fires
|
||||
if (use_mtp && req_spec_min_p > 0.0) {
|
||||
T = 1;
|
||||
while (T < S_mtp && dprob[(size_t) T - 1] >= (float) req_spec_min_p) ++T;
|
||||
}
|
||||
@@ -8644,7 +8652,7 @@ int main(int argc, char** argv) {
|
||||
if (o.suffix_draft > 0 && !first_window) {
|
||||
const int k = sfx.propose(S - 1, sbuf.data());
|
||||
sfx_match = sfx.last_match();
|
||||
if (k > 0 && sbuf[0] == drafts[0]) {
|
||||
if (k > 0 && (!use_mtp || sbuf[0] == drafts[0])) {
|
||||
const strata::spec::DraftPolicy::Pick pk = policy.choose(T, k, sfx_match);
|
||||
if (pk.lookup) { T = pk.t; from_sfx = true; }
|
||||
}
|
||||
@@ -8714,9 +8722,9 @@ int main(int argc, char** argv) {
|
||||
const Clock::time_point tw2 = Clock::now();
|
||||
// coupled drafts with penalties: the next window's row-0 history (`consumed` holds this window's
|
||||
// commit, outv[a] is its row 0) - the drafts extend it on the device as the verify rows will
|
||||
if (hist_n > 0 && mtp.coupled() && !eos && produced_n < max_new)
|
||||
if (use_mtp && hist_n > 0 && mtp.coupled() && !eos && produced_n < max_new)
|
||||
mtp.set_draft_history(consumed.data(), (int64_t) consumed.size(), outv[(size_t) a]);
|
||||
const bool drafted = eos || produced_n >= max_new ||
|
||||
const bool drafted = !use_mtp || eos || produced_n >= max_new ||
|
||||
mtp.draft(T, outv.data(), p, a, drafts.data(), err, dprob.data(), (float) req_spec_min_p);
|
||||
{
|
||||
const Clock::time_point tw3 = Clock::now();
|
||||
@@ -8867,11 +8875,13 @@ int main(int argc, char** argv) {
|
||||
h_stale = hash_cells(pool, w, L, end_cell, h_stale);
|
||||
}
|
||||
}
|
||||
const strata::core::QsaState& ms = mtp.kv_state();
|
||||
uint64_t h_mtp = 1469598103934665603ull;
|
||||
const int64_t mL = std::min<int64_t>(L, ms.max_cells);
|
||||
for (const auto& [pool, w] : kv_arrays(ms))
|
||||
if (pool != nullptr) h_mtp = hash_cells(pool, w, 0, mL, h_mtp);
|
||||
if (use_mtp) {
|
||||
const strata::core::QsaState& ms = mtp.kv_state();
|
||||
const int64_t mL = std::min<int64_t>(L, ms.max_cells);
|
||||
for (const auto& [pool, w] : kv_arrays(ms))
|
||||
if (pool != nullptr) h_mtp = hash_cells(pool, w, 0, mL, h_mtp);
|
||||
}
|
||||
if (!hash_ok) {
|
||||
std::printf("ERR reading state fingerprint\n");
|
||||
return 1;
|
||||
|
||||
Reference in new issue
Block a user