diff --git a/docs/architecture.md b/docs/architecture.md index edba1fc0ed..e22af6e051 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -289,13 +289,14 @@ These modules are private `mod` declarations — [`lib.rs`](../crates/e2e-report `engines/vllm` follows full domain extraction: -- [`install.rs`](../engines/vllm/src/install.rs) — ROCm/vLLM install execution: the static-pin and the ROCm 10.x discovery install routes, run through `uv`. It reads the build tables and target resolution from `wheel_builds.rs`, and asks `repair.rs` whether an already-resolvable environment still needs an install pass. +- [`discover_builds.rs`](../engines/vllm/src/discover_builds.rs) — the ROCm 10.x discovery table (`VLLM_ROCM_DISCOVER_BUILD_TABLE`, one row per supported `major.minor` line, with the `DiscoverVersion` series/exact constraint), the row lookup (`vllm_rocm_discover_build`) and the `major.minor` matcher it uses (`rocm_sdk_series_matches`). It is the single list of the ROCm SDK versions installed by discovery: install routing, the fail-closed static fallback and launch-time environment setup (`runtime_has_discover_build` in `runtime.rs`) all read these rows, and nothing keeps a second list in step with them. A leaf: it imports no other crate module, so `runtime.rs`, `wheel_builds.rs` and `install.rs` can all read it without importing one another's code. Its tests, including the one that pins which versions the table serves and in what order, live with it. +- [`install.rs`](../engines/vllm/src/install.rs) — ROCm/vLLM install execution: the static-pin and the ROCm 10.x discovery install routes, run through `uv`. It reads the static build table and target resolution from `wheel_builds.rs` and the discovery rows from `discover_builds.rs`, and asks `repair.rs` whether an already-resolvable environment still needs an install pass. - [`process.rs`](../engines/vllm/src/process.rs) — the resolve-model, launch, serve and stop handlers (including engine-recipe validation and device-policy/GPU-index resolution), vLLM server spawn, launch environment and path setup, and readiness polling. The text appended to a "never became ready" failure comes from `startup_diagnostics.rs`. - [`repair.rs`](../engines/vllm/src/repair.rs) — runtime-repair assessment: whether an already-resolvable managed vLLM environment violates vLLM's pinned dependencies and must be reinstalled (`assess_runtime_repair`, `RepairAssessment`), including the rule that treats the SDK's build of torch, and a torch the user chose with the alignment disabled, as intended rather than a defect. It imports `runtime.rs` and nothing from `install.rs`. - [`runtime.rs`](../engines/vllm/src/runtime.rs) — TheRock/managed-runtime resolution and TheRock library/bin path derivation; the path derivation performs no filesystem writes. The launch path's compat-shim writes (a `libmpi_cxx` stub, stale-numa-shim removal) are this module's separate `ensure_therock_compat_shims`, called only from `process.rs`; the running-state payload, which never calls it, falls back to a plain directory listing instead. - [`startup_diagnostics.rs`](../engines/vllm/src/startup_diagnostics.rs) — what a failed startup tells the user: the tail of the startup log, re-rendered line by line through `terminal::rendered_lines` (not stripped — stripping deletes line-break tokens with no separator, which welds a progress-bar repaint onto the next line), followed by the out-of-memory and engine-import-failure hints that point at `rocm diagnose`. Its single entry point is `startup_log_context`, which `process.rs` calls from `wait_for_vllm_ready`. It imports only `state.rs`, for the log-read cap. - [`state.rs`](../engines/vllm/src/state.rs) — service state file I/O, log tailing, and health/inference probing. -- [`wheel_builds.rs`](../engines/vllm/src/wheel_builds.rs) — which vLLM wheels to install for a ROCm SDK version: the static build table (`VLLM_ROCM_BUILD_TABLE`) and the ROCm 10.x discovery table (`VLLM_ROCM_DISCOVER_BUILD_TABLE`, with the `DiscoverVersion` series/exact constraint), the install-route choice (`vllm_install_route`), target resolution including the `ROCM_CLI_VLLM_ROCM_INDEX_URL` override (`vllm_install_target`), and the SDK-version matchers. It also holds `verified_torchaudio_release`, which the crate re-exports from `lib.rs` for the `rocm` binary. It imports only `runtime.rs` and runs no process. +- [`wheel_builds.rs`](../engines/vllm/src/wheel_builds.rs) — which vLLM wheels to install for a ROCm SDK version: the static build table (`VLLM_ROCM_BUILD_TABLE`), the install-route choice (`vllm_install_route`, which consults the discovery table in `discover_builds.rs`), target resolution including the `ROCM_CLI_VLLM_ROCM_INDEX_URL` override (`vllm_install_target`), and the static-table SDK-version matchers. It also holds `verified_torchaudio_release`, which the crate re-exports from `lib.rs` for the `rocm` binary. It imports only `discover_builds.rs` and runs no process. [`lib.rs`](../engines/vllm/src/lib.rs) keeps only CLI/envelope dispatch and the few items shared across those modules. diff --git a/engines/vllm/src/discover_builds.rs b/engines/vllm/src/discover_builds.rs new file mode 100644 index 0000000000..99d7a92462 --- /dev/null +++ b/engines/vllm/src/discover_builds.rs @@ -0,0 +1,284 @@ +// Copyright © Advanced Micro Devices, Inc., or its affiliates. +// +// SPDX-License-Identifier: MIT + +/// Whether `recorded` and `table_key` name the same ROCm `major.minor` line, +/// ignoring patch and any dev/pre-release suffix. See +/// [`vllm_rocm_discover_build`] for why the line, not the exact release, is +/// what a discover row covers. Lives here, beside the table, so that +/// `runtime.rs` and `wheel_builds.rs` can both match against it without either +/// importing the other's discover-build code. +pub(crate) fn rocm_sdk_series_matches(recorded: &str, table_key: &str) -> bool { + fn series(version: &str) -> Option<(u64, u64)> { + let mut parts = version.trim().split('.'); + let major = parts.next()?.parse().ok()?; + let minor: String = parts + .next()? + .chars() + .take_while(char::is_ascii_digit) + .collect(); + Some((major, minor.parse().ok()?)) + } + series(recorded).is_some_and(|version| Some(version) == series(table_key)) +} + +/// How a [`VllmRocmDiscoverBuild`] row constrains the release discovery may +/// resolve for one package. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub(crate) enum DiscoverVersion { + /// `{pkg}=={series}.*`: the newest release in the series. + Series(&'static str), + /// `{pkg}=={release}`: exactly this release. Under PEP 440 a specifier + /// without a local version still matches any `+rocm…` local version of + /// it, but not a longer release such as `{release}.2`. Needed where AMD + /// publishes rebuilds as extra release segments (torchaudio + /// `2.11.0`/`2.11.0.2`/`2.11.0.3`, each paired with a different torch), so + /// a series match would pick the rebuild for the wrong torch. + Exact(&'static str), +} + +impl DiscoverVersion { + /// The requirement handed to `uv` for `pkg`. + pub(crate) fn requirement(self, pkg: &str) -> String { + match self { + Self::Series(series) => format!("{pkg}=={series}.*"), + Self::Exact(release) => format!("{pkg}=={release}"), + } + } +} + +/// A ROCm SDK version whose vLLM/flash-attn/amd-aiter wheels aren't published +/// under a fixed filename (AMD rotates the dev-tag suffix constantly), so the +/// exact wheel must be discovered from the index at install time instead of +/// pinned in `wheel_builds::VLLM_ROCM_BUILD_TABLE`. +pub(crate) struct VllmRocmDiscoverBuild { + pub(crate) rocm_sdk_version: &'static str, + /// PEP 425 interpreter tag this row's wheels are published for. AMD builds + /// ROCm 10.x `vllm`, `flash-attn` and `amd-aiter` for exactly one CPython + /// version, so a venv on any other interpreter resolves nothing at all. + pub(crate) python_tag: &'static str, + /// Index publishing this row's rotating-dev-tag vLLM/flash-attn/amd-aiter + /// wheels. Per-row because ROCm 10.1 frameworks are staged on a different + /// host than 10.0's. + pub(crate) vllm_index_url: &'static str, + /// Index publishing this row's torch build. + pub(crate) torch_index_url: &'static str, + pub(crate) vllm_version_prefix: &'static str, + pub(crate) flash_attn_version_prefix: &'static str, + pub(crate) amd_aiter_version_prefix: &'static str, + pub(crate) torch_version_prefix: &'static str, + /// torchvision's version prefix is always the ROCm "Next" torch minor + /// plus 15 (torch 2.12 pairs with torchvision 0.27); torchaudio has no + /// such rule and is hardcoded per row to whatever AMD has actually + /// published for it. Both are discovered fresh alongside torch rather + /// than trusted from a pre-install snapshot, so the triplet installed + /// here is always coherent with the torch version this row actually pins + /// (see `install_vllm_rocm10_discover`). + pub(crate) torchvision_version_prefix: &'static str, + /// [`DiscoverVersion::Exact`] wherever the row's index publishes more than + /// one rebuild of a torchaudio series, which `whl-next` does (`2.11.0`, + /// `2.11.0.2`, `2.11.0.3`, each paired with a different torch): a series + /// match takes the newest, i.e. the rebuild for some *other* row's torch. + /// [`DiscoverVersion::Series`] is only safe on an index that serves one + /// build per series. + /// + /// An [`DiscoverVersion::Exact`] torchaudio is also the hardware-verified + /// build for the row's ROCm line, and `rocm install sdk` pins it too, via + /// [`verified_torchaudio_release`](crate::wheel_builds::verified_torchaudio_release): set one only for a build confirmed to + /// load against the row's torch on real hardware, never as a guess. + pub(crate) torchaudio_version: DiscoverVersion, +} + +/// Every ROCm SDK `major.minor` line the engine installs by live wheel +/// discovery, one row each, and the only list of those versions. +/// +/// Three readers follow it with nothing else to keep in step: install routing +/// ([`vllm_rocm_discover_build`], through `wheel_builds::vllm_install_route`), +/// the static-pin fallback that fails closed for a 10.x line with no row +/// (`wheel_builds::vllm_install_target`), and launch-time environment setup +/// (`runtime::runtime_has_discover_build`). Adding, removing or reordering a +/// row therefore changes all three together; +/// `discover_build_table_pins_the_versions_it_serves_in_order` makes that a +/// reviewed edit. +pub(crate) const VLLM_ROCM_DISCOVER_BUILD_TABLE: &[VllmRocmDiscoverBuild] = &[ + VllmRocmDiscoverBuild { + rocm_sdk_version: "10.0.0", + python_tag: "cp314", + vllm_index_url: "https://rocm.frameworks.amd.com/whl-multi-arch/vllm/", + torch_index_url: "https://stable.repo.amd.com/rocm/whl-next/", + vllm_version_prefix: "0.27", + flash_attn_version_prefix: "2.8", + amd_aiter_version_prefix: "0.1", + torch_version_prefix: "2.12", + torchvision_version_prefix: "0.27", + // Still a series match, unlike the 10.1 row below, and unverified + // against `whl-next` now that both rows read from it: that index is + // flat across ROCm lines, so a series match here can resolve a + // `+rocm10.1.0` wheel, which `ensure_rocm_local_version_matches` + // rejects. Left as-is rather than pinned blind -- which torchaudio + // rebuild pairs with 10.0's torch 2.12 needs a live 10.0 box to + // establish, and this row has no coverage on the self-hosted lanes. + // `rocm install sdk` reads this field too: see `torchaudio_version`. + torchaudio_version: DiscoverVersion::Series("2.11"), + }, + VllmRocmDiscoverBuild { + rocm_sdk_version: "10.1.0", + python_tag: "cp314", + vllm_index_url: "https://rocm.frameworks-prereleases.amd.com/whl-multi-arch-staging/vllm/", + // Torch stack from `whl-next`, not staging: it is the index + // `rocm install sdk` resolves the 10.1 SDK's own `+rocm10.1.0` torch + // stack from, so vLLM realigns onto the same builds rather than + // staging's `rc` ones. + torch_index_url: "https://stable.repo.amd.com/rocm/whl-next/", + vllm_version_prefix: "0.29", + flash_attn_version_prefix: "2.8", + amd_aiter_version_prefix: "0.1", + // 2.13, not 2.12: AMD's own `rocm/vllm:rocm10.1.0_..._vllm-0.29.0` + // image (whose Dockerfile build args pin `TORCH_VERSION=2.13.0`, + // `TORCHVISION_VERSION=0.28.0`) builds this exact vllm release + // against torch 2.13, not 2.12. `vllm` 0.29's own `_rocm_C.abi3.so` + // needs a `c10::NotImplementedError` constructor symbol torch + // 2.12.0+rocm10.1.0 does not export; 2.13 is published on this same + // `whl-next` index and matches what vllm was actually built against. + torch_version_prefix: "2.13", + torchvision_version_prefix: "0.28", + // Exact, not `2.11.*`: `whl-next` publishes three `+rocm10.1.0` + // torchaudio builds, `2.11.0`, `2.11.0.2` and `2.11.0.3`. `2.11.0` is + // a CPU-only rebuild (no `libamdhip64`/`libc10_hip`/`libtorch_hip` + // in its `.so`s) that predates torch's stable-ABI split and does not + // reference the `torch_exception_get_what` / `torch_new_stable_ivalue` + // symbols torch 2.13 exports. `2.11.0.2` and `2.11.0.3` are both HIP + // builds against that same stable ABI (confirmed on a live Strix Halo + // box: torch 2.13.0+rocm10.1.0 exports both symbols as `T`, and + // torchaudio 2.11.0.2 imports them as `U`); a series match would + // resolve the newest, `2.11.0.3`, so pin the lower of the two + // confirmed-working builds instead. `rocm install sdk` pins this same + // build for the 10.1 line: see `torchaudio_version`. + torchaudio_version: DiscoverVersion::Exact("2.11.0.2"), + }, +]; + +/// Looks up the discovery build recipe for a ROCm SDK version, if any. +/// +/// Matched on `major.minor`, ignoring patch and any dev/pre-release suffix. A +/// discover row is a live resolver recipe rather than one pinned filename, so +/// it does span a release line, but only a `major.minor` one: 10.0 and 10.1 +/// publish genuinely different wheels (vLLM `0.27` from +/// `rocm.frameworks.amd.com` versus `0.29` from the staging host), so a +/// major-only row would serve one SDK's wheels to the other. Patch is still +/// ignored, because AMD does rotate the patch and dev tag within a line +/// (`whl-multi-arch/torch/` carries `+rocm7.13.0`, `+rocm7.14.0` and +/// `+rocm7.14.1` as coexisting builds) and a row keyed to an exact string +/// would silently stop matching. An unknown line matches nothing and fails +/// closed in [`crate::wheel_builds::vllm_install_target`] rather than falling back to a +/// stale static pin. +pub(crate) fn vllm_rocm_discover_build( + rocm_sdk_version: &str, +) -> Option<&'static VllmRocmDiscoverBuild> { + VLLM_ROCM_DISCOVER_BUILD_TABLE + .iter() + .find(|build| rocm_sdk_series_matches(rocm_sdk_version, build.rocm_sdk_version)) +} + +#[cfg(test)] +mod tests { + use super::*; + + /// The ROCm SDK versions the discover-build table serves, in table order. + /// + /// Pinned on purpose: adding, removing or reordering a row changes which + /// runtimes are installed by discovery and which get the discovery launch + /// environment, so it has to show up as a reviewed edit of this list + /// rather than slip through a test that only compares the data with itself. + #[test] + fn discover_build_table_pins_the_versions_it_serves_in_order() { + let versions: Vec<&str> = VLLM_ROCM_DISCOVER_BUILD_TABLE + .iter() + .map(|build| build.rocm_sdk_version) + .collect(); + assert_eq!( + versions, + ["10.0.0", "10.1.0"], + "the discover-build table's versions or order changed: install routing, the \ + launch environment and the fail-closed static fallback all follow it" + ); + } + #[test] + fn vllm_rocm_discover_build_looks_up_known_and_unknown_versions() { + assert!(vllm_rocm_discover_build("10.0.0").is_some()); + // AMD tags preview wheels with the real target release (verified via + // whl-multi-arch/torch/'s coexisting +rocm7.13.0/7.14.0/7.14.1 + // builds), so a pre-release suffix on a known major.minor must still + // match its row (here the dedicated 10.1.0 one), not just an exact + // version string. + assert!(vllm_rocm_discover_build("10.1.0a20260822").is_some()); + assert!(vllm_rocm_discover_build("999.0.0").is_none()); + } + /// A series renders with the `.*` that lets `uv` take the newest release + /// in it; an exact release renders bare, so it cannot. + #[test] + fn discover_version_renders_series_and_exact_requirements() { + assert_eq!( + DiscoverVersion::Series("2.11").requirement("torchaudio"), + "torchaudio==2.11.*" + ); + // No trailing `.*`: that would also admit the `2.11.0.2`/`2.11.0.3` + // rebuilds an exact pin exists to exclude. + assert_eq!( + DiscoverVersion::Exact("2.11.0").requirement("torchaudio"), + "torchaudio==2.11.0" + ); + } + /// The 10.1 row must reach the staging host for vLLM, which is only + /// published there, but takes its torch stack from `whl-next` just like + /// 10.0, the same index `rocm install sdk` resolves its own + /// `+rocm10.1.0` torch stack from (though the SDK's resolve and this + /// row's discovery are independent: this row pins its own version + /// prefixes rather than matching whatever the SDK happened to install). + /// Its torchaudio is pinned exactly: a `2.11.*` match resolves the + /// newest rebuild, `2.11.0.3`; `2.11.0.2` is the lower of the two builds + /// confirmed (on a live Strix Halo box) to load against torch 2.13 + /// (therock-next-09). 10.0 keeps the production frameworks index for + /// vLLM. The live half of this is therock-next-09. + #[test] + fn discover_rows_select_their_own_indexes() { + let ten_zero = vllm_rocm_discover_build("10.0.0").expect("10.0.0 has a discover row"); + assert_eq!( + ten_zero.vllm_index_url, + "https://rocm.frameworks.amd.com/whl-multi-arch/vllm/" + ); + assert_eq!( + ten_zero.torch_index_url, + "https://stable.repo.amd.com/rocm/whl-next/" + ); + assert_eq!(ten_zero.vllm_version_prefix, "0.27"); + + // A real probe carries a patch and dev suffix the table key never does. + let ten_one = vllm_rocm_discover_build("10.1.0a20260928").expect("10.1 has a discover row"); + assert_eq!( + ten_one.vllm_index_url, + "https://rocm.frameworks-prereleases.amd.com/whl-multi-arch-staging/vllm/" + ); + assert_eq!( + ten_one.torch_index_url, + "https://stable.repo.amd.com/rocm/whl-next/" + ); + assert_eq!(ten_one.vllm_version_prefix, "0.29"); + // 2.13/0.28, not 2.12/0.27: the pair AMD's own + // `rocm/vllm:...vllm-0.29.0` image builds this vllm release against. + assert_eq!(ten_one.torch_version_prefix, "2.13"); + assert_eq!(ten_one.torchvision_version_prefix, "0.28"); + // `whl-next` carries `2.11.0`, `2.11.0.2` and `2.11.0.3` for + // `+rocm10.1.0`; `2.11.0` is CPU-only, and a series match would + // resolve the newest, `2.11.0.3`, not the confirmed-working + // `2.11.0.2`, so this must stay exact and never a series. + assert_eq!( + ten_one.torchaudio_version, + DiscoverVersion::Exact("2.11.0.2") + ); + + // An unpublished line must not borrow another line's wheels. + assert!(vllm_rocm_discover_build("10.2.0").is_none()); + assert!(vllm_rocm_discover_build("7.2.3").is_none()); + } +} diff --git a/engines/vllm/src/install.rs b/engines/vllm/src/install.rs index 8b5df52147..26453cb1ac 100644 --- a/engines/vllm/src/install.rs +++ b/engines/vllm/src/install.rs @@ -11,15 +11,17 @@ use rocm_engine_protocol::{InstallRequest, InstallResponse}; use std::path::{Path, PathBuf}; use std::process::Command as ProcessCommand; +use crate::discover_builds::{ + DiscoverVersion, VllmRocmDiscoverBuild, rocm_sdk_series_matches, vllm_rocm_discover_build, +}; use crate::repair::{RepairAssessment, assess_runtime_repair}; use crate::runtime::{ assessed_python_for_repair, describe_skipped_managed_runtimes, resolve_managed_runtime_python, - resolve_vllm_runtime, rocm_sdk_series_matches, runtime_is_managed, vllm_runtime_warnings, + resolve_vllm_runtime, runtime_is_managed, vllm_runtime_warnings, }; use crate::state::runtime_lock_hash; use crate::wheel_builds::{ - DiscoverVersion, VllmInstallRoute, VllmInstallTarget, VllmRocmDiscoverBuild, - vllm_install_route, vllm_install_target, vllm_rocm_discover_build, + VllmInstallRoute, VllmInstallTarget, vllm_install_route, vllm_install_target, }; pub(crate) fn install_response(request: InstallRequest) -> Result { diff --git a/engines/vllm/src/lib.rs b/engines/vllm/src/lib.rs index c444275bed..6d203b420d 100644 --- a/engines/vllm/src/lib.rs +++ b/engines/vllm/src/lib.rs @@ -17,6 +17,7 @@ use serde_json::Value; use std::io::{Read, Write}; use std::path::PathBuf; +mod discover_builds; mod install; mod process; mod repair; diff --git a/engines/vllm/src/process.rs b/engines/vllm/src/process.rs index 98ccd5ead5..1d6acf7c1e 100644 --- a/engines/vllm/src/process.rs +++ b/engines/vllm/src/process.rs @@ -922,19 +922,7 @@ mod tests { } #[test] fn launch_env_sets_vllm_rocm_target_device() -> Result<()> { - let runtime = VllmRuntime { - runtime_id: "therock-release:gfx120X-all".to_owned(), - env_id: "external-vllm-therock".to_owned(), - command: PathBuf::from("vllm"), - python_executable: None, - version: None, - source: "managed_runtime_manifest:test".to_owned(), - sdk_root: None, - sdk_bin: None, - sdk_bin_paths: Vec::new(), - sdk_library_paths: Vec::new(), - rocm_sdk_version: None, - }; + let runtime = VllmRuntime::for_test(); let mut command = ProcessCommand::new("vllm"); apply_therock_env(&mut command, &runtime)?; @@ -966,17 +954,9 @@ mod tests { std::os::unix::fs::symlink("/does/not/exist", &stale_shim)?; let runtime = VllmRuntime { - runtime_id: "therock-release:gfx120X-all".to_owned(), - env_id: "external-vllm-therock".to_owned(), - command: PathBuf::from("vllm"), python_executable: Some(env.path().join("bin").join("python")), - version: None, - source: "managed_runtime_manifest:test".to_owned(), sdk_root: Some(env.path().join("sdk")), - sdk_bin: None, - sdk_bin_paths: Vec::new(), - sdk_library_paths: Vec::new(), - rocm_sdk_version: None, + ..VllmRuntime::for_test() }; let mut command = ProcessCommand::new("vllm"); @@ -1006,17 +986,9 @@ mod tests { let env = tempfile::tempdir()?; let runtime = VllmRuntime { - runtime_id: "therock-release:gfx120X-all".to_owned(), - env_id: "external-vllm-therock".to_owned(), - command: PathBuf::from("vllm"), python_executable: Some(env.path().join("bin").join("python")), - version: None, - source: "managed_runtime_manifest:test".to_owned(), sdk_root: Some(env.path().join("sdk")), - sdk_bin: None, - sdk_bin_paths: Vec::new(), - sdk_library_paths: Vec::new(), - rocm_sdk_version: None, + ..VllmRuntime::for_test() }; let mut command = ProcessCommand::new("vllm"); @@ -1053,17 +1025,9 @@ mod tests { // `compat_dir` must not keep that directory on the loader path. let env = tempfile::tempdir()?; let runtime = VllmRuntime { - runtime_id: "therock-release:gfx120X-all".to_owned(), - env_id: "external-vllm-therock".to_owned(), - command: PathBuf::from("vllm"), python_executable: Some(env.path().join("bin").join("python")), - version: None, - source: "managed_runtime_manifest:test".to_owned(), sdk_root: Some(env.path().join("sdk")), - sdk_bin: None, - sdk_bin_paths: Vec::new(), - sdk_library_paths: Vec::new(), - rocm_sdk_version: None, + ..VllmRuntime::for_test() }; // Plant the leftover directly, bypassing `ensure_mpi_cxx_compat`: @@ -1097,15 +1061,10 @@ mod tests { VllmRuntime { runtime_id: "test".to_owned(), env_id: "test".to_owned(), - command: PathBuf::from("vllm"), python_executable, - version: None, source: "test".to_owned(), - sdk_root: None, - sdk_bin: None, - sdk_bin_paths: Vec::new(), - sdk_library_paths: Vec::new(), rocm_sdk_version, + ..VllmRuntime::for_test() } } #[test] diff --git a/engines/vllm/src/runtime.rs b/engines/vllm/src/runtime.rs index 448c3b188a..29b87b2e39 100644 --- a/engines/vllm/src/runtime.rs +++ b/engines/vllm/src/runtime.rs @@ -2,6 +2,7 @@ // // SPDX-License-Identifier: MIT +use crate::discover_builds::vllm_rocm_discover_build; use anyhow::{Context, Result, bail}; use rocm_core::{AppPaths, split_local_version}; use serde::Deserialize; @@ -28,6 +29,31 @@ pub(crate) struct VllmRuntime { pub(crate) rocm_sdk_version: Option, } +#[cfg(test)] +impl VllmRuntime { + /// The one place tests outside this struct's own definition get a runtime + /// from: a managed TheRock runtime with every optional part empty. A test + /// overrides only the fields it is about, with struct-update syntax + /// (`VllmRuntime { sdk_root: Some(root), ..VllmRuntime::for_test() }`), so a + /// field added to the struct is defaulted here once instead of breaking + /// every test module that builds one. + pub(crate) fn for_test() -> Self { + Self { + runtime_id: "therock-release:gfx120X-all".to_owned(), + env_id: "external-vllm-therock".to_owned(), + command: PathBuf::from("vllm"), + python_executable: None, + version: None, + source: "managed_runtime_manifest:test".to_owned(), + sdk_root: None, + sdk_bin: None, + sdk_bin_paths: Vec::new(), + sdk_library_paths: Vec::new(), + rocm_sdk_version: None, + } + } +} + #[derive(Debug, Clone, Default, Deserialize)] pub(crate) struct TheRockRuntimeManifest { #[serde(default)] @@ -95,57 +121,20 @@ pub(crate) fn runtime_is_managed(runtime: &VllmRuntime) -> bool { runtime.source.starts_with("managed_runtime_manifest") } -/// The ROCm SDK 10.0 release line, as it appears in both -/// [`ROCM_DISCOVER_BUILD_VERSIONS`] and `wheel_builds.rs`'s discover-build table. -pub(crate) const ROCM_SDK_10_0: &str = "10.0.0"; -/// The ROCm SDK 10.1 release line, as it appears in both -/// [`ROCM_DISCOVER_BUILD_VERSIONS`] and `wheel_builds.rs`'s discover-build table. -pub(crate) const ROCM_SDK_10_1: &str = "10.1.0"; - -/// ROCm SDK versions keyed by a row in `wheel_builds.rs`'s discover-build table -/// (see [`crate::wheel_builds::vllm_rocm_discover_build`] for the recipe each one -/// resolves to: wheel indexes, version prefixes, interpreter tag). Defined -/// here, in the lower layer, as the single source for which versions count — -/// `wheel_builds.rs`'s table literally uses these constants for its -/// `rocm_sdk_version` fields, and [`runtime_has_discover_build`] below -/// matches against the same two strings. This list and that table are still -/// two separate pieces of data, kept in agreement only by -/// `wheel_builds.rs`'s `vllm_rocm_discover_build_table_matches_the_discover_version_list` -/// test, not by construction — a new table row needs a matching entry here, -/// and that test is what catches it if one is missed. -pub(crate) const ROCM_DISCOVER_BUILD_VERSIONS: &[&str] = &[ROCM_SDK_10_0, ROCM_SDK_10_1]; - -/// Whether `recorded` and `table_key` name the same ROCm `major.minor` line, -/// ignoring patch and any dev/pre-release suffix. See -/// [`crate::wheel_builds::vllm_rocm_discover_build`] for why the line, not the -/// exact release, is what a discover row covers. Lives here, not in -/// `wheel_builds.rs`, alongside [`ROCM_DISCOVER_BUILD_VERSIONS`] so -/// [`runtime_has_discover_build`] can match without calling into `wheel_builds`. -pub(crate) fn rocm_sdk_series_matches(recorded: &str, table_key: &str) -> bool { - fn series(version: &str) -> Option<(u64, u64)> { - let mut parts = version.trim().split('.'); - let major = parts.next()?.parse().ok()?; - let minor: String = parts - .next()? - .chars() - .take_while(char::is_ascii_digit) - .collect(); - Some((major, minor.parse().ok()?)) - } - series(recorded).is_some_and(|version| Some(version) == series(table_key)) -} - /// Whether `runtime`'s recorded ROCm SDK version has a live discover-build -/// recipe. Exposed as runtime metadata, matched directly against -/// [`ROCM_DISCOVER_BUILD_VERSIONS`], so callers outside `wheel_builds` — the -/// vLLM launch path in `process.rs`, specifically — don't need to reach into -/// `wheel_builds`'s build-selection table for a plain yes/no check. +/// recipe: the same row lookup install routing uses +/// ([`vllm_rocm_discover_build`], over the one discover-build table in +/// `discover_builds.rs`), so a version is a discover build for launch-time +/// environment setup exactly when it is one for install routing. There is no +/// separate list of versions to keep in step with that table. Exposed as +/// runtime metadata so callers outside `wheel_builds` — the vLLM launch path +/// in `process.rs`, specifically — don't need to reach into its +/// build-selection code for a plain yes/no check. pub(crate) fn runtime_has_discover_build(runtime: &VllmRuntime) -> bool { - runtime.rocm_sdk_version.as_deref().is_some_and(|version| { - ROCM_DISCOVER_BUILD_VERSIONS - .iter() - .any(|key| rocm_sdk_series_matches(version, key)) - }) + runtime + .rocm_sdk_version + .as_deref() + .is_some_and(|version| vllm_rocm_discover_build(version).is_some()) } pub(crate) fn vllm_runtime_warnings(runtime: &VllmRuntime) -> Vec { @@ -857,21 +846,14 @@ mod tests { #[test] fn managed_env_reflects_managed_runtime_manifest_source() { let mut runtime = VllmRuntime { - runtime_id: "therock-release:gfx120X-all".to_owned(), - env_id: "external-vllm-therock".to_owned(), command: PathBuf::from(if cfg!(windows) { r"C:\venv\Scripts\vllm.exe" } else { "/home/user/.venv/bin/vllm" }), - python_executable: None, version: Some("test".to_owned()), source: "managed_runtime_manifest:vllm-source-pip-gfx120x-all".to_owned(), - sdk_root: None, - sdk_bin: None, - sdk_bin_paths: Vec::new(), - sdk_library_paths: Vec::new(), - rocm_sdk_version: None, + ..VllmRuntime::for_test() }; assert!(runtime_is_managed(&runtime)); @@ -897,18 +879,13 @@ mod tests { // assessed environment or it fixes an interpreter nobody found broken. let assessed = VllmRuntime { runtime_id: "nightly-wheel-gfx94x-dcgpu-7-14-0a20260611".to_owned(), - env_id: "external-vllm-therock".to_owned(), command: PathBuf::from("/rocm/runtimes/wheel/nightly-gfx94x/bin/vllm"), python_executable: Some(PathBuf::from( "/rocm/runtimes/wheel/nightly-gfx94x/bin/python", )), version: Some("0.26.0".to_owned()), source: "managed_runtime_manifest:nightly-wheel-gfx94x-dcgpu".to_owned(), - sdk_root: None, - sdk_bin: None, - sdk_bin_paths: Vec::new(), - sdk_library_paths: Vec::new(), - rocm_sdk_version: None, + ..VllmRuntime::for_test() }; let target = assessed_python_for_repair(&assessed).expect("a managed runtime has a python"); @@ -995,16 +972,10 @@ mod tests { fn runtime_with_sdk_version(version: Option<&str>) -> VllmRuntime { VllmRuntime { runtime_id: "nightly-wheel-gfx94x-dcgpu".to_owned(), - env_id: "external-vllm-therock".to_owned(), command: PathBuf::from("/rocm/runtimes/wheel/nightly-gfx94x/bin/vllm"), - python_executable: None, - version: None, source: "managed_runtime_manifest:nightly-wheel-gfx94x-dcgpu".to_owned(), - sdk_root: None, - sdk_bin: None, - sdk_bin_paths: Vec::new(), - sdk_library_paths: Vec::new(), rocm_sdk_version: version.map(ToOwned::to_owned), + ..VllmRuntime::for_test() } } #[test] @@ -1036,17 +1007,11 @@ mod tests { // for the step that does). let root = PathBuf::from("/tmp/rocm-sdk"); let runtime = VllmRuntime { - runtime_id: "therock-release:gfx120X-all".to_owned(), - env_id: "external-vllm-therock".to_owned(), - command: PathBuf::from("vllm"), - python_executable: None, - version: None, - source: "managed_runtime_manifest:test".to_owned(), sdk_root: Some(root.clone()), sdk_bin: Some(root.join("bin")), sdk_bin_paths: vec![root.join("runtime").join("bin")], sdk_library_paths: vec![root.join("runtime").join("lib")], - rocm_sdk_version: None, + ..VllmRuntime::for_test() }; let entries = therock_library_path_entries(&runtime); assert!(entries.contains(&root.join("runtime").join("lib"))); @@ -1074,17 +1039,9 @@ mod tests { #[cfg(target_os = "linux")] fn runtime_with_compat_dir(env_root: &Path) -> VllmRuntime { VllmRuntime { - runtime_id: "therock-release:gfx120X-all".to_owned(), - env_id: "external-vllm-therock".to_owned(), - command: PathBuf::from("vllm"), python_executable: Some(env_root.join("bin").join("python")), - version: None, - source: "managed_runtime_manifest:test".to_owned(), sdk_root: Some(env_root.join("sdk")), - sdk_bin: None, - sdk_bin_paths: Vec::new(), - sdk_library_paths: Vec::new(), - rocm_sdk_version: None, + ..VllmRuntime::for_test() } } @@ -1182,15 +1139,9 @@ mod tests { let runtime = VllmRuntime { runtime_id: "external-vllm-python".to_owned(), env_id: "external-vllm-python".to_owned(), - command: PathBuf::from("vllm"), python_executable: Some(env.path().join("bin").join("python")), - version: None, source: "environment python".to_owned(), - sdk_root: None, - sdk_bin: None, - sdk_bin_paths: Vec::new(), - sdk_library_paths: Vec::new(), - rocm_sdk_version: None, + ..VllmRuntime::for_test() }; let shim = ensure_therock_compat_shims(&runtime, rocm_core::openmpi::ensure_mpi_cxx_compat); diff --git a/engines/vllm/src/state.rs b/engines/vllm/src/state.rs index bca142849a..2691dc62fa 100644 --- a/engines/vllm/src/state.rs +++ b/engines/vllm/src/state.rs @@ -503,16 +503,12 @@ mod tests { engine_recipe: None, }; let runtime = VllmRuntime { - runtime_id: "therock-release:gfx120X-all".to_owned(), - env_id: "external-vllm-therock".to_owned(), command: PathBuf::from(if cfg!(windows) { r"C:\venv\Scripts\vllm.exe" } else { "/home/user/.venv/bin/vllm" }), - python_executable: None, version: Some("test".to_owned()), - source: "managed_runtime_manifest:test".to_owned(), sdk_root: Some(PathBuf::from(if cfg!(windows) { r"C:\rocm-sdk" } else { @@ -533,7 +529,7 @@ mod tests { } else { "/home/user/.venv/lib/python/site-packages/_rocm_sdk_libraries/lib" })], - rocm_sdk_version: None, + ..VllmRuntime::for_test() }; write_running_state(&request, &runtime, own_pid)?; @@ -671,17 +667,8 @@ mod tests { engine_recipe: Some(recipe), }; let runtime = VllmRuntime { - runtime_id: "therock-release:gfx120X-all".to_owned(), - env_id: "external-vllm-therock".to_owned(), - command: PathBuf::from("vllm"), - python_executable: None, version: Some("test".to_owned()), - source: "managed_runtime_manifest:test".to_owned(), - sdk_root: None, - sdk_bin: None, - sdk_bin_paths: Vec::new(), - sdk_library_paths: Vec::new(), - rocm_sdk_version: None, + ..VllmRuntime::for_test() }; write_running_state(&request, &runtime, std::process::id())?; diff --git a/engines/vllm/src/wheel_builds.rs b/engines/vllm/src/wheel_builds.rs index 1c69201507..e1358d9608 100644 --- a/engines/vllm/src/wheel_builds.rs +++ b/engines/vllm/src/wheel_builds.rs @@ -4,7 +4,9 @@ use anyhow::{Result, anyhow, bail}; -use crate::runtime::{ROCM_SDK_10_0, ROCM_SDK_10_1, rocm_sdk_series_matches}; +use crate::discover_builds::{ + DiscoverVersion, VLLM_ROCM_DISCOVER_BUILD_TABLE, vllm_rocm_discover_build, +}; /// Known-good `(ROCm SDK version, vLLM version, ABI tag)` combinations for /// `uv pip install vllm`, keyed by the ROCm SDK version recorded in the @@ -31,153 +33,6 @@ const VLLM_ROCM_BUILD_TABLE: &[VllmRocmBuild] = &[VllmRocmBuild { /// what lets [`vllm_rocm_build_from_index_url`] recover the build a custom /// index serves and keep the requirement pinned to it. const VLLM_ROCM_INDEX_PREFIX: &str = "https://wheels.vllm.ai/rocm"; -/// How a [`VllmRocmDiscoverBuild`] row constrains the release discovery may -/// resolve for one package. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub(crate) enum DiscoverVersion { - /// `{pkg}=={series}.*`: the newest release in the series. - Series(&'static str), - /// `{pkg}=={release}`: exactly this release. Under PEP 440 a specifier - /// without a local version still matches any `+rocm…` local version of - /// it, but not a longer release such as `{release}.2`. Needed where AMD - /// publishes rebuilds as extra release segments (torchaudio - /// `2.11.0`/`2.11.0.2`/`2.11.0.3`, each paired with a different torch), so - /// a series match would pick the rebuild for the wrong torch. - Exact(&'static str), -} - -impl DiscoverVersion { - /// The requirement handed to `uv` for `pkg`. - pub(crate) fn requirement(self, pkg: &str) -> String { - match self { - Self::Series(series) => format!("{pkg}=={series}.*"), - Self::Exact(release) => format!("{pkg}=={release}"), - } - } -} - -/// A ROCm SDK version whose vLLM/flash-attn/amd-aiter wheels aren't published -/// under a fixed filename (AMD rotates the dev-tag suffix constantly), so the -/// exact wheel must be discovered from the index at install time instead of -/// pinned in [`VLLM_ROCM_BUILD_TABLE`]. -pub(crate) struct VllmRocmDiscoverBuild { - pub(crate) rocm_sdk_version: &'static str, - /// PEP 425 interpreter tag this row's wheels are published for. AMD builds - /// ROCm 10.x `vllm`, `flash-attn` and `amd-aiter` for exactly one CPython - /// version, so a venv on any other interpreter resolves nothing at all. - pub(crate) python_tag: &'static str, - /// Index publishing this row's rotating-dev-tag vLLM/flash-attn/amd-aiter - /// wheels. Per-row because ROCm 10.1 frameworks are staged on a different - /// host than 10.0's. - pub(crate) vllm_index_url: &'static str, - /// Index publishing this row's torch build. - pub(crate) torch_index_url: &'static str, - pub(crate) vllm_version_prefix: &'static str, - pub(crate) flash_attn_version_prefix: &'static str, - pub(crate) amd_aiter_version_prefix: &'static str, - pub(crate) torch_version_prefix: &'static str, - /// torchvision's version prefix is always the ROCm "Next" torch minor - /// plus 15 (torch 2.12 pairs with torchvision 0.27); torchaudio has no - /// such rule and is hardcoded per row to whatever AMD has actually - /// published for it. Both are discovered fresh alongside torch rather - /// than trusted from a pre-install snapshot, so the triplet installed - /// here is always coherent with the torch version this row actually pins - /// (see `install_vllm_rocm10_discover`). - pub(crate) torchvision_version_prefix: &'static str, - /// [`DiscoverVersion::Exact`] wherever the row's index publishes more than - /// one rebuild of a torchaudio series, which `whl-next` does (`2.11.0`, - /// `2.11.0.2`, `2.11.0.3`, each paired with a different torch): a series - /// match takes the newest, i.e. the rebuild for some *other* row's torch. - /// [`DiscoverVersion::Series`] is only safe on an index that serves one - /// build per series. - /// - /// An [`DiscoverVersion::Exact`] torchaudio is also the hardware-verified - /// build for the row's ROCm line, and `rocm install sdk` pins it too, via - /// [`verified_torchaudio_release`]: set one only for a build confirmed to - /// load against the row's torch on real hardware, never as a guess. - pub(crate) torchaudio_version: DiscoverVersion, -} - -const VLLM_ROCM_DISCOVER_BUILD_TABLE: &[VllmRocmDiscoverBuild] = &[ - VllmRocmDiscoverBuild { - rocm_sdk_version: ROCM_SDK_10_0, - python_tag: "cp314", - vllm_index_url: "https://rocm.frameworks.amd.com/whl-multi-arch/vllm/", - torch_index_url: "https://stable.repo.amd.com/rocm/whl-next/", - vllm_version_prefix: "0.27", - flash_attn_version_prefix: "2.8", - amd_aiter_version_prefix: "0.1", - torch_version_prefix: "2.12", - torchvision_version_prefix: "0.27", - // Still a series match, unlike the 10.1 row below, and unverified - // against `whl-next` now that both rows read from it: that index is - // flat across ROCm lines, so a series match here can resolve a - // `+rocm10.1.0` wheel, which `ensure_rocm_local_version_matches` - // rejects. Left as-is rather than pinned blind -- which torchaudio - // rebuild pairs with 10.0's torch 2.12 needs a live 10.0 box to - // establish, and this row has no coverage on the self-hosted lanes. - // `rocm install sdk` reads this field too: see `torchaudio_version`. - torchaudio_version: DiscoverVersion::Series("2.11"), - }, - VllmRocmDiscoverBuild { - rocm_sdk_version: ROCM_SDK_10_1, - python_tag: "cp314", - vllm_index_url: "https://rocm.frameworks-prereleases.amd.com/whl-multi-arch-staging/vllm/", - // Torch stack from `whl-next`, not staging: it is the index - // `rocm install sdk` resolves the 10.1 SDK's own `+rocm10.1.0` torch - // stack from, so vLLM realigns onto the same builds rather than - // staging's `rc` ones. - torch_index_url: "https://stable.repo.amd.com/rocm/whl-next/", - vllm_version_prefix: "0.29", - flash_attn_version_prefix: "2.8", - amd_aiter_version_prefix: "0.1", - // 2.13, not 2.12: AMD's own `rocm/vllm:rocm10.1.0_..._vllm-0.29.0` - // image (whose Dockerfile build args pin `TORCH_VERSION=2.13.0`, - // `TORCHVISION_VERSION=0.28.0`) builds this exact vllm release - // against torch 2.13, not 2.12. `vllm` 0.29's own `_rocm_C.abi3.so` - // needs a `c10::NotImplementedError` constructor symbol torch - // 2.12.0+rocm10.1.0 does not export; 2.13 is published on this same - // `whl-next` index and matches what vllm was actually built against. - torch_version_prefix: "2.13", - torchvision_version_prefix: "0.28", - // Exact, not `2.11.*`: `whl-next` publishes three `+rocm10.1.0` - // torchaudio builds, `2.11.0`, `2.11.0.2` and `2.11.0.3`. `2.11.0` is - // a CPU-only rebuild (no `libamdhip64`/`libc10_hip`/`libtorch_hip` - // in its `.so`s) that predates torch's stable-ABI split and does not - // reference the `torch_exception_get_what` / `torch_new_stable_ivalue` - // symbols torch 2.13 exports. `2.11.0.2` and `2.11.0.3` are both HIP - // builds against that same stable ABI (confirmed on a live Strix Halo - // box: torch 2.13.0+rocm10.1.0 exports both symbols as `T`, and - // torchaudio 2.11.0.2 imports them as `U`); a series match would - // resolve the newest, `2.11.0.3`, so pin the lower of the two - // confirmed-working builds instead. `rocm install sdk` pins this same - // build for the 10.1 line: see `torchaudio_version`. - torchaudio_version: DiscoverVersion::Exact("2.11.0.2"), - }, -]; - -/// Looks up the discovery build recipe for a ROCm SDK version, if any. -/// -/// Matched on `major.minor`, ignoring patch and any dev/pre-release suffix. A -/// discover row is a live resolver recipe rather than one pinned filename, so -/// it does span a release line, but only a `major.minor` one: 10.0 and 10.1 -/// publish genuinely different wheels (vLLM `0.27` from -/// `rocm.frameworks.amd.com` versus `0.29` from the staging host), so a -/// major-only row would serve one SDK's wheels to the other. Patch is still -/// ignored, because AMD does rotate the patch and dev tag within a line -/// (`whl-multi-arch/torch/` carries `+rocm7.13.0`, `+rocm7.14.0` and -/// `+rocm7.14.1` as coexisting builds) and a row keyed to an exact string -/// would silently stop matching. An unknown line matches nothing and fails -/// closed in [`resolve_vllm_install_target`] rather than falling back to a -/// stale static pin. -pub(crate) fn vllm_rocm_discover_build( - rocm_sdk_version: &str, -) -> Option<&'static VllmRocmDiscoverBuild> { - VLLM_ROCM_DISCOVER_BUILD_TABLE - .iter() - .find(|build| rocm_sdk_series_matches(rocm_sdk_version, build.rocm_sdk_version)) -} - /// The torchaudio release confirmed on hardware for `rocm_sdk_version`'s ROCm /// `major.minor` line: the row's [`DiscoverVersion::Exact`] torchaudio, if it /// has one. `None` for a line with no row, or whose row still matches a series, @@ -390,35 +245,110 @@ fn vllm_rocm_build_from_index_url(index_url: &str) -> Option<(String, String)> { #[cfg(test)] mod tests { use super::*; - use crate::runtime::ROCM_DISCOVER_BUILD_VERSIONS; + fn runtime_recording_sdk_version(version: Option<&str>) -> crate::runtime::VllmRuntime { + crate::runtime::VllmRuntime { + runtime_id: "wheel-gfx1151".to_owned(), + command: std::path::PathBuf::from("/rocm/runtimes/wheel/gfx1151/bin/vllm"), + source: "managed_runtime_manifest:wheel-gfx1151".to_owned(), + rocm_sdk_version: version.map(ToOwned::to_owned), + ..crate::runtime::VllmRuntime::for_test() + } + } + + /// What every reader of the discover-build data decides for one recorded + /// ROCm SDK version: the row the install lookup finds, the install route, + /// whether launch-time env setup treats the runtime as a discover build, and + /// how the static-pin fallback answers (`Some(true)` resolves a pin, + /// `Some(false)` fails closed, `None` when no version is recorded). + #[derive(Debug, PartialEq, Eq)] + struct DiscoverReaders { + row: Option<&'static str>, + route: VllmInstallRoute, + launch_treats_as_discover: bool, + static_pin_resolves: Option, + } + + fn discover_readers(version: Option<&str>) -> DiscoverReaders { + DiscoverReaders { + row: version + .and_then(vllm_rocm_discover_build) + .map(|build| build.rocm_sdk_version), + route: vllm_install_route(None, version), + launch_treats_as_discover: crate::runtime::runtime_has_discover_build( + &runtime_recording_sdk_version(version), + ), + static_pin_resolves: version.map(|v| install_target(None, Some(v)).is_ok()), + } + } + + /// Install routing and launch-time env setup are two readers of the same + /// discover-build data. For every table row, spelled the way a real probe + /// spells it (exact, with a patch, with a dev suffix), both must agree that + /// the runtime is a discover build, and the static-pin fallback must fail + /// closed for it. For a version outside the table, both must agree it is not. #[test] - fn vllm_rocm_discover_build_table_matches_the_discover_version_list() { - // `ROCM_DISCOVER_BUILD_VERSIONS` (runtime.rs) and - // `VLLM_ROCM_DISCOVER_BUILD_TABLE` (here) are two separate pieces of data that - // must name the same ROCm SDK versions — the list drives launch-time env setup - // (`apply_therock_env`), the table drives install routing, and a row present in - // only one of them means a runtime gets installed one way and launched another. - // See the doc comment on `ROCM_DISCOVER_BUILD_VERSIONS` for why nothing but this - // test enforces the agreement. + fn every_discover_row_routes_installs_and_launch_env_the_same_way() { for build in VLLM_ROCM_DISCOVER_BUILD_TABLE { - assert!( - ROCM_DISCOVER_BUILD_VERSIONS.contains(&build.rocm_sdk_version), - "{} is a VLLM_ROCM_DISCOVER_BUILD_TABLE row but missing from \ - ROCM_DISCOVER_BUILD_VERSIONS; launch-time env setup would silently skip it", - build.rocm_sdk_version - ); + let key = build.rocm_sdk_version; + let (major_minor, _) = key + .rsplit_once('.') + .expect("table key is major.minor.patch"); + for spelling in [ + key.to_owned(), + format!("{major_minor}.7"), + format!("{key}a20260822"), + format!("{key}.dev0+abc"), + ] { + assert_eq!( + discover_readers(Some(&spelling)), + DiscoverReaders { + row: Some(key), + route: VllmInstallRoute::RocmDiscover, + launch_treats_as_discover: true, + static_pin_resolves: Some(false), + }, + "readers disagree for {spelling}, a spelling of table row {key}" + ); + } } - for version in ROCM_DISCOVER_BUILD_VERSIONS { - assert!( - VLLM_ROCM_DISCOVER_BUILD_TABLE - .iter() - .any(|build| build.rocm_sdk_version == *version), - "{version} is in ROCM_DISCOVER_BUILD_VERSIONS but has no \ - VLLM_ROCM_DISCOVER_BUILD_TABLE row; install routing has nothing to install \ - for a runtime launch-time env setup now treats as a discover build" + + // Outside the table: no row, static route, no discovery env. A 10.x line + // with no row still fails closed instead of taking the 7.2.3 default + // pin; other lines (and unparsable text) resolve that default. + assert_eq!( + discover_readers(Some("10.2.0")), + DiscoverReaders { + row: None, + route: VllmInstallRoute::Static, + launch_treats_as_discover: false, + static_pin_resolves: Some(false), + } + ); + for outside in ["7.2.3", "999.0.0", "not-a-version"] { + assert_eq!( + discover_readers(Some(outside)), + DiscoverReaders { + row: None, + route: VllmInstallRoute::Static, + launch_treats_as_discover: false, + static_pin_resolves: Some(true), + }, + "readers disagree for {outside}, which is outside the table" ); } + assert_eq!( + discover_readers(None), + DiscoverReaders { + row: None, + route: VllmInstallRoute::Static, + launch_treats_as_discover: false, + static_pin_resolves: None, + } + ); + // `static_pin_resolves: None` above means no version was recorded; the + // fallback itself fails for that case, with its own message. + assert!(install_target(None, None).is_err()); } fn install_target( @@ -541,17 +471,6 @@ mod tests { } } #[test] - fn vllm_rocm_discover_build_looks_up_known_and_unknown_versions() { - assert!(vllm_rocm_discover_build("10.0.0").is_some()); - // AMD tags preview wheels with the real target release (verified via - // whl-multi-arch/torch/'s coexisting +rocm7.13.0/7.14.0/7.14.1 - // builds), so a pre-release suffix on a known major.minor must still - // match its row (here the dedicated 10.1.0 one), not just an exact - // version string. - assert!(vllm_rocm_discover_build("10.1.0a20260822").is_some()); - assert!(vllm_rocm_discover_build("999.0.0").is_none()); - } - #[test] fn rocm_sdk_version_matches_ignores_dev_suffixes_and_rejects_other_releases() { assert!(rocm_sdk_version_matches("10.0.0", "10.0.0")); assert!(rocm_sdk_version_matches("7.13.0a20260423", "7.13.0")); @@ -595,73 +514,6 @@ mod tests { ); assert_eq!(vllm_install_route(None, None), VllmInstallRoute::Static); } - /// A series renders with the `.*` that lets `uv` take the newest release - /// in it; an exact release renders bare, so it cannot. - #[test] - fn discover_version_renders_series_and_exact_requirements() { - assert_eq!( - DiscoverVersion::Series("2.11").requirement("torchaudio"), - "torchaudio==2.11.*" - ); - // No trailing `.*`: that would also admit the `2.11.0.2`/`2.11.0.3` - // rebuilds an exact pin exists to exclude. - assert_eq!( - DiscoverVersion::Exact("2.11.0").requirement("torchaudio"), - "torchaudio==2.11.0" - ); - } - /// The 10.1 row must reach the staging host for vLLM, which is only - /// published there, but takes its torch stack from `whl-next` just like - /// 10.0, the same index `rocm install sdk` resolves its own - /// `+rocm10.1.0` torch stack from (though the SDK's resolve and this - /// row's discovery are independent: this row pins its own version - /// prefixes rather than matching whatever the SDK happened to install). - /// Its torchaudio is pinned exactly: a `2.11.*` match resolves the - /// newest rebuild, `2.11.0.3`; `2.11.0.2` is the lower of the two builds - /// confirmed (on a live Strix Halo box) to load against torch 2.13 - /// (therock-next-09). 10.0 keeps the production frameworks index for - /// vLLM. The live half of this is therock-next-09. - #[test] - fn discover_rows_select_their_own_indexes() { - let ten_zero = vllm_rocm_discover_build("10.0.0").expect("10.0.0 has a discover row"); - assert_eq!( - ten_zero.vllm_index_url, - "https://rocm.frameworks.amd.com/whl-multi-arch/vllm/" - ); - assert_eq!( - ten_zero.torch_index_url, - "https://stable.repo.amd.com/rocm/whl-next/" - ); - assert_eq!(ten_zero.vllm_version_prefix, "0.27"); - - // A real probe carries a patch and dev suffix the table key never does. - let ten_one = vllm_rocm_discover_build("10.1.0a20260928").expect("10.1 has a discover row"); - assert_eq!( - ten_one.vllm_index_url, - "https://rocm.frameworks-prereleases.amd.com/whl-multi-arch-staging/vllm/" - ); - assert_eq!( - ten_one.torch_index_url, - "https://stable.repo.amd.com/rocm/whl-next/" - ); - assert_eq!(ten_one.vllm_version_prefix, "0.29"); - // 2.13/0.28, not 2.12/0.27: the pair AMD's own - // `rocm/vllm:...vllm-0.29.0` image builds this vllm release against. - assert_eq!(ten_one.torch_version_prefix, "2.13"); - assert_eq!(ten_one.torchvision_version_prefix, "0.28"); - // `whl-next` carries `2.11.0`, `2.11.0.2` and `2.11.0.3` for - // `+rocm10.1.0`; `2.11.0` is CPU-only, and a series match would - // resolve the newest, `2.11.0.3`, not the confirmed-working - // `2.11.0.2`, so this must stay exact and never a series. - assert_eq!( - ten_one.torchaudio_version, - DiscoverVersion::Exact("2.11.0.2") - ); - - // An unpublished line must not borrow another line's wheels. - assert!(vllm_rocm_discover_build("10.2.0").is_none()); - assert!(vllm_rocm_discover_build("7.2.3").is_none()); - } /// Only an exact torchaudio pin counts as verified: the 10.1 row's /// `2.11.0.2` is, the 10.0 row's `2.11` series is not, and a line with no /// row has nothing to offer. `rocm install sdk` reads this same answer.