Skip to content

Commit e95ca06

Browse files
committed
Don't cache; separate from interpreter; use /sys/module/nvidia/version
1 parent fe39685 commit e95ca06

File tree

22 files changed

+703
-623
lines changed

22 files changed

+703
-623
lines changed

Cargo.lock

Lines changed: 11 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/uv-cli/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ pub struct PipCompileArgs {
12591259
#[arg(long, overrides_with("emit_index_annotation"), hide = true)]
12601260
pub no_emit_index_annotation: bool,
12611261

1262-
/// The backend to use when fetching packages in the `PyTorch` ecosystem (e.g., `cu126` or `auto`)
1262+
/// The backend to use when fetching packages in the `PyTorch` ecosystem (e.g., `cpu`, `cu126`, or `auto`).
12631263
///
12641264
/// When set, uv will ignore the configured index URLs for packages in the `PyTorch` ecosystem,
12651265
/// and will instead use the defined backend.
@@ -1269,7 +1269,7 @@ pub struct PipCompileArgs {
12691269
///
12701270
/// The `auto` mode will attempt to detect the appropriate `PyTorch` index based on the currently
12711271
/// installed CUDA drivers.
1272-
#[arg(long, value_enum)]
1272+
#[arg(long, value_enum, env = EnvVars::UV_TORCH_BACKEND)]
12731273
pub torch_backend: Option<TorchMode>,
12741274

12751275
#[command(flatten)]
@@ -1513,7 +1513,7 @@ pub struct PipSyncArgs {
15131513
#[arg(long)]
15141514
pub dry_run: bool,
15151515

1516-
/// The backend to use when fetching packages in the `PyTorch` ecosystem (e.g., `cu126` or `auto`)
1516+
/// The backend to use when fetching packages in the `PyTorch` ecosystem (e.g., `cpu`, `cu126`, or `auto`).
15171517
///
15181518
/// When set, uv will ignore the configured index URLs for packages in the `PyTorch` ecosystem,
15191519
/// and will instead use the defined backend.
@@ -1523,7 +1523,7 @@ pub struct PipSyncArgs {
15231523
///
15241524
/// The `auto` mode will attempt to detect the appropriate `PyTorch` index based on the currently
15251525
/// installed CUDA drivers.
1526-
#[arg(long, value_enum)]
1526+
#[arg(long, value_enum, env = EnvVars::UV_TORCH_BACKEND)]
15271527
pub torch_backend: Option<TorchMode>,
15281528

15291529
#[command(flatten)]
@@ -1818,7 +1818,7 @@ pub struct PipInstallArgs {
18181818
#[arg(long)]
18191819
pub dry_run: bool,
18201820

1821-
/// The backend to use when fetching packages in the `PyTorch` ecosystem (e.g., `cu126` or `auto`)
1821+
/// The backend to use when fetching packages in the `PyTorch` ecosystem (e.g., `cpu`, `cu126`, or `auto`)
18221822
///
18231823
/// When set, uv will ignore the configured index URLs for packages in the `PyTorch` ecosystem,
18241824
/// and will instead use the defined backend.
@@ -1828,7 +1828,7 @@ pub struct PipInstallArgs {
18281828
///
18291829
/// The `auto` mode will attempt to detect the appropriate `PyTorch` index based on the currently
18301830
/// installed CUDA drivers.
1831-
#[arg(long, value_enum)]
1831+
#[arg(long, value_enum, env = EnvVars::UV_TORCH_BACKEND)]
18321832
pub torch_backend: Option<TorchMode>,
18331833

18341834
#[command(flatten)]

crates/uv-platform-tags/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ doctest = false
1616
workspace = true
1717

1818
[dependencies]
19-
uv-pep440 = { workspace = true }
2019
uv-small-str = { workspace = true }
2120

2221
memchr = { workspace = true }

crates/uv-platform-tags/src/accelerator.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

crates/uv-platform-tags/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
pub use abi_tag::{AbiTag, ParseAbiTagError};
2-
pub use accelerator::Accelerator;
32
pub use language_tag::{LanguageTag, ParseLanguageTagError};
43
pub use platform::{Arch, Os, Platform, PlatformError};
54
pub use platform_tag::{ParsePlatformTagError, PlatformTag};
65
pub use tags::{BinaryFormat, IncompatibleTag, TagCompatibility, TagPriority, Tags, TagsError};
76

87
mod abi_tag;
9-
mod accelerator;
108
mod language_tag;
119
mod platform;
1210
mod platform_tag;

crates/uv-python/python/get_interpreter_info.py

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -405,47 +405,6 @@ def get_distutils_scheme():
405405
return get_distutils_scheme()
406406

407407

408-
def _detect_cuda_driver_version():
409-
"""Detect the installed CUDA Driver version.
410-
411-
Reads from the `UV_CUDA_DRIVER_VERSION` environment variable, if set; otherwise,
412-
queries `nvidia-smi` for the driver version.
413-
"""
414-
driver_version = os.getenv("UV_CUDA_DRIVER_VERSION")
415-
if driver_version is not None:
416-
return driver_version
417-
418-
import subprocess
419-
420-
try:
421-
result = subprocess.run(
422-
[
423-
"nvidia-smi",
424-
"--query-gpu=driver_version",
425-
"--format=csv",
426-
],
427-
check=True,
428-
capture_output=True,
429-
text=True,
430-
)
431-
return result.stdout.splitlines()[-1]
432-
except (FileNotFoundError, subprocess.CalledProcessError):
433-
return None
434-
435-
436-
def get_accelerator():
437-
cuda_driver_version = _detect_cuda_driver_version()
438-
if cuda_driver_version is None:
439-
accelerator = None
440-
else:
441-
accelerator = {
442-
"name": "cuda",
443-
"driver_version": cuda_driver_version,
444-
}
445-
446-
return accelerator
447-
448-
449408
def get_operating_system_and_architecture():
450409
"""Determine the Python interpreter architecture and operating system.
451410
@@ -574,7 +533,6 @@ def get_operating_system_and_architecture():
574533
)
575534
)
576535
sys.exit(0)
577-
578536
return {"os": operating_system, "arch": architecture}
579537

580538

@@ -593,21 +551,21 @@ def main() -> None:
593551
"sys_platform": sys.platform,
594552
}
595553

596-
os_arch = get_operating_system_and_architecture()
597-
accelerator = get_accelerator()
554+
os_and_arch = get_operating_system_and_architecture()
598555

599556
manylinux_compatible = False
600557

601-
if os_arch["os"]["name"] == "manylinux":
558+
if os_and_arch["os"]["name"] == "manylinux":
602559
# noinspection PyProtectedMember
603560
from .packaging._manylinux import _get_glibc_version, _is_compatible
604561

605562
manylinux_compatible = _is_compatible(
606-
arch=os_arch["arch"], version=_get_glibc_version()
563+
arch=os_and_arch["arch"], version=_get_glibc_version()
607564
)
608-
elif os_arch["os"]["name"] == "musllinux":
565+
elif os_and_arch["os"]["name"] == "musllinux":
609566
manylinux_compatible = True
610567

568+
611569
# By default, pip uses sysconfig on Python 3.10+.
612570
# But Python distributors can override this decision by setting:
613571
# sysconfig._PIP_USE_SYSCONFIG = True / False
@@ -665,14 +623,10 @@ def main() -> None:
665623
# Prior to the introduction of `sysconfig` patching, python-build-standalone installations would always use
666624
# "/install" as the prefix. With `sysconfig` patching, we rewrite the prefix to match the actual installation
667625
# location. So in newer versions, we also write a dedicated flag to indicate standalone builds.
668-
"standalone": (
669-
sysconfig.get_config_var("prefix") == "/install"
670-
or bool(sysconfig.get_config_var("PYTHON_BUILD_STANDALONE"))
671-
),
626+
"standalone": sysconfig.get_config_var("prefix") == "/install" or bool(sysconfig.get_config_var("PYTHON_BUILD_STANDALONE")),
672627
"scheme": get_scheme(use_sysconfig_scheme),
673628
"virtualenv": get_virtualenv(),
674-
"platform": os_arch,
675-
"accelerator": accelerator,
629+
"platform": os_and_arch,
676630
"manylinux_compatible": manylinux_compatible,
677631
# The `t` abiflag for freethreading Python.
678632
# https://peps.python.org/pep-0703/#build-configuration-changes

crates/uv-python/src/interpreter.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use uv_fs::{write_atomic_sync, PythonExt, Simplified};
2121
use uv_install_wheel::Layout;
2222
use uv_pep440::Version;
2323
use uv_pep508::{MarkerEnvironment, StringVersion};
24-
use uv_platform_tags::{Accelerator, Platform};
24+
use uv_platform_tags::Platform;
2525
use uv_platform_tags::{Tags, TagsError};
2626
use uv_pypi_types::{ResolverMarkerEnvironment, Scheme};
2727

@@ -53,7 +53,6 @@ pub struct Interpreter {
5353
target: Option<Target>,
5454
prefix: Option<Prefix>,
5555
pointer_size: PointerSize,
56-
accelerator: Option<Accelerator>,
5756
gil_disabled: bool,
5857
}
5958

@@ -77,7 +76,6 @@ impl Interpreter {
7776
sys_prefix: info.sys_prefix,
7877
sys_base_exec_prefix: info.sys_base_exec_prefix,
7978
pointer_size: info.pointer_size,
80-
accelerator: info.accelerator,
8179
gil_disabled: info.gil_disabled,
8280
sys_base_prefix: info.sys_base_prefix,
8381
sys_base_executable: info.sys_base_executable,
@@ -174,18 +172,12 @@ impl Interpreter {
174172
Ok(base_python)
175173
}
176174

177-
/// Returns the [`Platform`] for this Python executable.
175+
/// Returns the path to the Python virtual environment.
178176
#[inline]
179177
pub fn platform(&self) -> &Platform {
180178
&self.platform
181179
}
182180

183-
/// Returns the [`Accelerator`] for this Python executable.
184-
#[inline]
185-
pub fn accelerator(&self) -> Option<&Accelerator> {
186-
self.accelerator.as_ref()
187-
}
188-
189181
/// Returns the [`MarkerEnvironment`] for this Python executable.
190182
#[inline]
191183
pub const fn markers(&self) -> &MarkerEnvironment {
@@ -737,7 +729,6 @@ struct InterpreterInfo {
737729
stdlib: PathBuf,
738730
standalone: bool,
739731
pointer_size: PointerSize,
740-
accelerator: Option<Accelerator>,
741732
gil_disabled: bool,
742733
}
743734

crates/uv-settings/src/combine.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::path::PathBuf;
33

44
use url::Url;
55

6-
use crate::{FilesystemOptions, Options, PipOptions};
76
use uv_configuration::{
87
ConfigSettings, IndexStrategy, KeyringProviderType, RequiredVersion, TargetTriple,
98
TrustedPublishing,
@@ -15,6 +14,8 @@ use uv_python::{PythonDownloads, PythonPreference, PythonVersion};
1514
use uv_resolver::{AnnotationStyle, ExcludeNewer, ForkStrategy, PrereleaseMode, ResolutionMode};
1615
use uv_torch::TorchMode;
1716

17+
use crate::{FilesystemOptions, Options, PipOptions};
18+
1819
pub trait Combine {
1920
/// Combine two values, preferring the values in `self`.
2021
///

crates/uv-static/src/env_vars.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,4 +673,11 @@ impl EnvVars {
673673
///
674674
/// This is a quasi-standard variable, described, e.g., in `ncurses(3x)`.
675675
pub const COLUMNS: &'static str = "COLUMNS";
676+
677+
/// The CUDA driver version to assume when inferring the PyTorch backend.
678+
#[attr_hidden]
679+
pub const UV_CUDA_DRIVER_VERSION: &'static str = "UV_CUDA_DRIVER_VERSION";
680+
681+
/// Equivalent to the `--torch-backend` command-line argument (e.g., `cpu`, `cu126`, or `auto`).
682+
pub const UV_TORCH_BACKEND: &'static str = "UV_TORCH_BACKEND";
676683
}

crates/uv-torch/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ uv-distribution-types = { workspace = true }
1414
uv-normalize = { workspace = true }
1515
uv-pep440 = { workspace = true }
1616
uv-platform-tags = { workspace = true }
17+
uv-static = { workspace = true }
1718

1819
clap = { workspace = true, optional = true }
1920
either = { workspace = true }
21+
fs-err = { workspace = true }
2022
schemars = { workspace = true, optional = true }
2123
serde = { workspace = true }
24+
thiserror = { workspace = true }
25+
tracing = { workspace = true }
2226

2327
[lints]
2428
workspace = true

0 commit comments

Comments
 (0)