Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Give Repo tests (CPU) a budget it fits in, and name the patcher when it falls back (#10862)

Daniel Haned64d90ad905
diff --git a/.github/workflows/studio-backend-ci.yml b/.github/workflows/studio-backend-ci.yml
index 51c8e6376c5..d80bb2d152e 100644
--- a/.github/workflows/studio-backend-ci.yml
+++ b/.github/workflows/studio-backend-ci.yml
@@ -354,8 +354,22 @@ jobs:
# succeeds on CPU.
name: Repo tests (CPU)
runs-on: ubuntu-latest
- # Same reason as the matrix above: this one measured 13.4 minutes against the same 15.
- timeout-minutes: 30
+ # Same reason as the matrix above, and now the same number. The comment this replaces
+ # claimed 13.4 minutes. Across the last 40 runs of this job on main the pytest step
+ # alone measured 852s to 1683s (14.2 to 28.1 minutes), and the install plus the four
+ # steps after it add a further 351s. So the worst measured run needs 33.9 minutes and
+ # the cap was 30: it sat inside the spread rather than above it. The clearest single
+ # run is 0eedeeeb, which passed -- at 1738s, 62 seconds under the limit.
+ #
+ # Which run loses is therefore a property of the runner, not of the PR. #10849 and
+ # #10861 were both cancelled at 30m1x against a green main, on branches that touch
+ # none of this.
+ #
+ # A cancelled job is also worse than a slow one, twice over. The cap fires mid-step, so
+ # the run blames whichever step was unlucky -- on both of those it was "Shell installer
+ # tests", 84s in and unrelated -- and the shell, CLI and Docker steps never run at all,
+ # so the PR loses that coverage silently. The suite is not the problem; the budget was.
+ timeout-minutes: 45
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
@@ -393,7 +407,10 @@ jobs:
pip install \
python-multipart aiofiles sqlalchemy cryptography psutil \
pyyaml jinja2 mammoth unpdf requests typer \
- 'numpy<3' pytest pytest-asyncio pytest-xdist httpx
+ 'numpy<3' pytest pytest-asyncio pytest-xdist pytest-timeout httpx
+ # pytest-timeout: the --timeout flag on the pytest step below. Same reason as the
+ # backend pytest job -- without it a test that never returns is reported as the
+ # job being "cancelled", naming nothing.
# torchvision: unsloth_zoo.vision_utils imports it at module scope.
pip install --index-url https://download.pytorch.org/whl/cpu --extra-index-url https://pypi.org/simple \
'torch>=2.4,<2.11' 'torchvision<0.26' 'torchaudio<2.11'
@@ -465,8 +482,27 @@ jobs:
# steps below stay serial deliberately: the hardware-spoof step exists precisely
# because those files mutate hardware.py module globals, and all three already measure
# under 0.1 minutes on the runner, so there is nothing to win and isolation to lose.
+ #
+ # --timeout / the outer `timeout`: the job cap above went from 30 to 45 minutes, and
+ # a backstop is only worth raising if something below it can still name a hang. Both
+ # mirror the backend pytest job for the reasons written out there; the numbers are
+ # this suite's own.
+ #
+ # 330s per test comes off this suite's measured tail, not off taste. Under -n 4 over
+ # the whole discovered set the slowest is test_source_read_encoding.py::
+ # test_checked_in_file_reads_name_an_encoding at 63.6s, then 48.3s, then a run of
+ # ~31s docker-notebook durability cases. This step runs ~2.2x slower on a 4-vCPU
+ # runner than on the box those came off, so call the worst legitimate test ~140s:
+ # the cap is ~2.4x that. It is also the same 330 the backend pytest job settled on
+ # against its own tail. Nothing here is near it, and a deadlock is named in minutes.
+ #
+ # --timeout arms inside each xdist worker, so a wedged CONTROLLER escapes it. 2100s
+ # bounds the session from outside, where it cannot: 1.25x the worst of the 40 runs
+ # measured above, and 2100 + the 351s of surrounding steps still lands 4 minutes
+ # under the job cap, so this fires first and says where it was stuck.
run: |
- python -m pytest tests/ -q --tb=short -n 4 \
+ timeout --signal=INT --kill-after=60 2100 \
+ python -m pytest tests/ -q --tb=short -n 4 --timeout=330 \
--ignore=tests/qlora \
--ignore=tests/saving \
--ignore=tests/utils \
diff --git a/tests/utils/test_packing.py b/tests/utils/test_packing.py
index aecc56b5c91..cc66fcdc01f 100644
--- a/tests/utils/test_packing.py
+++ b/tests/utils/test_packing.py
@@ -798,6 +798,35 @@ def test_text_model_stream_without_metadata_keeps_packing():
assert next(iter(dataset))["text"] == "first"
+def _fake_sft_self():
+ """A stand-in `self` for the three `SFTTrainer._prepare_dataset` tests below
+ (four cases; the last one is parameterized).
+
+ Fails first, and by name, if `SFTTrainer` is not Unsloth's. Those tests call
+ `_prepare_dataset` unbound with a SimpleNamespace, which is fine against the
+ patched implementation (it reads `data_collator` and nothing else) and is not
+ fine against TRL's own, which reaches for `self._is_vlm`. So when the patch
+ silently falls back -- `import unsloth` warns and continues, see
+ `_patch_trl_rl_trainers` in unsloth/models/rl.py -- all four report
+
+ AttributeError: 'types.SimpleNamespace' object has no attribute '_is_vlm'
+
+ which names the fake object and not the patcher. That is what unsloth-zoo
+ #1192 vs the source anchor fixed in #10854 actually looked like from here,
+ and it is why 16 failures across five files took a while to add up to one
+ cause. Padding the namespace out with `_is_vlm` would be worse than the
+ AttributeError: the tests would then quietly pass against TRL's trainer and
+ assert nothing about Unsloth's.
+ """
+ assert SFTTrainer.__name__ == "UnslothSFTTrainer", (
+ f"trl.SFTTrainer is {SFTTrainer.__name__!r}, so Unsloth's SFT patch did not "
+ "apply and these tests would be exercising TRL's _prepare_dataset instead of "
+ "the patched one. `import unsloth` reports the cause as a warning "
+ "('Could not build the patched trl.trainer.sft_trainer'), not an error."
+ )
+ return SimpleNamespace(model = None)
+
+
def test_bfd_packing_truncates_before_packing(monkeypatch):
args = SimpleNamespace(
dataset_num_proc = 1,
@@ -805,7 +834,7 @@ def test_bfd_packing_truncates_before_packing(monkeypatch):
max_length = 4,
packing_strategy = "bfd",
)
- trainer = SimpleNamespace(model = None)
+ trainer = _fake_sft_self()
dataset = Dataset.from_dict({"prompt": ["abc"], "completion": ["defghij"]})
prepare_globals = SFTTrainer._prepare_dataset.__globals__
@@ -833,7 +862,7 @@ def test_wrapped_strategy_without_packing_still_truncates():
max_length = 4,
packing_strategy = "wrapped",
)
- trainer = SimpleNamespace(model = None)
+ trainer = _fake_sft_self()
dataset = Dataset.from_dict({"text": ["abcdefghi"]})
prepared = SFTTrainer._prepare_dataset(
@@ -859,7 +888,7 @@ def test_wrapped_packing_preserves_overlength_tokens(monkeypatch, legacy_api):
if not legacy_api:
args_kwargs["packing_strategy"] = "wrapped"
args = SimpleNamespace(**args_kwargs)
- trainer = SimpleNamespace(model = None)
+ trainer = _fake_sft_self()
dataset = Dataset.from_dict({"text": ["abcdefghi"]})
prepare_globals = SFTTrainer._prepare_dataset.__globals__
pack_dataset = prepare_globals["pack_dataset"]