Skip to content

Commit

Permalink
docker: add environment variable PYTORCH_VERSION (pytorch#50154)
Browse files Browse the repository at this point in the history
Summary:
The aim is being able to inspect a container image and determine immediately
which version of pytorch it contains.

Closes pytorch#48324

Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>

seemethere PTAL.
As you requested in pytorch#48324 (comment), I'm submitting the patch. But I could only do limited testing as I'm not sure these Makefile/Dockerfile are used for pushing the Docker Hub images (since the Makefile tags the image with a `v` prefix for the version, as in: `pytorch:v1.7.1`, but Docker Hub images don't have this prefix).

Also on the master branch we currently have the following:
```
$ git describe --tags
v1.4.0a0-11171-g68a6e46379
```
So it's a little off, but it behaves as expected on the `release/1.7` branch.

Pull Request resolved: pytorch#50154

Reviewed By: walterddr

Differential Revision: D25828491

Pulled By: seemethere

fbshipit-source-id: 500ec96cb5f5da1321610002d5e3678f4b0b94b5
  • Loading branch information
flx42 authored and hwangdeyu committed Jan 14, 2021
1 parent 296443d commit 1384a13
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ RUN /opt/conda/bin/conda install -c "${INSTALL_CHANNEL}" -y python=${PYTHON_VERS
RUN /opt/conda/bin/pip install torchelastic

FROM ${BASE_IMAGE} as official
ARG PYTORCH_VERSION
LABEL com.nvidia.volumes.needed="nvidia_driver"
RUN --mount=type=cache,id=apt-final,target=/var/cache/apt \
apt-get update && apt-get install -y --no-install-recommends \
Expand All @@ -71,6 +72,7 @@ ENV PATH /opt/conda/bin:$PATH
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility
ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64
ENV PYTORCH_VERSION ${PYTORCH_VERSION}
WORKDIR /workspace

FROM official as dev
Expand Down
10 changes: 6 additions & 4 deletions docker.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ BASE_DEVEL = nvidia/cuda:$(CUDA_VERSION)-cudnn$(CUDNN_VERSION)-de
INSTALL_CHANNEL = pytorch

PYTHON_VERSION = 3.7
PYTORCH_VERSION = $(shell git describe --tags)
# Can be either official / dev
BUILD_TYPE = dev
BUILD_PROGRESS = auto
BUILD_ARGS = --build-arg BASE_IMAGE=$(BASE_IMAGE) \
--build-arg PYTHON_VERSION=$(PYTHON_VERSION) \
--build-arg CUDA_VERSION=$(CUDA_VERSION) \
--build-arg PYTORCH_VERSION=$(PYTORCH_VERSION) \
--build-arg INSTALL_CHANNEL=$(INSTALL_CHANNEL)
EXTRA_DOCKER_BUILD_FLAGS ?=
DOCKER_BUILD = DOCKER_BUILDKIT=1 \
Expand All @@ -39,26 +41,26 @@ all: devel-image

.PHONY: devel-image
devel-image: BASE_IMAGE := $(BASE_DEVEL)
devel-image: DOCKER_TAG := $(shell git describe --tags)-devel
devel-image: DOCKER_TAG := $(PYTORCH_VERSION)-devel
devel-image:
$(DOCKER_BUILD)

.PHONY: devel-image
devel-push: BASE_IMAGE := $(BASE_DEVEL)
devel-push: DOCKER_TAG := $(shell git describe --tags)-devel
devel-push: DOCKER_TAG := $(PYTORCH_VERSION)-devel
devel-push:
$(DOCKER_PUSH)

.PHONY: runtime-image
runtime-image: BASE_IMAGE := $(BASE_RUNTIME)
runtime-image: DOCKER_TAG := $(shell git describe --tags)-runtime
runtime-image: DOCKER_TAG := $(PYTORCH_VERSION)-runtime
runtime-image:
$(DOCKER_BUILD)
docker tag $(DOCKER_FULL_NAME):$(DOCKER_TAG) $(DOCKER_FULL_NAME):latest

.PHONY: runtime-image
runtime-push: BASE_IMAGE := $(BASE_RUNTIME)
runtime-push: DOCKER_TAG := $(shell git describe --tags)-runtime
runtime-push: DOCKER_TAG := $(PYTORCH_VERSION)-runtime
runtime-push:
$(DOCKER_PUSH)

Expand Down

0 comments on commit 1384a13

Please sign in to comment.