forked from Kaggle/docker-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Kaggle#1132 from Kaggle/tpu-1vm-image
Get tensorflow, jax, and pytorch working on TPU1VM
- Loading branch information
Showing
9 changed files
with
158 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,27 @@ | ||
ARG BASE_IMAGE_TAG | ||
ARG LIBTPU_IMAGE_TAG | ||
ARG TENSORFLOW_WHL_IMAGE_TAG | ||
ARG TENSORFLOW_VERSION | ||
ARG TORCH_VERSION | ||
|
||
FROM gcr.io/cloud-tpu-v2-images/libtpu:${LIBTPU_IMAGE_TAG} as libtpu | ||
FROM gcr.io/kaggle-images/python-tpu-tensorflow-whl:${TENSORFLOW_WHL_IMAGE_TAG} AS tensorflow_whl | ||
FROM gcr.io/kaggle-images/python-tpu-tensorflow-whl:python-${BASE_IMAGE_TAG}-${TENSORFLOW_VERSION} AS tensorflow_whl | ||
FROM gcr.io/kaggle-images/python:${BASE_IMAGE_TAG} | ||
|
||
ENV ISTPUVM=1 | ||
|
||
COPY --from=libtpu /libtpu.so /lib | ||
|
||
COPY --from=tensorflow_whl /tmp/tensorflow_pkg/tensorflow*.whl /tmp/tensorflow_pkg/ | ||
RUN pip install /tmp/tensorflow_pkg/tensorflow*.whl && \ | ||
rm -rf /tmp/tensorflow_pkg | ||
rm -rf /tmp/tensorflow_pkg && \ | ||
/tmp/clean-layer.sh | ||
|
||
# https://cloud.google.com/tpu/docs/pytorch-xla-ug-tpu-vm#changing_pytorch_version | ||
RUN pip uninstall -y torch && \ | ||
pip install torch==${TORCH_VERSION} && \ | ||
pip install torch_xla[tpuvm] -f https://storage.googleapis.com/tpu-pytorch/wheels/tpuvm/torch_xla-${TORCH_VERSION}-cp37-cp37m-linux_x86_64.whl && \ | ||
/tmp/clean-layer.sh | ||
|
||
# https://cloud.google.com/tpu/docs/jax-quickstart-tpu-vm#install_jax_on_your_cloud_tpu_vm | ||
RUN pip install "jax[tpu]>=0.2.16" -f https://storage.googleapis.com/jax-releases/libtpu_releases.html && \ | ||
/tmp/clean-layer.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
usage() { | ||
cat << EOF | ||
Usage: $0 [OPTIONS] | ||
Build a new Python TPU 1VM Docker image. | ||
Options: | ||
-c, --use-cache Use layer cache when building a new image. | ||
EOF | ||
} | ||
|
||
CACHE_FLAG='--no-cache' | ||
DOCKERFILE='Dockerfile' | ||
IMAGE_TAG='kaggle/python-tpuvm-build' | ||
BUILD_ARGS='' | ||
|
||
while :; do | ||
case "$1" in | ||
-h|--help) | ||
usage | ||
exit | ||
;; | ||
-c|--use-cache) | ||
CACHE_FLAG='' | ||
;; | ||
-?*) | ||
usage | ||
printf 'ERROR: Unknown option: %s\n' "$1" >&2 | ||
exit | ||
;; | ||
*) | ||
break | ||
esac | ||
|
||
shift | ||
done | ||
|
||
BUILD_ARGS+=" --build-arg GIT_COMMIT=$(git rev-parse HEAD)" | ||
BUILD_ARGS+=" --build-arg BUILD_DATE=$(date '+%Y%m%d-%H%M%S')" | ||
|
||
# Read build args from config.txt file. | ||
SRCDIR=$(dirname "${BASH_SOURCE[0]}") | ||
for l in `cat ${SRCDIR}/config.txt`; do | ||
BUILD_ARGS+=" --build-arg $l" | ||
done | ||
|
||
readonly CACHE_FLAG | ||
readonly DOCKERFILE | ||
readonly IMAGE_TAG | ||
readonly BUILD_ARGS | ||
|
||
DOCKERFILE_PATH="$SRCDIR/$DOCKERFILE" | ||
|
||
set -x | ||
docker build --rm --pull $CACHE_FLAG -t "$IMAGE_TAG" -f "$DOCKERFILE_PATH" $BUILD_ARGS . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# TODO(b/213335159): Use ci-pretest for BASE_IMAGE_TAG once stable. | ||
BASE_IMAGE_TAG=v108 | ||
LIBTPU_IMAGE_TAG=libtpu_1.1.0_RC00 | ||
TENSORFLOW_VERSION=2.8.0 | ||
TORCH_VERSION=1.11.0 |