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(sweep): wire the standalone sweep config via --sweep-config (#1475)
Amir Fathic1e7ada48e32
diff --git a/changelog.d/0.75.1/1475.fixed.md b/changelog.d/0.75.1/1475.fixed.mdnew file mode 100644index 00000000..81f61aa4--- /dev/null+++ b/changelog.d/0.75.1/1475.fixed.md@@ -0,0 +1 @@+- Wire the "Standalone Sweep Config" docs example: `soup sweep --sweep-config sweep.yaml` now loads `strategy`/`n_runs`/`seed`/`params` from a separate YAML file, instead of `--param` being a required option that the documented invocation never supplied (#1465 by @AmirF194 in #1475).diff --git a/docs/backends-and-ops.md b/docs/backends-and-ops.mdindex 9a25854b..a9de3207 100644--- a/docs/backends-and-ops.md+++ b/docs/backends-and-ops.md@@ -895,8 +895,12 @@ Five-question wizard input β fully-validated `soup.yaml`. Literal allowlists o## Standalone Sweep Config+`--config` stays the base `soup.yaml` to train against; `--sweep-config` points at a+separate file holding the strategy, run count, seed and swept parameters, in place of+repeating `--param` on the command line.+```bash-soup sweep --config sweep.yaml+soup sweep --config soup.yaml --sweep-config sweep.yaml``````yaml@@ -911,6 +915,17 @@ params:Strict scalar allowlist on values (`str` / `int` / `float` / `bool`); `_MAX_FILE_BYTES=256KB`, `_MAX_PARAM_KEYS=32`, `_MAX_VALUES_PER_KEY=64`; `SweepSpec.params` is `MappingProxyType[str, Tuple[Any, ...]]` for genuine immutability.+`--param` and `--sweep-config` are mutually exclusive. With `--sweep-config`:++- The file's `strategy` and `seed` win over `--strategy`.+- A non-zero `n_runs` wins over `--max-runs`; `0` or absent falls back to `--max-runs`.+- `n_runs` only caps the run count, so a grid smaller than `n_runs` runs every combination+ (the example above is 3 x 3 = 9, so it runs 9 trials, not 20).+- `seed` seeds the random sampler.++A file that omits `strategy`, combined with `--strategy random --max-runs 2` on the command+line, silently runs grid, because the file's default `grid` wins over both flags.+## Alternative Model Hubs (ModelScope / Modelers)diff --git a/docs/commands.md b/docs/commands.mdindex 9d2a84f7..3c26e38a 100644--- a/docs/commands.md+++ b/docs/commands.md@@ -96,6 +96,7 @@ soup serve --model <m> --record-thumbs ./rl.db Capture π/π feedback intosoup serve --model <m> --kv-cache-type bf16|f16|q8_0|fp8 KV-cache type (transformers; q8_0 needs hqq; fp8 = vLLM+Hopper only) (v0.71.14)POST /v1/adapters/activate/<name> Hot-swap active LoRA adaptersoup sweep --config soup.yaml --param lr=... Hyperparameter search+soup sweep --config soup.yaml --sweep-config sweep.yaml Sweep from a standalone strategy/n_runs/seed/params filesoup diff --model-a ./a --model-b ./b Compare two modelssoup data inspect <path> View dataset statssoup data validate <path> Check format (auto-detect)diff --git a/src/soup_cli/commands/sweep.py b/src/soup_cli/commands/sweep.pyindex 968f5b68..a4db9aaf 100644--- a/src/soup_cli/commands/sweep.py+++ b/src/soup_cli/commands/sweep.py@@ -7,11 +7,13 @@ from pathlib import Pathfrom typing import Optionalimport typer+import yamlfrom rich.console import Consolefrom rich.panel import Panelfrom rich.table import Tablefrom soup_cli.config.loader import load_config+from soup_cli.utils.sweep_config import load_sweep_yamlfrom soup_cli.utils.terminal import for_terminalconsole = Console()@@ -57,12 +59,21 @@ def sweep("-c",help="Path to base soup.yaml config file",),- param: list[str] = typer.Option(- ...,+ param: Optional[list[str]] = typer.Option(+ None,"--param","-p",help="Parameter to sweep: key=val1,val2,val3 (e.g., lr=1e-5,2e-5,5e-5)",),+ sweep_config: Optional[str] = typer.Option(+ None,+ "--sweep-config",+ help=(+ "Path to a standalone sweep YAML (strategy/n_runs/seed/params) "+ "instead of --param; its strategy, n_runs and seed take "+ "precedence over --strategy/--max-runs"+ ),+ ),strategy: str = typer.Option("grid","--strategy",@@ -103,12 +114,35 @@ def sweep(console.print(f"[red]Config not found: {config_path}[/]")raise typer.Exit(1)+ if param and sweep_config:+ console.print("[red]Use either --param or --sweep-config, not both.[/]")+ raise typer.Exit(1)++ if sweep_config:+ try:+ spec = load_sweep_yaml(sweep_config)+ except (OSError, ValueError, TypeError, yaml.YAMLError) as exc:+ console.print(+ f"[red]Failed to load --sweep-config {for_terminal(sweep_config)}: "+ f"{for_terminal(exc)}[/]"+ )+ raise typer.Exit(1) from exc+ sweep_params = {key: list(values) for key, values in spec.params.items()}+ strategy = spec.strategy+ max_runs = spec.n_runs or max_runs+ random.seed(spec.seed)+ elif param:+ sweep_params = _parse_sweep_params(param)+ else:+ console.print(+ "[red]Provide --param, or --sweep-config for a standalone sweep file.[/]"+ )+ raise typer.Exit(1)+if strategy not in ("grid", "random"):console.print(f"[red]Invalid strategy: {strategy}. Must be grid or random.[/]")raise typer.Exit(1)- # Parse sweep parameters- sweep_params = _parse_sweep_params(param)if not sweep_params:console.print("[red]No valid sweep parameters provided.[/]")raise typer.Exit(1)diff --git a/tests/test_v0440_part_d.py b/tests/test_v0440_part_d.pyindex bbe32173..7b29872b 100644--- a/tests/test_v0440_part_d.py+++ b/tests/test_v0440_part_d.py@@ -6,6 +6,7 @@ import osfrom pathlib import Pathimport pytest+import yamlfrom typer.testing import CliRunnerfrom soup_cli.cli import app@@ -39,6 +40,8 @@ from soup_cli.utils.sweep_config import (parse_sweep_yaml,)+from .conftest import strip_ansi+runner = CliRunner()@@ -374,6 +377,166 @@ def test_load_sweep_yaml_rejects_null_byte(tmp_path, monkeypatch):load_sweep_yaml("bad\x00.yaml")+# --- sweep --sweep-config (#1465) -------------------------------------------+#+# docs/backends-and-ops.md's "Standalone Sweep Config" section documented+# `soup sweep --config sweep.yaml` (issue #1465): --param is a required+# option that this invocation never supplies, and load_sweep_yaml/SweepSpec+# above had no caller anywhere in the CLI. --sweep-config is the new,+# dedicated flag; --config keeps meaning "base soup.yaml" throughout.++_BASE_SOUP_YAML = """\+base: hf/model+task: sft+data:+ train: ./t.jsonl+ format: auto+output: ./o+"""++_SWEEP_YAML = """\+strategy: grid+n_runs: 20+seed: 42+params:+ lr: [0.0001, 0.0005]+ epochs: [1, 3]+"""+++def _write_sweep_fixture(tmp_path):+ (tmp_path / "soup.yaml").write_text(_BASE_SOUP_YAML, encoding="utf-8")+ (tmp_path / "sweep.yaml").write_text(_SWEEP_YAML, encoding="utf-8")+++def test_cli_sweep_config_dry_run_lists_the_grid(tmp_path, monkeypatch):+ monkeypatch.chdir(tmp_path)+ _write_sweep_fixture(tmp_path)+ result = runner.invoke(+ app,+ ["sweep", "--config", "soup.yaml", "--sweep-config", "sweep.yaml", "--dry-run"],+ )+ assert result.exit_code == 0, (result.output, repr(result.exception))+ # 2 lr values x 2 epochs values = 4 grid combinations, matching sweep.yaml.+ assert "Runs: 4" in strip_ansi(result.output)+ assert "Strategy: grid" in strip_ansi(result.output)+++def test_cli_sweep_config_seed_makes_random_reproducible(tmp_path, monkeypatch):+ monkeypatch.chdir(tmp_path)+ (tmp_path / "soup.yaml").write_text(_BASE_SOUP_YAML, encoding="utf-8")+ (tmp_path / "sweep.yaml").write_text(+ "strategy: random\nn_runs: 2\nseed: 7\n"+ "params:\n lr: [1, 2, 3, 4, 5]\n epochs: [1, 2, 3, 4, 5]\n",+ encoding="utf-8",+ )+ first = runner.invoke(+ app,+ ["sweep", "--config", "soup.yaml", "--sweep-config", "sweep.yaml", "--dry-run"],+ )+ second = runner.invoke(+ app,+ ["sweep", "--config", "soup.yaml", "--sweep-config", "sweep.yaml", "--dry-run"],+ )+ assert first.exit_code == 0 and second.exit_code == 0+ assert "Runs: 2" in strip_ansi(first.output)+ assert first.output == second.output+++def test_cli_sweep_config_overrides_cli_strategy_and_max_runs(tmp_path, monkeypatch):+ monkeypatch.chdir(tmp_path)+ _write_sweep_fixture(tmp_path)+ result = runner.invoke(+ app,+ [+ "sweep",+ "--config", "soup.yaml",+ "--sweep-config", "sweep.yaml",+ "--strategy", "random",+ "--max-runs", "1",+ "--dry-run",+ ],+ )+ assert result.exit_code == 0, (result.output, repr(result.exception))+ # sweep.yaml says strategy: grid, so its 4 combinations win over the+ # --strategy/--max-runs flags above, not a 1-run random sample.+ assert "Strategy: grid" in strip_ansi(result.output)+ assert "Runs: 4" in strip_ansi(result.output)+++def test_cli_sweep_without_param_or_sweep_config_fails(tmp_path, monkeypatch):+ monkeypatch.chdir(tmp_path)+ (tmp_path / "soup.yaml").write_text(_BASE_SOUP_YAML, encoding="utf-8")+ result = runner.invoke(app, ["sweep", "--config", "soup.yaml"])+ assert result.exit_code == 1+ assert "--sweep-config" in result.output+++def test_cli_sweep_rejects_param_and_sweep_config_together(tmp_path, monkeypatch):+ monkeypatch.chdir(tmp_path)+ _write_sweep_fixture(tmp_path)+ result = runner.invoke(+ app,+ [+ "sweep",+ "--config", "soup.yaml",+ "--param", "lr=1e-5,2e-5",+ "--sweep-config", "sweep.yaml",+ ],+ )+ assert result.exit_code == 1+ assert "not both" in result.output+++def test_cli_sweep_config_invalid_file_fails_cleanly(tmp_path, monkeypatch):+ monkeypatch.chdir(tmp_path)+ (tmp_path / "soup.yaml").write_text(_BASE_SOUP_YAML, encoding="utf-8")+ (tmp_path / "sweep.yaml").write_text("strategy: bogus\n", encoding="utf-8")+ result = runner.invoke(+ app,+ ["sweep", "--config", "soup.yaml", "--sweep-config", "sweep.yaml", "--dry-run"],+ )+ assert result.exit_code == 1+ assert "Failed to load --sweep-config" in result.output+++def _plan(tmp_path, monkeypatch, sweep_text):+ monkeypatch.chdir(tmp_path)+ (tmp_path / "soup.yaml").write_text(_BASE_SOUP_YAML, encoding="utf-8")+ (tmp_path / "sweep.yaml").write_text(sweep_text, encoding="utf-8")+ return runner.invoke(+ app,+ ["sweep", "--config", "soup.yaml", "--sweep-config", "sweep.yaml", "--dry-run"],+ )+++def test_cli_sweep_config_yaml_syntax_error_fails_cleanly(tmp_path, monkeypatch):+ result = _plan(tmp_path, monkeypatch, "strategy: [unclosed\nparams: {\n")+ assert result.exit_code == 1+ assert not isinstance(result.exception, yaml.YAMLError), repr(result.exception)+ assert "Failed to load --sweep-config" in strip_ansi(result.output)+++def test_cli_sweep_config_error_keeps_the_bracketed_key(tmp_path, monkeypatch):+ result = _plan(tmp_path, monkeypatch, "params:\n lr: 0.1\n")+ assert result.exit_code == 1+ assert "params[lr] must be a list" in strip_ansi(result.output)+++def test_cli_sweep_config_seed_comes_from_the_file(tmp_path, monkeypatch):+ body = (+ "strategy: random\nn_runs: 2\n"+ "params:\n lr: [1, 2, 3, 4, 5]\n epochs: [1, 2, 3, 4, 5]\n"+ )+ plans = {+ seed: strip_ansi(_plan(tmp_path, monkeypatch, f"seed: {seed}\n" + body).output)+ for seed in (7, 8)+ }+ again = strip_ansi(_plan(tmp_path, monkeypatch, "seed: 7\n" + body).output)+ assert plans[7] == again+ assert plans[7] != plans[8]++# --- llama_proxy ------------------------------------------------------------def test_known_subcommands_immutable():