Skip to content

serve: forward KV, setup flags, and aux flag type to web calibration - #238

Merged
Vasyl-Trefilov merged 3 commits into
RustingStudio:mainfrom
Pybsama:fix/serve-calibrate-setup-flags
Dec 6, 2026
Merged

Vasyl-Trefilov merged 3 commits into
RustingStudio:mainfrom
Pybsama:fix/serve-calibrate-setup-flags

Conversation

@Pybsama

@Pybsama Pybsama commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

Problem

When calibration is triggered from the chat page (POST /api/load with "calibrate": true), serve builds CalibSettings through calibrate(...) in src/main.rs, which left three fields behind compared to CLI rustingstrata calibrate:

  1. --kv was dropped: CalibSettings::kv stayed at the default "f16", so bench_sample spawned rustingstrata bench ... --kv f16. Inside Engine::runner, set_kv_env_for(&self.kv, ...) overwrote STRATA_KV_* back to f16 even though serve had set the server's KV env beforehand — calibrating a quantized KV setup (e.g. q8/q4/turbo4* from CLI or web load options) with full f16 KV VRAM.
  2. CalibSetup flags were dropped: CalibSettings::extra stayed empty, ignoring --k, --v, --threads, --cache-ram, --ram-margin, --max-ram, --cpu-frac, --host-share, --arena, --pin, and --prefill-cpu (including web-updated threads and cache_ram).
  3. --mtp-model was mislabeled as --draft-model: calibrate(...) unconditionally wrapped engine.aux_model_path() as "--draft-model", unlike CLI Cmd::Calibrate which preserves "--draft-model" vs "--mtp-model". On architectures such as Inkling 2 (bench_inkling2), forwarding an MTP head under --draft-model causes bench to treat it as a DSpark draft model.

Changes

  • Added Engine::calib_aux() (matching Cmd::Calibrate: --draft-model takes precedence over --mtp-model) and Engine::calib_setup() (forwarding non-default CalibSetup options while continuing to inherit STRATA_PLE set by serve).
  • Extracted serve_calib_settings(model, engine, margins_mb) and updated calibrate(...) plus its sole caller in serve to populate s.kv, s.extra, s.aux, and per-device vram_margin directly in MB without the byte shift round-trip.
  • Added unit test calibrate_cli_tests::serve_calibrate_forwards_kv_setup_and_aux_flag verifying CLI flags, round-tripping through Cli::try_parse_from into Cmd::Bench, web Engine::with overrides (kv/threads/cache_ram), --draft-model vs --mtp-model, and default-Engine empty extra.

Verification

  • cargo test --bin rustingstrata — 65 passed, 0 failed (including serve_calibrate_forwards_kv_setup_and_aux_flag)
  • cargo test --lib calibrate — 12 passed, 0 failed
  • cargo test --test gguf --test mcp --test tokenizer — 37 passed, 0 failed
  • cargo check --all-targets — clean (0 errors, 0 new warnings)

Comment thread src/main.rs
split_arg(engine.split.as_deref(), engine.device.len())?))
.and_then(|mb| {
let _ = split_arg(engine.split.as_deref(), engine.device.len())?;
calibrate(&p, &engine, &mb)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · Correctness · 1 of 2

split is validated then discarded, never forwarded to calibration serve --split 0.7,0.3 loads a sharded run, but calibrate() no longer receives split (old _split was also ignored) and serve_calib_settings has no split field, so bench measures an unsharded run and its VRAM margins/perf do not match serve.

Prompt for your AI agent
File: src/main.rs
Line: 2842
Symbol: run
Issue: split is validated then discarded, never forwarded to calibration serve --split 0.7,0.3 loads a sharded run, but calibrate() no longer receives split (old _split was also ignored) and serve_calib_settings has no split field, so bench measures an unsharded run and its VRAM margins/perf do not match serve.
Make the smallest change that fixes this, add a test, and change nothing unrelated.

Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good to double-check, though not forwarding --split matches v2 calibration's documented behavior in docs/CALIBRATION.md ("With several GPUs (--device 0,1) calibrate keeps the free-VRAM layer split. --split is ignored with a note.") and Cmd::Calibrate (src/main.rs), as well as main before this PR (_split). Multi-GPU sharding is still active during calibration because --device is forwarded to bench (using the free-VRAM split).

In 4446f8f, serve now also emits the same note: --split is ignored by calibrate; measurements use the free-VRAM split message when --split is set (after keeping the existing split_arg validation), and the test verifies --device 1,0 is forwarded while bench.split stays None.

Comment thread src/main.rs
assert_eq!(s.vram_margin, vec!["256", "512"]);
assert_eq!(s.aux, Some(("--mtp-model", PathBuf::from("head.gguf"))));
assert_eq!(s.extra, [
"--k", "q8", "--v", "f16", "--threads", "6", "--cache-ram", "0",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Low · Maintainability · 2 of 2

Test hand-builds bench_args instead of calling bench_sample/calibrate_v2 arg construction The round-trip test manually assembles bench args (order, --gpu, aux placement, extra placement) rather than invoking the actual bench_sample code. Any divergence in real bench_sample (ordering, env handling, extra flags) passes this test while breaking web calibration in production.

Prompt for your AI agent
File: src/main.rs
Line: 6115
Symbol: spec_space_stores_indices_not_actual_values
Issue: Test hand-builds bench_args instead of calling bench_sample/calibrate_v2 arg construction The round-trip test manually assembles bench args (order, --gpu, aux placement, extra placement) rather than invoking the actual bench_sample code. Any divergence in real bench_sample (ordering, env handling, extra flags) passes this test while breaking web calibration in production.
Make the smallest change that fixes this, add a test, and change nothing unrelated.

Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — fixed in 4446f8f by extracting bench_sample_args(...) from bench_sample and having serve_calibrate_forwards_kv_setup_and_aux_flag parse the production bench_sample_args output directly via Cli::try_parse_from.

@aletheore

aletheore Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Aletheore Flash Lite review

What this PR does. This pull request adds a unit test in src/main.rs covering bench_sample_args. The test checks that chunk, short, and mtp are passed as literal values for main calibration, while mtp, spec_type, draft_max, and ngram_n are resolved as indices into calibration lists with out-of-range values clamped to the last entry. It affects the calibrate_cli_tests module and the bench command argument parsing it exercises.

Merge confidence Review effort Merge risk
3 / 5 2 / 5 Medium
Area Files Lines
src 1 +50 −0

1 finding(s) posted as inline review comment(s). 3 earlier finding(s) from previous pushes still open.

# Severity Category Where
1 🔵 Low Maintainability main.rs:6190 Test never exercises KV, CalibSetup, or aux-model forwarding claimed by the PR All three bench_sample_args…
- 🟠 High Correctness main.rs:2842 Earlier finding, still open
- 🔵 Low Maintainability main.rs:6115 Earlier finding, still open
- 🔵 Low Maintainability main.rs:6136 Earlier finding, still open
Review details

Reviewed 1 file(s); skipped 0. Dismissed 0; outside PR diff 0. Grounding: 6 of 6 proposed finding(s).

Fix all with your agent
File: src/main.rs
Line: 6190
Symbol: the_baseline_chunk_is_each_engines_own_default
Issue: Test never exercises KV, CalibSetup, or aux-model forwarding claimed by the PR All three bench_sample_args calls pass None for the final argument and never set CalibSettings.kv or extra/setup fields, so a regression dropping --kv, setup flags, or mislabeling --draft-model/--mtp-model still passes this test.
Make the smallest change that fixes this, add a test, and change nothing unrelated.

Blast radius: no other file in the repo imports the changed file(s), per this commit's import graph.

@aletheore

aletheore Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

🔍 Aletheore evidence diff

What changed
Deterministic, computed from this commit's real scan and import graph - posted on every run, whether or not Flash Review found anything.

  • src/main.rs · modified · +203/-41 · +6 functions

Aggregate deltas

  • Modules: +0
  • Dependency graph edges: +0
  • Commits: 3

Comment thread src/main.rs

// Every forwarded flag must round-trip cleanly through `bench_sample_args` into `Cmd::Bench`.
let mut bench_args = vec![std::ffi::OsString::from("rustingstrata")];
bench_args.extend(bench_sample_args(&s, &Knobs::default(), &s.pp, s.reps, Path::new("out.json"), None));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Low · Maintainability · 1 of 1

Test uses Knobs::default() so mtp/spec/chunk/short knob selection is never exercised bench_sample_args is tested only with default knobs (all indices 0/defaults), so off-by-one, min-clamping, mtp_values index-vs-value, and spec_type/draft_max/ngram_n selection bugs in the extracted function would pass the test while failing in real sweeps with non-zero knobs.

Prompt for your AI agent
File: src/main.rs
Line: 6136
Symbol: serve_calibrate_forwards_kv_setup_and_aux_flag
Issue: Test uses Knobs::default() so mtp/spec/chunk/short knob selection is never exercised bench_sample_args is tested only with default knobs (all indices 0/defaults), so off-by-one, min-clamping, mtp_values index-vs-value, and spec_type/draft_max/ngram_n selection bugs in the extracted function would pass the test while failing in real sweeps with non-zero knobs.
Make the smallest change that fixes this, add a test, and change nothing unrelated.

Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — added bench_sample_args_maps_direct_and_indexed_knobs in 9947bc3 covering non-default direct knobs (chunk, short, mtp without --spec-*), spec sweep index-to-value lookup where index != value (mtp_values, spec_types, draft_max, ngram_n), and upper-bound clamping across all four spec lists, verified via Cli::try_parse_from into Cmd::Bench.

Comment thread src/main.rs
let mut main_knobs = Knobs::default();
main_knobs.set("chunk", 1024.0);
main_knobs.set("short", 513.0);
main_knobs.set("mtp", 3.0);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Low · Maintainability · 1 of 1

Test never exercises KV, CalibSetup, or aux-model forwarding claimed by the PR All three bench_sample_args calls pass None for the final argument and never set CalibSettings.kv or extra/setup fields, so a regression dropping --kv, setup flags, or mislabeling --draft-model/--mtp-model still passes this test.

Prompt for your AI agent
File: src/main.rs
Line: 6190
Symbol: the_baseline_chunk_is_each_engines_own_default
Issue: Test never exercises KV, CalibSetup, or aux-model forwarding claimed by the PR All three bench_sample_args calls pass None for the final argument and never set CalibSettings.kv or extra/setup fields, so a regression dropping --kv, setup flags, or mislabeling --draft-model/--mtp-model still passes this test.
Make the smallest change that fixes this, add a test, and change nothing unrelated.

Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This commit only added bench_sample_args_maps_direct_and_indexed_knobs to cover non-default direct/indexed/clamped knobs (addressing the previous comment); KV, CalibSetup, --vram-margin, --device, and --mtp-model/--draft-model forwarding through bench_sample_args are already covered right above in serve_calibrate_forwards_kv_setup_and_aux_flag (src/main.rs:6110-6174).

@Vasyl-Trefilov
Vasyl-Trefilov merged commit bcdbfb1 into RustingStudio:main Dec 6, 2026
5 checks passed
@Vasyl-Trefilov

Copy link
Copy Markdown
Member

Hi, ty, this is a good fix. I checked it with a web calibrate here: the bench now gets --kv q8, --threads 4 and --cache-ram 1024 from the server, before it was f16 and the defaults. Only the checked page options go into the bench args, so nothing new can come in from the page. Tests pass on my side, I merge it.

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