Skip to content

armgit / Soup

Public Imported from GitHub
0

Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.

fix(eval): handle typer.Exit cleanly in auto-eval custom tasks (#1641) (#1658)

Nurkhan Esenbek8ef35df881b7
diff --git a/changelog.d/0.75.1/1658.fixed.md b/changelog.d/0.75.1/1658.fixed.md
new file mode 100644
index 00000000..7ef64653
--- /dev/null
+++ b/changelog.d/0.75.1/1658.fixed.md
@@ -0,0 +1 @@
+- **Handle `typer.Exit` cleanly in `soup train` auto-eval custom tasks (#1641 by @kok-o in #1658).** Catch `typer.Exit` when executing auto-eval custom tasks to avoid printing an unhandled traceback and reporting the run as failed.
diff --git a/src/soup_cli/commands/train.py b/src/soup_cli/commands/train.py
index f2b8186b..69f70604 100644
--- a/src/soup_cli/commands/train.py
+++ b/src/soup_cli/commands/train.py
@@ -160,6 +160,11 @@ def _run_auto_eval_after_training(eval_config, output_dir: str, run_id: str) ->
output=None,
trust_remote_code=False,
)
+ except typer.Exit:
+ logger.debug("Auto-eval custom skipped", exc_info=True)
+ console.print(
+ "[yellow]Auto-eval custom skipped (see the message above)[/]"
+ )
except Exception as exc:
logger.exception("Auto-eval custom failed")
console.print(
diff --git a/tests/test_eval_platform.py b/tests/test_eval_platform.py
index 17092295..f2698116 100644
--- a/tests/test_eval_platform.py
+++ b/tests/test_eval_platform.py
@@ -1106,6 +1106,34 @@ class TestAutoEvalAfterTraining:
assert custom.call_args.kwargs["model"] == "/tmp/saved-adapter"
assert custom.call_args.kwargs["tasks"] == "tasks.jsonl"
+ def test_a_benchmark_that_exits_is_reported_as_skipped(self, capsys):
+ import typer
+
+ from soup_cli.commands.train import _run_auto_eval_after_training
+ from soup_cli.config.schema import EvalConfig
+
+ with patch("soup_cli.commands.eval.benchmark", side_effect=typer.Exit(1)):
+ _run_auto_eval_after_training(
+ EvalConfig(auto_eval=True, benchmarks=["mmlu"]), "out", "run-1"
+ )
+ out = " ".join(_strip_ansi(capsys.readouterr().out).split())
+ assert "Auto-eval benchmark skipped" in out
+ assert "Auto-eval benchmark failed" not in out
+
+ def test_a_custom_eval_that_exits_is_reported_as_skipped(self, capsys):
+ import typer
+
+ from soup_cli.commands.train import _run_auto_eval_after_training
+ from soup_cli.config.schema import EvalConfig
+
+ with patch("soup_cli.commands.eval.custom", side_effect=typer.Exit(1)):
+ _run_auto_eval_after_training(
+ EvalConfig(auto_eval=True, custom_tasks="tasks.jsonl"), "out", "run-1"
+ )
+ out = " ".join(_strip_ansi(capsys.readouterr().out).split())
+ assert "Auto-eval custom skipped" in out
+ assert "Auto-eval custom failed" not in out
+
def test_auto_eval_runs_on_the_adapter_this_run_saved(
self, tmp_path, monkeypatch
):