batch MTP (#846): opt-in --batch-mtp / STRATA_BATCH_MTP=1, warn instead of refusing, 1-row groups keep the 0.1.39 commit kernel, LRU graph cache only under the flag, the real draft geometry
Co-authored-by: rkcth <16263985+rkcth@users.noreply.github.com>
This commit is contained in:
1 parent
8cfb3fd7cc
commit
c8c79b17ea
5 files changed
+69
-42
No files matched your search
+27
-16
@@ -491,6 +491,7 @@ struct Options {
|
||||
/// The --batch slots in this many groups pipelined through the stages of a layer split (stage k
|
||||
/// runs one group while stage k+1 runs another). 1 = every slot in one window, stage after stage.
|
||||
int batch_groups = 1;
|
||||
bool batch_mtp = false; ///< --batch-mtp / STRATA_BATCH_MTP=1 (opt-in): one MTP proposal per batch slot
|
||||
std::string spec_oracle;
|
||||
int spec_corrupt = 0;
|
||||
/// Plan v0.3 P6: the MTP draft layer's runtime directory (tools/mtp_rt.py); drafts come from it.
|
||||
@@ -652,8 +653,10 @@ void usage() {
|
||||
" default 512), so the command `VRAM <reserve_mib>` (the server's POST /v1/vram) can\n"
|
||||
" give VRAM back to other programs between requests and take it back later\n"
|
||||
" --batch N / --slots N --serve (opt-in): up to N requests decode together in batch slots (2..8\n"
|
||||
" normally; MULTI_CONCURRENCY=TRUE waves more through eight-row windows),\n"
|
||||
" normally; --batch-mtp waves more through eight-row windows),\n"
|
||||
" each slot with its own session (VRAM like the main one); docs/BATCHING.md\n"
|
||||
" --batch-mtp --batch (opt-in, one GPU, needs --mtp and --spec): each slot also verifies one MTP\n"
|
||||
" proposal per window (STRATA_BATCH_MTP=1 does the same); needs VRAM per slot\n"
|
||||
" --batch-groups G --batch with a layer split: the slots in G groups pipelined through the GPUs\n"
|
||||
" --trim-stage-weights an explicit --layer-split: each GPU loads only its own layers' dense weights\n"
|
||||
" --prompt-cache-every N --serve: also checkpoint every N fresh prompt tokens (default 16384, 0 = off)\n"
|
||||
@@ -1431,6 +1434,7 @@ int main(int argc, char** argv) {
|
||||
else if (a == "--slots") o.batch = std::atoi(next("--slots")); // the same as --batch
|
||||
else if (a == "--trim-stage-weights") o.trim_stage_weights = true;
|
||||
else if (a == "--batch-groups") o.batch_groups = std::atoi(next("--batch-groups"));
|
||||
else if (a == "--batch-mtp") o.batch_mtp = true;
|
||||
else if (a == "--spec-oracle") o.spec_oracle = next("--spec-oracle");
|
||||
else if (a == "--spec-corrupt") o.spec_corrupt = std::atoi(next("--spec-corrupt"));
|
||||
else if (a == "--mtp") o.mtp = next("--mtp");
|
||||
@@ -2962,8 +2966,19 @@ int main(int argc, char** argv) {
|
||||
// slot of the batch windows. Before the expert cache is sized, so `--expert-cache auto` leaves them room.
|
||||
// Recommend, never force: a count the engine cannot run is said and adjusted (or batching left off) - the
|
||||
// engine still starts and serves one request at a time.
|
||||
const char* multi_concurrency = std::getenv("MULTI_CONCURRENCY");
|
||||
const bool batch_mtp_requested = multi_concurrency != nullptr && std::strcmp(multi_concurrency, "TRUE") == 0;
|
||||
// --batch-mtp / STRATA_BATCH_MTP=1 (opt-in): a slot also verifies one MTP proposal per window. Recommend, never
|
||||
// force: when it cannot run it is said and left off (plain batching still starts); default off = exactly 0.1.39.
|
||||
const char* batch_mtp_env = std::getenv("STRATA_BATCH_MTP");
|
||||
bool batch_mtp = o.batch_mtp || (batch_mtp_env != nullptr && batch_mtp_env[0] != '\0' && batch_mtp_env[0] != '0');
|
||||
if (batch_mtp) {
|
||||
const char* why = o.batch < 2 ? "it needs --batch 2 or more" : o.mtp.empty() ? "it needs --mtp"
|
||||
: o.spec < 2 ? "it needs --spec T (T >= 2)" : (multi_gpu || split_same || !stages.empty())
|
||||
? "it is for one GPU (no layer split or helper) for now" : !o.serve ? "it needs --serve" : nullptr;
|
||||
if (why != nullptr) {
|
||||
std::fprintf(stderr, "strata generate: WARNING: --batch-mtp is off: %s\n", why);
|
||||
batch_mtp = false;
|
||||
}
|
||||
}
|
||||
std::vector<std::vector<std::unique_ptr<strata::core::SessionState>>> bslot_ss;
|
||||
if (o.batch != 0) {
|
||||
const int cap = strata::kernels::kVerifyMaxT;
|
||||
@@ -2972,7 +2987,7 @@ int main(int argc, char** argv) {
|
||||
if (off != nullptr) {
|
||||
std::fprintf(stderr, "strata generate: WARNING: --batch %d is off: %s\n", o.batch, off);
|
||||
o.batch = 0;
|
||||
} else if (o.batch > cap && !batch_mtp_requested) {
|
||||
} else if (o.batch > cap && !batch_mtp) {
|
||||
std::fprintf(stderr, "strata generate: WARNING: --batch %d: a batch window holds at most %d rows, so %d "
|
||||
"slots\n", o.batch, cap, cap);
|
||||
o.batch = cap;
|
||||
@@ -3036,11 +3051,9 @@ 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;
|
||||
const bool batch_mtp = batch_mtp_requested;
|
||||
if (batch_mtp && (o.batch < 2 || o.mtp.empty() || multi_gpu)) {
|
||||
std::fprintf(stderr, "strata generate: MULTI_CONCURRENCY=TRUE needs at least two slots, --mtp and one GPU\n");
|
||||
return 2;
|
||||
}
|
||||
// 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{};
|
||||
std::vector<std::unique_ptr<strata::core::MtpDrafter>> slot_mtp;
|
||||
if (!o.mtp.empty()) {
|
||||
if (o.spec < 2) {
|
||||
@@ -3050,7 +3063,6 @@ int main(int argc, char** argv) {
|
||||
if (!o.mtp.empty()) mtp.set_prompt_len((int64_t) o.tokens.size());
|
||||
// the draft layer is the canonical model's MTP head (512 experts) even when the target is pruned,
|
||||
// so it always sees the canonical geometry; `static` because MtpDrafter keeps a reference
|
||||
static const strata::core::ModelGeometry draft_geometry{};
|
||||
// with a layer split across GPUs the drafter reads the last stage's residual: it lives on that device
|
||||
const strata::core::OnDevice on_mtp(last_st ? last_st->dev : -1);
|
||||
if (!o.mtp.empty() && !mtp.load(o.mtp, draft_geometry, last_st ? last_st->ss : ss, o.spec, err, o.mtp_window)) { std::fprintf(stderr, "strata generate: %s%s\n", err.c_str(), vram_free_note().c_str()); return 1; }
|
||||
@@ -5201,6 +5213,7 @@ int main(int argc, char** argv) {
|
||||
std::fprintf(stderr, "strata serve: layer split: layers %s, one hand-off per window\n", plan_s.c_str());
|
||||
}
|
||||
ver.set_remote_expert_opt(remote_opt.get());
|
||||
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, ver.final_R_all(), err)) {
|
||||
@@ -6050,12 +6063,11 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
if (batch_mtp) {
|
||||
// Admission first builds the solo draft KV; copy it into the slot before drafting.
|
||||
static const strata::core::ModelGeometry draft_g{};
|
||||
strata::core::ConversationKv image;
|
||||
if (!mtp.idle(e) || !slot_mtp[(size_t) b]->idle(e) ||
|
||||
!strata::core::conversation_kv_save(image, mtp.kv_state(), draft_g, upto, false, e) ||
|
||||
!strata::core::conversation_kv_save(image, mtp.kv_state(), draft_geometry, upto, false, e) ||
|
||||
!strata::core::conversation_kv_restore(image, slot_mtp[(size_t) b]->kv_state(),
|
||||
draft_g, upto, false, e) ||
|
||||
draft_geometry, upto, false, e) ||
|
||||
cudaDeviceSynchronize() != cudaSuccess)
|
||||
return false;
|
||||
slot_mtp[(size_t) b]->set_prompt_len(upto);
|
||||
@@ -6095,12 +6107,11 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
if (batch_mtp) {
|
||||
// A returning solo request resumes from its slot's draft KV.
|
||||
static const strata::core::ModelGeometry draft_g{};
|
||||
strata::core::ConversationKv image;
|
||||
if (!slot_mtp[(size_t) b]->idle(e) || !mtp.idle(e) ||
|
||||
!strata::core::conversation_kv_save(image, slot_mtp[(size_t) b]->kv_state(),
|
||||
draft_g, upto, false, e) ||
|
||||
!strata::core::conversation_kv_restore(image, mtp.kv_state(), draft_g, upto, false, e) ||
|
||||
draft_geometry, upto, false, e) ||
|
||||
!strata::core::conversation_kv_restore(image, mtp.kv_state(), draft_geometry, upto, false, e) ||
|
||||
cudaDeviceSynchronize() != cudaSuccess)
|
||||
return false;
|
||||
mtp.set_prompt_len(upto);
|
||||
|
||||
Reference in new issue
Block a user