limit DFlash2 draft ubatch to reduce compute buffer

This commit is contained in:
Denis Artyomov authored and xrip committed 2026-09-21 20:46:09 +03:00
1 parent d00e039632
commit 81cdd3ce48
2 files changed
+28

No files matched your search

+11
View File
@@ -1319,6 +1319,17 @@ common_init_result::common_init_result(common_params & params, bool model_only)
}
cparams_dft.n_rs_seq = 0;
// keep the fit estimate in sync with common_speculative_init_result (see there)
const bool has_block_draft = std::any_of(
params.speculative.types.begin(), params.speculative.types.end(),
[](common_speculative_type t) {
return t == COMMON_SPECULATIVE_TYPE_DRAFT_DFLASH || t == COMMON_SPECULATIVE_TYPE_DRAFT_DSPARK;
});
if (has_block_draft) {
cparams_dft.n_ubatch = std::min(cparams_dft.n_ubatch,
params_dft.n_parallel * (uint32_t) std::max(1, params_dft.speculative.draft.n_max + 1));
}
const common_fit_extra_model extra = {
/*.path_model =*/ params_dft.model.path.c_str(),
/*.mparams =*/ &mparams_dft,
+17
View File
@@ -2592,6 +2592,23 @@ common_speculative_init_result::common_speculative_init_result(
cparams.n_rs_seq = 0;
cparams.ctx_other = ctx_tgt;
// DFlash2/DSpark rank the full target vocabulary inside the draft graph (top_k / argmax
// on the lm_head output), so the worst-case compute buffer grows with n_ubatch * n_vocab.
// Their largest decode batch is one noise block per sequence (n_max + 1 tokens), so cap the
// ubatch to that; anything larger only inflates the reserved compute buffer.
const bool has_block_draft = std::any_of(
params.speculative.types.begin(), params.speculative.types.end(),
[](common_speculative_type t) {
return t == COMMON_SPECULATIVE_TYPE_DRAFT_DFLASH || t == COMMON_SPECULATIVE_TYPE_DRAFT_DSPARK;
});
if (has_block_draft) {
const uint32_t n_ubatch_dft = params.n_parallel * (uint32_t) std::max(1, params.speculative.draft.n_max + 1);
if (cparams.n_ubatch > n_ubatch_dft) {
LOG_INF("%s: capping draft context ubatch from %u to %u (block draft)\n", __func__, cparams.n_ubatch, n_ubatch_dft);
cparams.n_ubatch = n_ubatch_dft;
}
}
std::string model_path;
if (has_draft) {
model_path = params.speculative.draft.mparams.path;