Skip to content

Commit 7a39789

Browse files
Bordalexierule
authored andcommitted
require: adjust versions (#6363)
* adjust versions * release * manifest * pep8 * CI * fix * build
1 parent b542323 commit 7a39789

File tree

10 files changed

+75
-34
lines changed

10 files changed

+75
-34
lines changed

.github/workflows/ci_test-conda.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,20 @@ jobs:
2727
run: |
2828
conda info
2929
conda list
30+
# adjust versions according installed Torch version
31+
python ./requirements/adjust_versions.py requirements/extra.txt
32+
python ./requirements/adjust_versions.py requirements/examples.txt
3033
pip install --requirement requirements/devel.txt --upgrade-strategy only-if-needed
3134
pip list
3235
3336
- name: Pull checkpoints from S3
34-
# todo: consider adding coma caching, but ATM all models have less then 100KB
3537
run: |
3638
# enter legacy and update checkpoints from S3
3739
cd legacy
3840
curl https://pl-public-data.s3.amazonaws.com/legacy/checkpoints.zip --output checkpoints.zip
3941
unzip -o checkpoints.zip
4042
ls -l checkpoints/
4143
42-
# todo: require proper fix in docker image
43-
- name: Hotfix dependency
44-
run: |
45-
pip install torchtext==0.6.0 -U
46-
shell: bash
47-
4844
- name: Tests
4945
run: |
5046
# NOTE: run coverage on tests does not propagare faler status for Win, https://github.com/nedbat/coveragepy/issues/1003

.github/workflows/ci_test-full.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,17 @@ jobs:
104104
HOROVOD_WITHOUT_MXNET: 1
105105
HOROVOD_WITHOUT_TENSORFLOW: 1
106106
run: |
107-
# python -m pip install --upgrade --user pip
108-
pip install --requirement requirements.txt --find-links https://download.pytorch.org/whl/cpu/torch_stable.html --quiet --upgrade
109-
pip install --requirement ./requirements/devel.txt --find-links https://download.pytorch.org/whl/cpu/torch_stable.html --quiet --upgrade
110107
python --version
111108
pip --version
109+
# python -m pip install --upgrade --user pip
110+
pip install --requirement requirements.txt --find-links https://download.pytorch.org/whl/cpu/torch_stable.html --upgrade
111+
# adjust versions according installed Torch version
112+
python ./requirements/adjust_versions.py requirements/extra.txt
113+
python ./requirements/adjust_versions.py requirements/examples.txt
114+
pip install --requirement ./requirements/devel.txt --find-links https://download.pytorch.org/whl/cpu/torch_stable.html --upgrade
112115
pip list
113116
shell: bash
114117

115-
# todo: require proper fix in docker image
116-
- name: Hotfix dependency
117-
run: |
118-
pip install torchtext==0.6.0 -U
119-
shell: bash
120-
121118
- name: Reinstall Horovod if necessary
122119
if: runner.os != 'windows'
123120
env:

.github/workflows/events-nightly.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ jobs:
102102
id: extend
103103
104104
- name: Publish CUDA to Docker Hub
105-
# ToDo: extend also building for Nightly from pip
106-
if: matrix.pytorch_version < 1.8
107105
# publish master/release
108106
uses: docker/build-push-action@v2
109107
with:

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ recursive-include docs/source/_static/images/general/ pl_overview* tf_* tutorial
4646

4747
# Include the Requirements
4848
recursive-include requirements *.txt
49-
recursive-exclude requirements *.sh
49+
recursive-exclude requirements *.sh *.py
5050
include requirements.txt
5151
include pyproject.toml
5252

azure-pipelines.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ jobs:
7171
python -c "import torch ; mgpu = torch.cuda.device_count() ; assert mgpu >= 2, f'GPU: {mgpu}'"
7272
displayName: 'Env details'
7373
74-
# todo: require proper fix in docker image
75-
- bash: |
76-
pip install torchtext==0.7 -U
77-
displayName: 'HotFix'
78-
7974
- bash: |
8075
wget https://pl-public-data.s3.amazonaws.com/legacy/checkpoints.zip -P legacy/
8176
unzip -o legacy/checkpoints.zip -d legacy/

dockers/base-conda/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ ENV \
9898

9999
COPY ./requirements/extra.txt requirements-extra.txt
100100
COPY ./requirements/test.txt requirements-test.txt
101+
COPY ./requirements/adjust_versions.py requirements_adjust_versions.py
101102

102103
RUN \
103104
pip list | grep torch && \
104105
python -c "import torch; print(torch.__version__)" && \
106+
python requirements_adjust_versions.py requirements-extra.txt && \
105107
# Install remaining requirements
106108
pip install -r requirements-extra.txt --no-cache-dir && \
107109
pip install -r requirements-test.txt --no-cache-dir && \

dockers/base-cuda/Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,14 @@ RUN \
9494
# eventualy use pre-release
9595
#pip install "torch==${PYTORCH_VERSION}.*" --pre && \
9696
# set particular PyTorch version
97-
python -c "import re ; fname = 'requirements.txt' ; req = re.sub(r'torch[>=]+[\d\.]+', 'torch==${PYTORCH_VERSION}.*', open(fname).read()) ; open(fname, 'w').write(req)" && \
97+
python ./requirements/adjust_versions.py requirements.txt ${PYTORCH_VERSION} && \
98+
python ./requirements/adjust_versions.py requirements/extra.txt ${PYTORCH_VERSION} && \
99+
python ./requirements/adjust_versions.py requirements/examples.txt ${PYTORCH_VERSION} && \
98100
# Install all requirements
99101
# todo: find a way how to install nightly PT version
100102
# --pre --extra-index-url https://download.pytorch.org/whl/nightly/cu${cuda_ver[0]}${cuda_ver[1]}/torch_nightly.html
101103
pip install -r requirements/devel.txt --no-cache-dir && \
102-
rm -rf requirements*
104+
rm -rf requirements.* requirements/
103105

104106
RUN \
105107
# install DALI, needed for examples
@@ -113,7 +115,7 @@ RUN \
113115

114116
RUN \
115117
# install DeepSpeed from source.
116-
# todo: swap to pypi release once DeepSpeed releases a new version.
118+
# todo: swap to pypi release once DeepSpeed releases a new version >= 0.3.10
117119
pip install deepspeed@git+https://github.com/microsoft/DeepSpeed@ec8b1cb
118120

119121
RUN \

dockers/base-xla/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ RUN \
104104
python -c "fname = 'requirements/extra.txt' ; lines = [line for line in open(fname).readlines() if 'fairscale' not in line] ; open(fname, 'w').writelines(lines)" && \
105105
# drop TorchVision as it was installed with XLA
106106
python -c "fname = 'requirements/examples.txt' ; lines = [line for line in open(fname).readlines() if not line.startswith('torchvision')] ; open(fname, 'w').writelines(lines)" && \
107+
python ./requirements/adjust_versions.py ./requirements/extra.txt && \
107108
pip install --requirement ./requirements/devel.txt --no-cache-dir && \
108109
cd .. && \
109110
rm -rf pytorch-lightning && \

dockers/release/Dockerfile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ COPY ./ ./pytorch-lightning/
2727
RUN \
2828
# Disable cache
2929
#conda install "pip>20.1" && \
30-
#pip config set global.cache-dir false && \
31-
if [ -z $LIGHTNING_VERSION ] ; then \
32-
pip install ./pytorch-lightning --no-cache-dir ; \
30+
if [ ! -z "$LIGHTNING_VERSION" ] ; then \
3331
rm -rf pytorch-lightning ; \
34-
else \
35-
rm -rf pytorch-lightning ; \
36-
pip install https://github.com/PyTorchLightning/pytorch-lightning/archive/${LIGHTNING_VERSION}.zip --no-cache-dir ; \
37-
fi
32+
wget https://github.com/PyTorchLightning/pytorch-lightning/archive/${LIGHTNING_VERSION}.zip --progress=bar:force:noscroll ; \
33+
unzip ${LIGHTNING_VERSION}.zip ; \
34+
mv pytorch-lightning-*/ pytorch-lightning ; \
35+
rm *.zip ; \
36+
fi && \
37+
pip install ./pytorch-lightning["extra"] --no-cache-dir && \
38+
rm -rf pytorch-lightning
3839

3940
RUN python --version && \
4041
pip --version && \

requirements/adjust_versions.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
import re
3+
import sys
4+
from typing import Any, Dict
5+
6+
VERSIONS_LUT: Dict[str, Dict[str, Any]] = {
7+
"1.4.0": dict(torchvision="0.5.0", torchtext="0.5"),
8+
"1.5.0": dict(torchvision="0.6.0", torchtext="0.6"),
9+
"1.5.1": dict(torchvision="0.6.1", torchtext="0.6"),
10+
"1.6.0": dict(torchvision="0.7.0", torchtext="0.7"),
11+
"1.7.0": dict(torchvision="0.8.1", torchtext="0.8"),
12+
"1.7.1": dict(torchvision="0.8.2", torchtext="0.8.1"),
13+
"1.8.0": dict(torchvision="0.9.0", torchtext="0.9"),
14+
}
15+
16+
17+
def find_latest(ver: str, versions_all: list) -> str:
18+
# drop all except semantic version
19+
ver = re.search(r'([\.\d]+)', ver).groups()[0]
20+
# find candidates, by starting version pattern
21+
options = [v for v in versions_all if v.startswith(ver)]
22+
assert options, f"missing {ver} among {versions_all}"
23+
# take the last one...
24+
return sorted(options)[-1]
25+
26+
27+
def main(path_req: str, torch_version: str = None) -> None:
28+
with open(path_req, "r") as fp:
29+
req = fp.read()
30+
31+
if not torch_version:
32+
import torch
33+
torch_version = torch.__version__
34+
assert torch_version, f"invalid/missing Torch: {torch_version}"
35+
36+
torch_version = find_latest(torch_version, list(VERSIONS_LUT.keys()))
37+
dep_versions = VERSIONS_LUT[torch_version]
38+
dep_versions["torch"] = torch_version
39+
for lib in dep_versions:
40+
version = dep_versions[lib]
41+
replace = f"{lib}=={version}\n"
42+
req = re.sub(rf"{lib}[>=]*[\d\.]*{os.linesep}", replace, req)
43+
44+
with open(path_req, "w") as fp:
45+
fp.write(req)
46+
47+
48+
if __name__ == "__main__":
49+
main(*sys.argv[1:])

0 commit comments

Comments
 (0)