Skip to content

Commit

Permalink
Remove 'torch' from deps and warn instead (#343)
Browse files Browse the repository at this point in the history
Instead of enforcing the installation for 'torch' as a dependency, error
if 'torch' cannot be imported and point the user to how to install.

Co-authored-by: Scott Todd <scott.todd0@gmail.com>
  • Loading branch information
marbre and ScottTodd authored Dec 16, 2024
1 parent 6313718 commit fcf600a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,22 @@ Discord server).

1. Install from PyPI:

```bash
# Stable releases
pip install iree-turbine
Install a torch version that fulfills your needs:

# Nightly releases
pip install --find-links https://iree.dev/pip-release-links.html --upgrade --pre iree-turbine
```bash
# Fast installation of torch with just CPU support.
# See other options at https://pytorch.org/get-started/locally/
pip install torch --index-url https://download.pytorch.org/whl/test/cpu
```

The above does install some CUDA/cuDNN packages which are unnecessary for most
usage. To avoid this you can
[install just pytorch-cpu](https://pytorch.org/get-started/locally/) via:
Then install iree-turbine:

```bash
pip install -r pytorch-cpu-requirements.txt
# Stable releases
pip install iree-turbine
# Nightly releases
pip install --find-links https://iree.dev/pip-release-links.html --upgrade --pre iree-turbine
```

(or follow the "Developers" instructions below)
Expand Down Expand Up @@ -84,9 +85,8 @@ source .venv/bin/activate

### Install PyTorch for your system

If no explicit action is taken, the default PyTorch version will be installed.
On Linux this may give you a current CUDA-based version. Install a different
variant by doing so explicitly first, either by following the
You need to explicit install a PyTorch version that fulfills your needs.
On Linux, install a variant by either following the
[official instructions](https://pytorch.org/get-started/locally/) or by using
one of our `requirements.txt` files:

Expand Down
10 changes: 10 additions & 0 deletions iree/turbine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

import importlib.util

msg = """No module named 'torch'. Follow https://pytorch.org/get-started/locally/#start-locally to install 'torch'.
For example, on Linux to install with CPU support run:
pip3 install torch --index-url https://download.pytorch.org/whl/cpu
"""

if spec := importlib.util.find_spec("torch") is None:
raise ModuleNotFoundError(msg)
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def initialize_options(self):
f"numpy{get_version_spec('numpy')}",
f"iree-base-compiler{get_version_spec('iree-base-compiler')}",
f"iree-base-runtime{get_version_spec('iree-base-runtime')}",
"torch>=2.3.0",
f"Jinja2{get_version_spec('Jinja2')}",
f"ml_dtypes{get_version_spec('ml_dtypes')}",
f"typing_extensions{get_version_spec('typing_extensions')}",
Expand Down

0 comments on commit fcf600a

Please sign in to comment.