Merge branch 'f-138-fixB' into f-138-prs

This commit is contained in:
Niko1221 committed 2026-10-03 02:21:36 +02:00
commit 99f3dbd0b2
9 files changed
+162 -12

No files matched your search

+5
View File
@@ -190,6 +190,11 @@ The worker count above was used on a 16-core CPU; measure it for your CPU.
The 4K context is a smoke-test starting point, not a model limit. The expert cache
sizes itself automatically and leaves 1 GiB of VRAM headroom.
**The card also drives a Linux desktop (#560 #516):** keep more VRAM free than the default 700 MiB, e.g.
`./setup.sh --vram-reserve-mib 3072`. With the cache filling the card, the desktop's next VRAM need makes amdgpu move
GPU memory to system RAM (GTT), the OOM killer then ends KWin/plasmashell or `systemd-oomd` ends apps, or the
compositor fails with "Failed to pin framebuffer with error -12".
The installer supports this backend (see "Install with setup" above). Images run through the CPU encoder for now (`--vision cpu`).
Setup installs one AMD card, or several with `--gpus` (the engine's layer split; see RDNA4 below).
+6
View File
@@ -201,6 +201,12 @@ By hand: add `"--vram-reserve-mib", "2048"` to the config's `"args"` list and re
much smaller, so answers can be a little slower. The engine sizes its cache from the VRAM free when it starts: what
another program already holds then is left alone anyway; the reserve is room for what it takes later.
**An AMD card that also drives a Linux desktop (#560 #516):** with the default reserve the expert cache fills the
card, and when the desktop (the compositor, a browser, a new app) needs more VRAM, the amdgpu driver moves GPU memory
to system RAM, which the model's experts already fill: the OOM killer then ends the desktop session (KWin, plasmashell)
or the compositor fails ("Failed to pin framebuffer"). `./setup.sh --vram-reserve-mib 3072` fixed it in both reports
(about 2.3 GB fewer experts in VRAM, a few % of speed). Setup and the server window say so on such a PC.
**A card under 8 GB (#496):** when the default reserve leaves the expert cache too little room, the engine lowers the
reserve (down to 300 MiB) until it fits, and warns if the card then ends nearly full. If the start stops with "no VRAM
is left for the expert cache", that log line says how much is short; an 8K context and `--draft-vocab en` at setup
+34
View File
@@ -2544,6 +2544,36 @@ def warn_tight_ram(arena_mib) -> None:
+ "Close other programs, or run START-HERE --setup and pick a smaller size (Q2_0 / IQ2_XS).", flush=True)
DESKTOP_FREE_MIB = 2048 # #560 #516: below this, an AMD card that also drives a Linux desktop can run out
DESKTOP_RESERVE_MIB = 3072 # what kept KDE/Wayland alive beside a full expert cache in both reports
def linux_desktop(env=None) -> bool:
"""A graphical session on Linux (Wayland or X): its compositor, browser and apps take VRAM after the model has."""
env = os.environ if env is None else env
return os.name != "nt" and sys.platform != "darwin" and bool(env.get("WAYLAND_DISPLAY") or env.get("DISPLAY"))
def desktop_vram_note(backend, vram_free_mib, args: list, desktop: bool) -> str:
"""#560 #516: on Linux, when the desktop needs VRAM the AMD card does not have, amdgpu moves GPU memory (the expert
cache, ~24 GB) to system RAM, which the experts already fill - the OOM killer then ends the compositor. The
default reserve (700 MiB) is sized for a card without a desktop. A recommendation, nothing changes: "" when it
does not apply."""
if backend != "hip" or not desktop or not isinstance(vram_free_mib, int) or vram_free_mib >= DESKTOP_FREE_MIB:
return ""
try:
reserve = int(args[args.index("--vram-reserve-mib") + 1]) if "--vram-reserve-mib" in args else 700
except (ValueError, IndexError):
reserve = 700
if reserve >= DESKTOP_RESERVE_MIB:
return ""
return (f"[strata] note: {vram_free_mib} MiB of VRAM free with the model loaded. If this AMD card also drives your "
"desktop and the desktop or apps crash after the start (the driver moves the expert cache to RAM and "
"the OOM killer ends the session), keep more VRAM free: ./setup.sh --vram-reserve-mib "
f"{DESKTOP_RESERVE_MIB} (remembered; the expert cache gets "
f"{(DESKTOP_RESERVE_MIB - reserve) / 1024:.1f} GB less, a few % of speed)")
def lan_addresses() -> list[str]:
"""This PC's IPv4 addresses on its networks (what another device types in), without loopback/link-local."""
import socket
@@ -2895,6 +2925,10 @@ def main() -> int:
engine = StrataEngine(exe, engine_args(cfg), cwd=cfg.get("cwd"), log=cfg.get("log"), env=env, lazy=lazy)
engine.silence_s = silence # an attribute of its own: restart() keeps it
warn_tight_ram(engine.info.get("arena_mib"))
note = desktop_vram_note(cfg.get("backend"), engine.info.get("vram_free_mib"), engine.spawn[1],
linux_desktop())
if note: # #560 #516: before --open starts a browser on that card
print(note, flush=True)
else:
engine, vision, sampling_defaults = MockEngine(tok, a.script or [
"Thinking about it.</think>\n\nHello from the mock engine."]), None, {}
+25
View File
@@ -880,6 +880,31 @@ class DraftHeadHint(unittest.TestCase):
self.assertEqual(start_failure_hint(str(Path(tempfile.mkdtemp()) / "missing.log"), 0), "")
class DesktopVramNote(unittest.TestCase):
"""#560 #516: an AMD card on a Linux desktop with little VRAM left after the start gets a recommended reserve."""
def test_when_it_applies(self):
from serve.server import desktop_vram_note
note = desktop_vram_note("hip", 624, ["--kv", "int8"], True)
self.assertIn("624 MiB of VRAM free", note)
self.assertIn("--vram-reserve-mib 3072", note)
self.assertIn("2.3 GB less", note)
def test_when_it_does_not(self):
from serve.server import desktop_vram_note
self.assertEqual(desktop_vram_note(None, 624, [], True), "") # NVIDIA
self.assertEqual(desktop_vram_note("hip", 624, [], False), "") # no desktop session
self.assertEqual(desktop_vram_note("hip", 2994, [], True), "") # room left
self.assertEqual(desktop_vram_note("hip", None, [], True), "") # lazy start: no INFO yet
self.assertEqual(desktop_vram_note("hip", 900, ["--vram-reserve-mib", "4000"], True), "") # already raised
def test_desktop_detection(self):
from serve import server
with mock.patch.object(server.os, "name", "posix"), mock.patch.object(server.sys, "platform", "linux"):
self.assertTrue(server.linux_desktop({"WAYLAND_DISPLAY": "wayland-0"}))
self.assertFalse(server.linux_desktop({}))
class StartFailureLog(unittest.TestCase):
"""#496: whatever stopped the engine before READY, the error carries this start's last log lines."""
+21
View File
@@ -2792,6 +2792,24 @@ def small_card_note(ctx: int, draft_vocab: str | None) -> list[str]:
return lines
DESKTOP_RESERVE_MIB = 3072 # #560 #516: what kept a KDE/Wayland desktop alive beside a full expert cache
def linux_desktop(env=None) -> bool:
"""A graphical session on Linux (Wayland or X)."""
env = os.environ if env is None else env
return sys.platform.startswith("linux") and bool(env.get("WAYLAND_DISPLAY") or env.get("DISPLAY"))
def desktop_reserve_note() -> list[str]:
"""#560 #516: an AMD card that also drives a Linux desktop - with the default 700 MiB reserve the expert cache
fills it, and when the desktop needs more VRAM amdgpu moves the cache to system RAM, where the OOM killer then ends
the compositor. A recommendation, setup changes nothing."""
return [f"If this AMD card also drives your desktop and the desktop or apps crash once the model is loaded, keep "
f"more VRAM free: ./setup.sh --vram-reserve-mib {DESKTOP_RESERVE_MIB}",
" (remembered for this model; the expert cache gets ~2.3 GB less, a few % of speed)"]
def mtp_corrupt(mtp: Path, env=None) -> bool:
"""#327: True when the MTP tensors an install fetched are not the pinned checkpoint's (tools/mtp_fetch.py verify,
which hashes only files that changed since they last checked out). A mirror that ignored range requests left the
@@ -3601,6 +3619,9 @@ def main() -> int:
# is what it takes, and says what is short when even that is not enough. Setup only says what helps.
for line in small_card_note(ctx, draft_vocab): # a recommendation: nothing changes
say(" " + line)
elif hip and a.vram_reserve_mib is None and linux_desktop():
for line in desktop_reserve_note(): # #560 #516: a recommendation: nothing changes
say(" " + line)
if esp is not None:
# the package's profile, with llama.cpp's flags (the engine takes the same ones)
args += ["--control-vector-scaled", f"{esp}:1.0", "--control-vector-layer-range", "4", "44",
+3
View File
@@ -58,6 +58,9 @@ template <typename T> struct Dev {
~Dev() { cudaFree(p); }
void put(const std::vector<T>& h) {
ck(cudaMemcpy(p, h.data(), h.size() * sizeof(T), cudaMemcpyHostToDevice), "up");
// #548 #536: a pageable cudaMemcpy can return before its DMA lands, and the graph replays and the timing
// cases run on a cudaStreamNonBlocking stream that does not wait for the legacy stream - so wait here
ck(cudaDeviceSynchronize(), "up landed");
}
std::vector<T> get() const {
std::vector<T> h(n);
+20 -7
View File
@@ -80,17 +80,30 @@ const ggml_cuda_device_info & ggml_cuda_info() {
d.smpbo = prop.sharedMemPerBlock;
d.integrated = false;
d.supports_cooperative_launch = false;
#else
d.cc = 100 * strata::cc_major_of(prop.major) + 10 * strata::cc_minor_of(prop.minor); // STRATA_EMULATE_CC
d.smpbo = strata::smem_optin_of((int) prop.sharedMemPerBlockOptin);
d.integrated = prop.integrated != 0;
d.supports_cooperative_launch = prop.cooperativeLaunch != 0;
#endif
d.nsm = prop.multiProcessorCount;
d.smpb = prop.sharedMemPerBlock;
d.warp_size = prop.warpSize;
#else
// #542: the fields MMQ's choices read come from cudaDeviceGetAttribute, which is ABI-stable: a
// cudaDeviceProp filled by an older libcudart than the headers (a CUDA 13 build that links a CUDA 12
// libcudart.so) is shifted - sharedMemPerBlockOptin read 1 there, and every i-quant lost MMQ (#420's
// fits()). In a matched build both give the same values.
auto attr = [id](cudaDeviceAttr a) {
int v = 0;
CUDA_CHECK(cudaDeviceGetAttribute(&v, a, id));
return v;
};
d.cc = 100 * strata::cc_major_of(attr(cudaDevAttrComputeCapabilityMajor)) +
10 * strata::cc_minor_of(attr(cudaDevAttrComputeCapabilityMinor)); // STRATA_EMULATE_CC
d.smpbo = strata::smem_optin_of(attr(cudaDevAttrMaxSharedMemoryPerBlockOptin));
d.integrated = attr(cudaDevAttrIntegrated) != 0;
d.supports_cooperative_launch = attr(cudaDevAttrCooperativeLaunch) != 0;
d.nsm = attr(cudaDevAttrMultiProcessorCount);
d.smpb = (size_t) attr(cudaDevAttrMaxSharedMemoryPerBlock);
d.warp_size = attr(cudaDevAttrWarpSize);
#endif
d.vmm = false;
d.total_vram = prop.totalGlobalMem;
d.warp_size = prop.warpSize;
d.physical_device = id;
d.physical_share_count = 1;
d.virtual_index = 0;
+30 -5
View File
@@ -1990,9 +1990,18 @@ int main(int argc, char** argv) {
return 1;
}
void* arena = nullptr;
if (cudaMalloc(&arena, pool_bytes) != cudaSuccess) {
std::fprintf(stderr, "strata generate: cudaMalloc(%llu) for the weight arena failed\n",
(unsigned long long) pool_bytes);
if (const cudaError_t ce = cudaMalloc(&arena, pool_bytes); ce != cudaSuccess) {
// #486: the arena is the first large allocation and its size does not depend on the context, so what is
// missing is held by something else: say how much was free
cudaGetLastError();
size_t free_b = 0, total_b = 0;
cudaMemGetInfo(&free_b, &total_b);
std::fprintf(stderr, "strata generate: cudaMalloc(%llu) for the weight arena failed (%s): %llu MiB of %llu "
"MiB VRAM free on this GPU. The arena is allocated first, before the KV and expert "
"caches: another program (or an engine that is still exiting) holds the rest - "
"nvidia-smi / rocm-smi lists them\n",
(unsigned long long) pool_bytes, cudaGetErrorString(ce), (unsigned long long) (free_b >> 20),
(unsigned long long) (total_b >> 20));
return 1;
}
strata::core::WeightTable wt;
@@ -2297,8 +2306,14 @@ int main(int argc, char** argv) {
void* arena_s = nullptr;
if (cudaMalloc(&arena_s, pool_bytes) != cudaSuccess ||
!st.wt.load(o.pack, arena_s, pool_bytes, err, skip.empty() ? nullptr : &skip)) {
std::fprintf(stderr, "strata generate: layer split, CUDA%d weights: %s\n", st.dev,
err.empty() ? "the weight arena does not fit" : err.c_str());
cudaGetLastError();
size_t free_b = 0, total_b = 0; // #486: what that card had free
cudaMemGetInfo(&free_b, &total_b);
std::fprintf(stderr, "strata generate: layer split, CUDA%d weights: %s (%llu MiB needed, %llu MiB of %llu "
"MiB free on that card)\n", st.dev,
err.empty() ? "the weight arena does not fit" : err.c_str(),
(unsigned long long) (pool_bytes >> 20), (unsigned long long) (free_b >> 20),
(unsigned long long) (total_b >> 20));
return 1;
}
if (!o.native_dense_gguf.empty() && !st.dense.load(o.native_dense_gguf, st.wt, err, o.native_ple_key)) {
@@ -2703,6 +2718,16 @@ int main(int argc, char** argv) {
std::fprintf(stderr, "strata generate: GPU %d: %s, compute capability %d.%d%s\n", dev, name,
strata::cc_major_of(p.major), strata::cc_minor_of(p.minor),
strata::emulated_cc() ? " (STRATA_EMULATE_CC: a test mode, the card is emulated)" : "");
{ // #542: a build whose libcudart is older than its headers (a CUDA 13 kit with a dangling libcudart.so that
// CMake resolved to the system's CUDA 12 one) reads cudaDeviceProp shifted - silently, and slowly
int rt = 0;
if (cudaRuntimeGetVersion(&rt) == cudaSuccess && rt / 1000 != CUDART_VERSION / 1000)
std::fprintf(stderr, "strata generate: WARNING: this engine was compiled with CUDA %d.%d headers but "
"loaded a CUDA %d.%d runtime (libcudart): GPU properties can read wrong and some "
"kernels go unused. Rebuild it against one toolkit (cmake -DCUDAToolkit_ROOT=<the "
"toolkit>, with its libcudart.so present) (#542)\n",
CUDART_VERSION / 1000, CUDART_VERSION % 1000 / 10, rt / 1000, rt % 1000 / 10);
}
#endif
const std::string e = strata::core::device_code_error();
if (!e.empty()) {
+18
View File
@@ -368,5 +368,23 @@ class SmallCardTip(unittest.TestCase):
self.assertIn("close other programs", tip)
class DesktopReserveTip(unittest.TestCase):
"""#560 #516: an AMD card on a Linux desktop gets a recommended reserve (3072 MiB) - a tip, the config is not
changed."""
def test_desktop_detection(self):
with mock.patch.object(setup.sys, "platform", "linux"):
self.assertTrue(setup.linux_desktop({"WAYLAND_DISPLAY": "wayland-0"}))
self.assertTrue(setup.linux_desktop({"DISPLAY": ":0"}))
self.assertFalse(setup.linux_desktop({})) # a headless box / ssh
with mock.patch.object(setup.sys, "platform", "win32"):
self.assertFalse(setup.linux_desktop({"DISPLAY": ":0"})) # Windows counts the desktop itself (#497)
def test_the_tip(self):
tip = " ".join(setup.desktop_reserve_note())
self.assertIn("--vram-reserve-mib 3072", tip)
self.assertIn("desktop", tip)
if __name__ == "__main__":
unittest.main()