Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.
Python cliconsumer-gpudpofine-tuningggufhuggingfacellmllmopslocal-ailocal-llmloralow-vrammachine-learningollamapeftpythonpytorchqlorasfttransformers
fix(train): refuse the start confirm when stdin is not a TTY (#2052)
vaputa11fad3d71b5f
diff --git a/changelog.d/0.76.0/2052.fixed.md b/changelog.d/0.76.0/2052.fixed.mdnew file mode 100644index 00000000..f402eb78--- /dev/null+++ b/changelog.d/0.76.0/2052.fixed.md@@ -0,0 +1,5 @@+- `soup train` no longer stalls on the interactive `Start training?` confirm+ when stdin is not a TTY (pipes, CI, services): the run now refuses up front+ with a message naming `--yes`. Answering the confirm by piping `y` into+ stdin is replaced by that same refusal — pass `--yes` instead+ (#2077 reported by @feloau in #2052).diff --git a/docs/cli-reference.md b/docs/cli-reference.mdindex 402f0c0b..093e220f 100644--- a/docs/cli-reference.md+++ b/docs/cli-reference.md@@ -3647,7 +3647,7 @@ Usage: `soup train [OPTIONS]`| `--find-lr-end` | float | `0.1` | | LR range finder: ending LR (default 1e-1) || `--find-lr-steps` | integer | `100` | | LR range finder: number of sweep steps (default 100) || `--find-lr-output` | text | `lr_finder.json` | | LR range finder: JSON report path (default ./lr_finder.json) |-| `--yes`, `-y` | flag | off | | Skip confirmation prompt |+| `--yes`, `-y` | flag | off | | Skip the start-training confirmation. Required when stdin is not a TTY (scripts, CI, pipes). || `--trust-remote-code` | flag | off | | Allow loading models that ship custom Python via auto_map. Default deny (v0.36.0). Only enable if you trust the source. || `--echo-trap-tokenizer-aware` | flag | off | | Use tokenizer-id n-grams for echo-trap scoring. Requires training.echo_trap_enabled=true on grpo/ppo. || `--reward-hack-detector` | text | | | Reward-hacking detector for GRPO/PPO: info_rm \| rm_ensemble. Overrides training.reward_hack_detector. (v0.71.26) |diff --git a/src/soup_cli/commands/train.py b/src/soup_cli/commands/train.pyindex 4f3eb3ac..b002c6bf 100644--- a/src/soup_cli/commands/train.py+++ b/src/soup_cli/commands/train.py@@ -7,6 +7,7 @@ import jsonimport loggingimport osimport re+import sysfrom pathlib import Pathfrom typing import TYPE_CHECKING, Annotated, Any@@ -77,6 +78,11 @@ _UNWIRED_TRAINING_TUNABLES = ()+def _stdin_isatty() -> bool:+ """True when standard input is an interactive terminal."""+ return sys.stdin.isatty()++def _nondefault_unwired_training_settings(training_config) -> list[str]:"""Return staged training settings whose value differs from the schema default."""fields = type(training_config).model_fields@@ -678,7 +684,10 @@ def train(False,"--yes","-y",- help="Skip confirmation prompt",+ help=(+ "Skip the start-training confirmation. Required when stdin is "+ "not a TTY (scripts, CI, pipes)."+ ),),trust_remote_code: bool = typer.Option(False,@@ -1723,6 +1732,18 @@ def train(raise typer.Exit(1) from excif not dry_run and not yes:+ # #1913: on a non-TTY stdin the confirm can never be answered — a pipe+ # hangs until its writer closes (EOF aborts via typer) and an+ # unattended service waits forever. Fail with the escape hatch named.+ from soup_cli.utils.exit_codes import EXIT_USAGE_ERROR++ if not _stdin_isatty():+ console.print(+ "[red]stdin is not a TTY, so the start-training confirmation "+ "cannot be answered.[/] Pass --yes to start without the "+ "confirmation."+ )+ raise typer.Exit(EXIT_USAGE_ERROR)if not typer.confirm("Start training?", default=True):console.print("[yellow]Cancelled.[/]")raise typer.Exit()diff --git a/tests/test_train_nontty_confirm.py b/tests/test_train_nontty_confirm.pynew file mode 100644index 00000000..04a011a6--- /dev/null+++ b/tests/test_train_nontty_confirm.py@@ -0,0 +1,142 @@+"""Regression tests for #1913 Finding C: with stdin not a TTY and no `--yes`,+`soup train` printed the interactive `Start training? [Y/n]:` confirm and+stalled — a pipe waits until its writer closes (EOF → Aborted) and an+unattended service waits forever.++After the fix the run refuses up front with a diagnostic that names `--yes`.+The pre-fix behaviour of answering the confirm by piping `y` into stdin is+intentionally not preserved: a non-interactive stdin now always refuses, so+the escape hatch is the flag.+"""++from __future__ import annotations++from pathlib import Path+from unittest.mock import Mock++import pytest++from soup_cli.cli import app+from tests.cli_runner import CliRunner+from tests.conftest import strip_ansi+++class _DatasetLoadReachedError(Exception):+ """Stop before dataset loading can perform any work."""+++def loading_spies(monkeypatch):+ loader = Mock(side_effect=_DatasetLoadReachedError)+ builder = Mock(side_effect=AssertionError("The trainer must not be built"))+ monkeypatch.setattr("soup_cli.commands.train.load_dataset", loader)+ monkeypatch.setattr("soup_cli.trainer.dispatch.build_trainer", builder)+ return loader, builder+++def _output(result) -> str:+ return " ".join(strip_ansi(result.output).split())+++def _write_config(tmp_path: Path) -> Path:+ train = tmp_path / "train.jsonl"+ row = '{"messages": [{"role": "user", "content": "q"}, {"role": "assistant", "content": "a"}]}'+ train.write_text(+ row + "\n" + row + "\n", encoding="utf-8",+ )+ path = tmp_path / "soup.yaml"+ path.write_text(+ "base: some-model\ntask: sft\nbackend: transformers\n"+ f"data:\n train: {train.as_posix()}\n format: chatml\n"+ " val_split: 0\n"+ "training:\n quantization: none\n"+ f"output: {(tmp_path / 'out').as_posix()}\n",+ encoding="utf-8",+ )+ return path+++def test_train_without_tty_and_without_yes_exits_usage_error(+ tmp_path: Path, monkeypatch, loading_spies,+) -> None:+ monkeypatch.setenv("HF_HUB_OFFLINE", "1")+ monkeypatch.chdir(tmp_path)+ monkeypatch.setattr("soup_cli.commands.train._stdin_isatty", lambda: False)+ config = _write_config(tmp_path)++ result = CliRunner().invoke(app, ["train", "--config", str(config)])++ output = _output(result)+ assert result.exit_code == 3, (result.output, repr(result.exception))+ assert "stdin is not a TTY" in output+ assert "--yes" in output+ assert "Start training?" not in output+ loader, builder = loading_spies+ loader.assert_not_called()+ builder.assert_not_called()+++def test_train_with_yes_on_nontty_skips_the_confirm(+ tmp_path: Path, monkeypatch, loading_spies,+) -> None:+ monkeypatch.setenv("HF_HUB_OFFLINE", "1")+ monkeypatch.chdir(tmp_path)+ monkeypatch.setattr("soup_cli.commands.train._stdin_isatty", lambda: False)+ config = _write_config(tmp_path)++ result = CliRunner().invoke(+ app, ["train", "--config", str(config), "--yes"],+ )++ output = _output(result)+ loader, builder = loading_spies+ loader.assert_called_once()+ assert isinstance(result.exception, _DatasetLoadReachedError), (output, repr(result.exception))+ assert "stdin is not a TTY" not in output+ assert "Start training?" not in output+ builder.assert_not_called()+++def test_train_dry_run_on_nontty_without_yes_validates(+ tmp_path: Path, monkeypatch, loading_spies,+) -> None:+ monkeypatch.setenv("HF_HUB_OFFLINE", "1")+ monkeypatch.chdir(tmp_path)+ monkeypatch.setattr("soup_cli.commands.train._stdin_isatty", lambda: False)+ config = _write_config(tmp_path)+ loader, builder = loading_spies+ loader.side_effect = None+ loader.return_value = {"train": [{"text": "sample"}]}++ result = CliRunner().invoke(app, ["train", "--config", str(config), "--dry-run"])++ output = _output(result)+ assert result.exit_code == 0, (output, repr(result.exception))+ assert "Config valid" in output+ assert "stdin is not a TTY" not in output+ assert "Start training?" not in output+ loader.assert_called_once()+ builder.assert_not_called()+++def test_train_on_tty_answers_confirm_normally(+ tmp_path: Path, monkeypatch, loading_spies,+) -> None:+ import soup_cli.commands.train as train_mod++ monkeypatch.setenv("HF_HUB_OFFLINE", "1")+ monkeypatch.chdir(tmp_path)+ monkeypatch.setattr(train_mod, "_stdin_isatty", lambda: True)+ config = _write_config(tmp_path)++ result = CliRunner().invoke(+ app, ["train", "--config", str(config)], input="n\n",+ )++ output = _output(result)+ assert result.exit_code == 0, (output, repr(result.exception))+ assert "Start training?" in output+ assert "Cancelled." in output+ loader, builder = loading_spies+ loader.assert_not_called()+ builder.assert_not_called()