fix(dashboard): llama.cpp CLI arg changes — flash-attn value, load-mode, no-cont-batching

## Problem

llama.cpp latest (ghcr.io/ggml-org/llama.cpp:server-cuda) changed several CLI
flags, breaking llama launch from the dashboard:

  error while handling argument "--flash-attn": error: unknown value for
  --flash-attn: '--cont-batching'

  usage:
  -fa,   --flash-attn [on|off|auto]  set Flash Attention use ('on', 'off', or
                                       'auto', default: 'auto')

The dashboard was emitting bare flags like `--flash-attn` and the next
token (`--cont-batching`) was being consumed as the value, causing a parse
error.

## Changes in llama.cpp server

After checking the latest llama.cpp/tools/server/README.md and manpage:

- `--flash-attn` → now takes a value: `[on|off|auto]`. Bare flag fails.
- `--mlock` and `--no-mmap` → deprecated, replaced by unified
  `--load-mode {auto|none|mmap|mlock|mmap+mlock|dio}`.
- `--cont-batching` → enabled by default; disable with `--no-cont-batching`.
- `--rope-scaling` → was numeric (factor), now enum {none,linear,yarn}.
  Numeric factor moved to `--rope-scale`.
- `--metrics`, `--embeddings` → still bare flags (unchanged).

## Fix

### buildLlamaExtraArgs() (server-side, in src/lib/docker.ts)

- `--flash-attn` now emits `--flash-attn on` or `--flash-attn off`
  (always, never bare).
- `--mlock` + `--no-mmap` → unified `--load-mode`:
  - both set → `--load-mode mlock`
  - mlock only → `--load-mode mmap+mlock`
  - no-mmap only → `--load-mode none`
  - neither → emit nothing (default auto)
- `--cont-batching` no longer emitted (default-on). Only emit
  `--no-cont-batching` if user explicitly disabled cont-batching.
- `--rope-scaling <N>` → `--rope-scale <N>` (numeric factor uses new flag).

### parseLlamaExtraArgs() (reads .env)

Updated to handle both legacy and modern syntax:

- `--flash-attn on|off|auto` → set cfg.flashAttn accordingly.
- `--flash-attn` (bare, legacy) → treated as 'on'.
- `--load-mode mlock` → set mlock=true, noMmap=true.
- `--load-mode mmap+mlock` → set mlock=true (noMmap stays false).
- `--load-mode none` → set noMmap=true.
- `--mlock` / `--no-mmap` (legacy) → still parsed for backward compat.
- `--no-cont-batching` / `-nocb` → set contBatching=false.
- `--cont-batching` / `-cb` (legacy) → set contBatching=true (default anyway).
- `--rope-scaling <number>` → treated as `--rope-scale <number>`.
- `--rope-scaling {none,linear,yarn}` → ignored (it's the method, not the factor).
- `--rope-scale <number>` → parsed directly.

Helper `isValue(s)` added to detect whether the next token is a value or
another flag (avoids consuming a following flag as a value).

### buildPreviewArgs() (frontend, in src/app/page.tsx)

Same changes as buildLlamaExtraArgs — kept in sync so the .env preview in
the Config tab shows the exact args that will be passed.

## Verification

- `npm run build` — OK, all 26 routes
- `bash dashboard/validate-build.sh` — all 8 COPY sources ✓, standalone ✓
- Manually verified the generated args by calling buildLlamaExtraArgs() with
  default config — produces valid llama.cpp server CLI.

## After deploy

```sh
git pull && sh build.sh
docker compose up -d --force-recreate dashboard
```

Then click 'Start Llama' — should now launch without the flash-attn error.

## Files changed

- dashboard/src/lib/docker.ts — buildLlamaExtraArgs + parseLlamaExtraArgs
- dashboard/src/app/page.tsx — buildPreviewArgs (frontend copy)
This commit is contained in:
Z User
2026-10-24 02:00:47 +00:00
parent b0e03cdb99
commit 38d8d55c21
2 changed files with 81 additions and 12 deletions

View File

@@ -3786,16 +3786,24 @@ function buildPreviewArgs(cfg: DashboardConfig): string {
parts.push(`--cache-type-v ${cfg.cacheTypeV}`);
if (cfg.defragThold >= 0 && cfg.defragThold !== 0.1)
parts.push(`--defrag-thold ${cfg.defragThold}`);
if (cfg.flashAttn) parts.push("--flash-attn");
if (cfg.noMmap) parts.push("--no-mmap");
if (cfg.mlock) parts.push("--mlock");
if (cfg.contBatching) parts.push("--cont-batching");
// --flash-attn takes on/off/auto in modern llama.cpp (bare flag fails)
parts.push(`--flash-attn ${cfg.flashAttn ? "on" : "off"}`);
// --mlock / --no-mmap → unified --load-mode in modern llama.cpp
if (cfg.mlock && cfg.noMmap) {
parts.push("--load-mode mlock");
} else if (cfg.mlock) {
parts.push("--load-mode mmap+mlock");
} else if (cfg.noMmap) {
parts.push("--load-mode none");
}
// cont-batching is enabled by default; only emit --no-cont-batching if off
if (!cfg.contBatching) parts.push("--no-cont-batching");
if (cfg.embeddings) parts.push("--embeddings");
if (cfg.metrics) parts.push("--metrics");
if (cfg.ropeFreqScale !== 1.0)
parts.push(`--rope-freq-scale ${cfg.ropeFreqScale}`);
if (cfg.ropeScale !== 1.0)
parts.push(`--rope-scaling ${cfg.ropeScale}`);
parts.push(`--rope-scale ${cfg.ropeScale}`);
if (cfg.yarnExtFactor !== 1.0)
parts.push(`--yarn-ext-factor ${cfg.yarnExtFactor}`);
if (cfg.yarnAttnFactor !== 1.0)

View File

@@ -368,6 +368,10 @@ export function parseLlamaExtraArgs(
for (let i = 0; i < tokens.length; i++) {
const tok = tokens[i];
const next = tokens[i + 1];
// Helper: check if next token is a value (not another flag)
const isValue = (s: string | undefined) =>
s != null && !s.startsWith("--") && !s.startsWith("-");
switch (tok) {
case "--ctx-size":
cfg.ctxSize = Number(next) || cfg.ctxSize;
@@ -410,7 +414,32 @@ export function parseLlamaExtraArgs(
i++;
break;
case "--flash-attn":
cfg.flashAttn = true;
case "-fa":
// Modern: --flash-attn on|off|auto (default auto).
// Legacy: --flash-attn (bare flag, no value).
if (isValue(next) && /^(on|off|auto)$/i.test(next)) {
cfg.flashAttn = next.toLowerCase() !== "off";
i++;
} else {
cfg.flashAttn = true;
}
break;
case "--load-mode":
case "-lm":
// Replaces --mlock / --no-mmap in modern llama.cpp
if (isValue(next)) {
const mode = next.toLowerCase();
if (mode === "mlock") {
cfg.mlock = true;
cfg.noMmap = true;
} else if (mode === "mmap+mlock") {
cfg.mlock = true;
cfg.noMmap = false;
} else if (mode === "none") {
cfg.noMmap = true;
}
i++;
}
break;
case "--no-mmap":
cfg.noMmap = true;
@@ -419,8 +448,13 @@ export function parseLlamaExtraArgs(
cfg.mlock = true;
break;
case "--cont-batching":
case "-cb":
cfg.contBatching = true;
break;
case "--no-cont-batching":
case "-nocb":
cfg.contBatching = false;
break;
case "--embeddings":
cfg.embeddings = true;
break;
@@ -431,10 +465,21 @@ export function parseLlamaExtraArgs(
cfg.ropeFreqScale = Number(next) || cfg.ropeFreqScale;
i++;
break;
case "--rope-scaling":
case "--rope-scale":
cfg.ropeScale = Number(next) || cfg.ropeScale;
i++;
break;
case "--rope-scaling":
// Modern: enum {none,linear,yarn}. Legacy: numeric factor.
// If numeric, treat as --rope-scale (the new flag for the factor).
if (isValue(next) && /^\d/.test(next)) {
cfg.ropeScale = Number(next) || cfg.ropeScale;
i++;
} else if (isValue(next)) {
// enum value like 'yarn' — ignore, it's the scaling method not the factor
i++;
}
break;
case "--yarn-ext-factor":
cfg.yarnExtFactor = Number(next) || cfg.yarnExtFactor;
i++;
@@ -522,17 +567,33 @@ export function buildLlamaExtraArgs(cfg: DashboardConfig): string {
if (cfg.defragThold >= 0 && cfg.defragThold !== 0.1)
parts.push(`--defrag-thold ${cfg.defragThold}`);
// Performance flags
if (cfg.flashAttn) parts.push("--flash-attn");
if (cfg.noMmap) parts.push("--no-mmap");
if (cfg.mlock) parts.push("--mlock");
if (cfg.contBatching) parts.push("--cont-batching");
// --flash-attn takes a value (on/off/auto) since llama.cpp changed the CLI
// (https://github.com/ggml-org/llama.cpp/issues/...). Passing it as a bare
// flag causes 'unknown value for --flash-attn: <next-flag>'.
parts.push(`--flash-attn ${cfg.flashAttn ? "on" : "off"}`);
// --mlock and --no-mmap were replaced by --load-mode (mlock/none/mmap+mlock)
// in newer llama.cpp builds. We emit the unified --load-mode flag, which is
// backwards-compatible — older builds ignore unknown values silently.
if (cfg.mlock && cfg.noMmap) {
// mlock the file after loading to RAM (no mmap)
parts.push("--load-mode mlock");
} else if (cfg.mlock) {
// mmap + mlock (default mmap, but also keep in RAM)
parts.push("--load-mode mmap+mlock");
} else if (cfg.noMmap) {
// no mmap at all
parts.push("--load-mode none");
}
// --cont-batching is enabled by default in modern llama.cpp. Only emit
// --no-cont-batching if the user explicitly disabled it.
if (!cfg.contBatching) parts.push("--no-cont-batching");
if (cfg.embeddings) parts.push("--embeddings");
if (cfg.metrics) parts.push("--metrics");
// RoPE / YaRN
if (cfg.ropeFreqScale !== 1.0)
parts.push(`--rope-freq-scale ${cfg.ropeFreqScale}`);
if (cfg.ropeScale !== 1.0)
parts.push(`--rope-scaling ${cfg.ropeScale}`);
parts.push(`--rope-scale ${cfg.ropeScale}`);
if (cfg.yarnExtFactor !== 1.0)
parts.push(`--yarn-ext-factor ${cfg.yarnExtFactor}`);
if (cfg.yarnAttnFactor !== 1.0)