Skip to content

docker: adding environment variable PYTORCH_VERSION #48324

@flx42

Description

@flx42

🚀 Feature

Please consider setting the environment variable PYTORCH_VERSION in the published docker images.

Motivation

It's useful to be able to inspect a container image and determine immediately which version of pytorch it contains.

If you use the unmodified pytorch image from Docker Hub, you can look at the image tag of course, but this tag is often lost along the way: when you pull using the hash of the image, when you pull latest, when you create a derived image using a Dockerfile, when you docker commit, etc.

Pitch

It should be straightforward to do, all the required plumbing seems to be already present in docker.Makefile and Dockerfile.
Similarly to PYTHON_VERSION, ARG PYTORCH_VERSION should be added to the Dockerfile and then set with --build-arg using the version (which should be the same as the first part of image tag, i.e. $(shell git describe --tags)).

It will have to be exposed as an environment variable in the Dockerfile too:

ENV PYTORCH_VERSION=${PYTORCH_VERSION}

Alternatives

If we assume that we don't have the pytorch version in the container image tag, then the only alternative involves running the image and importing pytorch:

$ docker run -ti pytorch/pytorch@sha256:9cffbe6c391a0dbfa2a305be24b9707f87595e832b444c2bde52f0ea183192f1 \
       python -c 'import torch ; print(torch.__version__)' 
1.7.0

But running the image (and importing Torch) is costly and requires pulling the image. With an environment variable you can query the version without running the image, and without pulling the image for instance with the skopeo tool:

$ skopeo inspect docker://nvidia/cuda:latest | jq -r '.Env[]' | grep CUDA_VERSION
CUDA_VERSION=11.1.1

Additional context

While it doesn't seem to be part of the official docker images guidelines, it seems to be supported by most official images (with the exception of docker images packaging a Linux distro):

$ docker run -ti redis bash -c 'echo $REDIS_VERSION'
6.0.9

$ docker run -ti julia bash -c 'echo $JULIA_VERSION'
1.5.3

$ docker run -ti python bash -c 'echo $PYTHON_VERSION'
3.9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNot as big of a feature, but technically not a bug. Should be easy to fixmodule: dockertriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions