From 5076837cf04b13fc81fd08d134a1aea9be28b39a Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Sun, 31 May 2026 01:15:02 -0700 Subject: [PATCH 01/35] studio: make NVIDIA prebuilt selection track CUDA version bumps (Windows + Linux) (#5879) Make the NVIDIA prebuilt selection version-dynamic and driver-gated on both the Windows (ggml-org) and Linux (unslothai/llama.cpp) paths, so CUDA version bumps are handled with no code change while staying safe across driver versions. - Derive candidate CUDA runtime lines from the driver major; pick the highest upstream-published minor the driver can actually run, so a sub-13.3 driver is never handed an unguaranteed 13.3 build. - Pin b9360's cuda-13.1 build (immutable, hash-verified) as a GPU fallback for a Blackwell host on a 13.1/13.2 driver that the in-release 13.3 build gates off, on both the simple and published install paths. Dormant for every other host and self-disabling once upstream ships a driver-runnable build again. - Seed the published-path ordering from the release's real published minors so a future CUDA major is selectable with no code change. Refs #5861, #5817, #5807, #5858, #5854, #5826, #5887. --- studio/install_llama_prebuilt.py | 304 +++++++++-- tests/studio/install/test_selection_logic.py | 526 ++++++++++++++++++- 2 files changed, 795 insertions(+), 35 deletions(-) diff --git a/studio/install_llama_prebuilt.py b/studio/install_llama_prebuilt.py index 38fa31fff8..861a501570 100644 --- a/studio/install_llama_prebuilt.py +++ b/studio/install_llama_prebuilt.py @@ -222,6 +222,71 @@ DIRECT_LINUX_BUNDLE_PROFILES: dict[str, dict[str, Any]] = { }, } +# Lowest CUDA major we ship prebuilts for, and the highest major we probe for +# installed runtime libraries. Detection and runtime-line derivation are +# generated per major so a new toolkit (cuda14, ...) needs no code change while +# llama.cpp keeps the cudart64_.dll / libcudart.so. naming. +_MIN_CUDA_MAJOR = 12 +_MAX_PROBE_CUDA_MAJOR = 19 + +# Last ggml-org release whose Windows win-cuda-13 build is still sub-13.3 +# (cuda-13.1, b9360, 2026-05-27). Upstream bumped win-cuda-13 to 13.3 at b9365 +# and now ships only cuda-12.4 + cuda-13.3. cuda-12.4 predates Blackwell (ggml +# compiles sm_120 only at toolkit >= 12.8), so a Blackwell host on a 13.1/13.2 +# driver is gated off 13.3 and would drop to a CPU-only 12.4 build. b9360 is +# immutable, so we pin its cuda-13.1 build (plus paired cudart) as a GPU +# fallback for exactly those hosts. See unslothai/unsloth#5887. +_PINNED_BLACKWELL_FALLBACK_TAG = "b9360" +_PINNED_BLACKWELL_FALLBACK_RUNTIME = "13.1" +_PINNED_BLACKWELL_DRIVER_FLOOR = (13, 1) +_BLACKWELL_MIN_SM = 120 +# ggml compiles Blackwell sm_120 only at toolkit >= 12.8, so an in-release +# windows-cuda build at or above this already covers Blackwell and makes the +# older pinned 13.1 fallback unnecessary (cuda-12.4 is below it). +_BLACKWELL_MIN_TOOLKIT = (12, 8) +_PINNED_BLACKWELL_LLAMA_SHA256 = ( + "31ddb8b42d7ab4a47cab8c48c397519f580ca502df7e73f3ab396eacc16c8e8d" +) +_PINNED_BLACKWELL_CUDART_SHA256 = ( + "f96935e7e385e3b2d0189239077c10fe8fd7e95690fea4afec455b1b6c7e3f18" +) + + +def _cuda_runtime_lines_for_major(major: int) -> list[str]: + """Runtime lines a driver of this CUDA major can use, newest major first + down to the minimum we ship. A driver runs its own major and any older one + (backward compatibility).""" + return [f"cuda{m}" for m in range(major, _MIN_CUDA_MAJOR - 1, -1)] + + +def _resolve_linux_bundle_profile(bundle_profile: str) -> "dict[str, Any] | None": + """Profile (runtime line + sm coverage) for a linux-x64-cuda- + bundle. Known majors use their published coverage; an unknown future major + reuses the newest known major's coverage for the same class as a forward + default, with the post-build GPU smoke test as the backstop.""" + known = DIRECT_LINUX_BUNDLE_PROFILES.get(bundle_profile) + if known is not None: + return known + m = re.fullmatch( + r"cuda(?P\d+)-(?Polder|newer|portable)", bundle_profile + ) + if not m: + return None + base_key = max( + ( + k + for k, v in DIRECT_LINUX_BUNDLE_PROFILES.items() + if v["coverage_class"] == m.group("klass") + ), + key = lambda k: int(re.match(r"cuda(\d+)-", k).group(1)), + default = None, + ) + if base_key is None: + return None + profile = dict(DIRECT_LINUX_BUNDLE_PROFILES[base_key]) + profile["runtime_line"] = f"cuda{m.group('major')}" + return profile + @dataclass class HostInfo: @@ -769,6 +834,26 @@ def windows_cuda_asset_aliases( return aliases +def _published_windows_cuda_runtime( + upstream_assets: dict[str, str], major: int, driver: tuple[int, int] | None +) -> str | None: + """Highest cuda-. published upstream that `driver` can run by + default CUDA compatibility, i.e. (major, minor) <= driver. None if nothing + qualifies. Gating on the driver (not just the major) keeps a 13.3 build off + a driver that only advertises 13.1, where it would otherwise rely on the + unguaranteed minor-version-compatibility path.""" + if driver is None: + return None + best: int | None = None + for name in upstream_assets: + m = re.search(r"-bin-win-cuda-(\d+)\.(\d+)-x64\.zip$", name) + if m and int(m.group(1)) == major: + minor = int(m.group(2)) + if (major, minor) <= driver and (best is None or minor > best): + best = minor + return f"{major}.{best}" if best is not None else None + + def format_byte_count(num_bytes: float) -> str: units = ["B", "KiB", "MiB", "GiB", "TiB"] value = float(num_bytes) @@ -1225,7 +1310,7 @@ def parse_direct_linux_release_bundle( inferred_labels: list[str] = [] linux_asset_re = re.compile( - r"^app-(?P