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
ci: the test cells run the suite in parallel, one test file per worker (#1700)
Alpamys Makazhan55defcf480e6
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 6219591e..fa326192 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -581,7 +581,11 @@ jobs:key: hf-${{ runner.os }}-${{ hashFiles('.github/workflows/ci.yml') }}restore-keys: hf-${{ runner.os }}-- name: Install dependencies- run: pip install -e ".[dev]"+ # pytest-xdist runs the suite in parallel (see the test step below); its+ # psutil extra is what `-n logical` counts the CPUs with. Installed here+ # and not in the dev extra: a local run stays serial unless a contributor+ # asks for workers.+ run: pip install -e ".[dev]" "pytest-xdist[psutil]"- name: Warm HF Hub cache (models the tests load)# Pre-download the models the unit tests load, with retries, so a# transient HF Hub 429 (Too Many Requests) on a single matrix cell does@@ -678,7 +682,14 @@ jobs:path: ${{ runner.temp }}/hf-cachekey: hf-${{ runner.os }}-${{ hashFiles('.github/workflows/ci.yml') }}- name: Run unit tests with coverage- run: pytest tests/ -v --tb=short --junitxml=report.xml --cov=soup_cli --cov-report=xml:coverage.xml --cov-report=term-missing:skip-covered+ # One worker per logical CPU and one test FILE per worker (`loadfile`):+ # the tests of a file keep their order and their module-level state, and+ # two files may run at the same moment. Measured 2026-10-07 on Python+ # 3.12 (run 37577416935): ubuntu 2520 s -> 1133 s, Windows 4492 s ->+ # 1390 s, macOS 2003 s -> 992 s, with the same tests passing and coverage+ # unchanged. `--dist load` hands the tests of one file to several workers+ # and is not used: it was no faster, and one timing test failed under it.+ run: pytest tests/ -n logical --dist loadfile -v --tb=short --junitxml=report.xml --cov=soup_cli --cov-report=xml:coverage.xml --cov-report=term-missing:skip-covered- name: Upload coverage to Codecov# ubuntu / 3.10 is the ubuntu cell every gated run has (release, full,# approval) and a quick run does not. It was 3.11 until the approval rundiff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 3eca3972..5fd219ac 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -568,6 +568,16 @@ branch runs every cell.draft, whatever is pushed to it. Mark it ready for review and the quick setstarts on its current head.+**CI runs the tests in parallel.** Every `test (...)` cell runs the suite with+`pytest-xdist`, one test file per worker process (`-n logical --dist loadfile`).+The tests of one file still run in order in one process, but two files can run+at the same moment and in any order. So a test must not depend on another file+having run first, on the working directory another test left behind, or on the+terminal width of the process: give the console an explicit width in the test+instead of setting `COLUMNS`. To reproduce a failure that shows only in CI,+install the plugin (`pip install "pytest-xdist[psutil]"`) and run+`pytest tests/ -n logical --dist loadfile`.+See `.github/workflows/ci.yml`.### Stale CI marks (#1017)diff --git a/tests/test_ci_test_cells_run_in_parallel.py b/tests/test_ci_test_cells_run_in_parallel.pynew file mode 100644index 00000000..0013d478--- /dev/null+++ b/tests/test_ci_test_cells_run_in_parallel.py@@ -0,0 +1,144 @@+"""The `test` cells of CI run the suite in parallel, one test file per worker.++Measured on 2026-10-07 with Python 3.12 (run 37577416935 of the pytest-xdist trial, #1380 and+#1672): ubuntu 2520 s -> 1133 s, Windows 4492 s -> 1390 s, macOS 2003 s -> 992 s, with the same+tests passing and coverage unchanged. These pins keep the three choices that made that run+clean:++* `--dist loadfile`, never `load`: the tests of one file stay in one process and in order;+* `-n logical` with the plugin's `psutil` extra installed, which is what counts the CPUs;+* nothing in `pyproject.toml` turns workers on, so a local `pytest tests/` stays serial.++pyproject is read with regular expressions, not ``tomllib``, which is 3.11+ while this+repository supports 3.10: the convention of ``tests/test_requires_python_bound.py``.+"""++from __future__ import annotations++import re+import shlex+from pathlib import Path+from typing import Any++import pytest+import yaml++ROOT = Path(__file__).resolve().parent.parent+CI = ROOT / ".github" / "workflows" / "ci.yml"+PYPROJECT = ROOT / "pyproject.toml"+CONTRIBUTING = ROOT / "CONTRIBUTING.md"++RUN_STEP = "Run unit tests with coverage"+INSTALL_STEP = "Install dependencies"+++def _jobs() -> dict[str, Any]:+ return yaml.safe_load(CI.read_text(encoding="utf-8"))["jobs"]+++def _step(name: str) -> dict[str, Any]:+ steps = [step for step in _jobs()["test"]["steps"] if step.get("name") == name]+ assert len(steps) == 1, (name, steps)+ return steps[0]+++def _pytest_args() -> list[str]:+ args = shlex.split(str(_step(RUN_STEP)["run"]))+ assert args[:2] == ["pytest", "tests/"], args+ return args+++def _option(args: list[str], flag: str) -> list[str]:+ """Every value given to ``flag``, as ``flag value`` or ``flag=value``."""+ values = [args[index + 1] for index, arg in enumerate(args[:-1]) if arg == flag]+ values += [arg.split("=", 1)[1] for arg in args if arg.startswith(flag + "=")]+ return values+++class TestTheTestJobRunsInParallel:+ def test_one_worker_per_logical_cpu(self) -> None:+ assert _option(_pytest_args(), "-n") == ["logical"]++ def test_one_test_file_per_worker(self) -> None:+ """`load` hands the tests of one file to several workers: module-level state and+ test order inside a file are lost, and a timing test failed under it."""+ assert _option(_pytest_args(), "--dist") == ["loadfile"]++ def test_the_plugin_is_installed_with_its_cpu_counter(self) -> None:+ """Without the `psutil` extra `-n logical` falls back to another count."""+ requirements = shlex.split(str(_step(INSTALL_STEP)["run"]))+ assert requirements[:2] == ["pip", "install"], requirements+ assert "pytest-xdist[psutil]" in requirements+ assert ".[dev]" in requirements++ def test_the_plugin_is_installed_before_the_tests_run(self) -> None:+ names = [step.get("name") for step in _jobs()["test"]["steps"]]+ assert names.index(INSTALL_STEP) < names.index(RUN_STEP)++ @pytest.mark.parametrize(+ "argument",+ [+ "--junitxml=report.xml", # the nightly test-count badge parses it+ "--cov=soup_cli",+ "--cov-report=xml:coverage.xml", # the Codecov upload sends it+ "--cov-report=term-missing:skip-covered",+ "-v",+ "--tb=short",+ ],+ )+ def test_the_reports_the_later_steps_read_are_still_written(self, argument: str) -> None:+ assert argument in _pytest_args()++ def test_no_step_of_any_job_spreads_one_file_over_workers(self) -> None:+ text = CI.read_text(encoding="utf-8")+ runs = [+ str(step["run"])+ for job in _jobs().values()+ for step in job.get("steps", [])+ if "run" in step+ ]+ assert runs, text[:200]+ for run in runs:+ for mode in re.findall(r"--dist[ =](\S+)", run):+ assert mode == "loadfile", run+++class TestALocalRunStaysSerial:+ def _addopts(self) -> list[str]:+ text = PYPROJECT.read_text(encoding="utf-8")+ table = re.search(+ r"^\[tool\.pytest\.ini_options\]\n(.*?)(?=^\[|\Z)", text, re.M | re.S+ )+ assert table is not None+ line = re.search(r'^addopts\s*=\s*"(.*)"\s*$', table.group(1), re.M)+ assert line is not None, table.group(1)+ return shlex.split(line.group(1))++ def _extra_requirements(self) -> list[str]:+ text = PYPROJECT.read_text(encoding="utf-8")+ table = re.search(+ r"^\[project\.optional-dependencies\]\n(.*?)(?=^\[|\Z)", text, re.M | re.S+ )+ assert table is not None+ requirements = re.findall(r'"([^"\n]*)"', table.group(1))+ assert any(requirement.startswith("pytest") for requirement in requirements)+ return requirements++ def test_the_default_options_start_no_workers(self) -> None:+ """Workers are a CI choice. In `addopts` they would also be forced on every local+ run and on every subset run."""+ args = self._addopts()+ assert _option(args, "-n") == []+ assert _option(args, "--numprocesses") == []+ assert _option(args, "--dist") == []++ def test_the_plugin_is_not_a_dev_dependency(self) -> None:+ for requirement in self._extra_requirements():+ assert "xdist" not in requirement.lower(), requirement+++def test_contributing_says_what_a_parallel_run_asks_of_a_test() -> None:+ text = " ".join(CONTRIBUTING.read_text(encoding="utf-8").split())+ assert "CI runs the tests in parallel" in text+ assert "`-n logical --dist loadfile`" in text+ assert 'pip install "pytest-xdist[psutil]"' in textdiff --git a/tests/test_issue1347_boxed_scan.py b/tests/test_issue1347_boxed_scan.pyindex b4b345ef..9ec78064 100644--- a/tests/test_issue1347_boxed_scan.py+++ b/tests/test_issue1347_boxed_scan.py@@ -20,6 +20,11 @@ from soup_cli.utils.final_answer import BoxedAnswer, iter_boxed_answers, parse_c# Long enough that the scan's own cost dominates the interpreter's._GROWTH_INPUT = 20_000+# An absolute ceiling only a scan that is not linear can reach. The growth ratio next to it+# is what pins linearity; this catches a scan that is slow at every size. It was 3.0, and a+# linear scan measured 3.01 on a four-core runner with coverage on and every core busy with+# another test file, so it leaves ten times that.+_CEILING_SECONDS = 30.0def _best_seconds(text: str, repeats: int = 3) -> float:@@ -78,7 +83,7 @@ class TestIssue1347TheScanGrowsLinearly:small_seconds = _best_seconds(small)large_seconds = _best_seconds(large)assert large_seconds < small_seconds * 20, (small_seconds, large_seconds)- assert large_seconds < 3.0, large_seconds+ assert large_seconds < _CEILING_SECONDS, large_secondsdef test_closed_boxes_cost_linear_time_too(self):small = r"\boxed{B} " * _GROWTH_INPUT@@ -89,7 +94,7 @@ class TestIssue1347TheScanGrowsLinearly:small_seconds = _best_seconds(small)large_seconds = _best_seconds(large)assert large_seconds < small_seconds * 20, (small_seconds, large_seconds)- assert large_seconds < 3.0, large_seconds+ assert large_seconds < _CEILING_SECONDS, large_secondsclass TestIssue1347NestedBoxes: