Repository navigation
serve: forward KV, setup flags, and aux flag type to web calibration - #238
Conversation
| 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) |
There was a problem hiding this comment.
🟠 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.
There was a problem hiding this comment.
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.
| 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", |
There was a problem hiding this comment.
🔵 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.
There was a problem hiding this comment.
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 Flash Lite reviewWhat 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.
1 finding(s) posted as inline review comment(s). 3 earlier finding(s) from previous pushes still open.
Review detailsReviewed 1 file(s); skipped 0. Dismissed 0; outside PR diff 0. Grounding: 6 of 6 proposed finding(s). Fix all with your agentBlast radius: no other file in the repo imports the changed file(s), per this commit's import graph. |
🔍 Aletheore evidence diffWhat changed
Aggregate deltas
|
|
|
||
| // 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)); |
There was a problem hiding this comment.
🔵 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.
There was a problem hiding this comment.
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.
| let mut main_knobs = Knobs::default(); | ||
| main_knobs.set("chunk", 1024.0); | ||
| main_knobs.set("short", 513.0); | ||
| main_knobs.set("mtp", 3.0); |
There was a problem hiding this comment.
🔵 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.
There was a problem hiding this comment.
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).
|
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. |
Problem
When calibration is triggered from the chat page (
POST /api/loadwith"calibrate": true),servebuildsCalibSettingsthroughcalibrate(...)insrc/main.rs, which left three fields behind compared to CLIrustingstrata calibrate:--kvwas dropped:CalibSettings::kvstayed at the default"f16", sobench_samplespawnedrustingstrata bench ... --kv f16. InsideEngine::runner,set_kv_env_for(&self.kv, ...)overwroteSTRATA_KV_*back tof16even thoughservehad set the server's KV env beforehand — calibrating a quantized KV setup (e.g.q8/q4/turbo4*from CLI or web load options) with fullf16KV VRAM.CalibSetupflags were dropped:CalibSettings::extrastayed empty, ignoring--k,--v,--threads,--cache-ram,--ram-margin,--max-ram,--cpu-frac,--host-share,--arena,--pin, and--prefill-cpu(including web-updatedthreadsandcache_ram).--mtp-modelwas mislabeled as--draft-model:calibrate(...)unconditionally wrappedengine.aux_model_path()as"--draft-model", unlike CLICmd::Calibratewhich preserves"--draft-model"vs"--mtp-model". On architectures such as Inkling 2 (bench_inkling2), forwarding an MTP head under--draft-modelcausesbenchto treat it as a DSpark draft model.Changes
Engine::calib_aux()(matchingCmd::Calibrate:--draft-modeltakes precedence over--mtp-model) andEngine::calib_setup()(forwarding non-defaultCalibSetupoptions while continuing to inheritSTRATA_PLEset byserve).serve_calib_settings(model, engine, margins_mb)and updatedcalibrate(...)plus its sole caller inserveto populates.kv,s.extra,s.aux, and per-devicevram_margindirectly in MB without the byte shift round-trip.calibrate_cli_tests::serve_calibrate_forwards_kv_setup_and_aux_flagverifying CLI flags, round-tripping throughCli::try_parse_fromintoCmd::Bench, webEngine::withoverrides (kv/threads/cache_ram),--draft-modelvs--mtp-model, and default-Engine emptyextra.Verification
cargo test --bin rustingstrata— 65 passed, 0 failed (includingserve_calibrate_forwards_kv_setup_and_aux_flag)cargo test --lib calibrate— 12 passed, 0 failedcargo test --test gguf --test mcp --test tokenizer— 37 passed, 0 failedcargo check --all-targets— clean (0 errors, 0 new warnings)