From 848dfa27642321cb5a87e7610b7afcf25a7bac72 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 26 Jul 2026 17:29:04 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../test_docker_nb_strip_colab_scope.py | 9 ++- tests/python/test_docker_nb_sync_race.py | 23 ++++--- .../test_docker_pip_shim_training_stack.py | 67 +++++++++++++++---- .../test_docker_tf_sidecar_vllm_floor.py | 52 +++++++++----- 4 files changed, 107 insertions(+), 44 deletions(-) diff --git a/tests/python/test_docker_nb_strip_colab_scope.py b/tests/python/test_docker_nb_strip_colab_scope.py index a536a04bb5..6eeb457e67 100644 --- a/tests/python/test_docker_nb_strip_colab_scope.py +++ b/tests/python/test_docker_nb_strip_colab_scope.py @@ -59,8 +59,13 @@ def md(*lines): def code(src): - return {"cell_type": "code", "metadata": {}, "execution_count": None, - "outputs": [], "source": [src]} + return { + "cell_type": "code", + "metadata": {}, + "execution_count": None, + "outputs": [], + "source": [src], + } def nb(*cells): diff --git a/tests/python/test_docker_nb_sync_race.py b/tests/python/test_docker_nb_sync_race.py index e93011f22d..de2c26dca6 100644 --- a/tests/python/test_docker_nb_sync_race.py +++ b/tests/python/test_docker_nb_sync_race.py @@ -51,16 +51,16 @@ def test_the_refresh_is_still_detached(sync: str): # The whole point of the child is that a 60s ls-remote + clone must not delay # container startup. A fix that simply made the refresh synchronous would # pass every other test here and regress boot time. - assert re.search(r'UNSLOTH_NB_REFRESH_CHILD=1 "\$0" >/dev/null 2>&1 &', sync), ( - "the GitHub refresh must stay a detached child" - ) + assert re.search( + r'UNSLOTH_NB_REFRESH_CHILD=1 "\$0" >/dev/null 2>&1 &', sync + ), "the GitHub refresh must stay a detached child" def test_an_exclusive_lock_serialises_the_two_processes(sync: str): assert "lock_acquire()" in sync and "lock_release()" in sync - assert re.search(r"flock -w \"\$LOCK_WAIT\" 9", sync), ( - "the lock must be a real exclusive flock, and must not block forever" - ) + assert re.search( + r"flock -w \"\$LOCK_WAIT\" 9", sync + ), "the lock must be a real exclusive flock, and must not block forever" def test_the_lock_is_taken_before_anything_mutates_the_tree(sync: str): @@ -91,9 +91,9 @@ def test_the_parent_finalizes_before_it_forks(sync: str): def test_finalize_runs_at_most_once(sync: str): block = sync[sync.index("finalize() {") : sync.index("trap 'finalize; lock_release' EXIT")] - assert '[ "$_FINALIZED" = "1" ] && return 0' in block, ( - "the explicit pre-fork call and the EXIT trap must not strip twice" - ) + assert ( + '[ "$_FINALIZED" = "1" ] && return 0' in block + ), "the explicit pre-fork call and the EXIT trap must not strip twice" assert "_FINALIZED=1" in block @@ -113,8 +113,9 @@ def test_the_child_does_not_repeat_the_parents_finalize(sync: str): def test_the_child_re_arms_the_finalize_only_after_it_copies(sync: str): tail = sync[sync.index("refreshed from GitHub") :] - assert re.search(r'if \[ "\$updated" -gt 0 \]; then\s*\n\s*_FINALIZED=0\s*\n\s*finalize', - tail), ( + assert re.search( + r'if \[ "\$updated" -gt 0 \]; then\s*\n\s*_FINALIZED=0\s*\n\s*finalize', tail + ), ( "freshly copied notebooks arrive with the upstream Colab intro and have " "to be stripped, but only when something was actually copied" ) diff --git a/tests/python/test_docker_pip_shim_training_stack.py b/tests/python/test_docker_pip_shim_training_stack.py index 0633814458..e04548a6b5 100644 --- a/tests/python/test_docker_pip_shim_training_stack.py +++ b/tests/python/test_docker_pip_shim_training_stack.py @@ -73,7 +73,11 @@ def shim(tmp_path, monkeypatch): return mod -def _run(shim, args, tool = "pip"): +def _run( + shim, + args, + tool = "pip", +): """Return the args that reached the real tool after `install`, or None when the shim no-op'd. The always-injected protected-constraints pair is dropped.""" argv = ["uv", "pip", "install", *args] if tool == "uv" else ["pip", "install", *args] @@ -99,26 +103,54 @@ def _run(shim, args, tool = "pip"): # -------------------------------------------------------------------------- @pytest.mark.parametrize( "pkg", - ["trl", "peft", "datasets", "accelerate", "torchao", "torchcodec", - "huggingface-hub", "tokenizers", "safetensors"], + [ + "trl", + "peft", + "datasets", + "accelerate", + "torchao", + "torchcodec", + "huggingface-hub", + "tokenizers", + "safetensors", + ], ) def test_training_stack_is_protected(shim, pkg): - assert pkg in shim._KEEP, ( - f"{pkg} is baked and tested; a notebook pin replacing it invalidates the image" - ) + assert ( + pkg in shim._KEEP + ), f"{pkg} is baked and tested; a notebook pin replacing it invalidates the image" def test_the_original_gpu_stack_is_still_protected(shim): - for pkg in ["torch", "torchvision", "torchaudio", "triton", "xformers", - "vllm", "bitsandbytes", "unsloth", "unsloth-zoo"]: + for pkg in [ + "torch", + "torchvision", + "torchaudio", + "triton", + "xformers", + "vllm", + "bitsandbytes", + "unsloth", + "unsloth-zoo", + ]: assert pkg in shim._KEEP def test_unrelated_packages_are_not_swept_in(shim): # The criterion is "invalidates the tested stack", not "a notebook mentions # it". These are all installed by shipped notebooks and must stay installable. - for pkg in ["snac", "causal-conv1d", "mamba-ssm", "omegaconf", "timm", - "librosa", "trackio", "open-spiel", "protobuf", "sentencepiece"]: + for pkg in [ + "snac", + "causal-conv1d", + "mamba-ssm", + "omegaconf", + "timm", + "librosa", + "trackio", + "open-spiel", + "protobuf", + "sentencepiece", + ]: assert pkg not in shim._KEEP, f"{pkg} must still install for the notebooks that need it" @@ -133,8 +165,14 @@ def test_the_shipped_trl_cell_installs_nothing(shim): def test_a_mixed_cell_keeps_only_the_unbaked_package(shim): execd = _run( shim, - ["--no-deps", "trl==0.22.2", "peft==0.14.0", "datasets==3.0.0", - "accelerate==1.0.0", UNBAKED], + [ + "--no-deps", + "trl==0.22.2", + "peft==0.14.0", + "datasets==3.0.0", + "accelerate==1.0.0", + UNBAKED, + ], ) assert execd == ["--no-deps", UNBAKED], execd @@ -148,8 +186,9 @@ def test_cuda_matched_wheels_are_not_replaced_by_pypi_builds(shim): def test_transformers_companions_cannot_desynchronise_the_sidecars(shim): # Each sidecar ships its own matched huggingface_hub/tokenizers/safetensors; # replacing the base-venv copies desynchronises every sidecar at once. - assert _run(shim, ["huggingface_hub==0.30.0", "tokenizers==0.20.0", - "safetensors==0.4.0"]) is None + assert ( + _run(shim, ["huggingface_hub==0.30.0", "tokenizers==0.20.0", "safetensors==0.4.0"]) is None + ) def test_an_unbaked_package_still_installs(shim): diff --git a/tests/python/test_docker_tf_sidecar_vllm_floor.py b/tests/python/test_docker_tf_sidecar_vllm_floor.py index 44357d0f61..23b00c9add 100644 --- a/tests/python/test_docker_tf_sidecar_vllm_floor.py +++ b/tests/python/test_docker_tf_sidecar_vllm_floor.py @@ -50,9 +50,19 @@ COMPAT_PATH = REPO_ROOT / "docker" / "unsloth_nb_compat.py" # Every distinct transformers pin across the 433 shipped notebooks, and the # sidecar each must resolve to once 4.57.6 and 5.3.0 are gone. SHIPPED_PINS = [ - "4.48", "4.52.3", "4.55.4", "4.56.1", "4.56.2", - "4.57.0", "4.57.1", "4.57.3", "5.2.0", "5.3.0", - "5.5.0", "5.10.1", "5.11.0", + "4.48", + "4.52.3", + "4.55.4", + "4.56.1", + "4.56.2", + "4.57.0", + "4.57.1", + "4.57.3", + "5.2.0", + "5.3.0", + "5.5.0", + "5.10.1", + "5.11.0", ] @@ -125,13 +135,13 @@ def test_build_verifies_every_sidecar_against_the_baked_vllm(sidecar_block: str) def test_build_verification_needs_no_gpu(sidecar_block: str): # `import unsloth` raises NotImplementedError("cannot find any torch # accelerator") on the build host, so it can never be the gate. - assert "import unsloth" not in sidecar_block, ( - "the sidecar gate must not import unsloth: the build host has no GPU" - ) + assert ( + "import unsloth" not in sidecar_block + ), "the sidecar gate must not import unsloth: the build host has no GPU" def test_an_unverifiable_sidecar_is_deleted_not_shipped(sidecar_block: str): - assert re.search(r'DROPPED', sidecar_block), "a failed candidate must be reported" + assert re.search(r"DROPPED", sidecar_block), "a failed candidate must be reported" assert re.search(r'rm -rf "\$DEST"', sidecar_block), ( "a sidecar the baked vLLM cannot import must be removed, not shipped: it " "can never be selected safely and it costs image size" @@ -139,9 +149,9 @@ def test_an_unverifiable_sidecar_is_deleted_not_shipped(sidecar_block: str): def test_build_records_the_selection_floor(sidecar_block: str): - assert ".vllm_min_transformers" in sidecar_block, ( - "the lowest verified version must be recorded for unsloth_nb_compat" - ) + assert ( + ".vllm_min_transformers" in sidecar_block + ), "the lowest verified version must be recorded for unsloth_nb_compat" assert "sort -V | head -1" in sidecar_block, "the floor is the LOWEST survivor" @@ -176,12 +186,19 @@ def test_floor_is_read_back(fixed_root): "pin, expected", [ # every pin below the floor clamps UP to the lowest eligible sidecar - ("4.48", "t_5_5_0"), ("4.52.3", "t_5_5_0"), ("4.55.4", "t_5_5_0"), - ("4.56.1", "t_5_5_0"), ("4.56.2", "t_5_5_0"), ("4.57.0", "t_5_5_0"), - ("4.57.1", "t_5_5_0"), ("4.57.3", "t_5_5_0"), ("5.2.0", "t_5_5_0"), + ("4.48", "t_5_5_0"), + ("4.52.3", "t_5_5_0"), + ("4.55.4", "t_5_5_0"), + ("4.56.1", "t_5_5_0"), + ("4.56.2", "t_5_5_0"), + ("4.57.0", "t_5_5_0"), + ("4.57.1", "t_5_5_0"), + ("4.57.3", "t_5_5_0"), + ("5.2.0", "t_5_5_0"), ("5.3.0", "t_5_5_0"), # at and above the floor, the ceiling still decides - ("5.5.0", "t_5_5_0"), ("5.10.1", "t_5_10_2"), + ("5.5.0", "t_5_5_0"), + ("5.10.1", "t_5_10_2"), # newer than every sidecar -> the baked transformers ("5.11.0", None), ], @@ -196,9 +213,10 @@ def test_no_shipped_pin_can_reach_an_incompatible_sidecar(stale_root): for pin in SHIPPED_PINS: got = compat.sidecar_for(pin) name = Path(got).name if got else None - assert name not in ("t_4_57_6", "t_5_3_0"), ( - f"pin {pin} selected {name}, which the baked vLLM cannot import" - ) + assert name not in ( + "t_4_57_6", + "t_5_3_0", + ), f"pin {pin} selected {name}, which the baked vLLM cannot import" def test_model_tier_fallback_is_clamped_too(stale_root):