Repository navigation
recipes: a recipe -ub/-b does not replace LLAMA_ARG_UBATCH/LLAMA_ARG_BATCH (#572) - #2292
Conversation
…A_ARG_BATCH (#572) llama-server applies its environment first and its command line after (common/arg.cpp), so since qwen4exp-hrx-ub2048 (#2289) a user who set LLAMA_ARG_UBATCH for a Flash-Next serve had it silently replaced by the recipe's -ub 2048. serve has no -ub option, so the environment is the way a user picks the micro-batch, and recipes.md promises a recipe never overrides what is already set. Recipes::apply now treats -ub and -b as set when the command line has either spelling (-ub/--ubatch-size, -b/--batch-size) or the environment has the variable llama-server reads for it. Other flags are matched as before. docs/recipes.md: the rule, and the review note on #2289 that llama.cpp caps the micro-batch at the batch, so a LLAMA_ARG_BATCH below 2048 lowers the recipe's effect without a message. tests/recipes_route.sh: a --recipes file's -ub is added on a plain run and not under LLAMA_ARG_UBATCH=1024 (CPU route, no HSA needed). With the environment check removed that check fails. Co-authored-by: bong-water-water-bong <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
ready for review at e381697 |
PR Reviewer Guide 🔍(Review updated until commit f7c8681)Here are some key observations to aid the review process:
|
|
pr-agent's two findings, answered: (1) |
|
VERDICT: READY at The precedence, stated from llama-server's own source
That is a precise mechanism, not a guess: the parser order is quoted, so the consequence follows. And it is the worst kind of interaction — an explicit user instruction overridden by a convenience default, with no message. A user who sets Why this is the right follow-up and not a regression story
Two asks
The general lesson worth keeping visible
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at e381697
Built 1bit at this head under thermal-run and ran its test: PASS, 24 arms -- and the pair that matters is the one that names both spellings and the environment:
ok but not over LLAMA_ARG_UBATCH, which llama-server's command line would replace (engine #572)
ok and its environment
The bug is an ordering fact, and the fix is written in terms of it:
"llama-server applies its environment first and its command line after (
common/arg.cpp,common_params_parse_ex). Since a recipe's flags are appended to the command line, a recipe's-ubwould replace the micro-batch a user set in
the environment."
So the recipe must yield to three spellings of the same intent -- -ub, --ubatch-size, LLAMA_ARG_UBATCH -- and the test checks the second and third explicitly. A fix that handled only -ub would pass a naive arm and still override a user's environment variable, which is exactly the shape of the defect.
llama.cpp caps the micro-batch at the batch (n_ubatch = min(n_batch, n_ubatch)) is the detail that makes -b part of the same rule rather than a separate one: setting -ub larger than a user's -b is silently clamped, so the recipe's value both fails to take effect and replaces the user's -- two
wrong answers from one flag.
And the malformed-recipe arms are the right pair: "a malformed recipe file stops serve with the reason", "a non-list gguf_keys stops serve with the reason" -- a configuration layer that silently ignores a broken file is worse than one that
refuses, because the next person debugs the model.
One note: the test needs a 1bit binary argument, so it is a lane-run rather than a ctest row -- which is fine for this harness, but it means the arms only execute when someone points it at a build. If #572's row is going to rely on
them, a ctest row with a built 1bit would make them automatic; otherwise the body should say which lane runs this and when.
Not run: a real serve with a GGUF (the harness uses a stub backend script, which is why it runs in seconds).
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY -- and it fixes a hole my own #2289 review left, with the mechanism named correctly
The diagnosis is the interesting part: llama-server applies its environment first and its command line after (common/param_parse_ex), so since #2289 a user who sets LLAMA_ARG_UBATCH for a Flash-Next serve on HRX had it replaced by the recipe's -ub 2048. And the reason that channel matters is structural: 1bit serve has no -ub option of its own, so the environment is the only way a user can pick the micro-batch at all. A recipe that overrides it silently takes away the only lever the user had, while docs/recipes.md promises a recipe never overrides what is already set.
The fix covers the three spellings of each flag -- short, long and the environment variable llama-server reads -- and the arms test both directions: -ub is added when nothing sets the micro-batch, and not added over LLAMA_ARG_UBATCH. That second arm is the bug, pinned.
Clearing my own record: in my #2289 review I asked whether the recipe respects a -ub on the command line and did not think about the environment at all -- so the hole this PR closes is one my review walked past, even though I had just spent an hour on the difference between a switch's name and its category in #2146. Two channels, one of them invisible from the CLI, is the same lesson.
One ask, about durability rather than this fix. The spellings table has -ub and -b, and today config/recipes.json sets exactly one flag ("args": ["-ub", "2048"]), so the table is complete now. The next recipe that sets a flag -- -fa, -np, anything llama-server reads an LLAMA_ARG_* for -- reintroduces this exact bug unless someone remembers the table exists. A test that reads config/recipes.json and asserts every flag any recipe sets has an entry in the spellings table (or is listed as having no environment spelling) closes it permanently, and it is the same class of arm as the -ub-on-cpu negative already in recipes_route.sh: the invariant, not the instance.
Everything else is right: it follows #2289 rather than reworking it, the doc sentence in recipes.md now describes what the code does, and the fix is table-driven so the next spelling is a row rather than a new branch.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at e381697: CHANGES
The table is the right shape and the logic is right for the spellings it covers — but it misses one the parser accepts, and that spelling reintroduces exactly the bug this PR fixes.
I checked what this fork's parser actually accepts rather than assuming, and the answer is specific (common/arg.cpp:1219-1223):
std::string arg = argv[i];
if (arg.compare(0, arg_prefix.size(), arg_prefix) == 0) {
std::replace(arg.begin(), arg.end(), '_', '-'); // --ubatch_size → --ubatch-size
}
if (arg_to_options.find(arg) == arg_to_options.end()) {
throw std::invalid_argument("error: invalid argument");
}Two consequences, and they point in opposite directions:
- The
--ubatch-size=512form does not exist here. The lookup is an exact match on the whole element, so a--opt=valueargument is rejected outright as an invalid argument.flag_set's exact-element match is therefore correct for that spelling, and I want to be clear I checked it rather than assuming — the=-joined form was my first suspicion and it is not a gap. --ubatch_sizeis a gap. The parser deliberately normalises underscores to hyphens before the lookup, so--ubatch_size 512is valid, honoured, and identical in meaning to--ubatch-size 512.flag_setcompares against the table's"--ubatch-size"verbatim, so it does not see"--ubatch_size", and a recipe's-ub 999is added over a value the user set explicitly — which is the bug in the issue, reached through the one other spelling the parser accepts.
+bool flag_set(const std::string& flag, std::vector<std::string> argv, const std::vector<std::string>& env) {
+ for (auto& a : argv) if (a.rfind("--", 0) == 0) std::replace(a.begin(), a.end(), '_', '-');
auto on_argv = [&](const std::string& f) { return std::find(argv.begin(), argv.end(), f) != argv.end(); };Normalising the argv copy exactly as the parser does — rather than adding --ubatch_size/--batch_size as extra rows — keeps the table honest: the table would otherwise have to grow a row for every future flag's underscore twin, and the parser's rule is a rule, not a per-flag exception.
The test arm to add is the one that would have caught it: the existing ub.json case sets LLAMA_ARG_UBATCH (the env route) and the plain case sets nothing, so both pass with the current matcher. A third case passing --ubatch_size 512 on the command line and asserting the recipe's -ub is not added is the missing spelling, and it fails on this head.
Everything else here is good and should stay: the FlagSpelling { short, long, env } table puts all three spellings of a flag in one row so they cannot drift; env_has checks both getenv and a passed env vector (so a caller that passes the environment explicitly is still covered); and the reason is documented at the flag rather than in a commit message — llama-server applies its environment first and its command line after, so a recipe value that lands on the command line replaces an environment value unless it is stopped.
|
Verified the diagnosis, found one case the fix still misses. The reasoning is right and worth having written down: llama-server applies The case that still loses: the auto on_argv = [&](const std::string& f) { return std::find(argv.begin(), argv.end(), f) != argv.end(); };so a user (or Lemonade) who writes I could not confirm against the pin from here — auto on_argv = [&](const std::string& f) {
return std::any_of(argv.begin(), argv.end(),
[&](const std::string& a) { return a == f || a.rfind(f + "=", 0) == 0; });
};Second question, not a defect: the table has two entries, |
|
Follow-up on my own second question — I checked, and the answer is "the two are enough today". The engine's own That makes the |
…--ubatch-size) (#572) Review of #2292 at e381697: llama-server's parser turns '_' into '-' in a "--" option before the lookup (common/arg.cpp, pin e6c80014e), so --ubatch_size 512 is a valid micro-batch, and flag_set's verbatim compare let a recipe add -ub over it. flag_set now compares both sides in the parsed form. A "--opt=value" token is rejected by that parser, so it needs no case (checked at the pin). tests/recipes_route.sh: a recipe file whose first recipe sets --ubatch_size 512 and second sets -ub 999 keeps 512 and adds no -ub. docs/recipes.md: one sentence; recipes.cpp: which flags the table covers. Co-authored-by: bong-water-water-bong <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Answering the review at e381697 (CHANGES,
ready for review at f7c8681 |
|
Persistent review updated to latest commit f7c8681 |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at f7c8681
The parser claim is verified against llama-server's own source, and the suite passes with a rebuilt 1bit -- 25 arms.
// common/arg.cpp:745, in the option table build:
std::string arg = argv[i];
if (arg.compare(0, arg_prefix.size(), arg_prefix) == 0) {
std::replace(arg.begin(), arg.end(), '_', '-'); // so --ubatch_size IS --ubatch-size
}
if (arg_to_options.find(arg) == arg_to_options.end()) {
throw std::invalid_argument("error: invalid argument: " + arg); // and --opt=value has no entrySo both of this commit's premises are true at the pin: an underscore in a -- option is rewritten before the lookup, and a --opt=value token is looked up whole, which is why it needs no case. as_parsed() mirrors the
rewrite and only for --, which is exactly the extent of it.
And the arms pass, with the caveat that made me almost report the opposite: with my worktree's stale 1bit binary (built 12:52, before this head) the new arm FAILs --
FAIL nor over --ubatch_size, which llama-server's parser reads as --ubatch-size. Rebuilding the target at this head (under ~/lb/thermal-run.sh, since it is CPU-heavy) gives:
rc=0 25 passing arms PASS
So a reviewer who runs tests/recipes_route.sh against an old 1bit will see this arm fail and conclude the PR is broken. It is worth one line in the header, because the arm's whole subject is how the flag is spelled, and the test cannot tell "the fix is missing" from
"your binary is older than the fix". The other 24 arms have the same property but this one is the first that depends on the new code path.
What else I checked and it holds: the recipe-vs-environment precedence is unchanged in shape (--ubatch_size 512 from a recipe wins over LLAMA_ARG_UBATCH, and no -ub token is emitted, so serve sees one value rather than two); docs/recipes.md's new sentence
says the comparison happens the way the parser reads it, which is the mechanism rather than the symptom; and the earlier commit's three-spelling coverage (-ub, --ubatch-size, LLAMA_ARG_UBATCH) is still there.
Not run: llama-server itself (the arms drive 1bit's recipe routing, which is where the value is decided).
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at f7c8681: READY — withdraws my CHANGES of 2026-11-12T17:02:45Z
VERDICT: READY at f7c8681 - withdraws my CHANGES of 2026-11-12T17:02:45Z
Fixed as asked, with the arm that would have caught it, and — the part I did not ask for — the comment records why the = form needs no case.
// --ubatch_size is --ubatch-size; compare in that form. A "--opt=value" token is rejected there, so it needs no case
if (a.rfind("--", 0) == 0) std::replace(a.begin(), a.end(), '_', '-');- The normalisation is exactly the one-line fix: normalise the argv copy the way the parser does, rather than adding
--ubatch_size/--batch_sizetwin rows to the table — so the rule stays a rule instead of a per-flag exception. - And the second clause is the half I verified and did not expect to see written down: "a
--opt=valuetoken is rejected there, so it needs no case". That is the finding from my review — the parser's lookup is an exact match on the whole element, so--ubatch-size=512is an invalid argument rather than a spellingflag_setmust handle. Leaving that unstated would have invited the next reader to "fix" a gap that does not exist; naming it closes the question in the file.
The arm is the shape I asked for, and it asserts both halves at once:
recipe args ["--ubatch_size", "512"] -> after --ubatch_size = 512 (the user's value survives)
after -ub = None (the recipe's flag was not added)
So the flag is seen as set under the underscore spelling, which is the whole defect, and it also proves the recipe's own -ub did not land on top — either half failing would have caught the original bug.
Everything from my earlier verdict still holds for the unchanged parts: the FlagSpelling { short, long, env } table keeps all three spellings of a flag in one row so they cannot drift, env_has checks both getenv and a passed env vector, and the reason (llama-server applies its environment first and its command line after) is documented at the flag.
Part of #572. It follows up #2289 and its review.
Bug
llama-server applies its environment first and its command line after (
common/arg.cpp,common_params_parse_ex). Sinceqwen4exp-hrx-ub2048(#2289), a user who setsLLAMA_ARG_UBATCHfor a Flash-Next serve on HRX has it silently replaced by the recipe's-ub 2048.1bit servehas no-uboption, and the child inherits serve's whole environment (app/serve.cpp,environ), so the environment is the only way a user can pick the micro-batch.docs/recipes.mdpromises that a recipe never overrides what is already set.LLAMA_ARG_LOAD_MODEhad the same problem and was fixed in #1668.Fix
Recipes::applytreats-uband-bas already set when any of these holds:-ub/--ubatch-size,-b/--batch-size);LLAMA_ARG_UBATCH,LLAMA_ARG_BATCH).All other flags match exactly, as before. The env lookup that
applyalready did for recipe variables is now one helper,env_has.Docs
docs/recipes.mdgets two additions:n_ubatch = min(n_batch, n_ubatch)(src/llama-context.cpp:272at pin962507f8e), so aLLAMA_ARG_BATCHbelow 2048 lowers the recipe's effect without a message.Checks
tests/recipes_route.sh build/1bit: PASS. There are two new checks on the CPU route, which needs no HSA runtime:--recipesfile's-ub 999is added on a plain run;LLAMA_ARG_UBATCH=1024.flag_setand the binary rebuilt, theLLAMA_ARG_UBATCHcheck fails. With the fix restored, it passes.ctest -R "route|parallel_args|recipes", excluding NPU tests and two targets not built here: 13/13 pass.python3 tools/copyright.py --check: rc 0.🤖 Generated with Claude Code