Repository navigation
Count the part of a loaded model in RAM, and show it in lcode doctor - #260
Open
nasser1941 wants to merge 3 commits into
Open
nasser1941 wants to merge 3 commits into
nasser1941 wants to merge 3 commits into
Conversation
lcode doctor looked for lcode-qwen3.6-35b in /api/ps, where Ollama lists lcode-qwen3.6-35b:latest, so its Loaded line never appeared for the models lcode setup creates. It now finds the model the way the load line does (same_model) and says the same thing, with the context. The line after a load repeated /api/ps, which leaves out the weights that stay mapped from the model's file in system RAM: with Ollama 0.40, qwen3.6-35b at 32K on a 12 GB GPU showed as "10.5 GB, 98% on the GPU" while ~12 GB of experts were in RAM. For catalog models partly off the GPU, lcode now counts the model at the catalog's estimate, the one lcode setup and lcode doctor show: "~23 GB, 42% on the GPU and the rest in system RAM". With that share the warning that another program is using GPU memory can fire again; it now says how much of the model fits rather than calling the catalog's figure usual. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merging main put them under the 0.62.0 release, which doesn't have them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Fixes two places that reported a loaded model wrongly.
1.
lcode doctornever showed theLoadedlinecmd_doctorcompared/api/psnames with==.resolve_modelreturnslcode-qwen3.6-35b, while Ollama listslcode-qwen3.6-35b:latest, so the line never appeared for the modelslcode setupcreates. This was seen on a reallcode doctorrun with the model loaded. Doctor now usesresidency.placement, which matches the name withsame_model, and prints the same words as the line after a load, plus the context:2. The line after a load repeated
/api/ps/api/pscounts the memory Ollama's runner allocates. The weights it keeps in system RAM stay mapped from the model's file, so they're left out. With Ollama 0.40.13,lcode-qwen3.6-35bat 32K on the 12 GB laptop reportssize10.49 GB andsize_vram10.29 GB. lcode printed10.5 GB, 98% on the GPU and the rest in system RAM, while ~12 GB of experts were in RAM.For a catalog model that Ollama reports as partly off the GPU, lcode now counts the whole model at the catalog's estimate (
memory_gib, the same "~23 GB needed" thatlcode setup,lcode doctorand the context picker show), unless Ollama counts more.~marks the estimate.10.5 GB, 98% on the GPU and the rest in system RAM~23 GB, 42% on the GPU and the rest in system RAM6.6 GB, all on the GPUA read-only check on the laptop with Ollama 0.40.15 (the model was already loaded; nothing was loaded for this) gives
size9.78 GB andsize_vram9.58 GB, with 12.0 GiB of the model's file resident in the runner. The new line says~23 GB, 39% on the GPU.Why
memory_giband notin_ram_gibin_ram_gibismemory_gib − vram_gib, so it assumes the model gets the whole GPU: 10.7 GB here. Ollama puts 9.6–10.3 GB of the 12 GB there, so the part in RAM is ~2 GB more than that.in_ram_gibalso stays the same when another program takes GPU memory, which is exactly when the shortfall warning matters. Built on it, the share would come out at 47%, and the warning would fire only below ~4.5 GB on the GPU.expected_shareandSHORTFALLexpected_shareis unchanged: 53% for this case. With Ollama's numbers,gpu_sharewas 98%, so the "less of it is on the GPU than usual" warning could never fire. A model squeezed to 4 GB on the GPU by another program still counted 95%. With the estimate, a normal load is at 39–42% and the warning fires below 28%: under ~6.8 GB on the GPU. Before Ollama 0.40, with its full count of ~22.3 GB, it fired under ~6.2 GB. The warning saidusual (53%), but normal loads were never at 53% (they show 39–45%), so it now says(up to 53% fits). The dense-split warning uses the same share, so it no longer depends on whether Ollama counts a dense model's layers in RAM.Tests
In
tests/test_residency.py, usingFakeOllamaandmake_agent:test_a_load_is_reported_once_with_how_it_fits: a session with Ollama 0.40.13's/api/psentry says~23 GB, 42% on the GPUand gives no warning. The old code gives10.5 GB, 98%.test_less_on_the_gpu_than_usual_is_explained: the warning fires with the way Ollama 0.40 counts. The dense warning fires whether or not the part in RAM is counted.test_the_part_of_a_catalog_model_ollama_leaves_out_is_countedandtest_what_ollama_counts_stands_when_nothing_is_left_out_or_nothing_is_knowncover the estimate, the loaded context, CPU only, all on the GPU, a count above the estimate, and a model outside the catalog.test_doctor_shows_how_the_loaded_model_fits: doctor showsLoadedforlcode-qwen3.6-35b:latest, and nothing for another model. The old code shows nothing.uv run pytest,ruff check,ruff format --check,basedpyrightandmkdocs build --strictpass locally.Left alone
lcode benchhas its ownmemory_usefrom/api/ps(Loaded in 18s · 10.4 GB, 98% on the GPUindocs/bench.md), which also goes into its JSON results. It has the same cause, but changing it changes what results compare against.in_ram_gib(~11 GB of the model that doesn't fit on the GPU). Measured, that part is nearer 12–13 GiB, because the model doesn't get the whole GPU.🤖 Generated with Claude Code