Repository navigation
fix: align gpu-layers with llama.cpp -1/-2 word values - #68
Conversation
- reject -1, llama.cpp spells auto by it - accept -2 as all layers, the new default - keep an exact count behavior unchanged Task 1 of ngl-minus-one-minus-two-alignment. Signed-off-by: thxCode <thxcode0824@gmail.com>
- sync the two options lines with --help, default -2 - add The GPU Layers Word Values section - note the breaking change in both READMEs - qualify the unchanged-command-line claim for the word values Task 2 of ngl-minus-one-minus-two-alignment. Signed-off-by: thxCode <thxcode0824@gmail.com>
- extract newApp so tests can run the real flags - run both flags with -1, hooks must reject Task 3 of ngl-minus-one-minus-two-alignment. Signed-off-by: thxCode <thxcode0824@gmail.com>
|
🔍 OpenCodeReview found 1 issue(s) in this PR.
📄
|
There was a problem hiding this comment.
🟡 Changes recommended
A critical draft offload bug makes --gpu-layers 0 --gpu-layers-draft -2 estimate the draft model on CPU rather than fully offloaded, understating VRAM; the inherited limit needs an explicit override and regression coverage.
1 open issue
What changed in this PR
This PR updates the CLI’s GPU-layer sentinel handling to match llama.cpp’s meanings while retaining full offload as the estimator’s default.
Changes:
- Rejects
-1(auto) and values below-2for both main and draft GPU-layer flags. - Changes default literals to
-2and documents the breaking change. - Extracts app construction for integration tests and adds validation coverage.
| File | Description |
|---|---|
README.md |
Adds the breaking-change release note. |
cmd/gguf-parser/README.md |
Documents GPU-layer values, defaults, and compatibility. |
cmd/gguf-parser/main.go |
Wires validation, updates defaults, and extracts app construction. |
cmd/gguf-parser/main_test.go |
Tests rejection through both flag action hooks. |
cmd/gguf-parser/args.go |
Adds shared GPU-layer validation. |
cmd/gguf-parser/args_test.go |
Tests accepted values and validation errors. |
Review effort: Balanced
fixup: the draft -2 override, per review Signed-off-by: thxCode <thxcode0824@gmail.com>
|
Review round addressed — 1 finding triaged across 1 review, 1 inline thread, and 1 conversation comment (no suppressed blocks).
No upgrade-compatibility items beyond the breaking change this PR already declares (the Verification: OpenCodeReview reported 0 findings; no action needed. |

What
--gpu-layers -1and--gpu-layers-draft -1are rejected with an error.-2estimates as all layers offloaded and is the new default literal. An exactN >= 0behaves unchanged.Why
llama.cpp's
common/arg.cppre-spelled the two sentinel values of-ngl/--gpu-layersand-ngld/--gpu-layers-draft:automaps to-1,allmaps to-2, and the default isauto. GGUF Parser's cmd still carried the old meaning, every negative value fell through to the unset option, and the library estimates the unset option as full offload.A llama.cpp-style
-ngl -1therefore estimated as full offload, while the backend would count the offloadable layers from the host GPU devices at runtime. The estimate has no view of the host devices, so it cannot resolveauto.-2("all") worked only through that undocumented negative fall-through, not as a supported spelling.GPUStack passes
-ngl -1 | -2through to gguf-parser and disallows-1on its own side, see gpustack/gpustack#6768.The change
validateGPULayersrejects-1with a message that names llama.cpp'sautoand points to-2or an exact count, and rejects every value below-2. Both flags wire it through the per-flagActionhook, so an explicit-1errors during flag parsing, before any fetch.-1to-2, so the no-flag default still estimates full offload. The>= 0gates are untouched, and the libraryLMCOffloadLayersAPI stays as-is.--gpu-layers -1, which meant "all layers", must switch to-2or an exact count.Test plan
TestValidateGPULayerscovers the helper contract:-1and values below-2reject with the right message,-2/0/positives pass.TestGPULayersFlagsRejectTheLlamaCppAutoValueruns the real app, so removing anActionhook fails the suite; a mutation check (removing the draft hook) turned it red.go test -raceis green on the cmd module, and the root module is untouched by the branch.make buildproduced all six platform binaries. On a live model,--gpu-layers -2and no flag printed identical results, and--gpu-layers 0took the RAM-only path.