Repository navigation
Size a GPU model's context from free VRAM - #280
Merged
Merged
Conversation
On CUDA and Vulkan the context was a fixed 8192: VRAM was never read, the
factory only lowered its default, and device_free_total_gb() returned
None, so the large-model cap stayed at its 16384 floor too. A 27B model
on a 40GB A100 ran with 8192 and failed every request that read a file
("Requested tokens (12337) exceed context window of 8192").
llama.cpp reports each GPU's free and total memory; the context is now
sized from it as Apple Silicon's is from unified memory (ctx_for_memory,
shared), never under the default, and the fit guard and large-model cap
read it too.
make run-debug built slp-speech (whisper.cpp) every time. A new fetch-speech target downloads the release install.sh installs (or SPEECH_RELEASE=x.y.z), checks it against the release's checksums, and keeps only slp-speech and its lib/ under ~/.smartloop/cache/slp-speech/. Windows, whose archive is a zip, still builds it.
mupdf's system-fonts feature (font-kit) links fontconfig; CI installs libfontconfig1-dev, the README didn't say so, and a fresh box failed in yeslogic-fontconfig-sys's build script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On CUDA and Vulkan, a local model's context was a fixed 8192:
LlmFactorystarted atn_ctx = 8192and only ever lowered it (the large-model cap is applied asif n_ctx > cap).ModelService::device_free_total_gb()returnedNoneoff Apple Silicon, sowidened_ctx_capnever ran and the large-model cap stayed at its 16384 floor.Seen on an A100 40GB: qwen3.8-27b ran with 8192, and every docent request that read a file failed with
Requested tokens (12337) exceed context window of 8192.Change
gpu_memory_gb(): free/total VRAM summed over the discrete GPUs llama.cpp reports (list_llama_ggml_backend_devices; CUDA and Vulkan both fill it in).LlmFactory::ctx_for_memory(): the Apple Silicon sizing (free memory − weights − 2GB, at 0.75–2GB of KV per 8k, up to the device ceiling), now shared. The GPU branch uses it with the default 8192 as its floor; VRAM not reported, 8192 stays.device_free_total_gb()reports GPU VRAM, so the large-model cap widens with it.For the A100 case: ~16GB weights, ~38GB free →
n_ctx = 81920.Behavior to watch
GPU: …GB total, …GB free … — using n_ctx=….Also:
run-debugtakes slp-speech from a releasemake run-debugno longer builds slp-speech (whisper.cpp). A newfetch-speechtarget downloads<os>-<arch>-slp.tar.gzfor the releaseinstall.shinstalls (orSPEECH_RELEASE=x.y.z) from dl.smartloop.ai, checks it againstchecksums-sha256.txt, and keeps onlyslp/slp-speechandslp/lib/under~/.smartloop/cache/slp-speech/<version>/. Windows (zip archive) still builds it. Tried on Linux: 1.2.42 fetched, checksum matched,slp-speechresolves its bundledlibvulkan.so.1, a second run is a no-op.Also: fontconfig in the build requirements
The README's Linux build requirements now list
pkg-config libfontconfig1-dev(fontconfig-develon Fedora/RHEL), as CI installs: mupdf's system fonts (font-kit →yeslogic-fontconfig-sys) need it, and a fresh box'smake run-debugfailed in that crate's build script.Tests
New
tests/unit/test_gpu_context_from_vram.rs: the A100 case, the ceilings, a tight GPU keeping the floor, the large-model cap widening.cargo test: all pass.Related: #279 (stream the generation error instead of nothing), smartloop-labs/docent#106.
🤖 Generated with Claude Code