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: verify isolated core dependency floors (#1927)
Nurkhan Esenbek45d6942d23f2
diff --git a/.github/constraints/core-floor.txt b/.github/constraints/core-floor.txtnew file mode 100644index 00000000..56dd041c--- /dev/null+++ b/.github/constraints/core-floor.txt@@ -0,0 +1,14 @@+# #1802: every [project] dependency at its declared inclusive lower bound.+# Keep this core-only: [dev]/[train] require newer versions of these packages.+# tests/test_core_dependency_floors.py binds these pins to metadata and CI.+typer==0.15.4+click==8.0.0+rich==13.0.0+pydantic==2.0.0+pyyaml==6.0+# PyPI has no stable 0.16.0, and 0.16.1 is yanked; 0.16.2 is the first available+# admitted by >=0.16.0. Keep the declaration and this exception bound by the test.+huggingface-hub==0.16.2+# Likewise, PyPI has no 5.2.0 or 5.2.1; >=5.2.0 first admits 5.2.2.+plotext==5.2.2+packaging==21.0diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 00ae0013..0c7329ba 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -131,12 +131,12 @@ jobs:## So `plan` picks one of four matrices, and every job except `lint` follows it:#- # push to release/** RELEASE: all nine test cells + the five gated jobs+ # push to release/** RELEASE: all nine test cells + the six gated jobs# nightly run on main, a manual FULL: seven test cells (no Windows or macOS- # dispatch on 3.11) + the five gated jobs+ # dispatch on 3.11) + the six gated jobs# pull request labelled ci:full APPROVAL: the four required test cells (ubuntu# on 3.10 and 3.12, Windows and macOS on- # 3.12) + the five gated jobs+ # 3.12) + the six gated jobs# push to main, any other pull QUICK: lint + test (ubuntu-latest, 3.12)# request run# draft pull request nothing: no job starts@@ -474,13 +474,72 @@ jobs:path: ${{ runner.temp }}/hf-cachekey: hf-pytorch-smoke-${{ runner.os }}-${{ hashFiles('tests/test_smoke_train.py', 'pyproject.toml') }}+ # #1802: the training stack requires newer core dependencies, so its floor job+ # cannot exercise every light-core floor. Install only the core here, on the+ # oldest supported Python (PyYAML 6.0 has wheels for it), and start the CLI.+ core-floor:+ needs: plan+ if: needs.plan.outputs.full == 'true'+ runs-on: ubuntu-latest+ timeout-minutes: 15+ env:+ PYTHONUTF8: "1"+ PYTHONIOENCODING: "utf-8"+ steps:+ - uses: actions/checkout@v4+ - uses: actions/setup-python@v5+ with:+ python-version: "3.10"+ - name: Isolate core floors from runner tooling+ # Runner/image tooling can require newer packages (wheel>=0.46 needs+ # packaging>=24) than the core floor. Keep that graph outside this cell.+ run: |+ python -m venv "$RUNNER_TEMP/soup-core-floor"+ echo "$RUNNER_TEMP/soup-core-floor/bin" >> "$GITHUB_PATH"+ - name: Install the declared core dependency floors+ # pytest 9 requires packaging>=22, above Soup's packaging>=21 floor.+ # The test runner is tooling, so keep its compatible major here.+ run: pip install -e . "pytest>=7,<9" -c .github/constraints/core-floor.txt+ - name: Verify constrained core dependency graph+ run: python -m pip check+ - name: Assert core floor versions+ shell: python+ run: |+ import importlib.metadata as md+ import importlib.util+ import re+ from pathlib import Path++ from packaging.version import Version++ constraints = Path(".github/constraints/core-floor.txt").read_text(encoding="utf-8")+ pairs = re.findall(r"^([A-Za-z0-9_-]+)==([^\s#]+)\s*$", constraints, re.MULTILINE)+ expected = dict(pairs)+ assert expected and len(expected) == len(pairs), "missing or duplicate core pins"+ for name, want in expected.items():+ got = md.version(name)+ assert Version(got) == Version(want), f"core-floor expected {name}=={want}, got {got}"+ print(f"{name}={got} (matches declared floor)")+ for name in ("torch", "transformers", "accelerate", "peft", "trl", "datasets", "bitsandbytes"):+ assert importlib.util.find_spec(name) is None, f"core-floor installed {name}"+ - name: Run core floor command tree, help and startup checks+ run: >+ pytest -o addopts= -q+ tests/test_core_dependency_floors.py+ tests/test_cli_dependency_floors.py+ tests/test_click_argument_help.py+ tests/test_cli_startup_is_light.py+ tests/test_cli.py+ tests/test_cli_subprocess.py+ tests/test_plotext_compat.py+# #502/#503/#522/#571/#651: install the exact Torch 2.6.0 / Transformers 5.16.1 /# trl 0.29 / PEFT 0.20 support stack and Plotext 6.0.0 so pip cannot silently# upgrade the cell, then assert every pinned compatibility boundary.# #1802: the same file pins Typer and Click to the floors pyproject.toml declares,- # and the last step starts the CLI on them. It is the one cell that does: every- # other cell resolves the newest Typer, which is how a floor no command could run- # on stayed declared. The job keeps its name; branch protection requires it.+ # and the last step starts the CLI on them, alongside the core-only cell above.+ # The ordinary test matrix resolves the newest Typer, which is how a floor no+ # command could run on stayed declared. Keep the name; branch protection requires it.transformers-floor:needs: planif: needs.plan.outputs.full == 'true'diff --git a/changelog.d/0.76.0/1927.changed.md b/changelog.d/0.76.0/1927.changed.mdnew file mode 100644index 00000000..86a63cb9--- /dev/null+++ b/changelog.d/0.76.0/1927.changed.md@@ -0,0 +1 @@+- Verify core dependency floors in a dedicated, isolated CI cell, including real CLI help/startup and Plotext 5.2.2 rendering, without conflicts from preinstalled runner tooling (#1802 by @kok-o in #1927).diff --git a/src/soup_cli/utils/plotext_compat.py b/src/soup_cli/utils/plotext_compat.pyindex 633c50cd..84ad668b 100644--- a/src/soup_cli/utils/plotext_compat.py+++ b/src/soup_cli/utils/plotext_compat.py@@ -10,7 +10,9 @@ from rich.text import Textdef _v6_figure(plotext: Any) -> Any | None:"""Return plotext 6's figure object, or ``None`` for the 5.x API."""figure = getattr(plotext, "figure", None)- return figure if figure is not None and not callable(figure) else None+ # 5.2.2 also exposes a non-callable figure, but it lacks the 6.x API. Probe+ # the method we are about to call rather than assuming non-callable means v6.+ return figure if not callable(figure) and callable(getattr(figure, "clear", None)) else Nonedef render_histogram(diff --git a/tests/test_ci_full_matrix_on_approval.py b/tests/test_ci_full_matrix_on_approval.pyindex 448cbf25..2eac8fbb 100644--- a/tests/test_ci_full_matrix_on_approval.py+++ b/tests/test_ci_full_matrix_on_approval.py@@ -75,6 +75,7 @@ GATED_JOBS = ("torchao-contract","pytorch-smoke","transformers-floor",+ "core-floor",)#: The support matrix: what RELEASE runs, and what requires-python must match.SUPPORT_MATRIX = {@@ -1013,7 +1014,7 @@ class TestPinnedUpstream:"""A new job that installs `.[dev]` on its own resolves the newest release onevery pull request, which is the failure this switch removed."""installing = {name for name, job in _jobs().items() if _project_installs(job)}- assert installing == {*SWITCHED_JOBS, FLOOR_JOB}+ assert installing == {*SWITCHED_JOBS, FLOOR_JOB, "core-floor"}def test_no_environment_variable_constrains_a_job_behind_its_command_line(self):"""`PIP_CONSTRAINT` in an `env:` applies to every pip of that job on every run,@@ -1070,6 +1071,8 @@ UNPINNED_ON_PURPOSE = {("merge-freshness.yml", "reeval-open-prs"): TOOL,("publish.yml", "publish"): TOOL,# CORE: the project with no extra, so no torch and no transformers to pin.+ # Its separate core-floor constraints are checked by test_core_dependency_floors.py.+ (CI.name, "core-floor"): CORE,("codspeed.yml", "benchmark"): CORE,# NEWEST: started by a schedule or by hand, never by a pull request or a push, and# there to meet the newest release.diff --git a/tests/test_core_dependency_floors.py b/tests/test_core_dependency_floors.pynew file mode 100644index 00000000..6534e537--- /dev/null+++ b/tests/test_core_dependency_floors.py@@ -0,0 +1,150 @@+"""Every light-core dependency is installed at its declared floor in CI (#1802).++The training floor job cannot install old core dependencies that the training stack+requires newer versions of. The separate core-floor job installs no extra, checks+the resolved versions, and builds the entire command tree and starts light commands.+These guards run on newest-dependency jobs too, so changing a declaration, pin, or CI+command alone fails even before the real floor cell runs.+"""++from __future__ import annotations++import re+import shlex+from pathlib import Path+from unittest.mock import patch++import pytest+import yaml+from packaging.requirements import Requirement+from packaging.utils import canonicalize_name+from packaging.version import Version++from tests.test_click_argument_help import _core_requirements++ROOT = Path(__file__).resolve().parents[1]+CONSTRAINTS = ".github/constraints/core-floor.txt"+REQUIRED_TESTS = {+ "tests/test_core_dependency_floors.py",+ "tests/test_cli_dependency_floors.py",+ "tests/test_click_argument_help.py",+ "tests/test_cli_startup_is_light.py",+ "tests/test_cli.py",+ "tests/test_cli_subprocess.py",+ "tests/test_plotext_compat.py",+}+# PyPI has no stable release at these declarations. Values are the first+# non-yanked stable releases pip resolves (measured 2026-10-15; Hub 0.16.1 is yanked).+FIRST_PUBLISHED = {+ ("huggingface-hub", Version("0.16.0")): "0.16.2",+ ("plotext", Version("5.2.0")): "5.2.2",+}+++def _pins() -> dict[str, str]:+ pins: dict[str, str] = {}+ for raw in (ROOT / CONSTRAINTS).read_text(encoding="utf-8").splitlines():+ if not raw.strip() or raw.lstrip().startswith("#"):+ continue+ requirement = Requirement(raw)+ name = canonicalize_name(requirement.name)+ specs = list(requirement.specifier)+ assert len(specs) == 1 and specs[0].operator == "==", raw+ assert not requirement.extras and requirement.marker is None and requirement.url is None+ assert "*" not in specs[0].version, raw+ assert name not in pins, f"duplicate core-floor pin: {name}"+ pins[name] = specs[0].version+ return pins+++def _job() -> dict:+ workflow = yaml.safe_load((ROOT / ".github/workflows/ci.yml").read_text(encoding="utf-8"))+ assert "core-floor" in workflow["jobs"], "CI must run the declared light-core floors"+ return workflow["jobs"]["core-floor"]+++def _version_check() -> str:+ steps = _job()["steps"]+ checks = [step for step in steps if step.get("name") == "Assert core floor versions"]+ assert len(checks) == 1, "core-floor must check what pip actually installed"+ assert checks[0].get("shell") == "python"+ return checks[0]["run"]+++def test_every_core_dependency_is_pinned_to_its_declared_floor() -> None:+ declared = {canonicalize_name(req.name): req for req in _core_requirements()}+ pins = _pins()+ assert pins.keys() == declared.keys(), "pin every core dependency, and no training extra"+ for name, requirement in declared.items():+ floors = [spec.version for spec in requirement.specifier if spec.operator == ">="]+ assert len(floors) == 1, f"{name} needs one inclusive declared floor"+ expected = FIRST_PUBLISHED.get((name, Version(floors[0])), floors[0])+ assert Version(pins[name]) == Version(expected), (+ f"{name}: core-floor installs {pins[name]}, declared floor is {floors[0]}"+ )+ assert Version(pins[name]) in requirement.specifier+++def test_floor_job_installs_only_core_under_its_constraints() -> None:+ runs = [str(step.get("run", "")) for step in _job()["steps"]]+ installs = [run for run in runs if "pip install" in run]+ assert len(installs) == 1, "a later pip install can silently upgrade a core floor"+ words = shlex.split(installs[0])+ assert words[words.index("-e") + 1] == ".", "[dev] pulls in incompatible training deps"+ assert words[words.index("-c") + 1] == CONSTRAINTS+ assert not any("[" in word for word in words), "install no extras in the core floor cell"+ assert "python -m pip check" in runs+++def test_floor_job_isolates_pins_from_runner_tooling() -> None:+ steps = _job()["steps"]+ install_index = next(index for index, step in enumerate(steps)+ if "pip install" in step.get("run", ""))+ setup = "\n".join(step.get("run", "") for step in steps[:install_index])+ # A runner's wheel>=0.46 requires packaging>=24; Soup must exercise 21.0.+ # PATH must carry the venv into every subsequent pip, Python and pytest step.+ assert 'python -m venv "$RUNNER_TEMP/soup-core-floor"' in setup+ assert '"$RUNNER_TEMP/soup-core-floor/bin" >> "$GITHUB_PATH"' in setup+ assert "--system-site-packages" not in setup+++def test_floor_job_runs_command_tree_help_and_startup_checks() -> None:+ arguments: list[str] = []+ for step in _job()["steps"]:+ run = str(step.get("run", "")).strip()+ if run.startswith(("pytest ", "python -m pytest ")):+ words = shlex.split(run)+ arguments.extend(words[words.index("pytest") + 1 :])+ assert REQUIRED_TESTS <= set(arguments), f"core-floor must run {sorted(REQUIRED_TESTS)}"+ assert not {"-k", "-m", "--deselect"} & set(arguments), "do not hide floor failures"+++def test_installed_version_check_rejects_every_upgraded_pin() -> None:+ script = _version_check()+ pins = _pins()+ constraints = (ROOT / CONSTRAINTS).read_text(encoding="utf-8")+ with (+ patch("pathlib.Path.read_text", return_value=constraints),+ patch("importlib.util.find_spec", return_value=None),+ patch("importlib.metadata.version", side_effect=pins.__getitem__),+ ):+ exec(compile(script, "<core-floor version check>", "exec"), {})+ for name, version in pins.items():+ pins[name] = "999.0"+ with pytest.raises(AssertionError, match=re.escape(name)):+ exec(compile(script, "<core-floor version check>", "exec"), {})+ pins[name] = version+++def test_core_floor_check_rejects_an_installed_training_stack() -> None:+ script = _version_check()+ with (+ patch("pathlib.Path.read_text", return_value=(ROOT / CONSTRAINTS).read_text("utf-8")),+ patch("importlib.metadata.version", side_effect=_pins().__getitem__),+ patch(+ "importlib.util.find_spec",+ side_effect=lambda name: object() if name == "torch" else None,+ ),+ ):+ with pytest.raises(AssertionError, match="torch"):+ exec(compile(script, "<core-floor version check>", "exec"), {})diff --git a/tests/test_plotext_compat.py b/tests/test_plotext_compat.pyindex 454694ee..2bb26c85 100644--- a/tests/test_plotext_compat.py+++ b/tests/test_plotext_compat.py@@ -3,6 +3,7 @@from importlib.metadata import version as distribution_versionfrom io import StringIO+import pytestfrom packaging.version import Versionfrom rich.console import Console@@ -97,8 +98,12 @@ class _Plotext6:self.figure = _Figure6()-def test_plotext5_module_api_remains_supported() -> None:[email protected]("figure", [None, lambda: None, object()])+def test_plotext5_module_api_remains_supported(figure) -> None:plotext = _Plotext5()+ # 5.2.2 exposes a non-callable private figure object with no v6 clear/draw API;+ # later 5.x releases expose a callable figure factory. Both use module methods.+ plotext.figure = figureconsole = _Console()render_histogram(plotext,