From 212a4c5c4c74b71a29fbc22b4cf48deafb9ce453 Mon Sep 17 00:00:00 2001 From: Shogo Okada <33060490+okada-shogo@users.noreply.github.com> Date: Wed, 25 Nov 2026 00:35:59 +0900 Subject: [PATCH] poly: Inkling 2's prompt scratch lent between prompts with the drafter too With --draft-model, Inkling 2 kept its prompt batch's scratch in VRAM for the whole run (one layout), because the drafter's features were strided by the prompt batch's rows: 546 MiB on an RTX 2070 Super at --prompt-batch 1024, where the drafter's run without it has 32 MiB for the few tokens' layout. The features are now strided by the rows of the layout in use (buf_rows_), which is the prompt batch's in one layout as before, so the two scratch layouts (VecSzn's, as Qwen3.6 has them) and the lending to the expert cache between prompts are on with the drafter as well. Placement only: every call computes the same values in the same order; the features sit at another stride in the few tokens' layout. Co-Authored-By: Claude Opus 5.5 --- engine/src/poly/inkling2.cpp | 8 ++++---- engine/src/poly/inkling2.hpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/engine/src/poly/inkling2.cpp b/engine/src/poly/inkling2.cpp index c20d37404..dfc361edb 100644 --- a/engine/src/poly/inkling2.cpp +++ b/engine/src/poly/inkling2.cpp @@ -524,11 +524,11 @@ DsScreen Inkling2::ds_screen() const { // mixed into each drafter layer's keys and values at the rows' positions and the Markov head's context. void Inkling2::ds_commit(int n) { const size_t E = (size_t) n_embd_; - output_rows(0, n, ds_tap_ + 3 * (size_t) rows_ * E); + output_rows(0, n, ds_tap_ + 3 * (size_t) buf_rows_ * E); const DsPos p{recording_ ? at_ : nullptr, (long long) pos_}; DsMix m; m.tap = ds_tap_; - m.tap_stride = (size_t) rows_ * E; + m.tap_stride = (size_t) buf_rows_ * E; m.alpha = ds_alpha_; for (int l = 0; l < 3; ++l) m.norm[l] = ds_[(size_t) l].dflare; m.norm[3] = ds_mnorm_; @@ -732,7 +732,7 @@ bool Inkling2::scores_apart() const { #ifdef STRATA_VMM_RELEASE_WITH_ADDRESSES return false; #else - return !ds_file_ && !freeze_experts_asked_ && mmq_ && vmm_ && !split_ && rows_ >= kStageRows; + return !freeze_experts_asked_ && mmq_ && vmm_ && !split_ && rows_ >= kStageRows; #endif } @@ -1192,7 +1192,7 @@ void Inkling2::layer_head(Layer& L, int il, int n) { if (ds_file_) { // the drafter's features: the inputs of three layer runs const int visit = visit_of(il, pass_of(il)); for (int k = 0; k < 3; ++k) - if (visit == ds_visit_[k]) copy_rows(r_, ds_tap_ + (size_t) k * rows_ * n_embd_, n); + if (visit == ds_visit_[k]) copy_rows(r_, ds_tap_ + (size_t) k * buf_rows_ * n_embd_, n); } Slot& S = slots_[(size_t) slot_of(il, pass_of(il))]; const size_t ne = (size_t) n * n_embd_; diff --git a/engine/src/poly/inkling2.hpp b/engine/src/poly/inkling2.hpp index 9b3b44293..26250d6fd 100644 --- a/engine/src/poly/inkling2.hpp +++ b/engine/src/poly/inkling2.hpp @@ -42,8 +42,8 @@ class Inkling2 final : public Engine { void alloc_caches() override; void assign_scratch() override; // A call of a few tokens keeps a scratch of its own, and a prompt batch's is lent to the expert cache between - // prompts (Engine::use_scratch()). Not with the drafter, whose features are a whole call's rows, nor on ROCm on - // Linux, nor where nothing would be lent: the experts frozen, or every one of them in VRAM (inkling2.cpp). + // prompts (Engine::use_scratch()); the drafter's features are strided by the layout's rows (buf_rows_). Not on + // ROCm on Linux, nor where nothing would be lent: the experts frozen, or every one of them in VRAM (inkling2.cpp). bool scratch_layouts() const override; bool scores_apart() const; ///< the attention's scores outside the scratch, for its two layouts to share bool every_expert_fits() const;