diff --git a/Makefile b/Makefile index 1ce4913486..e463981cef 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,8 @@ ALL_STACKS:=base-notebook \ tensorflow-notebook \ datascience-notebook \ pyspark-notebook \ - all-spark-notebook + all-spark-notebook \ + tensorflow-notebook-gpu endif ALL_IMAGES:=$(ALL_STACKS) diff --git a/tensorflow-notebook-gpu/.dockerignore b/tensorflow-notebook-gpu/.dockerignore new file mode 100644 index 0000000000..9dea340f35 --- /dev/null +++ b/tensorflow-notebook-gpu/.dockerignore @@ -0,0 +1,2 @@ +# Documentation +README.md diff --git a/tensorflow-notebook-gpu/Dockerfile b/tensorflow-notebook-gpu/Dockerfile new file mode 100644 index 0000000000..0e7f172012 --- /dev/null +++ b/tensorflow-notebook-gpu/Dockerfile @@ -0,0 +1,81 @@ +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. +ARG BASE_CONTAINER=jupyter/scipy-notebook +FROM $BASE_CONTAINER + +LABEL maintainer="Jupyter Project " + +ARG CUDA=11.1 +ARG CUDNN=8.0.5.39-1 +ARG CUDNN_MAJOR_VERSION=8 +ARG LIB_DIR_PREFIX=x86_64 +ARG LIBNVINFER=7.2.1-1 +ARG LIBNVINFER_MAJOR_VERSION=7 + +# Fix DL4006 +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +USER root + +RUN apt-get update && apt-get install -y --no-install-recommends \ + gnupg2 curl ca-certificates && \ + curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub | apt-key add - && \ + echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/cuda.list && \ + echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list && \ + apt-get purge --autoremove -y curl \ + && rm -rf /var/lib/apt/lists/* + +ENV CUDA_VERSION 11.1.1 + +# For libraries in the cuda-compat-* package: https://docs.nvidia.com/cuda/eula/index.html#attachment-a +RUN apt-get update && apt-get install -y --no-install-recommends \ + cuda-cudart-11-1=11.1.74-1 \ + cuda-compat-11-1 \ + && ln -s cuda-11.1 /usr/local/cuda && \ + rm -rf /var/lib/apt/lists/* + +# Required for nvidia-docker v1 +RUN echo "/usr/local/nvidia/lib" >> /etc/ld.so.conf.d/nvidia.conf && \ + echo "/usr/local/nvidia/lib64" >> /etc/ld.so.conf.d/nvidia.conf + +ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} +ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64 + +# nvidia-container-runtime +ENV NVIDIA_VISIBLE_DEVICES all +ENV NVIDIA_DRIVER_CAPABILITIES compute,utility +ENV NVIDIA_REQUIRE_CUDA "cuda>=11.1 brand=tesla,driver>=418,driver<419 brand=tesla,driver>=440,driver<441 brand=tesla,driver>=450,driver<451" + +# Install all OS dependencies for notebook server that starts but lacks all +# features (e.g., download as all possible file formats) +ENV DEBIAN_FRONTEND noninteractive +RUN apt-get update \ + && apt-get install -yq --no-install-recommends \ + cuda-command-line-tools-${CUDA/./-} \ + libcublas-${CUDA/./-} \ + cuda-nvrtc-${CUDA/./-} \ + libcufft-${CUDA/./-} \ + libcurand-${CUDA/./-} \ + libcusolver-${CUDA/./-} \ + libcusparse-${CUDA/./-} \ + libcudnn8=${CUDNN}+cuda${CUDA} \ + libfreetype6-dev \ + libhdf5-serial-dev \ + libzmq3-dev \ + pkg-config \ + software-properties-common \ + cm-super \ + libnvinfer${LIBNVINFER_MAJOR_VERSION}=${LIBNVINFER}+cuda${CUDA} \ + libnvinfer-plugin${LIBNVINFER_MAJOR_VERSION}=${LIBNVINFER}+cuda${CUDA} \ +# python3-libnvinfer=${LIBNVINFER}+cuda${CUDA} \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +USER $NB_UID + +WORKDIR $HOME + +# Install Tensorflow +RUN pip install --quiet --no-cache-dir \ + 'tensorflow-gpu==2.3.1' && \ + fix-permissions "${CONDA_DIR}" && \ + fix-permissions "/home/${NB_USER}" diff --git a/tensorflow-notebook-gpu/README.md b/tensorflow-notebook-gpu/README.md new file mode 100644 index 0000000000..6fd94963b9 --- /dev/null +++ b/tensorflow-notebook-gpu/README.md @@ -0,0 +1,15 @@ +[![docker pulls](https://img.shields.io/docker/pulls/jupyter/tensorflow-notebook.svg)](https://hub.docker.com/r/jupyter/tensorflow-notebook/) +[![docker stars](https://img.shields.io/docker/stars/jupyter/tensorflow-notebook.svg)](https://hub.docker.com/r/jupyter/tensorflow-notebook/) +[![image metadata](https://images.microbadger.com/badges/image/jupyter/tensorflow-notebook.svg)](https://microbadger.com/images/jupyter/tensorflow-notebook "jupyter/tensorflow-notebook image metadata") + +# Jupyter Notebook Deep Learning Stack + +GitHub Actions in the https://github.com/jupyter/docker-stacks project builds and pushes this image +to Docker Hub. + +Please visit the project documentation site for help using and contributing to this image and +others. + +- [Jupyter Docker Stacks on ReadTheDocs](http://jupyter-docker-stacks.readthedocs.io/en/latest/index.html) +- [Selecting an Image :: Core Stacks :: jupyter/tensorflow-notebook](http://jupyter-docker-stacks.readthedocs.io/en/latest/using/selecting.html#jupyter-tensorflow-notebook) +- [Image Specifics :: Tensorflow](http://jupyter-docker-stacks.readthedocs.io/en/latest/using/specifics.html#tensorflow) diff --git a/tensorflow-notebook-gpu/hooks/run_hook b/tensorflow-notebook-gpu/hooks/run_hook new file mode 100755 index 0000000000..69c2175695 --- /dev/null +++ b/tensorflow-notebook-gpu/hooks/run_hook @@ -0,0 +1,45 @@ +#!/bin/bash +set -e + +# Apply tags +GIT_SHA_TAG=${GITHUB_SHA:0:12} +docker tag $IMAGE_NAME "$DOCKER_REPO:$GIT_SHA_TAG" + +# Update index +INDEX_ROW="|\`${BUILD_TIMESTAMP}\`|\`jupyter/${IMAGE_SHORT_NAME}:${GIT_SHA_TAG}\`|[Git diff](https://github.com/jupyter/docker-stacks/commit/${GITHUB_SHA})
[Dockerfile](https://github.com/jupyter/docker-stacks/blob/${GITHUB_SHA}/${IMAGE_SHORT_NAME}/Dockerfile)
[Build manifest](./${IMAGE_SHORT_NAME}-${GIT_SHA_TAG})|" +sed "/|-|/a ${INDEX_ROW}" -i "${WIKI_PATH}/Home.md" + +# Build manifest +MANIFEST_FILE="${WIKI_PATH}/manifests/${IMAGE_SHORT_NAME}-${GIT_SHA_TAG}.md" +mkdir -p $(dirname "$MANIFEST_FILE") + +cat << EOF > "$MANIFEST_FILE" +* Build datetime: ${BUILD_TIMESTAMP} +* Docker image: ${DOCKER_REPO}:${GIT_SHA_TAG} +* Docker image size: $(docker images ${IMAGE_NAME} --format "{{.Size}}") +* Git commit SHA: [${GITHUB_SHA}](https://github.com/jupyter/docker-stacks/commit/${GITHUB_SHA}) +* Git commit message: +\`\`\` +${COMMIT_MSG} +\`\`\` + +## Python Packages + +\`\`\` +$(docker run --rm ${IMAGE_NAME} python --version) +\`\`\` + +\`\`\` +$(docker run --rm ${IMAGE_NAME} conda info) +\`\`\` + +\`\`\` +$(docker run --rm ${IMAGE_NAME} conda list) +\`\`\` + +## Apt Packages + +\`\`\` +$(docker run --rm ${IMAGE_NAME} apt list --installed) +\`\`\` +EOF diff --git a/tensorflow-notebook-gpu/test/test_tensorflow.py b/tensorflow-notebook-gpu/test/test_tensorflow.py new file mode 100644 index 0000000000..f5a6910fd3 --- /dev/null +++ b/tensorflow-notebook-gpu/test/test_tensorflow.py @@ -0,0 +1,30 @@ +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. +import logging + +import pytest + +LOGGER = logging.getLogger(__name__) + + +@pytest.mark.parametrize( + "name,command", + [ + ( + "Hello world", + "import tensorflow as tf;print(tf.constant('Hello, TensorFlow'))", + ), + ( + "Sum", + "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))", + ), + ], +) +def test_tensorflow(container, name, command): + """Basic tensorflow tests""" + LOGGER.info(f"Testing tensorflow: {name} ...") + c = container.run(tty=True, command=["start.sh", "python", "-c", command]) + rv = c.wait(timeout=30) + assert rv == 0 or rv["StatusCode"] == 0, f"Command {command} failed" + logs = c.logs(stdout=True).decode("utf-8") + LOGGER.debug(logs)