Skip to content

fix: align gpu-layers with llama.cpp -1/-2 word values - #68

Merged
thxCode merged 4 commits into
mainfrom
fix/ngl-minus-one-minus-two-alignment
Nov 12, 2026
Merged

thxCode merged 4 commits into
mainfrom
fix/ngl-minus-one-minus-two-alignment

Conversation

@thxCode

@thxCode thxCode commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

What

--gpu-layers -1 and --gpu-layers-draft -1 are rejected with an error. -2 estimates as all layers offloaded and is the new default literal. An exact N >= 0 behaves unchanged.

Why

llama.cpp's common/arg.cpp re-spelled the two sentinel values of -ngl/--gpu-layers and -ngld/--gpu-layers-draft: auto maps to -1, all maps to -2, and the default is auto. 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 -1 therefore 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 resolve auto. -2 ("all") worked only through that undocumented negative fall-through, not as a supported spelling.

GPUStack passes -ngl -1 | -2 through to gguf-parser and disallows -1 on its own side, see gpustack/gpustack#6768.

The change

  • validateGPULayers rejects -1 with a message that names llama.cpp's auto and points to -2 or an exact count, and rejects every value below -2. Both flags wire it through the per-flag Action hook, so an explicit -1 errors during flag parsing, before any fetch.
  • The two flag defaults move from -1 to -2, so the no-flag default still estimates full offload. The >= 0 gates are untouched, and the library LMCOffloadLayers API stays as-is.
  • The parameter mapping in cmd/gguf-parser/README.md documents the word values, and the root README gains the release note.
  • BREAKING CHANGE: scripts passing --gpu-layers -1, which meant "all layers", must switch to -2 or an exact count.

Test plan

  • TestValidateGPULayers covers the helper contract: -1 and values below -2 reject with the right message, -2/0/positives pass.
  • TestGPULayersFlagsRejectTheLlamaCppAutoValue runs the real app, so removing an Action hook fails the suite; a mutation check (removing the draft hook) turned it red.
  • go test -race is green on the cmd module, and the root module is untouched by the branch. make build produced all six platform binaries. On a live model, --gpu-layers -2 and no flag printed identical results, and --gpu-layers 0 took the RAM-only path.

- 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>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 09:49
@gpustack-code-review

gpustack-code-review Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🔍 OpenCodeReview found 1 issue(s) in this PR.

  • ✅ Successfully posted inline: 0 comment(s)
  • 📋 Routed to summary by policy: 1 comment(s)

documentation · low

📄 cmd/gguf-parser/args.go (L109-L109)

⚠️ GitHub could not post this as an inline comment: Routed to summary (severity low · category documentation)

The new code makes an explicit distinction that the READMEs don't capture: omitting --gpu-layers-draft (default -2) inherits the main model's --gpu-layers value, while explicitly passing -2 forces full offload. Both README.md and cmd/gguf-parser/README.md currently say "-2 means offloading all layers, which is the default", which no longer matches the unset-flag path (inheriting, not necessarily full offload). Per the repo rule that docs and CLI change together, add a sentence to the GPU Layers Word Values section documenting the draft-model inheritance behavior.

Reviewed 417a1d9..d2ee947 only; earlier commits in this PR were reviewed in a previous run.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 -2 for both main and draft GPU-layer flags.
  • Changes default literals to -2 and 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

Comment thread cmd/gguf-parser/main.go Resolved
fixup: the draft -2 override, per review
Signed-off-by: thxCode <thxcode0824@gmail.com>
@thxCode

thxCode commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

Review round addressed — 1 finding triaged across 1 review, 1 inline thread, and 1 conversation comment (no suppressed blocks).

Finding Verdict Outcome
Copilot: draft -2 inherits the main model offload limit and understates VRAM (main.go, high) Engineering issue — confirmed Fixed in d2ee947: the draft assembly resolves through draftOffloadOverride(draft, draftSet); an explicit -2 appends the full-offload sentinel instead of inheriting, while an unset draft keeps following the main model. TestDraftOffloadOverride locks the decision matrix; the fix also covers the non-0 variants of the same defect.

No upgrade-compatibility items beyond the breaking change this PR already declares (the -1 rejection): the defect sat on explicit -2 calls that had no documented meaning before this PR, and the fix completes the -2 = "all layers" contract this PR documents.

Verification: go test -race -count=1 green on the cmd module, go vet clean, gofmt clean, make generate re-run — it fails on this machine for a pre-existing toolchain reason (the pinned stringer cannot type-check the root package against current dependency export data, the same mismatch as the golangci-lint binary); the branch touches no generator-fed types, so no generated output can drift from it.

OpenCodeReview reported 0 findings; no action needed.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block approval of the CLI GPU-layer changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@thxCode
thxCode merged commit 805b142 into main Nov 12, 2026
4 checks passed
@thxCode
thxCode deleted the fix/ngl-minus-one-minus-two-alignment branch November 12, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants