mirror of
https://github.com/unslothai/unsloth.git
synced 2026-07-10 00:08:58 +00:00
Studio: gate the staged prebuilt runtime validation behind a flag (off by default) (#6216)
The post-download llama-quantize / llama-server smoke test JIT-compiles CUDA kernels on the first GPU forward pass and stalls every install and update by minutes on Blackwell (sm_100). Gate it behind _RUN_STAGED_PREBUILT_VALIDATION, disabled for now, keeping the smoke test and the source-build fallback it triggers fully intact so it can be restored by flipping the flag to True. Hashless external prebuilts (e.g. lemonade) are not in the approved-sha256 manifest and rely on the functional smoke test as their only integrity gate, so they are always validated regardless of the flag; only approved bundles, already proven by the sha256 manifest, skip it. The sha256 archive verification and the static Linux/macOS preflights are unchanged and still run for every install.
This commit is contained in:
parent
2fadc7b22c
commit
a24c9987ca
2 changed files with 137 additions and 17 deletions
|
|
@ -174,6 +174,12 @@ TEST_MODEL_URL = "https://huggingface.co/ggml-org/models/resolve/main/tinyllamas
|
|||
TEST_MODEL_SHA256 = "270cba1bd5109f42d03350f60406024560464db173c0e387d91f0426d3bd256d"
|
||||
VALIDATION_MODEL_CACHE_DIRNAME = ".cache"
|
||||
VALIDATION_MODEL_CACHE_FILENAME = "stories260K.gguf"
|
||||
# Master switch for the staged runtime smoke test (llama-quantize + llama-server)
|
||||
# in validate_prebuilt_choice. Disabled for now: the llama-server GPU forward pass
|
||||
# JIT-compiles CUDA kernels on first load and stalls every install and update by
|
||||
# minutes on Blackwell (sm_100). The check and the source-build fallback it triggers
|
||||
# are kept intact -- set this to True to re-enable them.
|
||||
_RUN_STAGED_PREBUILT_VALIDATION = False
|
||||
INSTALL_LOCK_TIMEOUT_SECONDS = 300
|
||||
INSTALL_STAGING_ROOT_NAME = ".staging"
|
||||
GITHUB_AUTH_HOSTS = {"api.github.com", "github.com"}
|
||||
|
|
@ -6551,23 +6557,31 @@ def validate_prebuilt_choice(
|
|||
approved_checksums = approved_checksums,
|
||||
prebuilt_fallback_used = prebuilt_fallback_used,
|
||||
)
|
||||
validate_quantize(
|
||||
quantize_path,
|
||||
probe_path,
|
||||
quantized_path,
|
||||
install_dir,
|
||||
host,
|
||||
runtime_line = choice.runtime_line,
|
||||
)
|
||||
validate_server(
|
||||
server_path,
|
||||
probe_path,
|
||||
host,
|
||||
install_dir,
|
||||
runtime_line = choice.runtime_line,
|
||||
install_kind = choice.install_kind,
|
||||
)
|
||||
log(f"staged prebuilt validation succeeded for {choice.name}")
|
||||
# Hashless external prebuilts (e.g. lemonade) are not in the approved-sha256
|
||||
# manifest and rely on the functional smoke test as their only integrity gate,
|
||||
# so they are always validated. For an approved bundle the sha256 manifest
|
||||
# already proves integrity, so its runtime smoke test -- a cold CUDA-JIT pass
|
||||
# costing minutes on Blackwell sm_100 -- is gated behind
|
||||
# _RUN_STAGED_PREBUILT_VALIDATION, disabled for now. The check and the
|
||||
# source-build fallback it triggers are kept intact; flip the flag to restore it.
|
||||
if choice.expected_sha256 is None or _RUN_STAGED_PREBUILT_VALIDATION:
|
||||
validate_quantize(
|
||||
quantize_path,
|
||||
probe_path,
|
||||
quantized_path,
|
||||
install_dir,
|
||||
host,
|
||||
runtime_line = choice.runtime_line,
|
||||
)
|
||||
validate_server(
|
||||
server_path,
|
||||
probe_path,
|
||||
host,
|
||||
install_dir,
|
||||
runtime_line = choice.runtime_line,
|
||||
install_kind = choice.install_kind,
|
||||
)
|
||||
log(f"staged prebuilt validation succeeded for {choice.name}")
|
||||
return server_path, quantize_path
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2761,3 +2761,109 @@ def test_python_runtime_dirs_covers_cu13_and_library_bin(monkeypatch, tmp_path:
|
|||
assert str(cu13_arch) in dirs
|
||||
assert str(library_bin) in dirs
|
||||
assert str(torch_lib) in dirs
|
||||
|
||||
|
||||
def _nvidia_linux_host():
|
||||
return HostInfo(
|
||||
system = "Linux",
|
||||
machine = "x86_64",
|
||||
is_windows = False,
|
||||
is_linux = True,
|
||||
is_macos = False,
|
||||
is_x86_64 = True,
|
||||
is_arm64 = False,
|
||||
nvidia_smi = None,
|
||||
driver_cuda_version = None,
|
||||
compute_caps = ["10.0"],
|
||||
visible_cuda_devices = None,
|
||||
has_physical_nvidia = True,
|
||||
has_usable_nvidia = True,
|
||||
)
|
||||
|
||||
|
||||
def _run_validate_prebuilt_choice(monkeypatch, tmp_path, *, expected_sha256):
|
||||
"""Drive validate_prebuilt_choice with every heavy install step stubbed and
|
||||
return how many times the functional quantize/server smoke tests ran."""
|
||||
calls = {"quantize": 0, "server": 0}
|
||||
server_path = tmp_path / "install" / "build" / "bin" / "llama-server"
|
||||
quantize_path = tmp_path / "install" / "build" / "bin" / "llama-quantize"
|
||||
|
||||
src = INSTALL_LLAMA_PREBUILT
|
||||
monkeypatch.setattr(
|
||||
src, "preferred_source_archive", lambda *a, **k: ("repo", "ref", None, False)
|
||||
)
|
||||
monkeypatch.setattr(src, "hydrate_source_tree", lambda *a, **k: None)
|
||||
monkeypatch.setattr(src, "install_from_archives", lambda *a, **k: (server_path, quantize_path))
|
||||
monkeypatch.setattr(src, "preflight_linux_installed_binaries", lambda *a, **k: None)
|
||||
monkeypatch.setattr(src, "preflight_macos_installed_binaries", lambda *a, **k: None)
|
||||
monkeypatch.setattr(src, "ensure_repo_shape", lambda *a, **k: None)
|
||||
monkeypatch.setattr(src, "write_prebuilt_metadata", lambda *a, **k: None)
|
||||
monkeypatch.setattr(
|
||||
src,
|
||||
"validate_quantize",
|
||||
lambda *a, **k: calls.__setitem__("quantize", calls["quantize"] + 1),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
src, "validate_server", lambda *a, **k: calls.__setitem__("server", calls["server"] + 1)
|
||||
)
|
||||
|
||||
bundle_name = "app-b9998-linux-x64-cuda13-newer.tar.gz"
|
||||
source_archive = tmp_path / "source.tar.gz"
|
||||
bundle_archive = tmp_path / "bundle.tar.gz"
|
||||
source_archive.write_bytes(b"source")
|
||||
bundle_archive.write_bytes(b"bundle")
|
||||
|
||||
choice = AssetChoice(
|
||||
repo = "local",
|
||||
tag = "b9998",
|
||||
name = bundle_name,
|
||||
url = "file://bundle",
|
||||
source_label = "local",
|
||||
is_ready_bundle = True,
|
||||
install_kind = "linux-cuda",
|
||||
bundle_profile = "cuda13-newer",
|
||||
runtime_line = "cuda13",
|
||||
expected_sha256 = expected_sha256,
|
||||
)
|
||||
src.validate_prebuilt_choice(
|
||||
choice,
|
||||
_nvidia_linux_host(),
|
||||
tmp_path / "install",
|
||||
tmp_path / "work",
|
||||
tmp_path / "stories260K.gguf",
|
||||
requested_tag = "b9998",
|
||||
llama_tag = "b9998",
|
||||
release_tag = "b9998",
|
||||
approved_checksums = approved_checksums_for(
|
||||
"b9998",
|
||||
source_archive = source_archive,
|
||||
bundle_archive = bundle_archive,
|
||||
bundle_name = bundle_name,
|
||||
),
|
||||
prebuilt_fallback_used = False,
|
||||
quantized_path = tmp_path / "stories260K-q4.gguf",
|
||||
)
|
||||
return calls
|
||||
|
||||
|
||||
def test_validate_prebuilt_choice_approved_validation_skipped_when_flag_off(tmp_path, monkeypatch):
|
||||
# An approved (sha256-verified) bundle skips the staged smoke test while the
|
||||
# flag is off: the manifest hash is its integrity gate.
|
||||
calls = _run_validate_prebuilt_choice(monkeypatch, tmp_path, expected_sha256 = "ab" * 32)
|
||||
assert calls == {"quantize": 0, "server": 0}
|
||||
|
||||
|
||||
def test_validate_prebuilt_choice_hashless_build_always_validated(tmp_path, monkeypatch):
|
||||
# A hashless external build (e.g. lemonade) has no approved sha256, so the
|
||||
# functional smoke test is its only integrity gate and must run even while the
|
||||
# flag is off -- otherwise a corrupted/replaced archive could be activated.
|
||||
calls = _run_validate_prebuilt_choice(monkeypatch, tmp_path, expected_sha256 = None)
|
||||
assert calls == {"quantize": 1, "server": 1}
|
||||
|
||||
|
||||
def test_validate_prebuilt_choice_approved_validation_runs_when_flag_enabled(tmp_path, monkeypatch):
|
||||
# Flipping _RUN_STAGED_PREBUILT_VALIDATION back on restores the full smoke test
|
||||
# for approved bundles too, proving the check is kept intact, only gated off.
|
||||
monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "_RUN_STAGED_PREBUILT_VALIDATION", True)
|
||||
calls = _run_validate_prebuilt_choice(monkeypatch, tmp_path, expected_sha256 = "ab" * 32)
|
||||
assert calls == {"quantize": 1, "server": 1}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue