Skip to content

Commit b103f0a

Browse files
Balandatfacebook-github-bot
authored andcommitted
Allow dev versions of gpytorch & linear_operator for installation (#1466)
Summary: Previously, due to pinning `gpytorch` and `linear_operator` to specific versions in the requirements, we were always installing the respective release version, even when manually installing the current dev version prior (as was done in the github actions workflows). This PR introduces support for automagically converting these specific pins into "at least" pins provided a `ALLOW_LATEST_GPYTORCH_LINOP` env var is set. This mirrors a similar setup for Ax. Pull Request resolved: #1466 Reviewed By: saitcakmak Differential Revision: D40838409 Pulled By: Balandat fbshipit-source-id: baf0018a2bd21cbb8a527f7c2ad83e8b9478e52c
1 parent bc39aa1 commit b103f0a

File tree

7 files changed

+63
-30
lines changed

7 files changed

+63
-30
lines changed

.github/workflows/docs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ jobs:
2222
with:
2323
python-version: "3.8"
2424
- name: Install dependencies
25+
env:
26+
ALLOW_LATEST_GPYTORCH_LINOP: true
2527
run: |
2628
pip install git+https://github.com/cornellius-gp/linear_operator.git
2729
pip install git+https://github.com/cornellius-gp/gpytorch.git

.github/workflows/nightly.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
with:
2424
python-version: ${{ matrix.python-version }}
2525
- name: Install dependencies
26+
env:
27+
ALLOW_LATEST_GPYTORCH_LINOP: true
2628
run: |
2729
pip install --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
2830
pip install git+https://github.com/cornellius-gp/linear_operator.git
@@ -50,6 +52,8 @@ jobs:
5052
with:
5153
python-version: 3.8
5254
- name: Install dependencies
55+
env:
56+
ALLOW_LATEST_GPYTORCH_LINOP: true
5357
run: |
5458
pip install --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
5559
pip install git+https://github.com/cornellius-gp/linear_operator.git
@@ -93,6 +97,8 @@ jobs:
9397
run: git fetch --prune --unshallow
9498
- name: Install dependencies
9599
shell: bash -l {0}
100+
env:
101+
ALLOW_LATEST_GPYTORCH_LINOP: true
96102
# Don't need most deps for conda build, but need them for testing
97103
# We do need setuptools_scm though to properly parse the version
98104
run: |
@@ -123,6 +129,7 @@ jobs:
123129
run: git fetch --prune --unshallow
124130
- name: Install dependencies
125131
env:
132+
ALLOW_LATEST_GPYTORCH_LINOP: true
126133
ALLOW_BOTORCH_LATEST: true # allow Ax to install w/ new BoTorch release
127134
run: |
128135
pip install git+https://github.com/cornellius-gp/linear_operator.git

.github/workflows/reusable_tutorials.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ jobs:
3131
run: git fetch --prune --unshallow
3232
- if: ${{ !inputs.use_stable_pytorch_gpytorch }}
3333
name: Install latest PyTorch & GPyTorch
34+
env:
35+
ALLOW_LATEST_GPYTORCH_LINOP: true
3436
run: |
3537
pip install --pre torch torchvision -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
3638
pip install git+https://github.com/cornellius-gp/linear_operator.git

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
with:
2626
python-version: ${{ matrix.python-version }}
2727
- name: Install dependencies
28+
env:
29+
ALLOW_LATEST_GPYTORCH_LINOP: true
2830
run: |
2931
pip install --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
3032
pip install git+https://github.com/cornellius-gp/linear_operator.git
@@ -55,6 +57,8 @@ jobs:
5557
python-version: ${{ matrix.python-version }}
5658
- name: Install dependencies
5759
shell: bash -l {0}
60+
env:
61+
ALLOW_LATEST_GPYTORCH_LINOP: true
5862
run: |
5963
conda install -y -c pytorch-nightly pytorch cpuonly
6064
conda install -y pip scipy sphinx pytest flake8

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ by following the [PyTorch installation instructions](https://pytorch.org/get-sta
9292

9393
If you would like to try our bleeding edge features (and don't mind potentially
9494
running into the occasional bug here or there), you can install the latest
95-
development version directly from GitHub (this will also require installing
96-
the current GPyTorch development version):
95+
development version directly from GitHub. If you want to also install the
96+
current `gpytorch` and `linear_operator` development versions, you will need
97+
to ensure that the `ALLOW_LATEST_GPYTORCH_LINOP` environment variable is set):
9798
```bash
9899
pip install --upgrade git+https://github.com/cornellius-gp/linear_operator.git
99100
pip install --upgrade git+https://github.com/cornellius-gp/gpytorch.git
101+
export ALLOW_LATEST_GPYTORCH_LINOP=true
100102
pip install --upgrade git+https://github.com/pytorch/botorch.git
101103
```
102104

requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
multipledispatch
2+
scipy
3+
torch>=1.11
4+
pyro-ppl>=1.8.2
5+
gpytorch==1.9.0
6+
linear_operator==0.1.1

setup.py

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,24 @@
99

1010
from setuptools import find_packages, setup
1111

12-
12+
# Minimum required python version
1313
REQUIRED_MAJOR = 3
1414
REQUIRED_MINOR = 8
1515

16+
# Requirements for testing, formatting, and tutorials
17+
TEST_REQUIRES = ["pytest", "pytest-cov"]
18+
FMT_REQUIRES = ["flake8", "ufmt", "flake8-docstrings"]
19+
TUTORIALS_REQUIRES = [
20+
"ax-platform",
21+
"cma",
22+
"jupyter",
23+
"kaleido",
24+
"matplotlib",
25+
"memory_profiler",
26+
"pykeops",
27+
"torchvision",
28+
]
29+
1630
# Check for python version
1731
if sys.version_info < (REQUIRED_MAJOR, REQUIRED_MINOR):
1832
error = (
@@ -26,32 +40,35 @@
2640
)
2741
sys.exit(error)
2842

43+
# Assign root dir location for later use
44+
root_dir = os.path.dirname(__file__)
2945

30-
# Requirements
31-
TEST_REQUIRES = ["pytest", "pytest-cov"]
3246

33-
FMT_REQUIRES = ["flake8", "ufmt", "flake8-docstrings"]
47+
def read_deps_from_file(filname):
48+
"""Read in requirements file and return items as list of strings"""
49+
with open(os.path.join(root_dir, filname), "r") as fh:
50+
return [line.strip() for line in fh.readlines() if not line.startswith("#")]
3451

35-
# Read in the pinned versions of the formatting tools
36-
root_dir = os.path.dirname(__file__)
37-
with open(os.path.join(root_dir, "requirements-fmt.txt"), "r") as fh:
38-
FMT_REQUIRES += [
39-
line.strip() for line in fh.readlines() if not line.startswith("#")
52+
53+
# Read in the requirements from the requirements.txt file
54+
install_requires = read_deps_from_file("requirements.txt")
55+
56+
# Allow non-pinned (usually dev) versions of gpytorch and linear_operator
57+
if os.environ.get("ALLOW_LATEST_GPYTORCH_LINOP"):
58+
# Allows more recent previously installed versions. If there is no
59+
# previously installed version, installs the latest release.
60+
install_requires = [
61+
dep.replace("==", ">=")
62+
if "gpytorch" in dep or "linear_operator" in dep
63+
else dep
64+
for dep in install_requires
4065
]
4166

67+
# Read in pinned versions of the formatting tools
68+
FMT_REQUIRES += read_deps_from_file("requirements-fmt.txt")
69+
# Dev is test + formatting + docs generation
4270
DEV_REQUIRES = TEST_REQUIRES + FMT_REQUIRES + ["sphinx"]
4371

44-
TUTORIALS_REQUIRES = [
45-
"ax-platform",
46-
"cma",
47-
"jupyter",
48-
"kaleido",
49-
"matplotlib",
50-
"memory_profiler",
51-
"pykeops",
52-
"torchvision",
53-
]
54-
5572
# read in README.md as the long description
5673
with open(os.path.join(root_dir, "README.md"), "r") as fh:
5774
long_description = fh.read()
@@ -80,14 +97,7 @@
8097
long_description_content_type="text/markdown",
8198
python_requires=">=3.8",
8299
packages=find_packages(exclude=["test", "test.*"]),
83-
install_requires=[
84-
"torch>=1.11",
85-
"gpytorch==1.9.0",
86-
"linear_operator==0.1.1",
87-
"scipy",
88-
"multipledispatch",
89-
"pyro-ppl>=1.8.2",
90-
],
100+
install_requires=install_requires,
91101
extras_require={
92102
"dev": DEV_REQUIRES,
93103
"test": TEST_REQUIRES,

0 commit comments

Comments
 (0)