Trim the comments across the diffusion backend
Comment-only pass over the Python this PR touches: drop what the code already says, collapse multi-line explanations that still read on one line, and keep the reasoning that is not recoverable from the code. No code, docstring semantics or behaviour changes; verified with an AST comparison against the previous revision, and the backend suite is unchanged (same 37 environment failures as before: the API integration tests that need a live keyed server, the flash-attn install hooks, and the GPU memory fields).
This commit is contained in:
parent
ea3c3822a1
commit
36df317293
113 changed files with 3389 additions and 4087 deletions
|
|
@ -257,14 +257,14 @@ def test_install_downloads_verifies_extracts(tmp_path, monkeypatch):
|
|||
sd_cli = install(install_dir = tmp_path)
|
||||
assert sd_cli.name == "sd-cli" and sd_cli.is_file()
|
||||
assert not (tmp_path / name).exists() # archive cleaned up after extract
|
||||
# Ownership marker lets the uninstaller delete a Studio-installed sd.cpp beside a custom
|
||||
# root while keeping a user's own stable-diffusion.cpp checkout.
|
||||
# The ownership marker lets the uninstaller delete a Studio-installed sd.cpp beside a custom root
|
||||
# while keeping a user's own stable-diffusion.cpp checkout.
|
||||
assert (tmp_path / ".unsloth-studio-owned").is_file()
|
||||
|
||||
|
||||
def test_install_into_empty_dir_claims_ownership(tmp_path, monkeypatch):
|
||||
# An empty (or freshly created) target may be adopted: the marker is written so the uninstaller
|
||||
# can later remove the Studio-installed tree.
|
||||
# An empty (or freshly created) target may be adopted: the marker is written so the uninstaller can
|
||||
# later remove the Studio-installed tree.
|
||||
zb = _zip_with_sd_cli()
|
||||
_stub_release(monkeypatch, zip_bytes = zb, digest = "sha256:" + hashlib.sha256(zb).hexdigest())
|
||||
empty = tmp_path / "sdcpp"
|
||||
|
|
@ -274,8 +274,8 @@ def test_install_into_empty_dir_claims_ownership(tmp_path, monkeypatch):
|
|||
|
||||
|
||||
def test_install_into_nonempty_unowned_dir_is_refused(tmp_path, monkeypatch):
|
||||
# A pre-existing, non-empty directory Studio did not create (e.g. a user's own checkout) must
|
||||
# not be extracted into; install() refuses up front and leaves it untouched.
|
||||
# A pre-existing, non-empty directory Studio did not create (e.g. a user's own checkout) must not
|
||||
# be extracted into; install() refuses up front and leaves it untouched.
|
||||
zb = _zip_with_sd_cli()
|
||||
_stub_release(monkeypatch, zip_bytes = zb, digest = "sha256:" + hashlib.sha256(zb).hexdigest())
|
||||
target = tmp_path / "stable-diffusion.cpp"
|
||||
|
|
@ -293,8 +293,8 @@ def test_install_into_nonempty_unowned_dir_is_refused(tmp_path, monkeypatch):
|
|||
|
||||
|
||||
def test_reinstall_into_owned_dir_keeps_ownership(tmp_path, monkeypatch):
|
||||
# A directory that already carries our marker (a prior Studio install / upgrade) stays owned
|
||||
# even though it is now non-empty.
|
||||
# A directory that already carries our marker (a prior Studio install / upgrade) stays owned even
|
||||
# though it is now non-empty.
|
||||
zb = _zip_with_sd_cli()
|
||||
_stub_release(monkeypatch, zip_bytes = zb, digest = "sha256:" + hashlib.sha256(zb).hexdigest())
|
||||
target = tmp_path / "stable-diffusion.cpp"
|
||||
|
|
@ -315,10 +315,9 @@ def test_install_sha256_mismatch_raises_and_cleans_up(tmp_path, monkeypatch):
|
|||
|
||||
|
||||
def test_partial_install_failure_is_reclaimed_on_retry(tmp_path, monkeypatch):
|
||||
# A crash AFTER extraction (here the post-extract cudart fetch raises) leaves the target
|
||||
# non-empty. Because ownership is marked BEFORE the partial writes, the retry recognises the
|
||||
# debris as ours and re-extracts instead of tripping the "not a Studio-managed directory"
|
||||
# refusal, so native install self-heals without the user manually deleting the directory.
|
||||
# A crash AFTER extraction (here the post-extract cudart fetch raises) leaves the target non-empty.
|
||||
# Because ownership is marked BEFORE the partial writes, the retry recognises the debris as ours
|
||||
# and re-extracts instead of tripping the "not a Studio-managed directory" refusal.
|
||||
zb = _zip_with_sd_cli()
|
||||
_stub_release(monkeypatch, zip_bytes = zb, digest = "sha256:" + hashlib.sha256(zb).hexdigest())
|
||||
target = tmp_path / "sdcpp"
|
||||
|
|
@ -334,7 +333,7 @@ def test_partial_install_failure_is_reclaimed_on_retry(tmp_path, monkeypatch):
|
|||
|
||||
with pytest.raises(RuntimeError, match = "simulated interrupted"):
|
||||
install(install_dir = target)
|
||||
# The partial install left extracted files AND the ownership marker (written before the writes).
|
||||
# The partial install left extracted files AND the ownership marker.
|
||||
assert (target / ".unsloth-studio-owned").is_file()
|
||||
assert any(target.iterdir())
|
||||
|
||||
|
|
@ -372,8 +371,8 @@ def test_safe_extractall_extracts_normal_members(tmp_path):
|
|||
|
||||
|
||||
def test_find_sd_cpp_binary_honors_studio_home(tmp_path, monkeypatch):
|
||||
# A binary installed under a custom Studio root must be discovered without also
|
||||
# setting UNSLOTH_SD_CPP_PATH (matches default_install_dir's env handling).
|
||||
# A binary installed under a custom Studio root must be discovered without also setting
|
||||
# UNSLOTH_SD_CPP_PATH (matching default_install_dir's env handling).
|
||||
from core.inference import sd_cpp_engine as eng
|
||||
|
||||
monkeypatch.delenv("SD_CLI_PATH", raising = False)
|
||||
|
|
@ -389,8 +388,8 @@ def test_find_sd_cpp_binary_honors_studio_home(tmp_path, monkeypatch):
|
|||
# ── Unsloth mirror: default source + the CPU/Apple asset set it publishes ─────
|
||||
|
||||
_TAG = "master-741-484baa4"
|
||||
# Exactly what unslothai/stable-diffusion.cpp's CI publishes (CPU + Apple only; GPU
|
||||
# hosts run diffusers and never reach the native installer).
|
||||
# Exactly what unslothai/stable-diffusion.cpp's CI publishes (CPU + Apple only; GPU hosts run
|
||||
# diffusers and never reach the native installer).
|
||||
_MIRROR_ASSETS = [
|
||||
f"sd-{_TAG}-bin-Darwin-macOS-arm64.zip",
|
||||
f"sd-{_TAG}-bin-Darwin-macOS-x86_64.zip",
|
||||
|
|
@ -498,8 +497,8 @@ def test_install_falls_back_to_upstream_when_mirror_missing(tmp_path, monkeypatc
|
|||
sd_cli = install(install_dir = tmp_path)
|
||||
assert sd_cli.name == "sd-cli" and sd_cli.is_file()
|
||||
captured = capsys.readouterr()
|
||||
# The repo-fallback diagnostic goes to stderr so --print-asset's stdout stays a single
|
||||
# asset line; the "source ..." install note still prints to stdout.
|
||||
# The repo-fallback diagnostic goes to stderr so --print-asset's stdout stays a single asset line;
|
||||
# the "source ..." install note still prints to stdout.
|
||||
assert "falling back to leejet/stable-diffusion.cpp" in captured.err
|
||||
assert "source leejet/stable-diffusion.cpp" in captured.out
|
||||
|
||||
|
|
@ -516,9 +515,9 @@ def test_install_errors_when_neither_source_serves(tmp_path, monkeypatch):
|
|||
|
||||
|
||||
def test_mirror_windows_gpu_accel_is_no_match_not_cpu():
|
||||
# The mirror ships only a CPU win zip. An explicit --accelerator cuda/vulkan/rocm must
|
||||
# NOT silently resolve to that CPU build; it returns None so install() falls back to
|
||||
# upstream, which does build the accelerated asset.
|
||||
# The mirror ships only a CPU win zip. An explicit --accelerator cuda/vulkan/rocm must NOT silently
|
||||
# resolve to that CPU build; it returns None so install() falls back to upstream, which does build
|
||||
# the accelerated asset.
|
||||
for accel in ("cuda", "vulkan", "rocm"):
|
||||
assert _mresolve("Windows", "AMD64", accel) is None
|
||||
# auto / cpu still resolve to the CPU build.
|
||||
|
|
@ -532,8 +531,8 @@ def test_mirror_linux_gpu_accel_is_no_match_not_cpu():
|
|||
|
||||
|
||||
def test_upstream_full_matrix_still_resolves_gpu_accel():
|
||||
# Regression guard: the "explicit GPU accel -> None on miss" change must not break
|
||||
# the upstream matrix, which does publish the accelerated builds.
|
||||
# Regression guard: the "explicit GPU accel -> None on miss" change must not break the upstream
|
||||
# matrix, which does publish the accelerated builds.
|
||||
assert _resolve("Windows", "AMD64", "cuda") == "sd-master-8caa3f9-bin-win-cuda12-x64.zip"
|
||||
assert _resolve("Linux", "x86_64", "vulkan").endswith("x86_64-vulkan.zip")
|
||||
assert "rocm" in _resolve("Linux", "x86_64", "rocm")
|
||||
|
|
@ -543,8 +542,8 @@ def test_upstream_full_matrix_still_resolves_gpu_accel():
|
|||
|
||||
|
||||
def test_explicit_repo_override_equal_to_default_suppresses_fallback(tmp_path, monkeypatch):
|
||||
# A user who pins UNSLOTH_SD_CPP_REPO (even to the default value) must get exactly that
|
||||
# repo -- no surprise leejet substitution -- so a missing release errors instead.
|
||||
# A user who pins UNSLOTH_SD_CPP_REPO (even to the default value) must get exactly that repo -- no
|
||||
# surprise leejet substitution -- so a missing release errors instead.
|
||||
_stub_two_repos(
|
||||
monkeypatch, mirror_serves = False, upstream_serves = True, zip_bytes = b"", digest = ""
|
||||
)
|
||||
|
|
@ -557,8 +556,8 @@ def test_explicit_repo_override_equal_to_default_suppresses_fallback(tmp_path, m
|
|||
|
||||
|
||||
def test_pinned_tag_prefers_upstream_pin_over_mirror_latest(tmp_path, monkeypatch, capsys):
|
||||
# The mirror lacks the pinned tag but has a newer latest; upstream has the pin. The
|
||||
# pinned upstream build must win over the unpinned mirror-latest (reproducibility).
|
||||
# The mirror lacks the pinned tag but has a newer latest; upstream has the pin. The pinned upstream
|
||||
# build must win over the unpinned mirror-latest (reproducibility).
|
||||
monkeypatch.delenv("UNSLOTH_SD_CPP_REPO", raising = False)
|
||||
monkeypatch.setenv("UNSLOTH_SD_CPP_TAG", "master-999-pinned")
|
||||
zb = _zip_with_sd_cli()
|
||||
|
|
@ -613,8 +612,8 @@ def test_pinned_tag_prefers_upstream_pin_over_mirror_latest(tmp_path, monkeypatc
|
|||
|
||||
|
||||
def test_print_asset_uses_upstream_fallback(monkeypatch, capsys):
|
||||
# A host the mirror does not build (Linux Vulkan) must print the upstream asset that a
|
||||
# real install would fetch, not "no matching prebuilt".
|
||||
# A host the mirror does not build (Linux Vulkan) must print the upstream asset that a real install
|
||||
# would fetch, not "no matching prebuilt".
|
||||
monkeypatch.delenv("UNSLOTH_SD_CPP_REPO", raising = False)
|
||||
monkeypatch.delenv("UNSLOTH_SD_CPP_TAG", raising = False)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue