Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak nightly handling #70

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/monobase/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,7 @@ def build_user_venv(args: argparse.Namespace) -> None:
cmd = [uv, 'pip', 'compile', '--python-platform', 'x86_64-unknown-linux-gnu']
# PyPI is inconsistent with Torch index and may include nvidia packages for CPU torch
# Use the same Torch index instead
tv = (
Version.parse('0.0.0')
if torch_version is None
else Version.parse(torch_version)
)
cmd = cmd + index_args(tv, cuda_version) + [args.requirements]
cmd = cmd + index_args(torch_version, cuda_version) + [args.requirements]
env['VIRTUAL_ENV'] = udir
try:
proc = subprocess.run(cmd, check=True, env=env, capture_output=True, text=True)
Expand Down
23 changes: 14 additions & 9 deletions src/monobase/uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os.path
import subprocess
from typing import Optional

from opentelemetry import trace

Expand All @@ -15,18 +16,22 @@ def cuda_suffix(cuda_version: str) -> str:
return 'cpu' if cuda_version == 'cpu' else f'cu{cuda_version.replace(".", "")}'


def torch_index_url(torch_version: Version, cuda_version: str) -> str:
def torch_index_url(cuda_version: str, nightly: bool) -> str:
prefix = 'https://download.pytorch.org/whl'
if torch_version.extra:
prefix = f'{prefix}/nightly'
return f'{prefix}/{cuda_suffix(cuda_version)}'
cu = cuda_suffix(cuda_version)
if nightly:
return f'{prefix}/nightly/{cu}'
else:
return f'{prefix}/{cu}'


def index_args(torch_version: Version, cuda_version: str) -> list[str]:
def index_args(torch_version: Optional[str], cuda_version: str) -> list[str]:
# Nightly builds e.g. 2.6.1.dev20241121
nightly = torch_version is not None and '.dev' in torch_version
return [
# --extra-index-url has high priority than --index-url
'--extra-index-url',
torch_index_url(torch_version, cuda_version),
torch_index_url(cuda_version, nightly),
# PyPI is the default index URL
'--index-url',
'https://pypi.org/simple',
Expand All @@ -44,7 +49,7 @@ def pip_packages(
cu = cuda_suffix(cuda_version)
if torch_version.extra:
# Nightly build
prefix = torch_index_url(torch_version, cuda_version)
prefix = torch_index_url(cuda_version, True)
py = f'cp{python_version.replace(".", "")}'
pkgs = [
f'torch @ {prefix}/torch-{torch_version}%2B{cu}-{py}-{py}-linux_x86_64.whl',
Expand Down Expand Up @@ -125,7 +130,7 @@ def update_venv(
'--emit-index-annotation',
]
cmd = ['uv', 'pip', 'compile', '--python-platform', 'x86_64-unknown-linux-gnu']
cmd = cmd + emit_args + index_args(t, cuda_version) + ['-']
cmd = cmd + emit_args + index_args(torch_version, cuda_version) + ['-']
pkgs = pip_packages(t, python_version, cuda_version, pip_pkgs)
env = os.environ.copy()
env['VIRTUAL_ENV'] = vdir
Expand Down Expand Up @@ -192,7 +197,7 @@ def install_venv(

requirements = os.path.join(rdir, f'{venv}.txt')
cmd = [uv, 'pip', 'install', '--no-deps', '--requirement', requirements]
cmd += index_args(t, cuda_version)
cmd += index_args(torch_version, cuda_version)
env = os.environ.copy()
env['VIRTUAL_ENV'] = vdir
subprocess.run(cmd, check=True, env=env)
Expand Down
Loading