Inkling CUDA, 16 slots and more on a 16 GB RTX 50 card with a display: the plan counts the sliding-window rings where the engine puts them, and COMPACT_HYBRID takes over from 16 slots too (PLAN-0225 item 23)

PLAN-0224 item 23 (a 16 GB card at 64 slots keeps almost no expert on the card) re-measured on a rented RTX 5060 Ti 16 GB (SQ-20 v2, ctx 16K, --parallel 64, 128 new tokens per request):
- headless: COMPACT, all 3072 experts on the card, K/V and sliding-window rings in host memory: e2e 154.6 / steady 211.2 tok/s. This is the path item 7 / 22 made for 16 slots and more.
- with 800 MiB held (what a display holds; a VRAM ballast taken before the first allocation): COMPACT needs 15,102 MiB at 64 slots, 14,896 are free, the loader refuses it and the old path ran: the engine did NOT
  start ("not enough free GPU memory for the working buffers", every chunk size down to 64). Cause: the VRAM plan is made BEFORE the loader decides, with COMPACT's memory plan (the 40 sliding-window rings of 64
  slots, 5.4 GiB, counted as host memory); after the refusal the old path puts them on the card, and the experts had been placed without room for them (1,884 experts, 2,103 MiB left).

Changes (CUDA backend only):
- plan_vram_reserve (ink_cuda_backend.cu): the rings count as host memory from 16 slots on whenever the table's COMPACT runs (compact_vram, as the runner's swa_in_host), not only with C64_SPEC: the 12 / 8 GB
  hybrid rows have no C64_SPEC and held 5.7 GB back for rings that then went to the host (0 experts on the card at 64 slots on an 8 GB class card). The bytes left out are handed to the loader
  (sm120_plan_swa_host_bytes_ref).
- ink_runner.cuh, the loader's COMPACT check: (1) when COMPACT is refused and the plan had left the rings out, they are added to the experts' reserve ("held back from the experts" line); (2) the COMPACT_HYBRID
  fallback of item 17 also applies from 16 slots (it stays refused for 2..15 slots, as before).

Measured on the same card (SQ-20 v2, 16K per slot, 800 MiB held, 1 round, all requests answered):
- --parallel 64: not started -> COMPACT_HYBRID, 2,404 experts on the card, e2e 57.3 / steady 101.0 tok/s; headless unchanged (157.5 / 216.2 against 154.6 / 211.2).
- --parallel 32: e2e 36.6 / steady 62.2; --parallel 16: e2e 51.6 / steady 107.8 (both started on the hybrid; --parallel 4 still takes the old path and answers).
- the refusal path itself (STRATA_INK_SM120_COMPACT_HYBRID=0 at 800 MiB, 64 slots): before the change not started, now starts with 695 experts on the card and answers (e2e 8.1 tok/s: the rings fill the card, a start that works, not a fast one).
- 3.2 GiB free, 64 slots: a refusal with the message of the previous commit ("not enough free GPU memory to load the model ... 3197 of 15850 MiB free ... --parallel").
Builds: Linux sm_120 (CUDA 13.0) on the 5060 Ti, MSVC + CUDA 13.0 sm_120 on the owner PC. Not measured: RTX 5080 / 5070 Ti (their rows are default off), the 12 / 8 GB hybrid rows with the smaller plan (no such card;
the 5070 12 GB at 64 slots before this change: 0 experts on the card, 3.9 GiB free after the start), a real display's compute use.
This commit is contained in:
Niko1221 committed 2026-12-02 15:37:36 +01:00
1 parent 3c3d5f1d0b
commit ddc5a0e06a
3 files changed
+24 -2

No files matched your search

+7 -1
View File
@@ -151,6 +151,7 @@ struct VramPlan {
bool c64_host_kv = false;
int init_glob = 0;
size_t min_kv_bytes = 0;
size_t swa_host_bytes = 0; // the sliding-window rings the plan did not count because COMPACT keeps them in host memory (16 slots and more)
size_t dspark_pad = 0;
size_t ws_pad = 0;
size_t min_reserve_bytes = 0;
@@ -198,7 +199,11 @@ static VramPlan plan_vram_reserve(const VramPlanIn& in) {
: ((in.kv_offload_mode == 0 && in.total_vram <= (13ull << 30))
? std::min(std::max(256, opts.max_ctx), 2048)
: std::max(256, std::min(std::max(256, opts.max_ctx), (in.max_slots == 1) ? 8192 : 4096)));
p.min_kv_bytes = (p.c64_host_kv ? 0ull : (size_t)40 * in.max_slots * p.swa_r * p.per_visit_pos)
// The rings of the 40 sliding-window visits are in mapped host memory from 16 slots on whenever the table's COMPACT runs (the runner: swa_in_host = compact_vram && slots >= 16), with or without
// the C64_SPEC part: the plan must not hold 5.7 GB of VRAM back for them at 64 slots (the 12 / 8 GB hybrid rows have no C64_SPEC and kept 0 experts on the card: PLAN-0225 item 23).
const bool swa_host = (in.max_slots >= 16) && (p.c64_host_kv || opt5060.compact_vram);
p.swa_host_bytes = swa_host ? (size_t)40 * in.max_slots * p.swa_r * p.per_visit_pos : 0ull;
p.min_kv_bytes = (swa_host ? 0ull : (size_t)40 * in.max_slots * p.swa_r * p.per_visit_pos)
+ (size_t)strata::ink::kInkVisits * in.max_slots * 3 * strata::ink::kInkSconvCh * 4
+ (size_t)8 * in.max_slots * p.init_glob * p.per_visit_pos;
// Include O(1) prefill ws (~114 MiB) + DSpark (~224 MiB when enabled) + activation ws (WDDM floor added inside loader!)
@@ -705,6 +710,7 @@ public:
}
strata::ink::sm120_plan_slots_ref().store(max_slots_);
strata::ink::sm120_plan_swa_host_bytes_ref().store(plan.swa_host_bytes);
// Load .strata v1.1 / .gguf (Unsloth + ggml-org) / HF safetensors trunk + experts (Single-GPU, EP2, Layer-Split, or 4-tier GPU+RAM+SSD!)
// A card with too little free memory for even the shared layers (the trunk) is a refusal with a message, not the fatal GPU error that ends the engine (PLAN-0225 item 24).
bool loaded_ok = false;
+11 -1
View File
@@ -365,6 +365,7 @@ struct InkCudaModel {
double t0 = now_s();
const auto& opt5060_ld = ink_rtx5060ti_cfg(primary_gpu);
const bool compact_was_on_pre = opt5060_ld.compact_vram; // the plan was made with COMPACT's memory plan; a refusal below changes the table (PLAN-0225 item 23)
size_t vfree_pre = 0, vtot_pre = 0;
INK_CK(ink_cuda_mem_info(&vfree_pre, &vtot_pre));
bool do_compact_vram = opt5060_ld.compact_vram && !ssd_experts && vram_experts_gb <= 0.0 &&
@@ -424,7 +425,7 @@ struct InkCudaModel {
// PLAN-0225 item 17: a 16 GB row (COMPACT without the hybrid) whose card cannot hold every expert because a display or another program holds part of it: the experts are short by
// a few hundred MiB, not by the trunk. COMPACT_HYBRID (the 12 GB row's set) then runs instead of the old path (5060 Ti 16 GB, SQ-20 v2, 800 MiB held: decode 51 -> 108 tok/s on chat with
// DFlash 2, 48 -> 82 on code), when at least 3 GiB of experts still fit next to the compact trunk (below that the old path stays) and the run is one slot.
if (do_compact_vram && !opt5060_ld.compact_hybrid && all_sf4_or_mx8_pre && plan_slots_pre == 1 && vfree_pre < est_trunk + est_sec4 + compact_margin &&
if (do_compact_vram && !opt5060_ld.compact_hybrid && all_sf4_or_mx8_pre && (plan_slots_pre == 1 || plan_slots_pre >= 16) && vfree_pre < est_trunk + est_sec4 + compact_margin &&
vfree_pre >= est_trunk + (3ull << 30) && sm120_compact_to_hybrid(primary_gpu)) {
std::fprintf(stderr, "[Ink5060Ti] COMPACT needs %zu MiB for every expert, %zu MiB are free (a display or another program holds the rest): COMPACT_HYBRID runs instead of the old path "
"(the compact trunk, the experts that fit on the card, the rest in RAM; PACK / PREFILL / PLD / CORE_GRAPH / C64_SPEC off as on the 12 GB row; STRATA_INK_SM120_COMPACT_HYBRID=0 refuses COMPACT here)\n",
@@ -470,6 +471,15 @@ struct InkCudaModel {
}
}
}
if (compact_was_on_pre && !ink_rtx5060ti_cfg(primary_gpu).compact_vram) {
// COMPACT was refused after the VRAM plan counted the sliding-window rings of 16 slots and more as host memory: the old path puts them on the card, so the experts are placed with them held back
// (5060 Ti 16 GB, SQ-20 v2, 64 slots, 800 MiB held by a display: 206 MiB short of COMPACT, 1,884 experts placed, then "not enough free GPU memory for the working buffers" at every chunk size)
const size_t swa_planned = sm120_plan_swa_host_bytes_ref().load();
if (swa_planned > 0) {
extra_reserve_bytes += swa_planned;
std::fprintf(stderr, "[InkCUDA] COMPACT refused: the sliding-window K/V of %d slots (%zu MiB) stays on the card on the old path, held back from the experts\n", sm120_plan_slots_ref().load(), swa_planned >> 20);
}
}
if (do_compact_vram) {
// Opt-in RTX 5060 Ti 16 GB 100%-VRAM Compact Trunk Loader:
// - embed.weight (883 MiB BF16) -> pinned mapped host RAM (0 MiB VRAM!)
@@ -388,6 +388,12 @@ inline std::atomic<int>& sm120_plan_slots_ref() noexcept {
static std::atomic<int> v{1};
return v;
}
/// PLAN-0225 item 23: the bytes of sliding-window K/V that the VRAM plan left out because COMPACT keeps them in host memory from 16 slots on (set by the backend's plan, 0 when it counted them). When
/// the loader then refuses COMPACT (the card is a few hundred MiB short of every expert) the old path puts these rings on the card, and the experts must be placed with them reserved.
inline std::atomic<size_t>& sm120_plan_swa_host_bytes_ref() noexcept {
static std::atomic<size_t> v{0};
return v;
}
inline void sm120_compact_refuse(int dev) noexcept {
Sm120Cfg& s = const_cast<Sm120Cfg&>(sm120_cfg(dev)); // static, non-const storage underneath