Skip to content

fix(cli): select devices for evaluation and calibration - #71

Merged
Unshure merged 1 commit into
strands-labs:mainfrom
ikenyal:fix/eval-calibrate-device
Oct 14, 2026
Merged

Unshure merged 1 commit into
strands-labs:mainfrom
ikenyal:fix/eval-calibrate-device

Conversation

@ikenyal

@ikenyal ikenyal commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Human Overview

I wanted evaluation and calibration to work on machines without CUDA, just like ask and serve. This change lets both commands select or explicitly receive a torch device, without changing the calibration method or evaluation metrics.

Description

eval and calibrate omit the device argument, so the existing library functions default to CUDA even on machines without it.

Add --device to both commands. An explicit value is forwarded unchanged; when omitted, the existing _auto_device() chooses CUDA, then MPS, then CPU. Document the torch-only evaluation path.

The calibration algorithm, metric calculations, dataset splits, CLI visibility, and library function defaults remain unchanged. This is independent of the serving warmup in #70.

Related Issues

Fixes #44

Type of Change

Bug fix

Testing

Full offline suites: Python 3.12 — 411 passed, 21 skipped; Python 3.10 with CI floor pins — 396 passed, 22 skipped. The 17 distributed tests passed separately. Added 17 regressions covering device selection/forwarding, preserved CLI settings, help, and real CPU checkpoint calibration/evaluation. ruff check ., mypy ./src (CI-style detached lint environment), formatting of the new test, and package builds passed.

  • I ran pytest -q locally (GPU tests skip automatically without CUDA)
  • I ran ruff check . and mypy ./src locally and both pass

Additional Details

Validation scope
  • All 17 new regression cases failed before the implementation. CUDA/MPS availability and argument forwarding are tested with stubs. Both automatic CPU fallback and explicit --device cpu also run the real CLI on a tiny local random-weight Qwen3 checkpoint, save calibration, and evaluate with the saved temperatures.
  • The tests preserve the default calibration/test split, sampling limit, batch size, raw evaluation, and report output. They download no model weights and run with HF_HUB_OFFLINE=1.
  • pytest -q -m distributed passed 17 CPU tests; one unavailable optional-backend module was skipped during collection. The normal suites deselected these distributed tests.
  • No released-checkpoint CUDA or MPS run was performed. This change does not claim identical floating-point metrics across devices or improved inference performance. MLX evaluation/calibration is outside this change.
  • Python 3.12 used torch 2.14.1 and transformers 5.19.0. Python 3.10 used the CI pins: torch 2.7.1, transformers 5.15.0, peft 0.21.0, and huggingface_hub 1.5.0.
  • The existing tensor-to-scalar warning in test_gemma4_train remains on Python 3.12. The Python 3.10 environment has the same upstream Starlette httpx deprecation warning seen on unchanged tests. No warning suppression, dependency, or typing-policy changes are included; lint uses the same detached setup as CI.

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

The dependency item is not applicable: both the selection helper and library device arguments are already on main; this PR does not depend on #70 or a package release.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ikenyal
ikenyal marked this pull request as ready for review October 12, 2026 19:23
Unshure added a commit that referenced this pull request Oct 13, 2026
- pytest pythonpath now adds "tests" and "training/tests" too, so
  `pytest training/tests` on its own succeeds (test_variance imports
  helpers from tests/test_checkpoint_load and tests/test_hf_export, which
  previously only resolved when tests/ was collected first).
- mypy scope extended from `./src` to `./src ./training --exclude
  training/tests`, so train/evaluate/soup/distributed/data/* are now
  strict-checked (36 source files vs 13). `datasets.*` restored to the
  ignore_missing_imports overrides since training now imports it.
- Stale src/strands_decider/data/ path refs rewritten to training/data/
  in test_adequacy, test_distill, test_catchall docstrings,
  data/README.md, gen_adequacy_openrouter.py, gen_documents.py and
  gen_documents_openrouter.py.
- Added a comment on the [train] extra explaining it's for the repo
  install, since the code that uses `datasets` lives under training/
  (not in the wheel).

Deferred: the #71 collision (device selection on eval/calibrate) --
easier to carry here once #71 lands.
Unshure added a commit that referenced this pull request Oct 13, 2026
…from the CLI (#73)

* refactor(cli): split inference from training; drop training commands from the CLI

The published `strands_decider` package now ships inference only
(ask/serve/info); training, evaluation, calibration, soup and corpus-building
move to `training/`, invoked as `python -m training.<module>` from the recipe
scripts.

- src/strands_decider/ keeps the shared modules (modeling, schema, prompting,
  naming, hf_export, vision) plus the serving stack.
- training/ gains train.py, evaluate.py, soup.py, distributed.py and data/
  (moved via git mv to preserve history), with typer entry points so
  `python -m training.{train,evaluate,soup,data}` replace the removed
  `strands-decider {train,eval,calibrate,soup,data}` subcommands.
- recipe.sh and recipe_v7.sh rewritten to call the modules directly.
- Tests, configs, docs and setup-host.sh repointed to the new paths; pytest
  pythonpath adds "." so `import training.*` resolves without an install.

* refactor(training): hoist CLI imports to module top; drop _main wrappers

train.py / evaluate.py / soup.py had their typer/rich imports and command
functions buried inside a `_main()` wrapper -- a leftover habit from the
inference CLI, where lazy imports keep `ask` snappy. The training entry
points are not latency-sensitive and typer/rich are already in the base
install, so this does nothing but add indent.

Flatten each to top-level imports and a module-level `app` (evaluate) or
`_cli` function (train, soup), with the `__main__` block running typer
directly.

* test: move training/eval tests to training/tests/

Mirrors the inference/training split: tests covering training code
(train, evaluate, soup, distributed, data/*, configs, recipe scripts,
data/SHA256SUMS) move to training/tests/, while inference-side tests
stay in tests/. conftest.py (determinism + env setup) lifts to the
repo root so both test trees pick it up.

pyproject.toml: testpaths = ["tests", "training/tests"]; the SLF001
ruff ignore extended to training/tests. CI's tests.yml now watches
training/** and includes training/ in coverage.

ROOT path lookups in moved tests updated from parents[1] to parents[2]
(the files are one directory deeper now).

* fix(training): absolute import for SlotHead in train.py's init_from path

train.py:409's `from .modeling import SlotHead` was a leftover relative
import to the now-missing training.modeling. Only fires when
cfg.init_from loads an existing checkpoint, which the test suite does
not exercise, so hatch run test stayed green. Verified by training a
second checkpoint with init_from pointing at a prior run.

* fix(refactor): close out stale references after the training/inference split

Blockers:
- evaluation/*.py imports from training.*, but recipe.sh invoked them as
  `python evaluation/<name>.py`, which puts evaluation/ at sys.path[0]
  (so `training` is unimportable). Added evaluation/__init__.py and
  changed training/recipe.sh:200-210 to `python -m evaluation.<name>`.
- data/checks/verify_synth_{labels,pairs}.py still imported from
  strands_decider.data.* -- repointed to training.data.*.

Stale references:
- training/README.md and training/distributed.py docstring still showed
  `-m strands_decider.cli train`; now `-m training.train`.
- data/README.md, data/sources.md, data/generators/README.md,
  data/generators/gen_paraphrases_openrouter.py: `python -m
  strands_decider.data.*` and `strands-decider {train,eval,calibrate,data}`
  rewritten to the new `python -m training.*` form.
- src/strands_decider/hf_export.py's model-card "Trained by" line and the
  internal_evals docstring; src/strands_decider/modeling.py's
  --max-options and `calibrate` comments. hf_export's strings land in the
  published model-card provenance, so they are intentionally caught here.
- training/tests/test_configs.py:11 cosmetic docstring.

Verified: `python -m evaluation.multistep_eval --help` and
`python -m evaluation.pair_eval` both run; the full test suite stays green.

* fix(refactor): fix remaining bare-path script invocations under the new layout

data/checks/verify_synth_{labels,pairs}.py now import from training.data.*
(the strands_decider.data package no longer exists), so invoking them as
`python data/checks/<name>.py` -- the form their docstring still showed --
puts data/checks/ at sys.path[0] and the import fails. The same regression
hit evaluation/multistep_eval.py and friends, whose docstrings and
evaluation/README.md's step-5 block still had `python evaluation/<name>.py`.

Make data/ and data/checks/ Python packages (empty __init__.py), repoint the
verify_synth_pairs docstring to `python -m data.checks.verify_synth_pairs`,
and sweep the evaluation scripts and README to `python -m evaluation.<name>`.
Verified with `python -m data.checks.verify_synth_labels` and
`python -m data.checks.verify_synth_pairs` (both pass), and
`python -m evaluation.pair_eval` (prints its usage block from the right
cwd); test suite stays green.

* chore(refactor): address review feedback on PR #73

- pytest pythonpath now adds "tests" and "training/tests" too, so
  `pytest training/tests` on its own succeeds (test_variance imports
  helpers from tests/test_checkpoint_load and tests/test_hf_export, which
  previously only resolved when tests/ was collected first).
- mypy scope extended from `./src` to `./src ./training --exclude
  training/tests`, so train/evaluate/soup/distributed/data/* are now
  strict-checked (36 source files vs 13). `datasets.*` restored to the
  ignore_missing_imports overrides since training now imports it.
- Stale src/strands_decider/data/ path refs rewritten to training/data/
  in test_adequacy, test_distill, test_catchall docstrings,
  data/README.md, gen_adequacy_openrouter.py, gen_documents.py and
  gen_documents_openrouter.py.
- Added a comment on the [train] extra explaining it's for the repo
  install, since the code that uses `datasets` lives under training/
  (not in the wheel).

Deferred: the #71 collision (device selection on eval/calibrate) --
easier to carry here once #71 lands.

* revert(hf_export): keep `strands-decider train` in the Gemma 4 model card

Per review (PR #73 r4262485759): the Gemma 4 v1 models that are already
published were trained with `strands-decider train`, so naming the new
`python -m training.train` command in their card misdates it. The
retrain docstring further down already points today's readers at
`training/recipe.sh`, so keeping the historic command here loses no
information.

The Qwen `trained_by` line (line 106) is unaffected because it already
names `training/recipe.sh all`, not the removed CLI verb.

* refactor(training.evaluate): rename `evaluate` subcommand back to `eval`

Per review (PR #73 r4262485775): the lab notes and the recipe scripts all
say "eval", and `python -m training.evaluate evaluate` reads awkwardly.
Rename the subcommand (eval_cmd, @app.command("eval")) and sweep the
tree: training/recipe.sh, training/recipe_v7.sh, evaluation/README.md,
docs/architecture.md, src/strands_decider/hf_export.py's provenance
line, and the sibling calibrate docstring's split-reference now say
`python -m training.evaluate eval`.

Also restore the two pieces of help text that fell off during the
original move: eval's "Defaults to the `test` half, which calibrate does
not fit on" and calibrate's "Run this before serving. Without it,
`confidence` is whatever the raw head produced, and the documented
thresholds will not hold." Verified with `python -m training.evaluate
{eval,calibrate} --help`; full suite + mypy still clean.
@Unshure
Unshure force-pushed the fix/eval-calibrate-device branch from add7335 to 4fe3505 Compare October 13, 2026 20:55
The eval and calibrate commands omit the device argument and inherit the
library's CUDA default on every host. Add an explicit --device override
and reuse the existing CUDA, MPS, then CPU automatic selection.

Keep the library defaults, calibration algorithm, metric calculations,
and data split behavior unchanged. Add offline forwarding regressions
and real CPU-checkpoint calibration/evaluation checks, and document the
torch-only device selection.

Fixes strands-labs#44
@Unshure
Unshure force-pushed the fix/eval-calibrate-device branch from 4fe3505 to cee8351 Compare October 13, 2026 21:05
@Unshure
Unshure merged commit ea25191 into strands-labs:main Oct 14, 2026
12 checks passed
nonatofabio added a commit that referenced this pull request Oct 14, 2026
…e mlx

#71 added --device to eval and calibrate. collect_logits still moved the bare model to the
device, so on MPS and CPU it ran without the serving kernels and fp32 CPU torso that
strands-decider serve uses. It now prepares the model through SystemOneEngine: on CPU, eval
runs 3.4 times faster, and MPS gives the numbers CPU and serve give. --device mlx is
refused with a clear message; MLX has no logits path.
nonatofabio added a commit that referenced this pull request Oct 16, 2026
…e mlx (#79)

#71 added --device to eval and calibrate. collect_logits still moved the bare model to the
device, so on MPS and CPU it ran without the serving kernels and fp32 CPU torso that
strands-decider serve uses. It now prepares the model through SystemOneEngine: on CPU, eval
runs 3.4 times faster, and MPS gives the numbers CPU and serve give. --device mlx is
refused with a clear message; MLX has no logits path.
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.

eval and calibrate hardcode device=cuda, so neither can run on a Mac

4 participants