Archived
Merge upstream main (v1.15.1 -> v1.17.0, 152 commits) into the SYCL port
Conflicts, both sides kept:
- abi: RAD_ABI_VERSION 37 (upstream); the fork's RadBuildCtx.plain_norm after upstream's
expert_file_tier, widened to int64_t so it starts past ABI 37's 208-byte struct instead of in
its tail padding (abi_layout_test); RadSyclStream rows after RadShapeGen*.
- arch/common/rad_block_gdn_fp8.h: upstream's q8_rot guard and the fork's o_plain guard
combined; the decode-row q_o.step only where q_o is declared (!o_plain).
- docs/OPS.md: upstream's optional params on sample_logprobs, the fork's q_temp on
mtp_couple_propose.
Also ignores /baseline-models/ (local model copies).
Host tests: arch_test's MTP lint/graph-pin failures are unchanged from before the merge (the
fork's mtp.fc LinearFP8, 10a99a5); avx_check's hand-built moe_gemm_q w4a8 case also fails on
upstream's own files; images/videos need FFmpeg; three binaries over their CPU budget on this VM.
SYCL card tests 3/3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
45f3b510c7
365 files changed
+56942
-6331
No files matched your search
@@ -48,7 +48,11 @@ struct StepSlot {
|
||||
* drafter's context rows by it. 0 after a chain verify, which needs neither. */
|
||||
int32_t npath;
|
||||
int32_t path[RAD_SCHED_MAX_SPEC];
|
||||
int32_t pad[2];
|
||||
/* The last verify step's row of its last committed position, in that step's own row order,
|
||||
* which a block drafter's context pass mirrors. ADV_BLOCK hands it to the query pass
|
||||
* (RadBatch::anchor_rows): LiLiCorr's correlator reads the context state there. */
|
||||
int32_t hrow;
|
||||
int32_t pad[1];
|
||||
};
|
||||
|
||||
enum AdvMode : int32_t {
|
||||
@@ -115,6 +119,7 @@ struct AdvanceArgs {
|
||||
int32_t n_groups = 0;
|
||||
char* slab = nullptr; /* this rank's device slab */
|
||||
int64_t tok_off = 0, pos_off = 0, ctx_off = 0, acc_off = 0, out_off = 0;
|
||||
int64_t arow_off = -1; /* [n_seq] ADV_BLOCK: each row's StepSlot::hrow; -1 when not carved */
|
||||
int64_t sid_off = 0, cu_off = 0, q_off = 0;
|
||||
/* [4][row_pitch] int32: device-row flag; the verify step's token row of the row's first
|
||||
* verified position; its first sampled row, or -1 for a row that sampled nothing; and one
|
||||
|
||||
@@ -153,6 +153,7 @@ RAD_ADV_FN void adv_row(const AdvanceArgs& a, int i) {
|
||||
S.ctx = head + 1;
|
||||
S.n_acc = acc + 1;
|
||||
S.tok[0] = y[acc == 0 ? 0 : S.path[acc - 1]];
|
||||
S.hrow = rtok + (acc == 0 ? 0 : S.path[acc - 1]); /* rows are nodes, in order */
|
||||
S.npath = acc;
|
||||
return;
|
||||
}
|
||||
@@ -167,6 +168,7 @@ RAD_ADV_FN void adv_row(const AdvanceArgs& a, int i) {
|
||||
const int32_t head = ctx[i] + (rtok - k) + acc;
|
||||
S.acc = acc;
|
||||
S.head = head;
|
||||
S.hrow = rtok + acc;
|
||||
S.ctx = head + 1;
|
||||
S.n_acc = acc + 1;
|
||||
S.tok[0] = y[acc];
|
||||
@@ -296,6 +298,7 @@ RAD_ADV_FN void adv_row(const AdvanceArgs& a, int i) {
|
||||
for (int32_t j = 1; j < n; ++j) tok[k + j] = aux;
|
||||
for (int32_t j = 0; j < n; ++j) adv_pos(a, pos, k + j, base + j);
|
||||
ctx[i] = base;
|
||||
if (a.arow_off >= 0) adv_i32(a, a.arow_off)[i] = S.hrow;
|
||||
adv_groups(a, i, k, base, n);
|
||||
return;
|
||||
}
|
||||
|
||||
+45
-1
@@ -123,6 +123,7 @@ void BatchBuilder::carve(Set& s, char* h) {
|
||||
/* The advance's per-sequence runtime-window data (advance.h); 0 when there is none. */
|
||||
pair(&s.h_rpos, &s.d_rpos, S);
|
||||
pair(&s.h_tlen, &s.d_tlen, S);
|
||||
pair(&s.h_arow, &s.d_arow, S);
|
||||
s.h_grp = ::rad::carve<AdvGroup>(h, oh, (int64_t)s.groups.size());
|
||||
s.d_grp = ::rad::carve<AdvGroup>(d, od, (int64_t)s.groups.size());
|
||||
for (size_t gi = 0; gi < s.groups.size(); ++gi) {
|
||||
@@ -135,6 +136,7 @@ void BatchBuilder::carve(Set& s, char* h) {
|
||||
* moves a rotary position off the token index. */
|
||||
pair(&s.h_rope, &s.d_rope, mm_on_ ? 3 * T : 0);
|
||||
pair(&s.h_mmrow, &s.d_mmrow, mm_on_ ? T : 0);
|
||||
pair(&s.h_bidi, &s.d_bidi, bidi_on_ ? 4 * T : 0);
|
||||
/* Each row's adapter slot, carved only when the engine serves adapters, so an engine without
|
||||
* them lays the slab out as if the array did not exist. */
|
||||
pair(&s.h_lora, &s.d_lora, lora_on_ ? T : 0);
|
||||
@@ -245,6 +247,7 @@ int BatchBuilder::alloc_set(Set& s, const std::vector<KVGroupInfo>& groups) {
|
||||
o.kv.assign(ranks_.size(), std::vector<RadKVGroupBatch>(s.groups.size()));
|
||||
o.stream.assign(ranks_.size(), std::vector<RadKVStream>(s.groups.size()));
|
||||
o.batch.assign(ranks_.size(), RadBatch{});
|
||||
o.kv_used_max_h.assign(s.groups.size(), 0);
|
||||
o.seqs.clear();
|
||||
o.seqs.reserve((size_t)max_seqs_); /* a build fills it without allocating */
|
||||
o.has_seqs = false;
|
||||
@@ -480,6 +483,7 @@ int BatchBuilder::layout(Program& prog, const Config& cfg) {
|
||||
});
|
||||
|
||||
mm_on_ = prog.encoder.modalities != 0 || prog.audio_encoder.modalities != 0;
|
||||
bidi_on_ = prog.encoder.modalities != 0 && prog.encoder.bidirectional != 0;
|
||||
lora_on_ = cfg.lora.enabled();
|
||||
pw_cap_ = prog.plugin_words;
|
||||
return RAD_OK;
|
||||
@@ -725,7 +729,13 @@ int BatchBuilder::build_groups(const StepPlan& plan, const IKVManager& kv, Set&
|
||||
first = kv.first_block_pos(e.seq, (int32_t)gi);
|
||||
has_win = kv.runtime_window(e.seq, (int32_t)gi, &win);
|
||||
if (has_win) {
|
||||
assert(!ring_blocks || ring_blocks == (int32_t)win.ring_blocks);
|
||||
/* The ring size sets the group header's geometry, so every sequence in the
|
||||
* group must report the same one. */
|
||||
if (ring_blocks && ring_blocks != (int32_t)win.ring_blocks) {
|
||||
RAD_ERR("kv group %d: sequences report ring sizes of %d and %d blocks",
|
||||
(int)gi, (int)ring_blocks, (int)win.ring_blocks);
|
||||
return RAD_E_STATE;
|
||||
}
|
||||
ring_blocks = (int32_t)win.ring_blocks;
|
||||
}
|
||||
bt_len = (int64_t)bt.size();
|
||||
@@ -808,6 +818,10 @@ int BatchBuilder::build_groups(const StepPlan& plan, const IKVManager& kv, Set&
|
||||
(int)g.sidx_pitch);
|
||||
}
|
||||
}
|
||||
int32_t group_used = 0;
|
||||
for (int64_t i = 0; i < n_seq; ++i)
|
||||
group_used = std::max(group_used, g.h_used[i]);
|
||||
o.kv_used_max_h[gi] = group_used;
|
||||
/* A state group's rows are one slot per sequence: n_seq words, restaged whole. */
|
||||
if (!L.paged) {
|
||||
stage(g.bt_fix, np, n_seq);
|
||||
@@ -846,6 +860,7 @@ int BatchBuilder::build_groups(const StepPlan& plan, const IKVManager& kv, Set&
|
||||
b.block_table = on_rank(base, s.dev[0], g.d_bt);
|
||||
b.block_table_pitch = pitch;
|
||||
b.seqused = on_rank(base, s.dev[0], g.d_used);
|
||||
b.seqused_h = g.h_used;
|
||||
b.state_index = on_rank(base, s.dev[0], g.d_sidx);
|
||||
b.state_index_pitch = g.sidx_pitch;
|
||||
b.block_size = L.block_size;
|
||||
@@ -933,6 +948,7 @@ const RadBatch* BatchBuilder::build(const StepPlan& plan, const IKVManager& kv,
|
||||
int64_t n_out = 0, n_dout = 0;
|
||||
int32_t rope_mixed = 0;
|
||||
int64_t n_mm = 0;
|
||||
int64_t n_bidi = 0;
|
||||
bool lora_rows = false;
|
||||
int32_t cvec_rows = 0;
|
||||
int64_t n_pw = 0;
|
||||
@@ -1022,6 +1038,23 @@ const RadBatch* BatchBuilder::build(const StepPlan& plan, const IKVManager& kv,
|
||||
n_mm += got;
|
||||
}
|
||||
}
|
||||
/* The part of each picture's or video frame's run inside this chunk, read both ways
|
||||
* (RadBatch::n_bidi), on a trunk pass: its rows see the keys up to the run's end, or the
|
||||
* chunk's where a run longer than any step was cut (Scheduler::bidi_fit). */
|
||||
if (bidi_on_ && plan.draft_pass == 0 && shift == 0 && e.req && e.req->media) {
|
||||
const mm::PromptMedia& pm = *e.req->media;
|
||||
const int64_t c0 = e.ctx_len, c1 = c0 + e.n_tokens, T = max_tok_;
|
||||
for (const mm::RopeLayout::Run& run : pm.rope.runs) {
|
||||
const int64_t a = std::max<int64_t>(run.tok, c0);
|
||||
const int64_t b = std::min<int64_t>((int64_t)run.tok + run.n, c1);
|
||||
if (a >= b || pm.items[(size_t)run.item].item->kind == mm::Kind::Audio) continue;
|
||||
s.h_bidi[n_bidi] = (int32_t)b;
|
||||
s.h_bidi[T + n_bidi] = (int32_t)(k + a - c0);
|
||||
s.h_bidi[2 * T + n_bidi] = (int32_t)(b - a);
|
||||
s.h_bidi[3 * T + n_bidi] = (int32_t)i;
|
||||
++n_bidi;
|
||||
}
|
||||
}
|
||||
if (e.ckpt_tok >= 0 && e.ckpt_slot >= 0) {
|
||||
/* checkpoint_tok indexes this step's tokens: the sequence's base plus the offset the
|
||||
* scheduler chose, the last token of a checkpoint interval (§7.3). */
|
||||
@@ -1075,6 +1108,7 @@ const RadBatch* BatchBuilder::build(const StepPlan& plan, const IKVManager& kv,
|
||||
s.h_q[i] = e.n_tokens;
|
||||
s.h_ctx[i] = e.ctx_len;
|
||||
s.h_acc[i] = e.n_accepted;
|
||||
s.h_arow[i] = -1;
|
||||
if (e.is_prefill) { if (e.n_tokens > max_q_pf) max_q_pf = e.n_tokens; }
|
||||
else { if (e.n_tokens > max_q_dec) max_q_dec = e.n_tokens; }
|
||||
}
|
||||
@@ -1205,6 +1239,7 @@ const RadBatch* BatchBuilder::build(const StepPlan& plan, const IKVManager& kv,
|
||||
B.n_seq = n_seq;
|
||||
B.token_ids = on_rank(base, b0, s.d_tok);
|
||||
B.positions = on_rank(base, b0, s.d_pos);
|
||||
B.positions_h = s.h_pos;
|
||||
B.cu_seqlens = on_rank(base, b0, s.d_cu);
|
||||
B.seq_ids = on_rank(base, b0, s.d_sid);
|
||||
B.n_out = n_out;
|
||||
@@ -1220,6 +1255,7 @@ const RadBatch* BatchBuilder::build(const StepPlan& plan, const IKVManager& kv,
|
||||
B.max_q_len_decode = max_q_dec;
|
||||
B.max_q_len_prefill = max_q_pf;
|
||||
B.max_ctx_len = (int32_t)ctx_bound;
|
||||
B.kv_used_max_h = o.kv_used_max_h.data();
|
||||
B.n_kv_groups = (int)o.kv[r].size();
|
||||
B.kv = o.kv[r].data();
|
||||
B.draft_pass = plan.draft_pass;
|
||||
@@ -1230,10 +1266,17 @@ const RadBatch* BatchBuilder::build(const StepPlan& plan, const IKVManager& kv,
|
||||
B.num_accepted = cfg_.n_spec > 0 ? on_rank(base, b0, s.d_acc) : nullptr;
|
||||
/* Staged above on a tree step: each row's parent row, -2 for an ordinary causal one. */
|
||||
B.spec_parent = plan.spec_is_tree ? on_rank(base, b0, s.d_parent) : nullptr;
|
||||
/* Pass 1 is a block drafter's query pass (a serial head has no pass 1). */
|
||||
B.anchor_rows = plan.draft_pass == 1 ? on_rank(base, b0, s.d_arow) : nullptr;
|
||||
B.rope_pos = mm_on_ ? on_rank(base, b0, s.d_rope) : nullptr;
|
||||
B.rope_mixed = rope_mixed;
|
||||
B.n_mm_rows = n_mm;
|
||||
B.mm_rows = n_mm ? on_rank(base, b0, s.d_mmrow) : nullptr;
|
||||
B.n_bidi = n_bidi;
|
||||
B.bidi_used = n_bidi ? on_rank(base, b0, s.d_bidi) : nullptr;
|
||||
B.bidi_row = n_bidi ? s.h_bidi + max_tok_ : nullptr;
|
||||
B.bidi_n = n_bidi ? s.h_bidi + 2 * max_tok_ : nullptr;
|
||||
B.bidi_seq = n_bidi ? s.h_bidi + 3 * max_tok_ : nullptr;
|
||||
B.mm_embd = n_mm ? mm_dev_[r] : nullptr;
|
||||
/* Null on a step with no adapter row: the core then issues no adapter op, and the step
|
||||
* runs the same pass as an engine serving no adapters. */
|
||||
@@ -1309,6 +1352,7 @@ AdvanceArgs BatchBuilder::advance_args(int rank) const {
|
||||
a.ctx_off = off(s.d_ctx);
|
||||
a.acc_off = off(s.d_acc);
|
||||
a.out_off = off(s.d_out);
|
||||
a.arow_off = off(s.d_arow);
|
||||
a.sid_off = off(s.d_sid);
|
||||
a.cu_off = off(s.d_cu);
|
||||
a.q_off = off(s.d_q);
|
||||
|
||||
@@ -220,12 +220,19 @@ private:
|
||||
* runtime window (advance.h). Per sequence because each prompt has its own floor. */
|
||||
int32_t *h_rpos = nullptr, *d_rpos = nullptr;
|
||||
int32_t *h_tlen = nullptr, *d_tlen = nullptr;
|
||||
/* [max_seqs] a block drafter's query pass: each row's last committed row in the context
|
||||
* pass just run (RadBatch::anchor_rows), written on the card by ADV_BLOCK. */
|
||||
int32_t *h_arow = nullptr, *d_arow = nullptr;
|
||||
|
||||
char* h_derived = nullptr; /* derivation staging, byte-addressed */
|
||||
/* [3][n_tok] rotary positions and [n_tok] encoder-row targets (RadBatch::rope_pos,
|
||||
* mm_rows): carved only when the program declared an encoder, empty otherwise. */
|
||||
int32_t *h_rope = nullptr, *d_rope = nullptr;
|
||||
int32_t *h_mmrow = nullptr, *d_mmrow = nullptr;
|
||||
/* [4][max_tok] the runs read both ways (RadBatch::n_bidi): their key counts (the one plane
|
||||
* the device reads), first rows, rows and sequences; carved only when the program's
|
||||
* encoder asks for them (RadEncoderDecl::bidirectional). */
|
||||
int32_t *h_bidi = nullptr, *d_bidi = nullptr;
|
||||
/* [n_tok] each row's runtime LoRA adapter slot (RadBatch::lora_slot): carved only when the
|
||||
* engine serves adapters, empty otherwise. */
|
||||
int32_t *h_lora = nullptr, *d_lora = nullptr;
|
||||
@@ -265,6 +272,7 @@ private:
|
||||
/* Per rank and group, the RadKVStream a batch names: each rank's own copy, outside the slab. */
|
||||
std::vector<std::vector<RadKVStream>> stream;
|
||||
std::vector<RadBatch> batch;
|
||||
std::vector<int32_t> kv_used_max_h;
|
||||
/* The build's sequences in row order (step_seqs); none for an encoder pass. */
|
||||
std::vector<uint64_t> seqs;
|
||||
bool has_seqs = false;
|
||||
@@ -344,6 +352,7 @@ private:
|
||||
* (see RadBatch::mm_embd). The staging is refilled only after its last upload has run
|
||||
* (`mm_ev_`). */
|
||||
bool mm_on_ = false;
|
||||
bool bidi_on_ = false; /* RadEncoderDecl::bidirectional */
|
||||
/* The engine serves runtime LoRA adapters (Config::lora): the batch carries each row's slot. */
|
||||
bool lora_on_ = false;
|
||||
/* Program::plugin_words: the words a sequence may carry, 0 for none. */
|
||||
|
||||
@@ -9,11 +9,13 @@
|
||||
|
||||
namespace rad {
|
||||
|
||||
/* lcm, with a non-positive side meaning "no constraint yet". */
|
||||
/* lcm, with a non-positive side meaning "no constraint yet". The sides are plugin-declared; an lcm
|
||||
* past int64 saturates, so the quantum check refuses it rather than wrapping to a small one. */
|
||||
static int64_t lcm64(int64_t a, int64_t b) {
|
||||
if (a <= 0) return b;
|
||||
if (b <= 0) return a;
|
||||
return std::lcm(a, b);
|
||||
const int64_t q = a / std::gcd(a, b);
|
||||
return q > INT64_MAX / b ? INT64_MAX : q * b;
|
||||
}
|
||||
|
||||
/* The op's sequence-chunk parameter, found by role (RAD_PROLE_SEQ_CHUNK) in its schema. Steps
|
||||
|
||||
+160
-28
@@ -138,7 +138,14 @@ int Scheduler::init(Program& prog, const Config& cfg, IKVManager* kv, IPrefixCac
|
||||
"prompt unfinished while other sequences decode, the next %lld steps carry "
|
||||
"decode rows only and admit nothing", (long long)cfg.prefill_interleave,
|
||||
(long long)cfg.prefill_interleave);
|
||||
else if (cfg.prefill_interleave < 0)
|
||||
RAD_INFO("scheduler: --prefill-interleave auto: after a prefill chunk that leaves its "
|
||||
"prompt unfinished while other sequences decode, decode-only steps follow for up "
|
||||
"to %.2f of the chunk step's measured time (at most %lld steps)",
|
||||
cfg.prefill_interleave_share, (long long)kInterleaveAutoMax);
|
||||
interleave_left_ = 0;
|
||||
ema_chunk_s_ = 0.0;
|
||||
ema_decode_s_ = 0.0;
|
||||
held_prefill_ = 0;
|
||||
draft_refill_ = 0;
|
||||
if (cfg.n_spec > 0 && prog.drafter.kind == RAD_DRAFT_BLOCK && prog.drafter.window > 0 &&
|
||||
@@ -375,6 +382,11 @@ int Scheduler::add_locked(std::unique_ptr<Request> r) {
|
||||
s.arrived_us = mono_us();
|
||||
s.first_tok_us = 0;
|
||||
s.preempted_us = 0;
|
||||
/* A recycled slot keeps its struct, and the prefill figure is computed from admitted_us
|
||||
* whenever it is non-zero: left standing, it would date this request's first token to the
|
||||
* admission of whichever request held the slot before. The re-admission guard below needs
|
||||
* it zero for the same reason -- a stale stamp would read as an earlier admission. */
|
||||
s.admitted_us = 0;
|
||||
s.slot = slot;
|
||||
s.card = -1;
|
||||
s.running = false;
|
||||
@@ -584,14 +596,11 @@ void Scheduler::trim_prefix_cache() {
|
||||
if (short_by > 0) (void)pc_->trim(short_by);
|
||||
}
|
||||
|
||||
void Scheduler::close_request(SchedReq& s, ReqState st, const char* reason, bool defer_free,
|
||||
bool publish, int status, const char* why) {
|
||||
++step_finished_;
|
||||
/* Publish before freeing: this is the only moment the whole prefix is both computed and still
|
||||
* owned. insert() takes its own KV references, so the blocks survive the free below. Cancelled
|
||||
* and failed requests are published too; their prompts were computed, and a client that hangs
|
||||
* up mid-answer is likely to ask for that prefix again. */
|
||||
if (publish && cfg_.prefix_cache && pc_ && kv_->has_sequence(s.req->id) &&
|
||||
/* What a request computed, into the prefix cache, while it still owns the blocks: at its close,
|
||||
* and at a preemption, whose recompute then adopts its prompt instead of computing it again.
|
||||
* True when published. */
|
||||
bool Scheduler::publish_prefix(SchedReq& s) {
|
||||
if (cfg_.prefix_cache && pc_ && kv_->has_sequence(s.req->id) &&
|
||||
s.req->n_computed > 0 && !kv_->has_runtime_window(s.req->id)) {
|
||||
/* R-SWA: a sequence with a runtime window is not published (KVManager::set_window). Its
|
||||
* table is a reference plus a ring rather than a prefix from position 0, and the window
|
||||
@@ -613,8 +622,20 @@ void Scheduler::close_request(SchedReq& s, ReqState st, const char* reason, bool
|
||||
RAD_DEBUG("prefix cache: request %llu not published: %s",
|
||||
(unsigned long long)s.req->id, rad_strerror(rc));
|
||||
trim_prefix_cache();
|
||||
return rc >= 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Scheduler::close_request(SchedReq& s, ReqState st, const char* reason, bool defer_free,
|
||||
bool publish, int status, const char* why) {
|
||||
++step_finished_;
|
||||
/* Publish before freeing: this is the only moment the whole prefix is both computed and still
|
||||
* owned. insert() takes its own KV references, so the blocks survive the free below. Cancelled
|
||||
* and failed requests are published too; their prompts were computed, and a client that hangs
|
||||
* up mid-answer is likely to ask for that prefix again. */
|
||||
if (publish) (void)publish_prefix(s);
|
||||
|
||||
if (cfg_.prefix_cache && pc_) pc_->release(*s.req);
|
||||
/* Prompt lookup's index is this text's alone. */
|
||||
@@ -901,6 +922,8 @@ int Scheduler::requests_locked(ReqStat* out, int max) const {
|
||||
o.slot = s.slot;
|
||||
o.age_s = (double)(now - s.arrived_us) / 1e6;
|
||||
o.ttft_s = s.first_tok_us ? (double)(s.first_tok_us - s.arrived_us) / 1e6 : -1.0;
|
||||
o.prefill_s = (s.first_tok_us && s.admitted_us)
|
||||
? (double)(s.first_tok_us - s.admitted_us) / 1e6 : -1.0;
|
||||
/* Since the first token, not admission, so time spent queued does not read as slow
|
||||
* decode. */
|
||||
const double dec = s.first_tok_us ? (double)(now - s.first_tok_us) / 1e6 : 0.0;
|
||||
@@ -968,7 +991,7 @@ int64_t Scheduler::chunk_end(const Request& r, int64_t n_target) const {
|
||||
* so a chunk clamped to it is already aligned; in the other order a chunk past the checkpoint
|
||||
* would be rounded down and miss the boundary. */
|
||||
int64_t Scheduler::plan_chunk(int64_t n_computed, int64_t n_target, int64_t budget,
|
||||
int64_t* checkpoint_pos, int64_t keep_at) const {
|
||||
int64_t* checkpoint_pos, int64_t keep_at, const Request* r) const {
|
||||
if (checkpoint_pos) *checkpoint_pos = -1;
|
||||
int64_t remaining = n_target - n_computed;
|
||||
if (remaining <= 0 || budget <= 0) return 0;
|
||||
@@ -1093,9 +1116,48 @@ int64_t Scheduler::plan_chunk(int64_t n_computed, int64_t n_target, int64_t budg
|
||||
if (checkpoint_pos && *checkpoint_pos > aligned) *checkpoint_pos = -1;
|
||||
}
|
||||
}
|
||||
if (r) {
|
||||
const int64_t fit = bidi_fit(*r, n_computed, n_target, want, budget);
|
||||
/* A trimmed chunk keeps a window snapshot it still carries (as above); a grown one drops it. */
|
||||
if (fit != want && checkpoint_pos && (fit > want || *checkpoint_pos > n_computed + fit))
|
||||
*checkpoint_pos = -1;
|
||||
want = fit;
|
||||
}
|
||||
return want;
|
||||
}
|
||||
|
||||
/* A chunk that ended inside a run read both ways would give the run's rows of this chunk keys the
|
||||
* next chunk writes. So it ends before the run, on a quantum (and before every run that lands in,
|
||||
* as a video's frames do); a chunk that starts at or inside the run (nothing fits before it) runs
|
||||
* to the run's end, rounded up to a quantum unless the sequence ends first, past every run that
|
||||
* lands in, or waits for a step that holds that. A run no step holds is cut where the chunk falls,
|
||||
* and its rows see the run up to the cut (RadBatch::bidi_used). */
|
||||
int64_t Scheduler::bidi_fit(const Request& r, int64_t n_computed, int64_t n_target, int64_t want,
|
||||
int64_t budget) const {
|
||||
if (!prog_ || !prog_->encoder.bidirectional || !r.media || want <= 0) return want;
|
||||
const mm::PromptMedia& pm = *r.media;
|
||||
const int64_t Q = std::max<int64_t>(geo_.quantum, 1);
|
||||
/* The run read both ways that a chunk ending at `end` would cut, or null. */
|
||||
auto cut = [&](int64_t end) -> const mm::RopeLayout::Run* {
|
||||
if (end >= n_target) return nullptr;
|
||||
const mm::RopeLayout::Run* run = pm.rope.run_at(end);
|
||||
if (!run || run->tok == end || pm.items[(size_t)run->item].item->kind == mm::Kind::Audio)
|
||||
return nullptr;
|
||||
return run;
|
||||
};
|
||||
int64_t end = n_computed + want;
|
||||
for (const mm::RopeLayout::Run* run = cut(end); run; run = cut(end)) {
|
||||
const int64_t before = (int64_t)run->tok / Q * Q;
|
||||
if (before <= n_computed) break;
|
||||
end = before;
|
||||
}
|
||||
if (!cut(end)) return end - n_computed;
|
||||
for (const mm::RopeLayout::Run* run = cut(end); run; run = cut(end))
|
||||
end = std::min<int64_t>(n_target, ((int64_t)run->tok + run->n + Q - 1) / Q * Q);
|
||||
if (end - n_computed <= budget) return end - n_computed;
|
||||
return end - n_computed > cfg_.max_tok ? want : 0;
|
||||
}
|
||||
|
||||
/* The tail checkpoint of a `target`-token prompt, or -1. Under --prefix-resume exact, where its
|
||||
* last chunk starts (below). Under nearest, its last quantum boundary, only past the first
|
||||
* interval (a shorter prompt is cheap to redo) and only where it gains at least a quarter
|
||||
@@ -1215,14 +1277,44 @@ int64_t Scheduler::busy_cap(int64_t n_computed, int64_t n_target, int64_t budget
|
||||
return std::min(std::max(cap, Q), budget);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ decode-only steps */
|
||||
/* How many decode-only steps follow a chunk that ran beside decoding sequences
|
||||
* (--prefill-interleave). N as given; under auto, as many as fit in Config::prefill_interleave_share of a chunk
|
||||
* step's measured time at a decode step's, so the prefill gives up at most a fifth of its rate
|
||||
* (a quarter of a chunk step) however many sequences decode, and the decoders get the steps that
|
||||
* share buys: several where decode steps are cheap beside the chunk, none where one costs more
|
||||
* than a quarter of it (they still ride every chunk). One until both costs are measured, which
|
||||
* takes the first decode-only step. Both are wall times read off step_finished, so under auto
|
||||
* which steps carry a chunk follows the device's timing and differs from run to run; a number
|
||||
* schedules the same steps every time. */
|
||||
void Scheduler::step_cost_locked(bool chunk, double seconds) {
|
||||
double& ema = chunk ? ema_chunk_s_ : ema_decode_s_;
|
||||
ema = ema > 0.0 ? ema + kInterleaveEma * (seconds - ema) : seconds;
|
||||
}
|
||||
|
||||
void Scheduler::note_step_cost(bool chunk, double seconds) {
|
||||
std::lock_guard<std::mutex> lk(mu_);
|
||||
if (seconds > 0) step_cost_locked(chunk, seconds);
|
||||
}
|
||||
|
||||
int64_t Scheduler::interleave_steps() const {
|
||||
if (cfg_.prefill_interleave >= 0) return cfg_.prefill_interleave;
|
||||
if (ema_chunk_s_ <= 0.0 || ema_decode_s_ <= 0.0) return 1;
|
||||
const double n = cfg_.prefill_interleave_share * ema_chunk_s_ / ema_decode_s_;
|
||||
return n >= (double)kInterleaveAutoMax ? kInterleaveAutoMax : (int64_t)n;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ preemption */
|
||||
void Scheduler::preempt_back() {
|
||||
bool Scheduler::preempt_back() {
|
||||
int32_t slot = running_.back();
|
||||
SchedReq& s = *reqs_[(size_t)slot];
|
||||
Request& r = *s.req;
|
||||
|
||||
/* Preemption by recompute: the blocks go back and the request restarts from zero. Its output
|
||||
* is the tail of its token sequence, so it simply re-prefills prompt ++ output. */
|
||||
* is the tail of its token sequence, so it simply re-prefills prompt ++ output. What it computed
|
||||
* is published first: the recompute adopts it from the cache, and under pressure the cache gives
|
||||
* the blocks back (the newest entries last). */
|
||||
const bool published = publish_prefix(s);
|
||||
kv_->preempt(r.id);
|
||||
drop_card(s);
|
||||
r.n_computed = 0;
|
||||
@@ -1242,6 +1334,7 @@ void Scheduler::preempt_back() {
|
||||
running_.pop_back();
|
||||
queue_insert(waiting_, slot); /* original arrival -> the front of its priority class */
|
||||
++m_.preemptions;
|
||||
return published;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ admission */
|
||||
@@ -1319,6 +1412,7 @@ int Scheduler::admit_one(SchedReq& s, int64_t budget, int64_t reserve) {
|
||||
const RestoreResult rr = pc_->restore(r, whole_only);
|
||||
if (rr == RestoreResult::Declined) {
|
||||
s.restore_waited = true;
|
||||
admit_next_step_ = true;
|
||||
RAD_DEBUG("admit %llu: the restore waits a step for %d deferred release(s)",
|
||||
(unsigned long long)r.id, n_deferred_);
|
||||
return RAD_E_FULL;
|
||||
@@ -1471,9 +1565,12 @@ int Scheduler::admit_one(SchedReq& s, int64_t budget, int64_t reserve) {
|
||||
* to what really has to run. */
|
||||
const int64_t cap = busy_cap(r.n_computed, target, budget, reserve, !plan_.e.empty());
|
||||
const int64_t end = chunk_end(r, target);
|
||||
want = plan_chunk(r.n_computed, end, cap, &ckpt, r.checkpoint_at);
|
||||
if (cap < budget && want > 0)
|
||||
admit_full_ = plan_chunk(r.n_computed, end, budget, nullptr, r.checkpoint_at);
|
||||
want = plan_chunk(r.n_computed, end, cap, &ckpt, r.checkpoint_at, &r);
|
||||
/* A run read both ways (bidi_fit) the share cannot hold takes the step instead. */
|
||||
if (want <= 0 && cap < budget && prog_->encoder.bidirectional)
|
||||
want = plan_chunk(r.n_computed, end, budget, &ckpt, r.checkpoint_at, &r);
|
||||
else if (cap < budget && want > 0)
|
||||
admit_full_ = plan_chunk(r.n_computed, end, budget, nullptr, r.checkpoint_at, &r);
|
||||
}
|
||||
int rc = RAD_OK;
|
||||
if (want <= 0) rc = RAD_E_FULL;
|
||||
@@ -1522,6 +1619,8 @@ int Scheduler::admit_one(SchedReq& s, int64_t budget, int64_t reserve) {
|
||||
|
||||
if (s.card < 0) { s.card = free_cards_.back(); free_cards_.pop_back(); }
|
||||
r.state = ReqState::Running;
|
||||
if (!s.admitted_us) s.admitted_us = mono_us(); /* first admission; a re-admit after
|
||||
* preemption keeps the original stamp */
|
||||
s.preempted_us = 0;
|
||||
s.running = true;
|
||||
server::sink_admitted(r.sink);
|
||||
@@ -1552,6 +1651,9 @@ void Scheduler::undo_hit(SchedReq& s) {
|
||||
bool Scheduler::preempted_can_prefill(const SchedReq& s) const {
|
||||
const Request& r = *s.req;
|
||||
const int64_t target = s.seq_len();
|
||||
/* What the recompute adopts from the cache (its own prefix, published at the preemption) needs
|
||||
* no new block. */
|
||||
const int64_t hit = (cfg_.prefix_cache && pc_) ? pc_->lookup(r, nullptr, nullptr).n_attn_tokens : 0;
|
||||
|
||||
for (size_t g = 0; g < kvgeom_.g.size(); ++g) {
|
||||
const KVGeom::G& gg = kvgeom_.g[g];
|
||||
@@ -1559,7 +1661,7 @@ bool Scheduler::preempted_can_prefill(const SchedReq& s) const {
|
||||
* wanted the whole prompt from a pool of none and kept a preempted request out for good. */
|
||||
if (!gg.paged || kv_->total_blocks((int32_t)g) <= 0) continue;
|
||||
int64_t need = (target + gg.block_size - 1) / gg.block_size -
|
||||
(int64_t)kv_->block_table(r.id, (int32_t)g).size();
|
||||
(int64_t)kv_->block_table(r.id, (int32_t)g).size() - hit / gg.block_size;
|
||||
if (need < 0) need = 0;
|
||||
for (int32_t slot : running_) {
|
||||
const SchedReq& rs = *reqs_[(size_t)slot];
|
||||
@@ -1692,7 +1794,7 @@ const RadBatch* Scheduler::step() {
|
||||
running_.erase(std::find(running_.begin(), running_.end(), victim));
|
||||
running_.push_back(victim);
|
||||
}
|
||||
preempt_back();
|
||||
if (preempt_back()) evict_rounds = 0; /* its blocks stay in the cache: evict them first */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1704,7 +1806,7 @@ const RadBatch* Scheduler::step() {
|
||||
bool any_decoding = false;
|
||||
bool hold_prefill = false;
|
||||
held_prefill_ = 0;
|
||||
if (cfg_.prefill_interleave > 0) {
|
||||
if (cfg_.prefill_interleave != 0) {
|
||||
for (int32_t slot : running_) {
|
||||
const SchedReq& s = *reqs_[(size_t)slot];
|
||||
if (!s.req || !s.running) continue;
|
||||
@@ -1820,10 +1922,13 @@ const RadBatch* Scheduler::step() {
|
||||
const int64_t cap = busy_cap(r.n_computed, target, budget, reserve, !plan_.e.empty(),
|
||||
/*rows_only=*/shares == 0);
|
||||
const int64_t end = chunk_end(r, target);
|
||||
want = plan_chunk(r.n_computed, end, cap, &ckpt, r.checkpoint_at);
|
||||
if (cap < budget && want > 0 && capped_at < 0) {
|
||||
want = plan_chunk(r.n_computed, end, cap, &ckpt, r.checkpoint_at, &r);
|
||||
/* A run read both ways (bidi_fit) the share cannot hold takes the step instead. */
|
||||
if (want <= 0 && cap < budget && prog_->encoder.bidirectional)
|
||||
want = plan_chunk(r.n_computed, end, budget, &ckpt, r.checkpoint_at, &r);
|
||||
else if (cap < budget && want > 0 && capped_at < 0) {
|
||||
const int64_t full = plan_chunk(r.n_computed, end, budget, nullptr,
|
||||
r.checkpoint_at);
|
||||
r.checkpoint_at, &r);
|
||||
if (want < full) { capped_at = (int32_t)plan_.e.size(); capped_full = full; }
|
||||
}
|
||||
/* A prefill with no room left does not end the walk: it takes nothing this step, but
|
||||
@@ -1910,7 +2015,9 @@ const RadBatch* Scheduler::step() {
|
||||
/* The back of the running set gives its blocks up. When that is this request, the
|
||||
* requests ahead of it hold the pool: it is preempted by recompute and waits for
|
||||
* them, rather than failed. */
|
||||
preempt_back();
|
||||
/* A victim that published keeps its blocks in the cache: eviction gets its rounds
|
||||
* back, so they are reclaimed before anyone else is preempted. */
|
||||
if (preempt_back()) evict_rounds = 0;
|
||||
preempted_here = true;
|
||||
if (last) { yielded = true; break; }
|
||||
}
|
||||
@@ -2001,13 +2108,28 @@ const RadBatch* Scheduler::step() {
|
||||
(int64_t)plan_.e.size() + 1 < cfg_.max_seqs && free_cards_.size() > 1
|
||||
? share_tok : 0;
|
||||
admit_full_ = 0;
|
||||
admit_next_step_ = false;
|
||||
const int as = admit_one(s, budget, areserve);
|
||||
if (as == kAdmitWait) { ++at; continue; }
|
||||
/* A preempted request waiting for its whole-recompute gate lets the next one be asked;
|
||||
* an overdue one does not. The room the overdue path made this step is for it, and a
|
||||
* request queued behind it would take that room back: a victim just forced off for it,
|
||||
* its prompt published, needs almost nothing to come back, and under KV pressure the
|
||||
* same victim was forced off and re-admitted 26 times in 16 s while the overdue request
|
||||
* waited. */
|
||||
if (as == kAdmitWait) {
|
||||
if (s.req->state == ReqState::Preempted && preempt_wait_overdue(s)) break;
|
||||
++at;
|
||||
continue;
|
||||
}
|
||||
/* An overdue preempted prefill on an idle engine that still cannot be admitted will
|
||||
* not become admissible by waiting: nothing is running to finish and free the pool.
|
||||
* Fail it (spec §17) and ask the next request, instead of parking the step loop. */
|
||||
if (as < 0 && running_.empty() && s.req && s.req->state == ReqState::Preempted &&
|
||||
preempt_wait_overdue(s)) {
|
||||
* Fail it (spec §17) and ask the next request, instead of parking the step loop. Not
|
||||
* when this step admitted someone ahead of it (the budget or a card went to them) or
|
||||
* the refusal is a restore waiting a step for deferred releases: both clear by the
|
||||
* next step, and failing them lost two of ten preempted requests under KV pressure
|
||||
* once their prompts were published at the preemption (1. 11. 2026). */
|
||||
if (as < 0 && running_.empty() && plan_.e.empty() && !admit_next_step_ && s.req &&
|
||||
s.req->state == ReqState::Preempted && preempt_wait_overdue(s)) {
|
||||
RAD_WARN("request %llu failed: overdue preempted prefill could not be admitted "
|
||||
"with nothing running (%s)",
|
||||
(unsigned long long)s.req->id, rad_strerror(as));
|
||||
@@ -2081,7 +2203,7 @@ const RadBatch* Scheduler::step() {
|
||||
if (cfg_.busy_prefill_chunk > 0) limit = std::min(limit, std::max(had, cfg_.busy_prefill_chunk));
|
||||
int64_t ckpt = -1;
|
||||
const int64_t grown = e.ckpt_slot < 0 && limit > had
|
||||
? plan_chunk(r.n_computed, chunk_end(r, s.seq_len()), limit, &ckpt, r.checkpoint_at)
|
||||
? plan_chunk(r.n_computed, chunk_end(r, s.seq_len()), limit, &ckpt, r.checkpoint_at, &r)
|
||||
: had;
|
||||
if (grown > had && kv_->ensure_from(r.id, r.n_computed + grown, r.n_computed) >= 0) {
|
||||
e.n_tokens = (int32_t)grown;
|
||||
@@ -2135,13 +2257,13 @@ const RadBatch* Scheduler::step() {
|
||||
case RAD_PHASE_MIXED: ++m_.steps_mixed; break;
|
||||
default: ++m_.steps_decode; break;
|
||||
}
|
||||
if (cfg_.prefill_interleave > 0) {
|
||||
if (cfg_.prefill_interleave != 0) {
|
||||
/* Armed only while a prompt continues past this step: after a last chunk nothing is left
|
||||
* to interleave, and holding would only keep the next request out. */
|
||||
bool continues = false;
|
||||
for (const StepEntry& e : plan_.e)
|
||||
if (e.is_prefill && !e.produces_token) continues = true;
|
||||
if (any_pf) interleave_left_ = any_decoding && continues ? cfg_.prefill_interleave : 0;
|
||||
if (any_pf) interleave_left_ = any_decoding && continues ? interleave_steps() : 0;
|
||||
else if (interleave_left_ > 0) --interleave_left_;
|
||||
if (held_prefill_ > 0) ++m_.steps_held;
|
||||
}
|
||||
@@ -2562,7 +2684,14 @@ int Scheduler::commit(StepResult& res) {
|
||||
/* Not while a step issued ahead writes past `valid`; that step's commit rolls back to
|
||||
* the end it reaches. */
|
||||
if (a < e.n_spec && !(next_open_ && s.entry_next >= 0)) {
|
||||
#ifdef RAD_ENABLE_KV_ROLLBACK_TEST_HOOK
|
||||
if (kv_rollback_test_hook_) kv_rollback_test_hook_(r.id, e.n_spec, a, valid, true);
|
||||
#endif
|
||||
int st = kv_->rollback(r.id, valid);
|
||||
#ifdef RAD_ENABLE_KV_ROLLBACK_TEST_HOOK
|
||||
if (st >= 0 && kv_rollback_test_hook_)
|
||||
kv_rollback_test_hook_(r.id, e.n_spec, a, valid, false);
|
||||
#endif
|
||||
if (st < 0) RAD_WARN("kv rollback for request %llu: %s",
|
||||
(unsigned long long)r.id, rad_strerror(st));
|
||||
}
|
||||
@@ -2736,6 +2865,9 @@ void Scheduler::step_finished() {
|
||||
/* The window ages by all elapsed time, idle included; only the busy part is added as time the
|
||||
* tokens took. */
|
||||
const double aged = std::chrono::duration<double>(step_end - last_step_at_).count();
|
||||
/* --prefill-interleave auto's two step costs (interleave_steps). */
|
||||
if (wall > 0 && cfg_.prefill_interleave < 0)
|
||||
step_cost_locked(plan_.phase != RAD_PHASE_DECODE, wall);
|
||||
if (wall > 0) {
|
||||
constexpr double kWindowS = 1.0;
|
||||
const double f = std::exp(-aged / kWindowS);
|
||||
|
||||
+42
-2
@@ -19,6 +19,9 @@
|
||||
#include "ngram.h"
|
||||
|
||||
#include <chrono>
|
||||
#ifdef RAD_ENABLE_KV_ROLLBACK_TEST_HOOK
|
||||
#include <functional>
|
||||
#endif
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
@@ -42,6 +45,9 @@ struct SchedReq {
|
||||
/* Wall clock, for the live request table; `arrival` is a counter and cannot measure time. */
|
||||
int64_t arrived_us = 0;
|
||||
int64_t first_tok_us = 0; /* 0 until the first output token: this request's TTFT */
|
||||
int64_t admitted_us = 0; /* 0 until the first admission: where the queue ends, so a
|
||||
* prefill rate can divide by the prefill alone. ttft covers
|
||||
* the wait for admission (GUIDE); this excludes it. */
|
||||
int64_t preempted_us = 0; /* when this state became Preempted; 0 otherwise. Bounds the
|
||||
* whole-recompute admission wait (--preempt-wait-ms). */
|
||||
|
||||
@@ -274,6 +280,7 @@ public:
|
||||
int32_t slot = -1;
|
||||
double age_s = 0;
|
||||
double ttft_s = -1; /* negative until the first token */
|
||||
double prefill_s = -1; /* first token minus admission; negative until both */
|
||||
double decode_tps = 0; /* this request's own, since its first token */
|
||||
};
|
||||
/* Oldest first, since the oldest is the one most likely stuck. Returns how many were
|
||||
@@ -463,7 +470,15 @@ public:
|
||||
* token budget, and the checkpoint position it will land on (-1 for none). `keep_at` is the
|
||||
* request's own checkpoint (Request::checkpoint_at), 0 for none. */
|
||||
int64_t plan_chunk(int64_t n_computed, int64_t n_target, int64_t budget,
|
||||
int64_t* checkpoint_pos, int64_t keep_at = 0) const;
|
||||
int64_t* checkpoint_pos, int64_t keep_at = 0,
|
||||
const Request* r = nullptr) const;
|
||||
/* Visible for tests: `want` tokens of `r` from `n_computed` cut so the chunk ends inside no run
|
||||
* the language model reads both ways (RadEncoderDecl::bidirectional): before the run on a
|
||||
* quantum, or at its end when the chunk starts in it and `budget` holds that, else 0. A run
|
||||
* longer than any step keeps the cut where it falls. `want` unchanged for a program with no
|
||||
* such runs. */
|
||||
int64_t bidi_fit(const Request& r, int64_t n_computed, int64_t n_target, int64_t want,
|
||||
int64_t budget) const;
|
||||
|
||||
/* The smallest step the prefill stager overlaps, in tokens (0 = no stager), set once by the
|
||||
* engine after init. --busy-prefill-chunk keeps a held-back chunk at or above it (busy_cap).
|
||||
@@ -489,8 +504,21 @@ public:
|
||||
* multi-token chunk past the floor would overwrite keys its own earlier rows still read, while
|
||||
* one token a step attends as its decode step did. Otherwise `n_target`. */
|
||||
int64_t chunk_end(const Request& r, int64_t n_target) const;
|
||||
/* --prefill-interleave: the decode-only steps that follow a chunk run beside decoding
|
||||
* sequences. N as configured; under auto, from the measured step costs (see the definition).
|
||||
* Visible for tests, as is note_step_cost, which feeds auto a step's wall time as
|
||||
* step_finished does: `chunk` for a step that carried a prefill chunk, else a decode step. */
|
||||
int64_t interleave_steps() const;
|
||||
void note_step_cost(bool chunk, double seconds);
|
||||
|
||||
private:
|
||||
#ifdef RAD_ENABLE_KV_ROLLBACK_TEST_HOOK
|
||||
friend class Engine;
|
||||
/* Test-build-only observer at the concrete rollback operation. */
|
||||
void set_kv_rollback_test_hook(std::function<void(uint64_t, int, int, int64_t, bool)> hook) {
|
||||
kv_rollback_test_hook_ = std::move(hook);
|
||||
}
|
||||
#endif
|
||||
Program* prog_ = nullptr;
|
||||
Config cfg_{};
|
||||
ChunkGeometry geo_{};
|
||||
@@ -503,11 +531,15 @@ private:
|
||||
int64_t span_min_ = 0;
|
||||
/* Set by admit_one when it held the admitted chunk back: what it would have taken. */
|
||||
int64_t admit_full_ = 0;
|
||||
bool admit_next_step_ = false; /* admit_one's refusal is a wait for the next step */
|
||||
/* Whether this step's prefill may span (ChunkGeometry::span): set by step() for the step it
|
||||
* plans, true only for a prefill alone in its step, and read by plan_chunk. True outside a
|
||||
* step, so plan_chunk called directly answers for a span. */
|
||||
bool span_now_ = true;
|
||||
IKVManager* kv_ = nullptr;
|
||||
#ifdef RAD_ENABLE_KV_ROLLBACK_TEST_HOOK
|
||||
std::function<void(uint64_t, int, int, int64_t, bool)> kv_rollback_test_hook_;
|
||||
#endif
|
||||
IPrefixCache* pc_ = nullptr;
|
||||
|
||||
/* Does a prefix-cache hit leave a hole in a block drafter's own KV? Only if some paged group
|
||||
@@ -748,6 +780,13 @@ private:
|
||||
* the hold is spent, or the chunk would wait as long as the decoders keep stepping ahead. */
|
||||
int64_t interleave_left_ = 0;
|
||||
int64_t held_prefill_ = 0;
|
||||
/* --prefill-interleave auto: the decode-only steps after a chunk (interleave_steps), sized by
|
||||
* the running means of a step that carried a chunk and of a decode step, in seconds, fed by
|
||||
* step_finished. */
|
||||
static constexpr double kInterleaveEma = 0.25;
|
||||
static constexpr int64_t kInterleaveAutoMax = 64;
|
||||
double ema_chunk_s_ = 0.0, ema_decode_s_ = 0.0;
|
||||
void step_cost_locked(bool chunk, double seconds);
|
||||
/* The throughput window (step_finished): each kind's tokens and the wall time the steps
|
||||
* covered, both decayed with the same time constant, so their ratio is tokens over time. */
|
||||
double tps_win_prefill_ = 0.0, tps_win_decode_ = 0.0, tps_win_time_ = 0.0;
|
||||
@@ -796,7 +835,8 @@ private:
|
||||
const Request* serial_req(const SerialSeq& m) const;
|
||||
/* Both snapshots resolve the same way; the two wrappers exist because the row types differ. */
|
||||
const Request* live_req(int32_t slot, uint64_t id) const;
|
||||
void preempt_back();
|
||||
bool preempt_back(); /* true: the victim published its prefix */
|
||||
bool publish_prefix(SchedReq& s);
|
||||
/* A preempted request waits until the pool can hold its WHOLE remaining recompute, the rest
|
||||
* of every running prefill, and one block of headroom per runner. Admitting it against only
|
||||
* the next token steals the blocks a running prefill still needs and preempt_back() resets
|
||||
|
||||
Reference in new issue
Block a user