From 3ab6951b0e73de3f04442205b6f0e7bd7e0c1984 Mon Sep 17 00:00:00 2001 From: jt Date: Thu, 15 May 2025 19:25:26 -0700 Subject: [PATCH 1/5] use uv --- README.md | 10 +++++++++- pyproject.toml | 12 ++++++------ torchruntime/installer.py | 15 ++++++++++----- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 56ce1b4..9aa5987 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,12 @@ -# torchruntime +# torchruntime-uv + +A fork of easydiffusion/torchruntime that uses uv instead of pip + +Original readme below: + +--- + + [![Discord Server](https://img.shields.io/discord/1014774730907209781?label=Discord)](https://discord.com/invite/u9yhsFmEkB) **torchruntime** is a lightweight package for automatically installing the appropriate variant of PyTorch on a user's computer, based on their OS, and GPU manufacturer and GPU model. diff --git a/pyproject.toml b/pyproject.toml index e90568c..65683f0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,13 +3,13 @@ requires = [ "setuptools",] build-backend = "setuptools.build_meta" [project] -name = "torchruntime" -version = "1.17.3" -description = "Meant for app developers. A convenient way to install and configure the appropriate version of PyTorch on the user's computer, based on the OS and GPU manufacturer and model number." +name = "torchruntime-uv" +version = "1.0.0" +description = "A fork of easydiffusion/torchruntime that uses uv by default instead of pip" readme = "README.md" requires-python = ">=3.0" classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: Microsoft :: Windows :: Windows 10", "Operating System :: Microsoft :: Windows :: Windows 11", "Operating System :: POSIX :: Linux", "Operating System :: MacOS",] -keywords = [ "torch", "ai", "ml", "llm", "installer", "runtime",] +keywords = [ "torch", "ai", "ml", "llm", "installer", "runtime", "uv",] dynamic = [ "dependencies",] [[project.authors]] name = "cmdr2" @@ -19,8 +19,8 @@ email = "secondary.cmdr2@gmail.com" torchruntime = "torchruntime.__main__:main" [project.urls] -Homepage = "https://github.com/easydiffusion/torchruntime" -"Bug Tracker" = "https://github.com/easydiffusion/torchruntime/issues" +Homepage = "https://github.com/mohnjiles/torchruntime-uv" +"Bug Tracker" = "https://github.com/mohnjiles/torchruntime-uv/issues" [tool.isort] profile = "black" diff --git a/torchruntime/installer.py b/torchruntime/installer.py index 4c5f248..43ae09c 100644 --- a/torchruntime/installer.py +++ b/torchruntime/installer.py @@ -9,7 +9,7 @@ os_name = platform.system() -PIP_PREFIX = [sys.executable, "-m", "pip", "install"] +PIP_PREFIX = ["uv", "pip", "install"] CUDA_REGEX = re.compile(r"^(nightly/)?cu\d+$") ROCM_REGEX = re.compile(r"^(nightly/)?rocm\d+\.\d+$") @@ -76,9 +76,13 @@ def get_install_commands(torch_platform, packages): raise ValueError(f"Unsupported platform: {torch_platform}") -def get_pip_commands(cmds): +def get_pip_commands(cmds, use_uv=True): assert not any(cmd is None for cmd in cmds) - return [PIP_PREFIX + cmd for cmd in cmds] + if use_uv: + pip_prefix = ["uv", "pip", "install"] + else: + pip_prefix = [sys.executable, "-m", "pip", "install"] + return [pip_prefix + cmd for cmd in cmds] def run_commands(cmds): @@ -87,13 +91,14 @@ def run_commands(cmds): subprocess.run(cmd) -def install(packages=[]): +def install(packages=[], use_uv=True): """ packages: a list of strings with package names (and optionally their versions in pip-format). e.g. ["torch", "torchvision"] or ["torch>=2.0", "torchaudio==0.16.0"]. Defaults to ["torch", "torchvision", "torchaudio"]. + use_uv: bool, whether to use uv for installation. Defaults to True. """ gpu_infos = get_gpus() torch_platform = get_torch_platform(gpu_infos) cmds = get_install_commands(torch_platform, packages) - cmds = get_pip_commands(cmds) + cmds = get_pip_commands(cmds, use_uv=use_uv) run_commands(cmds) From c9003a0239c689cef79f40a96fad21224801cb91 Mon Sep 17 00:00:00 2001 From: jt Date: Thu, 13 Nov 2025 18:02:27 -0800 Subject: [PATCH 2/5] add --uv flag --- torchruntime/__main__.py | 17 +++++++++++++---- torchruntime/installer.py | 8 ++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/torchruntime/__main__.py b/torchruntime/__main__.py index 8079d11..97d1acd 100644 --- a/torchruntime/__main__.py +++ b/torchruntime/__main__.py @@ -15,8 +15,9 @@ def print_usage(entry_command: str): Examples: {entry_command} install + {entry_command} install --uv {entry_command} install torch==2.2.0 torchvision==0.17.0 - {entry_command} install torch>=2.0.0 torchaudio + {entry_command} install --uv torch>=2.0.0 torchaudio {entry_command} install torch==2.1.* torchvision>=0.16.0 torchaudio==2.1.0 {entry_command} test # Runs all tests (import, devices, math, functions) @@ -31,6 +32,9 @@ def print_usage(entry_command: str): If no packages are specified, the latest available versions of torch, torchaudio and torchvision will be installed. +Options: + --uv Use uv instead of pip for installation + Version specification formats (follows pip format): package==2.1.0 Exact version package>=2.0.0 Minimum version @@ -56,8 +60,11 @@ def main(): command = sys.argv[1] if command == "install": - package_versions = sys.argv[2:] if len(sys.argv) > 2 else None - install(package_versions) + args = sys.argv[2:] if len(sys.argv) > 2 else [] + use_uv = "--uv" in args + # Remove --uv from args to get package list + package_versions = [arg for arg in args if arg != "--uv"] if args else None + install(package_versions, use_uv=use_uv) elif command == "test": subcommand = sys.argv[2] if len(sys.argv) > 2 else "all" test(subcommand) @@ -65,7 +72,9 @@ def main(): info() else: print(f"Unknown command: {command}") - print_usage() + entry_path = sys.argv[0] + cli = "python -m torchruntime" if "__main__.py" in entry_path else "torchruntime" + print_usage(cli) if __name__ == "__main__": diff --git a/torchruntime/installer.py b/torchruntime/installer.py index 43ae09c..475244f 100644 --- a/torchruntime/installer.py +++ b/torchruntime/installer.py @@ -9,7 +9,7 @@ os_name = platform.system() -PIP_PREFIX = ["uv", "pip", "install"] +PIP_PREFIX = [sys.executable, "-m", "pip", "install"] CUDA_REGEX = re.compile(r"^(nightly/)?cu\d+$") ROCM_REGEX = re.compile(r"^(nightly/)?rocm\d+\.\d+$") @@ -76,7 +76,7 @@ def get_install_commands(torch_platform, packages): raise ValueError(f"Unsupported platform: {torch_platform}") -def get_pip_commands(cmds, use_uv=True): +def get_pip_commands(cmds, use_uv=False): assert not any(cmd is None for cmd in cmds) if use_uv: pip_prefix = ["uv", "pip", "install"] @@ -91,10 +91,10 @@ def run_commands(cmds): subprocess.run(cmd) -def install(packages=[], use_uv=True): +def install(packages=[], use_uv=False): """ packages: a list of strings with package names (and optionally their versions in pip-format). e.g. ["torch", "torchvision"] or ["torch>=2.0", "torchaudio==0.16.0"]. Defaults to ["torch", "torchvision", "torchaudio"]. - use_uv: bool, whether to use uv for installation. Defaults to True. + use_uv: bool, whether to use uv for installation. Defaults to False. """ gpu_infos = get_gpus() From 888b18ad21c0d3377321a97b2026c2f10396e2a7 Mon Sep 17 00:00:00 2001 From: jt Date: Thu, 13 Nov 2025 18:03:09 -0800 Subject: [PATCH 3/5] undo readme changes for PR --- README.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/README.md b/README.md index b2ea8cc..8f47618 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,3 @@ -# torchruntime-uv - -A fork of easydiffusion/torchruntime that uses uv instead of pip - -Original readme below: - ---- - - [![Discord Server](https://img.shields.io/discord/1014774730907209781?label=Discord)](https://discord.com/invite/u9yhsFmEkB) **torchruntime** is a lightweight package for automatically installing the appropriate variant of PyTorch on a user's computer, based on their OS, and GPU manufacturer and GPU model. From 9220394b2c4ce576235d6bc7a81805bd7d227f69 Mon Sep 17 00:00:00 2001 From: jt Date: Thu, 13 Nov 2025 18:14:09 -0800 Subject: [PATCH 4/5] add test --- tests/test_installer.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_installer.py b/tests/test_installer.py index 70e7d21..ade0358 100644 --- a/tests/test_installer.py +++ b/tests/test_installer.py @@ -92,6 +92,17 @@ def test_get_pip_commands_valid(): assert result == expected +def test_get_pip_commands_with_uv(): + cmds = [["package1"], ["package2", "--upgrade"]] + expected = [ + ["uv", "pip", "install", "package1"], + ["uv", "pip", "install", "package2", "--upgrade"], + ] + + result = get_pip_commands(cmds, use_uv=True) + assert result == expected + + def test_get_pip_commands_none_input(): cmds = [["package1"], None] with pytest.raises(AssertionError): From 2145c5b18246c8434829143dfcd69ce40fdb4ca4 Mon Sep 17 00:00:00 2001 From: jt Date: Thu, 13 Nov 2025 18:14:45 -0800 Subject: [PATCH 5/5] fix readme again --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8f47618..f116f1b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +# torchruntime [![Discord Server](https://img.shields.io/discord/1014774730907209781?label=Discord)](https://discord.com/invite/u9yhsFmEkB) **torchruntime** is a lightweight package for automatically installing the appropriate variant of PyTorch on a user's computer, based on their OS, and GPU manufacturer and GPU model.