Skip to content

Commit

Permalink
deps(torch): support PyTorch 2.0+ only (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
XuehaiPan authored May 10, 2024
1 parent 4c4c646 commit 190ca72
Show file tree
Hide file tree
Showing 22 changed files with 90 additions and 85 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ concurrency:
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
CUDA_VERSION: "11.7"
TEST_TORCH_SPECS: "cpu cu116"
CUDA_VERSION: "12.1"
TEST_TORCH_SPECS: "cpu cu118"

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ concurrency:
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
CUDA_VERSION: "11.7"
CUDA_VERSION: "12.1"

jobs:
lint:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ concurrency:
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
CUDA_VERSION: "11.7"
CUDA_VERSION: "12.1"

jobs:
test:
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ repos:
- id: debug-statements
- id: double-quote-string-fixer
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.4
rev: v18.1.5
hooks:
- id: clang-format
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.3
rev: v0.4.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

-
- Drop PyTorch 1.x support by [@XuehaiPan](https://github.com/XuehaiPan) in [#215](https://github.com/metaopt/torchopt/pull/215).

------

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cmake_minimum_required(VERSION 3.11) # for FetchContent
project(torchopt LANGUAGES CXX)

include(FetchContent)
set(PYBIND11_VERSION v2.11.1)
set(PYBIND11_VERSION v2.12.0)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# $ docker build --target devel --tag torchopt-devel:latest .
#

ARG cuda_docker_tag="11.7.1-cudnn8-devel-ubuntu22.04"
ARG cuda_docker_tag="12.1.0-cudnn8-devel-ubuntu22.04"
FROM nvidia/cuda:"${cuda_docker_tag}" AS builder

ENV DEBIAN_FRONTEND=noninteractive
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ docker-devel:
docker: docker-base docker-devel

docker-run-base: docker-base
docker run --network=host --gpus=all -v /:/host -h ubuntu -it $(PROJECT_NAME):$(COMMIT_HASH)
docker run -it --network=host --gpus=all --shm-size=4gb -v /:/host -v "${PWD}:/workspace" \
-h ubuntu -w /workspace $(PROJECT_NAME):$(COMMIT_HASH)

docker-run-devel: docker-devel
docker run --network=host --gpus=all -v /:/host -h ubuntu -it $(PROJECT_NAME)-devel:$(COMMIT_HASH)
docker run -it --network=host --gpus=all --shm-size=4gb -v /:/host -v "${PWD}:/workspace" \
-h ubuntu -w /workspace $(PROJECT_NAME)-devel:$(COMMIT_HASH)

docker-run: docker-run-base
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,11 @@ Then run the following command to install TorchOpt from PyPI ([![PyPI](https://i
pip3 install torchopt
```

If the minimum version of PyTorch is not satisfied, `pip` will install/upgrade it for you. Please be careful about the `torch` build for CPU / CUDA support (e.g. `cpu`, `cu116`, `cu117`).
If the minimum version of PyTorch is not satisfied, `pip` will install/upgrade it for you. Please be careful about the `torch` build for CPU / CUDA support (e.g. `cpu`, `cu118`, `cu121`).
You may need to specify the extra index URL for the `torch` package:

```bash
pip3 install torchopt --extra-index-url https://download.pytorch.org/whl/cu117
pip3 install torchopt --extra-index-url https://download.pytorch.org/whl/cu121
```

See <https://pytorch.org> for more information about installing PyTorch.
Expand All @@ -450,7 +450,7 @@ git clone https://github.com/metaopt/torchopt.git
cd torchopt

# You may need `CONDA_OVERRIDE_CUDA` if conda fails to detect the NVIDIA driver (e.g. in docker or WSL2)
CONDA_OVERRIDE_CUDA=11.7 conda env create --file conda-recipe-minimal.yaml
CONDA_OVERRIDE_CUDA=12.1 conda env create --file conda-recipe-minimal.yaml

conda activate torchopt
make install-editable # or run `pip3 install --no-build-isolation --editable .`
Expand Down
8 changes: 4 additions & 4 deletions conda-recipe-minimal-cpu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ channels:
- conda-forge

dependencies:
- python = 3.10
- python = 3.11
- pip

# Learning
- pytorch::pytorch >= 1.13 # sync with project.dependencies
- pytorch::pytorch >= 2.0 # sync with project.dependencies
- pytorch::torchvision
- pytorch::pytorch-mutex = *=*cpu*
- pip:
Expand All @@ -40,10 +40,10 @@ dependencies:
- cmake >= 3.11
- make
- cxx-compiler
- pybind11 >= 2.10.1
- pybind11 >= 2.11.1

# Misc
- optree >= 0.4.1
- typing-extensions >= 4.0.0
- typing-extensions
- numpy
- python-graphviz
18 changes: 9 additions & 9 deletions conda-recipe-minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,41 @@
#
# Create virtual environment with command:
#
# $ CONDA_OVERRIDE_CUDA=11.7 conda env create --file conda-recipe-minimal.yaml
# $ CONDA_OVERRIDE_CUDA=12.1 conda env create --file conda-recipe-minimal.yaml
#

name: torchopt

channels:
- pytorch
- nvidia/label/cuda-11.7.1
- nvidia/label/cuda-12.1.0
- defaults
- conda-forge

dependencies:
- python = 3.10
- python = 3.11
- pip

# Learning
- pytorch::pytorch >= 1.13 # sync with project.dependencies
- pytorch::pytorch >= 2.0 # sync with project.dependencies
- pytorch::torchvision
- pytorch::pytorch-mutex = *=*cuda*
- pip:
- torchviz

# Device select
- nvidia/label/cuda-11.7.1::cuda-toolkit = 11.7
- nvidia/label/cuda-12.1.0::cuda-toolkit = 12.1

# Build toolchain
- cmake >= 3.11
- make
- cxx-compiler
- nvidia/label/cuda-11.7.1::cuda-nvcc
- nvidia/label/cuda-11.7.1::cuda-cudart-dev
- pybind11 >= 2.10.1
- nvidia/label/cuda-12.1.0::cuda-nvcc
- nvidia/label/cuda-12.1.0::cuda-cudart-dev
- pybind11 >= 2.11.1

# Misc
- optree >= 0.4.1
- typing-extensions >= 4.0.0
- typing-extensions
- numpy
- python-graphviz
40 changes: 20 additions & 20 deletions conda-recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,49 @@
#
# Create virtual environment with command:
#
# $ CONDA_OVERRIDE_CUDA=11.7 conda env create --file conda-recipe.yaml
# $ CONDA_OVERRIDE_CUDA=12.1 conda env create --file conda-recipe.yaml
#

name: torchopt

channels:
- pytorch
- nvidia/label/cuda-11.7.1
- nvidia/label/cuda-12.1.0
- defaults
- conda-forge

dependencies:
- python = 3.10
- python = 3.11
- pip

# Learning
- pytorch::pytorch >= 1.13 # sync with project.dependencies
- pytorch::pytorch >= 2.0 # sync with project.dependencies
- pytorch::torchvision
- pytorch::pytorch-mutex = *=*cuda*
- pip:
- torchviz
- sphinxcontrib-katex # for documentation
- jax # for tutorials
- jaxlib # for tutorials
- optax # for tutorials
- jaxopt # for tests
- conda-forge::jax # for tutorials
- conda-forge::jaxlib # for tutorials
- conda-forge::optax # for tutorials
- conda-forge::jaxopt # for tests
- tensorboard # for examples

# Device select
- nvidia/label/cuda-11.7.1::cuda-toolkit = 11.7
- nvidia/label/cuda-12.1.0::cuda-toolkit = 12.1

# Build toolchain
- cmake >= 3.11
- make
- cxx-compiler
- nvidia/label/cuda-11.7.1::cuda-nvcc
- nvidia/label/cuda-11.7.1::cuda-cudart-dev
- nvidia/label/cuda-12.1.0::cuda-nvcc
- nvidia/label/cuda-12.1.0::cuda-cudart-dev
- patchelf >= 0.14
- pybind11 >= 2.10.1
- pybind11 >= 2.11.1

# Misc
- optree >= 0.4.1
- typing-extensions >= 4.0.0
- typing-extensions
- numpy
- matplotlib-base
- seaborn
Expand All @@ -83,10 +83,10 @@ dependencies:
- pytest
- pytest-cov
- pytest-xdist
- isort >= 5.11.0
- conda-forge::black-jupyter >= 22.6.0
- pylint >= 2.15.0
- mypy >= 0.990
- isort
- conda-forge::black-jupyter
- pylint
- mypy
- flake8
- flake8-bugbear
- flake8-comprehensions
Expand All @@ -96,8 +96,8 @@ dependencies:
- ruff
- doc8
- pydocstyle
- clang-format >= 14
- clang-tools >= 14 # clang-tidy
- cpplint
- conda-forge::clang-format >= 14
- conda-forge::clang-tools >= 14 # clang-tidy
- conda-forge::cpplint
- conda-forge::pre-commit
- conda-forge::identify
16 changes: 8 additions & 8 deletions docs/conda-recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
#
# Create virtual environment with command:
#
# $ CONDA_OVERRIDE_CUDA=11.7 conda env create --file docs/conda-recipe.yaml
# $ CONDA_OVERRIDE_CUDA=12.1 conda env create --file docs/conda-recipe.yaml
#

name: torchopt-docs

channels:
- pytorch
- nvidia/label/cuda-11.7.1
- nvidia/label/cuda-12.1.0
- defaults
- conda-forge

dependencies:
- python = 3.10
- python = 3.11
- pip

# Learning
- pytorch::pytorch >= 1.13 # sync with project.dependencies
- pytorch::pytorch >= 2.0 # sync with project.dependencies
- pytorch::cpuonly
- pytorch::pytorch-mutex = *=*cpu*
- pip:
Expand All @@ -42,13 +42,13 @@ dependencies:
- cmake >= 3.11
- make
- cxx-compiler
- nvidia/label/cuda-11.7.1::cuda-nvcc
- nvidia/label/cuda-11.7.1::cuda-cudart-dev
- pybind11 >= 2.10.1
- nvidia/label/cuda-12.1.0::cuda-nvcc
- nvidia/label/cuda-12.1.0::cuda-cudart-dev
- pybind11 >= 2.11.1

# Misc
- optree >= 0.4.1
- typing-extensions >= 4.0.0
- typing-extensions
- numpy
- matplotlib-base
- seaborn
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--extra-index-url https://download.pytorch.org/whl/cpu
# Sync with project.dependencies
torch >= 1.13
torch >= 2.0

--requirement ../requirements.txt

Expand Down
8 changes: 4 additions & 4 deletions docs/source/developer/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Before contributing to TorchOpt, please follow the instructions below to setup.
.. code-block:: bash
# You may need `CONDA_OVERRIDE_CUDA` if conda fails to detect the NVIDIA driver (e.g. in docker or WSL2)
CONDA_OVERRIDE_CUDA=11.7 conda env create --file conda-recipe.yaml
CONDA_OVERRIDE_CUDA=12.1 conda env create --file conda-recipe.yaml
conda activate torchopt
Expand Down Expand Up @@ -91,14 +91,14 @@ To build compatible **manylinux2014** (:pep:`599`) wheels for distribution, you
pip3 install --upgrade cibuildwheel
export TEST_TORCH_SPECS="cpu cu116" # `torch` builds for testing
export CUDA_VERSION="11.7" # version of `nvcc` for compilation
export TEST_TORCH_SPECS="cpu cu118" # `torch` builds for testing
export CUDA_VERSION="12.1" # version of `nvcc` for compilation
python3 -m cibuildwheel --platform=linux --output-dir=wheelhouse --config-file=pyproject.toml
It will install the CUDA compiler with ``CUDA_VERSION`` in the build container. Then build wheel binaries for all supported CPython versions. The outputs will be placed in the ``wheelhouse`` directory.

To build a wheel for a specific CPython version, you can use the |CIBW_BUILD|_ environment variable.
For example, the following command will build a wheel for Python 3.7:
For example, the following command will build a wheel for Python 3.8:

.. code-block:: bash
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ You can use the following commands with `conda <https://github.com/conda/conda>`
cd torchopt
# You may need `CONDA_OVERRIDE_CUDA` if conda fails to detect the NVIDIA driver (e.g. in docker or WSL2)
CONDA_OVERRIDE_CUDA=11.7 conda env create --file conda-recipe-minimal.yaml
CONDA_OVERRIDE_CUDA=12.1 conda env create --file conda-recipe-minimal.yaml
conda activate torchopt
Expand Down
4 changes: 2 additions & 2 deletions examples/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--extra-index-url https://download.pytorch.org/whl/cu117
torch >= 1.13
--extra-index-url https://download.pytorch.org/whl/cu121
torch >= 2.0
torchvision

--requirement ../requirements.txt
Expand Down
Loading

0 comments on commit 190ca72

Please sign in to comment.