mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-04 23:38:47 +00:00
Merge f-0225-ink (580852d82f) into int-0225
Conflicts: terminal/tools/strata_mcp.py (default context in the install plan: kept INK-KV's inkling_fit.default_context for Inkling and the ling32 branch from f-ling32-prod), docs/SETTINGS.md (regenerated from the register with tools/settings_register.py --docs; the register merged without a conflict and its check is clean).
This commit is contained in:
commit
951a4af886
15 files changed
+534
-31
No files matched your search
@@ -49,6 +49,29 @@ request stopped 1.2 to 1.8 GB short of the context that had been planned ("VRAM
|
||||
request ends with a message that says how much is free and what to do, and the engine stays up;
|
||||
- several slots, layer split and cards without virtual memory keep the earlier growth; `STRATA_INK_KV_VMM=0` takes it back on any card.
|
||||
|
||||
## The default context is 128K (0.2.25)
|
||||
|
||||
A start that names no context gets 128K (131072 tokens) on every machine, 8 GB cards included: where the K/V of 128K does not fit the card it goes to host RAM (2.15 GB at 128K
|
||||
in FP8, 4.3 GB in FP16), as on a 12 GB card. There is no smaller default for any kind of machine; you change the context in the app (the context choice of the model) or in the TUI
|
||||
(`strata launch --context 64k`, the Context step), and a context you named or saved in a preset is never changed.
|
||||
|
||||
The default steps down only when the load would truly fail at 128K: the K/V of one slot has nowhere to go (not in the card, not in RAM), for example an 8 GB card with 6 GB of RAM.
|
||||
The line says so (`Context set to 32K because 128K cannot be loaded in this machine's memory ...`). Where 128K loads but part of the model streams from the SSD (a 16 GB Mac) it stays 128K
|
||||
and the line says what is slow and which size fits. A named or saved context is refused only when the engine could not start it at all, with the number that would fit; one that
|
||||
loads, slowly, is accepted with the same honest line. Nothing that ran in 0.2.24 is refused.
|
||||
|
||||
What 128K costs against 32K: on an Arc A750 8 GB (SQ-10) the K/V takes 4,256 MiB of the card (1,184 MiB at 32K), 70 of 3,072 experts stay on the card (1,180 at 32K), decode is 5% lower
|
||||
and prompt reading 32% lower; on an RTX 5070 12 GB the K/V is 2,112 MiB of host RAM (528 MiB at 32K) with the same experts on the card.
|
||||
Each slot reserves the K/V of the whole context, so the number of slots "fit to your card" gives is lower at 128K (a 24 GB card: 1 where 32K gave 2).
|
||||
|
||||
## The cold-expert lane (0.2.25)
|
||||
|
||||
On a card that cannot hold every expert, the experts that are not on the card are computed either on the CPU where they are, or copied into the card and computed by its kernels (the
|
||||
exact lane: the same bits as an all-resident run). The start times a short run of decode steps with each lane and keeps the faster one; `STRATA_INK_EXACT=1` or `0` forces a lane.
|
||||
The probe is noisy, and the old rule kept the CPU lane unless the copy-in lane was 10% faster: on an RTX 5070 12 GB that measured 9.1 against 8.7 ms/token it kept the slower lane
|
||||
(decode 65-68 tok/s, 34 on a 4K document, against 73 and 56 with the copy-in lane). Now the probe runs three times, alternating the lanes, takes the median of each, and keeps
|
||||
the exact lane unless the CPU lane is clearly (10%) faster; a tie goes to the exact lane. `STRATA_INK_LANE_PROBE_OLD=1` brings the old rule back.
|
||||
|
||||
## Settings
|
||||
|
||||
`STRATA_HIP_KV_FP8_SMALL=1` (0.2.23) still gives a discrete AMD card of 13 GiB or less the FP8 cache; see [SETTINGS.md](SETTINGS.md).
|
||||
|
||||
+2
-1
@@ -474,7 +474,7 @@ Off unless you set them. The last column says where each one is described.
|
||||
| `STRATA_WATCHDOG_S` | text | NVIDIA and AMD, Intel Arc | [DETAILS.md](DETAILS.md) |
|
||||
| `STRATA_WDDM_BUDGET` | number | AMD, Intel Arc | [AMD_HIP.md](AMD_HIP.md) |
|
||||
|
||||
## Switches that go back to earlier behaviour (155)
|
||||
## Switches that go back to earlier behaviour (156)
|
||||
|
||||
These behaviours are on by default. Setting the switch returns the earlier behaviour; the notes in the register say which
|
||||
version made it the default.
|
||||
@@ -526,6 +526,7 @@ version made it the default.
|
||||
| `STRATA_INK_IQ_TC_MASK` | number | NVIDIA and AMD | v0.2.23 | - |
|
||||
| `STRATA_INK_KEEP_MAPPED_PAGES` | on / off | NVIDIA and AMD | v0.2.21 | - |
|
||||
| `STRATA_INK_KV_VMM` | on / off | NVIDIA and AMD | v0.2.24 | [INKLING_KV.md](INKLING_KV.md) |
|
||||
| `STRATA_INK_LANE_PROBE_OLD` | on / off | NVIDIA and AMD | - | [INKLING_KV.md](INKLING_KV.md) |
|
||||
| `STRATA_INK_MOE_V1` | on / off | NVIDIA and AMD | v0.2.21 | - |
|
||||
| `STRATA_INK_NO_CAND` | on / off | NVIDIA and AMD | v0.2.21 | - |
|
||||
| `STRATA_INK_OOM_RETRY` | number | NVIDIA and AMD | v0.2.21 | - |
|
||||
|
||||
@@ -324,6 +324,9 @@ if(STRATA_BUILD_TESTS)
|
||||
target_include_directories(ink_batch_budget_test PRIVATE src/inkling2)
|
||||
add_test(NAME ink_batch_budget_test COMMAND ink_batch_budget_test)
|
||||
# #6770 / #6755: when strata-inkling's CUDA global K/V may grow in VRAM (net growth, not the whole new K/V; no GPU)
|
||||
add_executable(ink_cold_lane_test tests/core/ink_cold_lane_test.cpp)
|
||||
target_include_directories(ink_cold_lane_test PRIVATE include)
|
||||
add_test(NAME ink_cold_lane_test COMMAND ink_cold_lane_test)
|
||||
add_executable(ink_kv_grow_test tests/core/ink_kv_grow_test.cpp)
|
||||
target_include_directories(ink_kv_grow_test PRIVATE include)
|
||||
add_test(NAME ink_kv_grow_test COMMAND ink_kv_grow_test)
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// strata-inkling CUDA, hybrid placement: which lane computes the cold experts (the ones that are not on the card), decided by a short probe at the start.
|
||||
//
|
||||
// STRATA_INK_EXACT unset: the same few decode steps are timed with the CPU lane and with the card's own copy-in lane (the "exact" lane: the same bits as an all-resident run), once
|
||||
// per lane, and the faster one is kept. The probe is noisy (the PC's own load moves the CPU lane's time by 10 to 30 %) and the old rule kept the CPU lane unless the copy-in lane was
|
||||
// clearly (10 %) faster: on an RTX 5070 12 GB (Windows, SQ-10, drafter off, the published 0.2.24 packages) the probe measured the CPU lane at 9.0 to 9.5 ms and the copy-in lane at
|
||||
// 8.6 ms (ratio 0.95), the old rule kept the CPU lane, and every start decoded 65-68 tok/s and 34.5 on a 4K document where the copy-in lane gives 73 and 56.4 (+11 to +64 %); with a
|
||||
// busier PC the same card measured 12 against 8.6 and chose the copy-in lane. The rule below runs the probe three times, alternating the lanes (the median of each lane), and keeps the
|
||||
// exact lane unless the CPU lane is clearly (10 %) faster; a tie goes to the exact lane.
|
||||
//
|
||||
// STRATA_INK_LANE_PROBE_OLD=1 brings the old rule back (one probe per lane, the CPU lane unless the copy-in lane is 10 % faster).
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace strata::core {
|
||||
|
||||
/// The median of the timed probes of one lane (the middle one of an odd count, the mean of the two middle ones of an even count); 0 for no probe.
|
||||
inline double ink_probe_median(std::vector<double> v) {
|
||||
if (v.empty()) return 0.0;
|
||||
std::sort(v.begin(), v.end());
|
||||
const size_t n = v.size();
|
||||
return (n % 2) ? v[n / 2] : 0.5 * (v[n / 2 - 1] + v[n / 2]);
|
||||
}
|
||||
|
||||
/// true: the cold experts are copied into the card and computed by its kernels (the exact lane); false: computed on the CPU where they are.
|
||||
/// `t_cpu`, `t_card`: the probe's time per token with each lane. `old_rule`: STRATA_INK_LANE_PROBE_OLD=1.
|
||||
inline bool ink_cold_lane_exact(double t_cpu, double t_card, bool old_rule) {
|
||||
if (old_rule) return t_card < 0.9 * t_cpu;
|
||||
return !(t_cpu < 0.9 * t_card);
|
||||
}
|
||||
|
||||
} // namespace strata::core
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "ink_head_screen.cuh" // PERF-STEP: INT8-screened exact top-128 of the head (STRATA_INK_HEAD_SCREEN)
|
||||
|
||||
#include "strata/artifact/strata_reader.hpp"
|
||||
#include "strata/core/ink_cold_lane.hpp"
|
||||
#include "strata/core/ink_kv_grow.hpp"
|
||||
#include "strata/core/ink_kv_reserve.hpp"
|
||||
#include "strata/core/vmm.hpp"
|
||||
@@ -6786,9 +6787,10 @@ struct InkCudaRunner {
|
||||
}
|
||||
|
||||
// Launch probe for the cold-expert lane (STRATA_INK_EXACT unset): the same short run of decode steps is timed with the CPU lane and with
|
||||
// the card's own copy-in lane (exact), on the placement the loaders made (the tier is paused and learns nothing), and the faster one is kept:
|
||||
// the CPU lane unless the card's copy is clearly (10%) faster, because a CPU lane is the default of this engine and the probe is noisy.
|
||||
// Runs once after the runner exists, before any request; a slot is reset when a request takes it, so the probe leaves no state behind.
|
||||
// the card's own copy-in lane (exact), on the placement the loaders made (the tier is paused and learns nothing). The probe is run three times, alternating the lanes, and the median of
|
||||
// each lane is compared (strata/core/ink_cold_lane.hpp): the exact (copy-in) lane unless the CPU lane is clearly (10%) faster, a tie going to the exact lane. The old rule (one probe per
|
||||
// lane, the CPU lane unless the copy-in lane was 10% faster) kept the CPU lane on a quiet RTX 5070 at a ratio of 0.95 and decoded 11 to 64% slower than the copy-in lane;
|
||||
// STRATA_INK_LANE_PROBE_OLD=1 brings it back. Runs once after the runner exists, before any request; a slot is reset when a request takes it, so the probe leaves no state behind.
|
||||
void pick_cold_lane() {
|
||||
auto& h = m.hybrid;
|
||||
if (h.lane_pref != 0 || !h.active || m.n_host_experts == 0) return; // forced lane, or nothing is cold
|
||||
@@ -6816,10 +6818,17 @@ struct InkCudaRunner {
|
||||
return ms[ms.size() / 2];
|
||||
};
|
||||
h.probing = true;
|
||||
const double t_cpu = run_lane(false);
|
||||
const double t_card = run_lane(true);
|
||||
const char* old_env = std::getenv("STRATA_INK_LANE_PROBE_OLD");
|
||||
const bool old_rule = old_env && old_env[0] == '1';
|
||||
std::vector<double> v_cpu, v_card;
|
||||
for (int rep = 0; rep < (old_rule ? 1 : 3); ++rep) {
|
||||
v_cpu.push_back(run_lane(false));
|
||||
v_card.push_back(run_lane(true));
|
||||
}
|
||||
h.probing = false;
|
||||
const bool exact = t_card < 0.9 * t_cpu;
|
||||
const double t_cpu = strata::core::ink_probe_median(v_cpu);
|
||||
const double t_card = strata::core::ink_probe_median(v_card);
|
||||
const bool exact = strata::core::ink_cold_lane_exact(t_cpu, t_card, old_rule);
|
||||
h.set_lane(exact);
|
||||
if (ink_rtx5060ti_cfg(m.primary_gpu).compact_hybrid && !exact && t_cpu > 0.0 && t_card > 0.0 && h.dec_share_user < 0.0) {
|
||||
// COMPACT_HYBRID row: the split of the batched cold experts comes from this box's own two lane times (see auto_pcie_share)
|
||||
@@ -6836,8 +6845,8 @@ struct InkCudaRunner {
|
||||
std::fill(h.h_use_batch.begin(), h.h_use_batch.end(), 0.0f); // the eager copy lane counted its routing here
|
||||
if (h.d_trace_n) { INK_CK(cudaMemsetAsync(h.d_trace_n, 0, 4, st)); h.trace_flushed = 0; }
|
||||
INK_CK(cudaStreamSynchronize(st));
|
||||
std::fprintf(stderr, "[InkHybrid] cold experts: launch probe (%d decode steps each): CPU lane %.1f ms/token, copy into the card %.1f ms/token -> %s%s\n",
|
||||
kTimed, t_cpu, t_card, exact ? "copied into the card and computed by its kernels (identical answers wherever an expert lives)"
|
||||
std::fprintf(stderr, "[InkHybrid] cold experts: launch probe (%d decode steps each, median of %d): CPU lane %.1f ms/token, copy into the card %.1f ms/token -> %s%s\n",
|
||||
kTimed, (int)v_cpu.size(), t_cpu, t_card, exact ? "copied into the card and computed by its kernels (identical answers wherever an expert lives)"
|
||||
: "computed on the CPU where they are (the answer can differ from an all-resident run in rounding)",
|
||||
" (STRATA_INK_EXACT=1 or 0 forces a lane)");
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ inline bool dormant_dspark_allowed() {
|
||||
}
|
||||
|
||||
struct BackendOpts {
|
||||
int max_ctx = 32768;
|
||||
int max_ctx = 131072; // 128K on every card (owner, 2026-12-02); the plan lowers it with a line when the card cannot hold it
|
||||
int parallel = 1; // 1..64 concurrent slots
|
||||
int chunk = 512; // prompt tokens per step; the CUDA backend picks a larger one by itself while chunk_auto (see strata/core/ink_chunk.hpp)
|
||||
bool chunk_auto = true; // false once --chunk is given; only the CUDA backend reads it, every other backend uses chunk as it is
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// ink_cold_lane.hpp: the probe's median and the lane rule (no GPU).
|
||||
#include "strata/core/ink_cold_lane.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
using namespace strata::core;
|
||||
|
||||
static int failed = 0;
|
||||
#define CHECK(c) do { if (!(c)) { std::fprintf(stderr, "ink_cold_lane_test: FAILED line %d: %s\n", __LINE__, #c); ++failed; } } while (0)
|
||||
|
||||
int main() {
|
||||
// the median
|
||||
CHECK(ink_probe_median({}) == 0.0);
|
||||
CHECK(ink_probe_median({8.6}) == 8.6);
|
||||
CHECK(ink_probe_median({9.5, 9.0, 12.4}) == 9.5); // an outlier does not move it
|
||||
CHECK(ink_probe_median({3.0, 1.0}) == 2.0);
|
||||
CHECK(ink_probe_median({5.0, 1.0, 3.0, 2.0}) == 2.5);
|
||||
|
||||
// the quiet RTX 5070 of the published packages: CPU lane 9.1 ms, copy-in lane 8.6 ms (ratio 0.945): the exact lane now (the old rule kept the CPU lane and lost 11 to 64 %)
|
||||
CHECK(ink_cold_lane_exact(9.1, 8.6, false));
|
||||
CHECK(!ink_cold_lane_exact(9.1, 8.6, true));
|
||||
// a busy PC: CPU lane 12.1 ms, copy-in 8.6: the exact lane under both rules
|
||||
CHECK(ink_cold_lane_exact(12.1, 8.6, false));
|
||||
CHECK(ink_cold_lane_exact(12.1, 8.6, true));
|
||||
// the CPU lane clearly faster (more than 10 %): the CPU lane under both rules
|
||||
CHECK(!ink_cold_lane_exact(7.0, 8.6, false));
|
||||
CHECK(!ink_cold_lane_exact(7.0, 8.6, true));
|
||||
// a tie goes to the exact lane (the old rule kept the CPU lane)
|
||||
CHECK(ink_cold_lane_exact(8.6, 8.6, false));
|
||||
CHECK(!ink_cold_lane_exact(8.6, 8.6, true));
|
||||
// the CPU lane 5 % faster: not clearly, so the exact lane (the new rule's hysteresis is on the CPU side)
|
||||
CHECK(ink_cold_lane_exact(8.17, 8.6, false));
|
||||
// exactly 10 % faster is not "clearly": the boundary stays with the exact lane
|
||||
CHECK(ink_cold_lane_exact(0.9 * 8.6, 8.6, false));
|
||||
CHECK(!ink_cold_lane_exact(0.89 * 8.6, 8.6, false));
|
||||
|
||||
if (failed) { std::fprintf(stderr, "ink_cold_lane_test: %d failure(s)\n", failed); return 1; }
|
||||
std::printf("ink_cold_lane_test: ok\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -23602,6 +23602,41 @@
|
||||
"retire_after": "",
|
||||
"retired_in": ""
|
||||
},
|
||||
{
|
||||
"name": "STRATA_INK_LANE_PROBE_OLD",
|
||||
"backends": [
|
||||
"cuda-hip"
|
||||
],
|
||||
"reads": [
|
||||
{
|
||||
"file": "engine/src/inkling2/cuda/ink_runner.cuh",
|
||||
"line": 6821,
|
||||
"backend": "cuda-hip",
|
||||
"fn": "getenv"
|
||||
}
|
||||
],
|
||||
"parse": "flag",
|
||||
"default_state": "off",
|
||||
"code_default": null,
|
||||
"engine_sets": [],
|
||||
"engine_defaults": [],
|
||||
"launch_files": [],
|
||||
"launch_sets": [],
|
||||
"launch_reads": [],
|
||||
"doc_mentions": [
|
||||
"docs/INKLING_KV.md:73"
|
||||
],
|
||||
"first_commit": "",
|
||||
"first_date": "2026-12-02",
|
||||
"since": null,
|
||||
"last_commit": "",
|
||||
"last_date": "2026-12-02",
|
||||
"status": "rollback",
|
||||
"owner": "inkling2/cuda",
|
||||
"note": "Rollback (0.2.25): =1 brings back the old cold-expert lane rule of the launch probe (one probe per lane, the CPU lane unless the copy-in lane is 10% faster). The default now runs the probe three times, alternating the lanes, and keeps the median of each: the exact (copy-in) lane unless the CPU lane is clearly (10%) faster, a tie going to the exact lane. A quiet RTX 5070 12 GB measured CPU 9.0-9.2 ms against copy-in 8.7 and the old rule kept the slower CPU lane (decode 65-68 tok/s and 34 on a 4K document against 73 and 56 with the copy-in lane). STRATA_INK_EXACT=1 or 0 still forces a lane.",
|
||||
"retire_after": "",
|
||||
"retired_in": ""
|
||||
},
|
||||
{
|
||||
"name": "STRATA_INK_M1_DNPF",
|
||||
"backends": [
|
||||
|
||||
+27
-4
@@ -11738,8 +11738,13 @@ def install_inkling2(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopte
|
||||
want_ctx = a.context or inkling_family.DEFAULT_CONTEXT
|
||||
plan_extra = inkling_plan_extra(gpu) if not unified else {}
|
||||
plan_extra["backend"] = "hip" if hip else ("sycl" if getattr(a, "backend", None) == "sycl" else ("metal" if sys.platform == "darwin" else "cuda"))
|
||||
lines = inkling_menu_lines(vram_gib, ram_gib, unified, want_ctx, vision, igpu=igpu, arch=arch, extra=plan_extra)
|
||||
rec = inkling_fit.recommend(vram_gib, ram_gib, unified, want_ctx, vision, igpu=igpu, arch=arch, **plan_extra)
|
||||
if not a.context: # no context named: 128K, or the largest size of the bucket list that fits this machine's memory (owner, 2026-12-02)
|
||||
dc = inkling_fit.default_context(rec["build"], vram_gib, ram_gib, bool(rec.get("unified", unified)), vision=vision, **plan_extra)
|
||||
if dc["stepped"]:
|
||||
want_ctx = dc["context"]
|
||||
rec = inkling_fit.recommend(vram_gib, ram_gib, unified, want_ctx, vision, igpu=igpu, arch=arch, **plan_extra)
|
||||
lines = inkling_menu_lines(vram_gib, ram_gib, unified, want_ctx, vision, igpu=igpu, arch=arch, extra=plan_extra)
|
||||
say()
|
||||
order = [b for b, _ in lines]
|
||||
for i, (b, text) in enumerate(lines, 1):
|
||||
@@ -11748,13 +11753,31 @@ def install_inkling2(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopte
|
||||
ok(f"size: {model}")
|
||||
tag = run_tag(a, family, fam, model)
|
||||
ctx = a.context or inkling_family.DEFAULT_CONTEXT
|
||||
ctx_default = inkling_family.DEFAULT_CONTEXT
|
||||
if not a.context: # the chosen size, not the recommended one, decides how far the default has to step down
|
||||
dcm = inkling_fit.default_context(model, vram_gib, ram_gib, bool(rec.get("unified", unified)), vision=vision, **plan_extra)
|
||||
ctx = ctx_default = dcm["context"]
|
||||
if dcm["note"]:
|
||||
warn(dcm["note"])
|
||||
else: # a context the person named is never changed: refused with the number that would fit
|
||||
chk = inkling_fit.context_check(model, ctx, vram_gib, ram_gib, bool(rec.get("unified", unified)), vision=vision, **plan_extra)
|
||||
if chk["refuse"]:
|
||||
fail(chk["message"], (f"for example: --context {chk['fits_at'] // 1024}k" if chk["fits_at"] else None))
|
||||
elif chk["message"]:
|
||||
warn(chk["message"])
|
||||
if not a.context:
|
||||
ctxs = inkling_family.CONTEXTS
|
||||
say()
|
||||
say(" Context length = how much text the model can see at once (32K by default; up to 1M supported).")
|
||||
say(" Context length = how much text the model can see at once (128K by default; up to 1M supported).")
|
||||
for i, c in enumerate(ctxs, 1):
|
||||
say(f" {i}) {c // 1024}K tokens" + (" (recommended)" if c == inkling_family.DEFAULT_CONTEXT else ""))
|
||||
ctx = ctxs[int(ask("Context?", [str(i) for i in range(1, len(ctxs) + 1)], str(ctxs.index(inkling_family.DEFAULT_CONTEXT) + 1), a.yes)) - 1]
|
||||
say(f" {i}) {c // 1024}K tokens" + (" (recommended)" if c == ctx_default else ""))
|
||||
ctx = ctxs[int(ask("Context?", [str(i) for i in range(1, len(ctxs) + 1)], str(ctxs.index(ctx_default) + 1), a.yes)) - 1]
|
||||
if ctx > ctx_default: # picked in the menu: named by the person, so never changed; refused only when it cannot load, else said
|
||||
chk = inkling_fit.context_check(model, ctx, vram_gib, ram_gib, bool(rec.get("unified", unified)), vision=vision, **plan_extra)
|
||||
if chk["refuse"]:
|
||||
fail(chk["message"], (f"for example: --context {chk['fits_at'] // 1024}k" if chk["fits_at"] else None))
|
||||
elif chk["message"]:
|
||||
warn(chk["message"])
|
||||
par = max(1, min(inkling_family.MAX_PARALLEL, int(getattr(a, "parallel", None) or 1))) # --parallel N: the slots the planner makes room for (0221 APPTUI: it planned for one)
|
||||
with custom_build(inkling_fit, model, a) as fit_build: # a custom build: the closest published build moved to the real file size
|
||||
placed = inkling_fit.place(fit_build, vram_gib, ram_gib, unified, ctx, vision, parallel=par, **plan_extra, **inkling_plan_kv(a, plan_extra.get("backend")))
|
||||
|
||||
@@ -718,10 +718,39 @@ class Catalog:
|
||||
if mac is not None:
|
||||
return int(mac.recommend_context(float(hw["ram_gb"])))
|
||||
if family == "inkling-2-mini":
|
||||
from strata_control import inkling_family
|
||||
return inkling_family.DEFAULT_CONTEXT
|
||||
return self.inkling_context(str(model or ""), hw)["context"] # 128K, or the largest size that fits this computer (inkling_fit.default_context)
|
||||
return default_context.pick(self.contexts_for(family, model))
|
||||
|
||||
def inkling_context(self, model: str, hw: dict | None = None, ctx: int | None = None) -> dict:
|
||||
"""Inkling-2-Mini's start context on this computer (owner, 2026-12-02): with `ctx` None the default, 128K or the largest size of the bucket list that fits this machine's memory
|
||||
({"context", "stepped", "note"}: the note is the one plain line saying why it stepped down); with `ctx` named by the person, the check that refuses it with the number that would fit
|
||||
({"fits", "fits_at", "message"}). The same planner as setup's (strata_control/inkling_fit.py); a failed look keeps 128K and accepts the named size."""
|
||||
from strata_control import inkling_family, inkling_fit
|
||||
top = inkling_family.DEFAULT_CONTEXT
|
||||
try:
|
||||
hw = hw or self.hardware()
|
||||
comp = Computer(ram_gb=hw.get("ram_gb"), gpus=list(hw.get("gpus") or []), engine_vendor=self.engine_vendor(hw))
|
||||
gpus = comp.usable_gpus
|
||||
g0 = gpus[0] if gpus else {}
|
||||
unified = bool(hw.get("mac") or g0.get("unified_gb") or g0.get("uma") or g0.get("unified"))
|
||||
ram = float(comp.ram_gb or 0.0)
|
||||
vendor = str(comp.engine_vendor or "")
|
||||
backend = "metal" if hw.get("mac") else {"amd": "hip", "intel": "sycl"}.get(vendor, "cuda" if gpus else None)
|
||||
arch = str(g0.get("arch") or "")
|
||||
kw = dict(backend=backend, sm=int(arch) if arch.isdigit() else None)
|
||||
if unified:
|
||||
vram = None
|
||||
else:
|
||||
vram = max(0.0, float(comp.main_vram_gb or 0.0) - 0.75) # the driver and the desktop keep about 0.75 GiB (as the slot plan)
|
||||
kw["desktop"] = True
|
||||
if ctx is None:
|
||||
return inkling_fit.default_context(model, vram, ram, unified, **kw)
|
||||
return inkling_fit.context_check(model, int(ctx), vram, ram, unified, **kw)
|
||||
except Exception: # noqa: BLE001 - a plan that cannot be made keeps the old behaviour
|
||||
if ctx is None:
|
||||
return {"context": top, "default": top, "stepped": False, "note": None}
|
||||
return {"fits": True, "fits_at": int(ctx), "refuse": False, "message": None}
|
||||
|
||||
# ---- pictures
|
||||
def engine_backend(self) -> str | None:
|
||||
"""The installed engine's backend (cuda, hip, sycl, cpu, metal), else the one this computer's graphics card needs, else None."""
|
||||
|
||||
@@ -525,7 +525,17 @@ def apply_defaults(s: S.LaunchSettings, catalog) -> tuple[S.LaunchSettings, list
|
||||
if broken:
|
||||
notices.append(S.Notice("warn", broken, ""))
|
||||
if s.family and s.model:
|
||||
if s.context is None:
|
||||
if s.family == "inkling-2-mini" and s.model:
|
||||
if s.context is None: # 128K, or the largest size that fits with one plain line saying so (owner, 2026-12-02)
|
||||
dc = catalog.inkling_context(str(s.model), hw)
|
||||
s.context = dc["context"]
|
||||
if dc["note"]:
|
||||
notices.append(S.Notice("warn", dc["note"], ""))
|
||||
else: # a context named or saved (a preset) is never changed; refused only when it cannot load (nothing that ran in 0.2.24 is refused), else said
|
||||
chk = catalog.inkling_context(str(s.model), hw, int(s.context))
|
||||
if chk["message"]:
|
||||
notices.append(S.Notice("error" if chk["refuse"] else "warn", chk["message"], ""))
|
||||
elif s.context is None:
|
||||
s.context = catalog.max_context(s.family, s.model, hw)
|
||||
from strata_control import gpu_fit as _gf
|
||||
_q4 = _gf.strix_q4_stall_note(s.model, comp.gpus) # REMOVE with the Strix stall fix (gpu_fit.STRIX_Q4_NOTE)
|
||||
|
||||
@@ -44,7 +44,7 @@ SSD_NEAR_RESIDENT_GB = 2.0
|
||||
VISION_GB = 0.637 # Inkling-2-Mini-Vision-v2.strata (636,551,168 B; 0.2.22's file is 636,526,592 B; CPU / on-demand on <=12 GiB GPUs)
|
||||
DSPARK_GGUF_GB = 0.636 # PLANNER memory term of a GGUF build's drafter weights, unchanged from 0.2.22 (no DSpark file is downloaded any more); the DFlash 2 reserve (about 0.44 GiB measured on an RTX 5060 Ti) is the DFLASH2 lane's to re-measure
|
||||
DFLASH2_GB = 0.552 # the DFlash 2 sidecar every build downloads beside the model: dflash2.safetensors (551,600,700 B: Strata's Q8 + SF4 mix; the original is 989,975,616 B)
|
||||
DEFAULT_CONTEXT = 32768 # docs/10-GUI-TUI.md default: 32K (up to 1M available)
|
||||
DEFAULT_CONTEXT = 131072 # 128K on every card (owner, 2026-12-02; the app and the other families have opened at 128K since 2026-11-01); up to 1M available
|
||||
CONTEXTS = [8192, 32768, 65536, 131072, 262144]
|
||||
MAX_CONTEXT = 1048576
|
||||
DEFAULT_PARALLEL = 1
|
||||
@@ -590,6 +590,81 @@ def max_context(build: str, vram_gib: float | None, ram_gib: float, unified: boo
|
||||
return best
|
||||
|
||||
|
||||
def _context_ladder(top: int) -> list[int]:
|
||||
"""The context sizes the plan steps through, largest first: the buckets of CONTEXTS up to `top` (128K, 64K, 32K, 8K)."""
|
||||
return sorted((c for c in set(CONTEXTS) if c <= int(top)), reverse=True)
|
||||
|
||||
|
||||
def _context_fits(build: str, ctx: int, vram_gib: float | None, ram_gib: float, unified: bool, vision: bool, dspark: bool, kw: dict) -> bool:
|
||||
"""The test max_context uses: no expert on the SSD and the K/V of one slot placed."""
|
||||
placed = place(build, vram_gib, ram_gib, unified, ctx, vision, 1, dspark, **kw)
|
||||
return placed["ssd_gb"] <= 0.05 and bool(placed.get("kv_fits", True))
|
||||
|
||||
|
||||
def _context_loads(build: str, ctx: int, vram_gib: float | None, ram_gib: float, unified: bool, vision: bool, dspark: bool, kw: dict) -> bool:
|
||||
"""False only when the engine could not start at this context at all: the K/V of one slot has nowhere to go (not in the card, not in RAM). Experts that stream from the SSD still load, slowly."""
|
||||
if str(kw.get("backend") or "").strip().lower() in ("sycl", "hip"):
|
||||
return True # their K/V lives in VRAM and grows on demand (HIP spills to the host when the card is full); the plan's number is an estimate there: Arc A750 8 GB started SQ-10 at 128K
|
||||
# (K/V 4,256 MiB on the card, 70 of 3,072 experts) where the plan says "does not fit". An estimate never refuses a start that ran.
|
||||
placed = place(build, vram_gib, ram_gib, unified, ctx, vision, 1, dspark, **kw)
|
||||
return bool(placed.get("kv_fits", True))
|
||||
|
||||
|
||||
def default_context(build: str, vram_gib: float | None, ram_gib: float, unified: bool = False, *, vision: bool = False, dspark: bool = True,
|
||||
backend: str | None = None, desktop: bool = False, ram_free_gib: float | None = None, extra_vram_gib: float = 0.0,
|
||||
sm: int | None = None) -> dict:
|
||||
"""The context a start with NO context named gets (owner, 2026-12-02: "128K always as a default they can change within the app or tui"): 128K (DEFAULT_CONTEXT) on every machine, 8 GB cards
|
||||
included (the K/V goes to host RAM where it does not fit the card). No smaller default per kind of machine. It steps down only when the load would truly fail at 128K (the K/V of one slot
|
||||
has nowhere to go: not enough host RAM), to the largest size of the bucket list that loads, with one plain line saying so. When 128K loads but part of the model streams from the SSD
|
||||
(a 16 GB Mac), 128K stays and the line says what is slow and which size would fit. The person changes the context in the app or the TUI; a context the person names is never changed
|
||||
(context_check).
|
||||
Returns {"context": tokens, "default": DEFAULT_CONTEXT, "stepped": bool, "slow": bool, "note": str | None}."""
|
||||
top = DEFAULT_CONTEXT
|
||||
kw = dict(extra_vram_gib=extra_vram_gib, backend=backend, desktop=desktop, ram_free_gib=ram_free_gib, sm=sm)
|
||||
keep = {"context": top, "default": top, "stepped": False, "slow": False, "note": None}
|
||||
if build not in BUILDS:
|
||||
return keep
|
||||
if _context_fits(build, top, vram_gib, ram_gib, unified, vision, dspark, kw):
|
||||
return keep
|
||||
if _context_loads(build, top, vram_gib, ram_gib, unified, vision, dspark, kw):
|
||||
chk = context_check(build, top, vram_gib, ram_gib, unified, vision=vision, dspark=dspark, **kw)
|
||||
return {**keep, "slow": bool(chk["message"]), "note": chk["message"]} # loads, slowly: 128K stays, said honestly
|
||||
for c in _context_ladder(top - 1):
|
||||
if _context_loads(build, c, vram_gib, ram_gib, unified, vision, dspark, kw):
|
||||
note = (f"Context set to {c // 1024}K because {top // 1024}K cannot be loaded in this machine's memory (the conversation memory has nowhere to go); "
|
||||
"choose a smaller model or close apps for more, then pick a larger context in the app or the TUI.")
|
||||
return {"context": c, "default": top, "stepped": True, "slow": False, "note": note}
|
||||
return keep
|
||||
|
||||
|
||||
def context_check(build: str, ctx: int, vram_gib: float | None, ram_gib: float, unified: bool = False, *, vision: bool = False, dspark: bool = True,
|
||||
backend: str | None = None, desktop: bool = False, ram_free_gib: float | None = None, extra_vram_gib: float = 0.0,
|
||||
sm: int | None = None) -> dict:
|
||||
"""A context the PERSON named (--context, or saved in a preset): never changed silently, and never refused when it loads (nothing that ran in 0.2.24 may be refused in 0.2.25). Three outcomes:
|
||||
it fits (`message` None); it loads but part of the model streams from the SSD, which is slow (`message` says so with the number that would fit, `refuse` False: the caller shows it and goes on);
|
||||
or it cannot load at all, the K/V of one slot has nowhere to go (`refuse` True, `message` with the number that would fit: the caller stops).
|
||||
Returns {"fits": bool, "fits_at": tokens | None, "refuse": bool, "message": str | None}."""
|
||||
kw = dict(extra_vram_gib=extra_vram_gib, backend=backend, desktop=desktop, ram_free_gib=ram_free_gib, sm=sm)
|
||||
ctx = int(ctx)
|
||||
if build not in BUILDS or _context_fits(build, ctx, vram_gib, ram_gib, unified, vision, dspark, kw):
|
||||
return {"fits": True, "fits_at": ctx, "refuse": False, "message": None}
|
||||
loads = _context_loads(build, ctx, vram_gib, ram_gib, unified, vision, dspark, kw)
|
||||
fits_at = next((c for c in _context_ladder(ctx - 1) if _context_fits(build, c, vram_gib, ram_gib, unified, vision, dspark, kw)), None)
|
||||
if fits_at is not None:
|
||||
if loads:
|
||||
msg = (f"{ctx // 1024}K of context does not fit in this machine's memory for {build}: part of the model streams from the SSD, which is slow. "
|
||||
f"{fits_at // 1024}K fits (--context {fits_at // 1024}k); a smaller model or closing apps also helps.")
|
||||
else:
|
||||
msg = (f"{ctx // 1024}K of context does not fit in this machine's memory for {build}; {fits_at // 1024}K does. "
|
||||
f"Use --context {fits_at // 1024}k, choose a smaller model, or close apps for more memory.")
|
||||
elif not loads:
|
||||
msg = (f"{ctx // 1024}K of context cannot be loaded in this machine's memory for {build}: the conversation memory has nowhere to go. "
|
||||
"Use a smaller --context, choose a smaller model, or close apps for more memory.")
|
||||
else:
|
||||
msg = None # the model itself needs the SSD at every size: the context is not the problem
|
||||
return {"fits": False, "fits_at": fits_at, "refuse": not loads, "message": msg}
|
||||
|
||||
|
||||
def disk_gb(build: str, vision: bool = False, dspark: bool = True) -> float:
|
||||
"""The download of a build: the model file, the DFlash 2 sidecar (`dspark` is the old name of the drafter switch) and the Vision shard when pictures are on."""
|
||||
extra_drafter = DFLASH2_GB if dspark else 0.0
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
"""Inkling-2-Mini's default context is 128K on EVERY machine, 8 GB cards included (owner, 2026-12-02: "128K always as a default they can change within the app or tui"). No smaller default per
|
||||
kind of machine: where the K/V of 128K does not fit the card it goes to host RAM (as on the RTX 5070). The default steps down only when the load would truly fail (the K/V of one slot has nowhere
|
||||
to go: not enough host RAM), with one honest line. Where 128K loads but part of the model streams from the SSD (a 16 GB Mac) it stays 128K and the line says what is slow.
|
||||
|
||||
A context the person names (--context, or saved in a preset) is never changed, and nothing that loaded and ran in 0.2.24 is refused: it is accepted when it fits, accepted with an honest line when it
|
||||
loads slowly, refused with the number that would fit only when the engine could not start it at all.
|
||||
|
||||
The sizes come from the same planner everything else uses (strata_control/inkling_fit.py)."""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
TERMINAL = Path(__file__).resolve().parents[2]
|
||||
if str(TERMINAL) not in sys.path:
|
||||
sys.path.insert(0, str(TERMINAL))
|
||||
|
||||
from strata_control import inkling_family, inkling_fit as F
|
||||
from tests.terminal.launch_support import HW_12, HW_24, Home, catalog
|
||||
|
||||
STEP_NOTE = "Context set to "
|
||||
|
||||
|
||||
class TheDefaultIs128K(unittest.TestCase):
|
||||
def test_the_default_is_128k_everywhere_it_is_read(self):
|
||||
self.assertEqual(F.DEFAULT_CONTEXT, 131072)
|
||||
self.assertEqual(inkling_family.DEFAULT_CONTEXT, 131072)
|
||||
self.assertIn(F.DEFAULT_CONTEXT, F.CONTEXTS)
|
||||
|
||||
def test_the_engine_default_is_128k_too(self):
|
||||
# `strata-inkling` with no --max-context (BackendOpts::max_ctx); the plan lowers it with a line when the card cannot hold it
|
||||
text = (TERMINAL.parent / "engine" / "src" / "inkling2" / "ink_backend.h").read_text(encoding="utf-8")
|
||||
self.assertRegex(text, r"int max_ctx = 131072;")
|
||||
|
||||
def test_there_is_no_smaller_default_for_any_kind_of_machine(self):
|
||||
# the per-class table of an earlier draft is gone: one number, 128K
|
||||
self.assertFalse(hasattr(F, "DEFAULT_CONTEXT_BY_CLASS"))
|
||||
self.assertFalse(hasattr(F, "default_context_top"))
|
||||
|
||||
|
||||
class EveryMachineThatLoads128KKeepsIt(unittest.TestCase):
|
||||
def _d(self, build, vram, ram, unified=False, backend="cuda"):
|
||||
return F.default_context(build, vram, ram, unified, backend=backend, desktop=not unified)
|
||||
|
||||
def test_a_24_gb_card_with_sq20_gets_128k_and_no_line(self):
|
||||
d = self._d("SQ-20", 24.0 - 0.75, 64.0)
|
||||
self.assertEqual((d["context"], d["stepped"], d["slow"], d["note"]), (131072, False, False, None))
|
||||
|
||||
def test_a_12_gb_card_with_sq15_gets_128k_and_no_line(self):
|
||||
d = self._d("SQ-15", 12.0 - 0.75, 64.0)
|
||||
self.assertEqual((d["context"], d["stepped"], d["note"]), (131072, False, None))
|
||||
|
||||
def test_an_8_gb_card_gets_128k_with_16_or_32_gb_of_ram_and_the_k_v_goes_to_host_ram(self):
|
||||
for ram in (16.0, 32.0):
|
||||
d = self._d("SQ-10", 8.0 - 0.75, ram)
|
||||
self.assertEqual((d["context"], d["stepped"], d["note"]), (131072, False, None), ram)
|
||||
placed = F.place("SQ-10", 8.0 - 0.75, ram, False, 131072, False, backend="cuda", desktop=True)
|
||||
self.assertEqual(placed["ssd_gb"], 0.0)
|
||||
self.assertTrue(placed["kv_fits"])
|
||||
self.assertEqual(placed["kv_offload"], "on") # the K/V is in host RAM (2.15 GB), not in the card
|
||||
|
||||
def test_a_16_gb_mac_keeps_128k_and_says_what_is_slow(self):
|
||||
d = self._d("SQ-10", None, 16.0, True, "metal")
|
||||
self.assertEqual(d["context"], 131072)
|
||||
self.assertFalse(d["stepped"])
|
||||
self.assertTrue(d["slow"])
|
||||
self.assertIn("128K of context does not fit in this machine's memory for SQ-10", d["note"])
|
||||
self.assertIn("streams from the SSD", d["note"])
|
||||
self.assertRegex(d["note"], r"\d+K fits \(--context \d+k\)")
|
||||
|
||||
def test_a_model_that_needs_the_ssd_at_every_size_is_not_blamed_on_the_context(self):
|
||||
d = self._d("SQ-20", 12.0 - 0.75, 12.0)
|
||||
self.assertEqual((d["context"], d["stepped"], d["slow"], d["note"]), (131072, False, False, None))
|
||||
|
||||
def test_an_unknown_build_keeps_128k(self):
|
||||
d = F.default_context("no-such-build", 12.0, 32.0)
|
||||
self.assertEqual((d["context"], d["stepped"], d["note"]), (131072, False, None))
|
||||
|
||||
|
||||
class AnEstimateNeverRefusesAStartThatRan(unittest.TestCase):
|
||||
def test_intel_and_amd_cards_keep_128k_and_are_never_refused(self):
|
||||
# Arc A750 8 GB started SQ-10 at 128K (K/V 4,256 MiB on the card): the plan's "does not fit" is an estimate there, not a reason to step down or refuse
|
||||
for backend in ("sycl", "hip"):
|
||||
d = F.default_context("SQ-15", 8.0 - 0.75, 62.0, False, backend=backend, desktop=True)
|
||||
self.assertEqual((d["context"], d["stepped"]), (131072, False), backend)
|
||||
c = F.context_check("SQ-15", 131072, 8.0 - 0.75, 62.0, False, backend=backend, desktop=True)
|
||||
self.assertFalse(c["refuse"], backend)
|
||||
|
||||
|
||||
class OnlyALoadThatWouldTrulyFailStepsDown(unittest.TestCase):
|
||||
def test_an_8_gb_card_with_6_gb_of_ram_steps_down_with_one_honest_line(self):
|
||||
# the K/V of 128K fits neither the card nor RAM (the planner says kv_fits False): the engine could not start
|
||||
self.assertFalse(F.place("SQ-10", 8.0 - 0.75, 6.0, False, 131072, False, backend="cuda", desktop=True)["kv_fits"])
|
||||
d = F.default_context("SQ-10", 8.0 - 0.75, 6.0, False, backend="cuda", desktop=True)
|
||||
self.assertTrue(d["stepped"])
|
||||
self.assertLess(d["context"], 131072)
|
||||
self.assertIn(d["context"], F.CONTEXTS)
|
||||
self.assertTrue(d["note"].startswith(STEP_NOTE + f"{d['context'] // 1024}K because 128K cannot be loaded"))
|
||||
self.assertEqual(d["note"].count("\n"), 0)
|
||||
|
||||
def test_the_step_is_the_largest_size_that_loads_and_the_next_one_up_does_not(self):
|
||||
d = F.default_context("SQ-10", 8.0 - 0.75, 6.0, False, backend="cuda", desktop=True)
|
||||
loads = lambda c: F.place("SQ-10", 8.0 - 0.75, 6.0, False, c, False, backend="cuda", desktop=True)["kv_fits"]
|
||||
self.assertTrue(loads(d["context"]))
|
||||
for c in [c for c in F.CONTEXTS if d["context"] < c <= 131072]:
|
||||
self.assertFalse(loads(c), c)
|
||||
|
||||
|
||||
class ANamedOrSavedContextIsNeverChangedAndOnlyRefusedWhenItCannotLoad(unittest.TestCase):
|
||||
"""Nothing that loaded and ran in 0.2.24 may be refused in 0.2.25: a named or saved context that fits is accepted, one that loads but streams from the SSD is accepted with an honest
|
||||
line, and only one the engine could not start at all (the K/V of one slot has nowhere to go) is refused, with the number that would fit."""
|
||||
|
||||
def test_128k_on_a_16_gb_mac_loads_slowly_so_it_is_said_not_refused(self):
|
||||
c = F.context_check("SQ-10", 131072, None, 16.0, True, backend="metal")
|
||||
self.assertFalse(c["fits"])
|
||||
self.assertFalse(c["refuse"])
|
||||
self.assertIn("streams from the SSD", c["message"])
|
||||
self.assertIn(f"{c['fits_at'] // 1024}K fits (--context {c['fits_at'] // 1024}k)", c["message"])
|
||||
|
||||
def test_the_number_that_fits_is_accepted_without_a_line(self):
|
||||
fits_at = F.context_check("SQ-10", 131072, None, 16.0, True, backend="metal")["fits_at"]
|
||||
c = F.context_check("SQ-10", fits_at, None, 16.0, True, backend="metal")
|
||||
self.assertTrue(c["fits"])
|
||||
self.assertFalse(c["refuse"])
|
||||
self.assertIsNone(c["message"])
|
||||
|
||||
def test_a_context_the_engine_could_not_start_is_refused_with_the_number_that_fits(self):
|
||||
c = F.context_check("SQ-10", 131072, 8.0 - 0.75, 6.0, False, backend="cuda", desktop=True)
|
||||
self.assertTrue(c["refuse"])
|
||||
self.assertIn("128K of context", c["message"])
|
||||
if c["fits_at"]:
|
||||
self.assertIn(f"{c['fits_at'] // 1024}K", c["message"])
|
||||
self.assertTrue(F.place("SQ-10", 8.0 - 0.75, 6.0, False, c["fits_at"], False, backend="cuda", desktop=True)["kv_fits"])
|
||||
else:
|
||||
self.assertIn("cannot be loaded", c["message"])
|
||||
|
||||
def test_a_model_that_needs_the_ssd_at_every_size_is_not_refused_for_its_context(self):
|
||||
c = F.context_check("SQ-20", 131072, 12.0 - 0.75, 12.0, False, backend="cuda", desktop=True)
|
||||
self.assertFalse(c["refuse"])
|
||||
self.assertIsNone(c["message"])
|
||||
self.assertIsNone(c["fits_at"])
|
||||
|
||||
|
||||
class TheLaunchUsesTheSameRule(unittest.TestCase):
|
||||
MAC16 = {"ram_gb": 16.0, "mac": True, "os": "macOS", "disk_free_gb": 500.0, "cpu": {"avx2": True, "name": "Apple M2"},
|
||||
"gpus": [{"index": 0, "name": "Apple M2", "vram_gb": 16.0, "unified_gb": 16.0, "usable": True, "vendor": "apple"}]}
|
||||
SMALL = {"ram_gb": 6.0, "os": "Test OS", "disk_free_gb": 500.0, "cpu": {"avx2": True, "name": "test cpu"},
|
||||
"gpus": [{"index": 0, "name": "NVIDIA GeForce RTX 3070", "vram_gb": 8.0, "usable": True, "vendor": "nvidia"}]}
|
||||
|
||||
def test_the_catalog_gives_a_16_gb_mac_128k_with_the_slow_line(self):
|
||||
with Home():
|
||||
cat = catalog(self.MAC16)
|
||||
dc = cat.inkling_context("SQ-10", self.MAC16)
|
||||
self.assertEqual((dc["context"], dc["stepped"], dc["slow"]), (131072, False, True))
|
||||
self.assertIn("streams from the SSD", dc["note"])
|
||||
self.assertEqual(cat.max_context("inkling-2-mini", "SQ-10", self.MAC16), 131072)
|
||||
|
||||
def test_the_catalog_gives_a_24_gb_card_128k_and_no_line(self):
|
||||
with Home():
|
||||
cat = catalog(HW_24)
|
||||
self.assertEqual(cat.max_context("inkling-2-mini", "SQ-20", HW_24), 131072)
|
||||
self.assertIsNone(cat.inkling_context("SQ-20", HW_24)["note"])
|
||||
|
||||
def test_launch_with_no_context_keeps_128k_on_a_mac_that_loads_it_slowly(self):
|
||||
from strata_cli.launch import cmd as C
|
||||
from strata_cli.launch import settings as S
|
||||
with Home():
|
||||
cat = catalog(self.MAC16)
|
||||
s, notes = C.apply_defaults(S.LaunchSettings(family="inkling-2-mini", model="SQ-10"), cat)
|
||||
self.assertEqual(s.context, 131072)
|
||||
self.assertEqual([n for n in notes if n.level == "error"], [])
|
||||
self.assertTrue(any(n.level == "warn" and "streams from the SSD" in n.text for n in notes))
|
||||
|
||||
def test_launch_with_no_context_steps_down_only_when_the_load_would_fail(self):
|
||||
from strata_cli.launch import cmd as C
|
||||
from strata_cli.launch import settings as S
|
||||
with Home():
|
||||
cat = catalog(self.SMALL)
|
||||
s, notes = C.apply_defaults(S.LaunchSettings(family="inkling-2-mini", model="SQ-10"), cat)
|
||||
self.assertLess(s.context, 131072)
|
||||
self.assertEqual([n for n in notes if n.level == "error"], [])
|
||||
self.assertTrue(any(n.level == "warn" and n.text.startswith(STEP_NOTE) and "cannot be loaded" in n.text for n in notes))
|
||||
|
||||
def test_a_named_context_that_loads_slowly_keeps_its_number_with_a_warning_and_no_error(self):
|
||||
from strata_cli.launch import cmd as C
|
||||
from strata_cli.launch import settings as S
|
||||
with Home():
|
||||
cat = catalog(self.MAC16)
|
||||
s, notes = C.apply_defaults(S.LaunchSettings(family="inkling-2-mini", model="SQ-10", context=131072), cat)
|
||||
self.assertEqual(s.context, 131072) # never changed
|
||||
self.assertEqual([n for n in notes if n.level == "error"], []) # it loads: not refused
|
||||
self.assertTrue(any(n.level == "warn" and "streams from the SSD" in n.text for n in notes))
|
||||
|
||||
def test_a_saved_preset_that_loaded_in_0_2_24_still_loads(self):
|
||||
# regression: the SQ-15 preset with 128K on a 12 GB card with 64 GB of RAM (the experts' rest and the K/V in RAM) ran in 0.2.24 and must neither be changed nor refused
|
||||
from strata_cli.launch import cmd as C
|
||||
from strata_cli.launch import settings as S
|
||||
with Home():
|
||||
cat = catalog(HW_12)
|
||||
s, notes = C.apply_defaults(S.LaunchSettings(family="inkling-2-mini", model="SQ-15", context=131072, vision="on"), cat)
|
||||
self.assertEqual(s.context, 131072)
|
||||
self.assertEqual([n for n in notes if n.level == "error"], [])
|
||||
self.assertFalse(any("does not fit" in n.text for n in notes))
|
||||
|
||||
def test_launch_refuses_a_named_context_the_engine_could_not_start_and_names_the_number(self):
|
||||
from strata_cli.launch import cmd as C
|
||||
from strata_cli.launch import settings as S
|
||||
with Home():
|
||||
cat = catalog(self.SMALL)
|
||||
self.assertTrue(cat.inkling_context("SQ-10", self.SMALL, 131072)["refuse"]) # 8 GB card, 6 GB of RAM: the K/V of 128K has nowhere to go
|
||||
_, notes = C.apply_defaults(S.LaunchSettings(family="inkling-2-mini", model="SQ-10", context=131072), cat)
|
||||
errors = [n for n in notes if n.level == "error"]
|
||||
self.assertEqual(len(errors), 1)
|
||||
self.assertIn("128K of context", errors[0].text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -34,30 +34,31 @@ class TestInklingFitAndHardwareSelection(unittest.TestCase):
|
||||
self.assertTrue(rec["fits"])
|
||||
|
||||
def test_discrete_16gb_and_24gb_mac_select_sq15(self):
|
||||
# (every plan here is the 32K plan: since 0.2.25 the default context is 128K, which test_inkling_default_context.py covers)
|
||||
# #6613: 16 GiB discrete GPU at 32K plans SQ-15 as safe hybrid (never OOMing on KV growth),
|
||||
# while speed preference selects 100%-VRAM SQ-10 and 24 GiB Mac UMA fits SQ-15 100% in memory.
|
||||
# quality: the biggest build with part of its experts in RAM (safe on HIP, slow); CUDA balanced: SQ-15 all in the card, K/V in RAM
|
||||
rec_16 = inkling_fit.recommend(vram_gib=16, ram_gib=32, preference="quality", fp8_kv=False)
|
||||
rec_16 = inkling_fit.recommend(vram_gib=16, ram_gib=32, preference="quality", fp8_kv=False, ctx=32768)
|
||||
self.assertEqual(rec_16["build"], "SQ-15")
|
||||
self.assertEqual(rec_16["mode"], "ram_vram_zero_ssd")
|
||||
self.assertTrue(rec_16["fits"])
|
||||
self.assertLessEqual(rec_16["placement"]["vram_gb"], 10.6)
|
||||
rec_16_cuda = inkling_fit.recommend(vram_gib=16, ram_gib=32, backend="cuda", preference="balanced", fp8_kv=False)
|
||||
rec_16_cuda = inkling_fit.recommend(vram_gib=16, ram_gib=32, backend="cuda", preference="balanced", fp8_kv=False, ctx=32768)
|
||||
self.assertEqual(rec_16_cuda["build"], "SQ-15")
|
||||
self.assertEqual(rec_16_cuda["mode"], "full_vram")
|
||||
self.assertGreater(rec_16_cuda["placement"]["host_kv_gb"], 0.5)
|
||||
# "balanced" with a backend that is not named, or HIP, keeps SQ-10 (the K/V grow pool of #6613 has no room beside SQ-15)
|
||||
for bkd in (None, "hip"):
|
||||
rec_16_safe = inkling_fit.recommend(vram_gib=16, ram_gib=32, backend=bkd, preference="balanced", fp8_kv=False)
|
||||
rec_16_safe = inkling_fit.recommend(vram_gib=16, ram_gib=32, backend=bkd, preference="balanced", fp8_kv=False, ctx=32768)
|
||||
self.assertEqual(rec_16_safe["build"], "SQ-10", bkd)
|
||||
self.assertEqual(rec_16_safe["mode"], "full_vram", bkd)
|
||||
|
||||
rec_16_speed = inkling_fit.recommend(vram_gib=16, ram_gib=32, preference="speed", fp8_kv=False)
|
||||
rec_16_speed = inkling_fit.recommend(vram_gib=16, ram_gib=32, preference="speed", fp8_kv=False, ctx=32768)
|
||||
self.assertEqual(rec_16_speed["build"], "SQ-10")
|
||||
self.assertEqual(rec_16_speed["mode"], "full_vram")
|
||||
self.assertTrue(rec_16_speed["fits"])
|
||||
|
||||
rec_mac24 = inkling_fit.recommend(vram_gib=None, ram_gib=24, unified=True)
|
||||
rec_mac24 = inkling_fit.recommend(vram_gib=None, ram_gib=24, unified=True, ctx=32768) # 32K: see the 16 GB Mac above
|
||||
self.assertEqual(rec_mac24["build"], "SQ-15")
|
||||
self.assertEqual(rec_mac24["mode"], "full_vram")
|
||||
self.assertTrue(rec_mac24["fits"])
|
||||
@@ -82,7 +83,8 @@ class TestInklingFitAndHardwareSelection(unittest.TestCase):
|
||||
self.assertEqual(rec_8["build"], "SQ-10")
|
||||
self.assertTrue(rec_8["fits"])
|
||||
|
||||
rec_mac16 = inkling_fit.recommend(vram_gib=None, ram_gib=16, unified=True)
|
||||
# at 32K: the default context is 128K since 0.2.25, which a 16 GB Mac does not hold; it steps down (test_inkling_default_context.py), this test is about the build
|
||||
rec_mac16 = inkling_fit.recommend(vram_gib=None, ram_gib=16, unified=True, ctx=32768)
|
||||
self.assertEqual(rec_mac16["build"], "SQ-10")
|
||||
self.assertTrue(rec_mac16["fits"])
|
||||
|
||||
|
||||
@@ -753,7 +753,7 @@ class Strata:
|
||||
rec = inkling_fit.recommend(vram_gib, ram_gib, unified, None, vision, igpu=igpu, arch=arch)
|
||||
placed = inkling_fit.place(build, vram_gib, ram_gib, rec["unified"], None, vision)
|
||||
return {"placement": placed, "mode": inkling_fit.mode(placed), "recommended": rec["build"] == build,
|
||||
"unified": rec["unified"], "context": inkling_fit.DEFAULT_CONTEXT, "kv_gb": inkling_fit.kv_cache_gb(),
|
||||
"unified": rec["unified"], "context": inkling_fit.default_context(build, vram_gib, ram_gib, rec["unified"])["context"], "kv_gb": inkling_fit.kv_cache_gb(),
|
||||
"parallel_choices": list(inkling_fit.PARALLEL_CHOICES)}
|
||||
|
||||
def ling32_fit_row(self, build, ram, usable, ctx: int | None = None, vision: bool = True) -> dict | None:
|
||||
@@ -1738,11 +1738,12 @@ class Strata:
|
||||
dl_gb = round(sum((inkling_family.size_of(n) or 0) for n in inkling_family.files_of(b, vision=True, drafter=True)) / 1e9, 1)
|
||||
why = (f"{ram:.0f} GB of RAM + {vram:.0f} GB of VRAM: Inkling-2-Mini {b} ({inkling_fit.BUILDS[b]['footprint_gb']:.1f} GB) "
|
||||
f"runs cleanly on 4+ GB GPUs with routed experts in RAM")
|
||||
ctx_ink = inkling_fit.default_context(b, vram, ram, False)["context"] # 128K, or the largest size that fits (a named context is refused when it does not)
|
||||
cmd = (("START-HERE.bat --setup" if WIN else "./setup.sh --setup") +
|
||||
f" --yes --family {inkling_family.FAMILY} --model {b} --context {inkling_family.DEFAULT_CONTEXT}" +
|
||||
f" --yes --family {inkling_family.FAMILY} --model {b} --context {ctx_ink}" +
|
||||
(f" --backend {backend}" if backend in ("hip", "sycl") else ""))
|
||||
return {"family": inkling_family.FAMILY, "model": b, "title": f"{inkling_family.TITLE} {b}",
|
||||
"context": inkling_family.DEFAULT_CONTEXT, "backend": backend,
|
||||
"context": ctx_ink, "backend": backend,
|
||||
"gpu": {k: best.get(k) for k in ("index", "name", "vram_gb")},
|
||||
"download_gb": dl_gb, "why": why, "notes": notes, "setup_command": cmd}
|
||||
else:
|
||||
@@ -2903,16 +2904,16 @@ class Tools:
|
||||
from strata_control import hy4_family
|
||||
context = context or hy4_family.DEFAULT_CONTEXT
|
||||
elif md.get("inkling"):
|
||||
from strata_control import inkling_family
|
||||
context = context or inkling_family.DEFAULT_CONTEXT
|
||||
from strata_control import inkling_family, inkling_fit
|
||||
context = context or inkling_fit.default_context(model, None, float(hw.get("ram_gb") or 0.0), True, backend="metal")["context"] # 128K, or the largest size that fits the unified memory
|
||||
else:
|
||||
context = context or (s.mac().recommend_context(hw.get("ram_gb") or 0) if s.mac() else 32768)
|
||||
if context is None:
|
||||
usable = s.engine_gpus(hw)
|
||||
vram = max((g["vram_gb"] for g in usable), default=12)
|
||||
if md.get("inkling"):
|
||||
from strata_control import inkling_family
|
||||
context = inkling_family.DEFAULT_CONTEXT
|
||||
from strata_control import inkling_fit
|
||||
context = inkling_fit.default_context(model, max(0.0, float(vram) - 0.75), float(hw.get("ram_gb") or 0.0), False, desktop=True)["context"] # 128K, or the largest size that fits the card
|
||||
elif md.get("ling32"):
|
||||
from strata_control import ling32_family
|
||||
context = ling32_family.DEFAULT_CONTEXT
|
||||
|
||||
Reference in new issue
Block a user