Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker/nvidia #7109

Merged
merged 7 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion dockers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ docker image list
docker image rm pytorch-lightning:latest
```

### Run docker image with GPUs
## Run docker image with GPUs

To run docker image with access to you GPUs you need to install
```bash
Expand All @@ -63,3 +63,23 @@ and later run the docker image with `--gpus all` so for example
```
docker run --rm -it --gpus all pytorchlightning/pytorch_lightning:base-cuda-py3.7-torch1.6
```

## Run Jupyter server

Inspiration comes from https://u.group/thinking/how-to-put-jupyter-notebooks-in-a-dockerfile

1. Build the docker image:
```bash
docker image build \
-t pytorch-lightning:v1.2.9 \
-f dockers/nvidia/Dockerfile \
--build-arg LIGHTNING_VERSION=1.2.9 \
.
```
2. start the server and map ports:
```bash
docker run --rm -it --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all -p 8888:8888 pytorch-lightning:v1.2.9
```
3. Connect in local browser:
- copy the generated path e.g. `http://hostname:8888/?token=0719fa7e1729778b0cec363541a608d5003e26d4910983c6`
- replace the `hostname` by `localhost`
26 changes: 18 additions & 8 deletions dockers/nvidia/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
# limitations under the License.

# https://docs.nvidia.com/deeplearning/frameworks/pytorch-release-notes/rel_21-03.html#rel_21-03
FROM nvcr.io/nvidia/pytorch:20.12-py3
FROM nvcr.io/nvidia/pytorch:21.03-py3

MAINTAINER PyTorchLightning <https://github.com/PyTorchLightning>

ARG LIGHTNING_VERSION=""

RUN python -c "import torch ; print(torch.__version__)" >> torch_version.info

COPY ./ /workspace/pytorch-lightning/

RUN \
cd /workspace && \
mv pytorch-lightning/notebooks . && \
mv pytorch-lightning/pl_examples . && \
# replace by specific version if asked
if [ ! -z "$LIGHTNING_VERSION" ] ; then \
rm -rf pytorch-lightning ; \
Expand All @@ -33,18 +33,28 @@ RUN \
mv pytorch-lightning-*/ pytorch-lightning ; \
rm *.zip ; \
fi && \
# save the examples
mv pytorch-lightning/notebooks . && \
mv pytorch-lightning/pl_examples . && \

# Installations
python -c "fname = './pytorch-lightning/requirements/extra.txt' ; lines = [line for line in open(fname).readlines() if not line.startswith('horovod')] ; open(fname, 'w').writelines(lines)" && \
pip install -r ./pytorch-lightning/requirements/extra.txt --no-cache-dir --upgrade-strategy only-if-needed && \
pip install -r ./pytorch-lightning/requirements/examples.txt --no-cache-dir --upgrade-strategy only-if-needed && \
pip install ./pytorch-lightning --no-cache-dir && \
pip install "Pillow>=8.1" "torchtext>=0.9.0" ipython[all] --no-cache-dir --upgrade-strategy only-if-needed && \
rm -rf pytorch-lightning
pip install "Pillow>=8.1" --no-cache-dir --upgrade-strategy only-if-needed && \
rm -rf pytorch-lightning && \
pip list

ENV PYTHONPATH="/workspace"

RUN python --version && \
RUN \
TORCH_VERSION=$(cat torch_version.info) && \
rm torch_version.info && \
python --version && \
pip --version && \
pip list && \
pip list | grep torch && \
python -c "from torch import __version__ as ver ; assert ver == '$TORCH_VERSION', ver" && \
python -c "import pytorch_lightning as pl; print(pl.__version__)"

# CMD ["/bin/bash"]
CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root"]