Keep MTP drafting in concurrent batch slots
This commit is contained in:
1 parent
5ab99da482
commit
8cfb3fd7cc
7 files changed
+364
-108
No files matched your search
@@ -43,7 +43,7 @@ public:
|
||||
/// Loads `rt_dir` (from tools/mtp_rt.py) and allocates the layer's K/V and buffers for up to `max_t` rows.
|
||||
/// Call before the VRAM expert tier is sized: this takes ~0.9 GB.
|
||||
bool load(const std::string& rt_dir, const ModelGeometry& g, SessionState& ss, int max_t, std::string& err,
|
||||
int64_t window = 32768);
|
||||
int64_t window = 32768, const MtpDrafter* shared = nullptr);
|
||||
/// The prompt's length: prefill() skips the cells the attention window can never reach again.
|
||||
void set_prompt_len(int64_t n) { prompt_len_ = n; }
|
||||
/// At most this many drafts per round (below max_t - 1): a window longer than the MTP's comes from elsewhere.
|
||||
@@ -58,7 +58,8 @@ public:
|
||||
/// the draft head over rt/draft_vocab.bin's subset. The expert cache is sized before bind(), so it reserves this.
|
||||
uint64_t bind_bytes(uint64_t head_row_bytes, int64_t n_vocab) const;
|
||||
/// The main model's embedding and head, and the verify window's final residuals (T rows, hc*n_embd each).
|
||||
bool bind(const WeightTable& wt, const NativeHead* head, const float* window_R, std::string& err);
|
||||
bool bind(const WeightTable& wt, const NativeHead* head, const float* window_R, std::string& err,
|
||||
const MtpDrafter* shared = nullptr);
|
||||
|
||||
/// Prompt cells [cell0, cell0 + n): residual rows `R_rows` (device, hc*n_embd each) and `next_tokens` (host,
|
||||
/// the token at position cell+1). Runs in batches of up to max_t rows.
|
||||
@@ -145,6 +146,9 @@ private:
|
||||
std::vector<Tensor> tensors_;
|
||||
uint8_t* dense_ = nullptr;
|
||||
uint8_t* experts_ = nullptr;
|
||||
// Slot drafters borrow immutable weights and head; each still owns its state and scratch.
|
||||
bool owns_weights_ = true;
|
||||
bool owns_draft_head_ = true;
|
||||
void* state_arena_ = nullptr;
|
||||
QsaState st_;
|
||||
void* arena_ = nullptr;
|
||||
|
||||
@@ -149,8 +149,11 @@ public:
|
||||
/// listed are not touched, so an idle slot keeps its state (a finished conversation it may continue later).
|
||||
bool run_slot_rows(const int* rows, int S, const int32_t* tokens, const int64_t* pos, PoolMultiFn pool, void* user,
|
||||
int32_t* out, std::string& err);
|
||||
/// Keep every row of the last batch window: each slot's state advances by its one token.
|
||||
/// Keep every row of the last batch window.
|
||||
bool commit_slots(std::string& err);
|
||||
/// Commit an accepted prefix in each contiguous slot group of the last window. `keep` has
|
||||
/// one entry per slot (indexed by slot ID), each in 1..that slot's group length.
|
||||
bool commit_slot_prefixes(const int* keep, std::string& err);
|
||||
|
||||
// ---- The stages of a layer split as a PIPELINE. A batch window over the slot GROUP
|
||||
// [base, base + S) is launched on ONE stage with its commit right behind it on the stage's stream (a batch window
|
||||
@@ -221,14 +224,18 @@ private:
|
||||
int row_base_ = 0; ///< ... its hand-off rows start here (a pipeline group's own rows)
|
||||
int brow_[8] = {}; ///< ... and row t is slot brow_[t]
|
||||
bool last_batch_ = false; ///< the last run was a batch window (set_plan_slot: one group)
|
||||
std::map<uint64_t, cudaGraphExec_t> exec_bm_, commit_bm_; ///< key: batch_key(rows, S, hand-off base)
|
||||
std::map<std::vector<int>, cudaGraphExec_t> exec_bm_, commit_bm_; ///< full row layout avoids slot-ID collisions
|
||||
int last_rows_[8] = {}; ///< the slots of the last batch window's rows
|
||||
uint64_t bkey(const int* rows, int S, int hbase) const { // #871: the doorbell variant has its own graphs
|
||||
return batch_key(rows, S, hbase) | (ar_off_ ? (1ull << 63) : 0ull);
|
||||
std::vector<int> bkey(const int* rows, int S, int hbase) const { // #871: the doorbell variant has its own graphs
|
||||
std::vector<int> k = batch_key(rows, S, hbase);
|
||||
k.push_back(ar_off_ ? 1 : 0);
|
||||
return k;
|
||||
}
|
||||
static uint64_t batch_key(const int* rows, int S, int hbase) {
|
||||
uint64_t k = (uint64_t) hbase << 40 | (uint64_t) S << 32;
|
||||
for (int t = 0; t < S; ++t) k |= (uint64_t) (rows[t] & 15) << (4 * t);
|
||||
static std::vector<int> batch_key(const int* rows, int S, int hbase) {
|
||||
std::vector<int> k;
|
||||
k.reserve((size_t) S + 1);
|
||||
k.push_back(hbase);
|
||||
for (int t = 0; t < S; ++t) k.push_back(rows[t]);
|
||||
return k;
|
||||
}
|
||||
// batch_launch / batch_poll
|
||||
|
||||
Reference in new issue
Block a user