From b39092042e8acd7a80f8e6fb7df54aae08b3880a Mon Sep 17 00:00:00 2001 From: Christoph Schranz Date: Mon, 8 Apr 2024 18:15:16 +0200 Subject: [PATCH 1/4] update to v1.7 CUDA 12.3 --- .build/Dockerfile | 130 ++++----- .build/docker-stacks | 2 +- .build/docker_healthcheck.py | 15 +- .../setup-scripts/setup-julia-packages.bash | 12 +- .build/setup-scripts/setup_julia.py | 20 +- .build/start-notebook.py | 17 +- .build/start-singleuser.py | 9 +- .build/start.sh | 23 +- custom/gpulibs.Dockerfile | 31 ++- custom/header.Dockerfile | 2 +- custom/usefulpackages.Dockerfile | 41 +-- extra/Getting_Started/GPU-processing.ipynb | 259 ++++++++++-------- generate-Dockerfile.sh | 2 +- 13 files changed, 332 insertions(+), 231 deletions(-) diff --git a/.build/Dockerfile b/.build/Dockerfile index 6f137e7..bd89ef3 100755 --- a/.build/Dockerfile +++ b/.build/Dockerfile @@ -7,7 +7,7 @@ # Use NVIDIA CUDA as base image and run the same installation as in the other packages. # The version of cuda must match those of the packages installed in src/Dockerfile.gpulibs -FROM nvidia/cuda:12.0.1-cudnn8-runtime-ubuntu22.04 +FROM nvidia/cuda:12.3.2-cudnn9-runtime-ubuntu22.04 LABEL authors="Christoph Schranz , Mathematical Michael " # This is a concatenated Dockerfile, the maintainers of subsequent sections may vary. RUN chmod 1777 /tmp && chmod 1777 /var/tmp @@ -43,8 +43,8 @@ USER root # but lacks all features (e.g., download as all possible file formats) ENV DEBIAN_FRONTEND noninteractive RUN apt-get update --yes && \ - # - `apt-get upgrade` is run to patch known vulnerabilities in apt-get packages as - # the Ubuntu base image is rebuilt too seldom sometimes (less than once a month) + # - `apt-get upgrade` is run to patch known vulnerabilities in system packages + # as the Ubuntu base image is rebuilt too seldom sometimes (less than once a month) apt-get upgrade --yes && \ apt-get install --yes --no-install-recommends \ # - bzip2 is necessary to extract the micromamba executable. @@ -52,13 +52,14 @@ RUN apt-get update --yes && \ ca-certificates \ locales \ sudo \ - # - tini is installed as a helpful container entrypoint that reaps zombie - # processes and such of the actual executable we want to start, see - # https://github.com/krallin/tini#why-tini for details. + # - `tini` is installed as a helpful container entrypoint, + # that reaps zombie processes and such of the actual executable we want to start + # See https://github.com/krallin/tini#why-tini for details tini \ wget && \ apt-get clean && rm -rf /var/lib/apt/lists/* && \ echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \ + echo "C.UTF-8 UTF-8" >> /etc/locale.gen && \ locale-gen # Configure environment @@ -67,9 +68,9 @@ ENV CONDA_DIR=/opt/conda \ NB_USER="${NB_USER}" \ NB_UID=${NB_UID} \ NB_GID=${NB_GID} \ - LC_ALL=en_US.UTF-8 \ - LANG=en_US.UTF-8 \ - LANGUAGE=en_US.UTF-8 + LC_ALL=C.UTF-8 \ + LANG=C.UTF-8 \ + LANGUAGE=C.UTF-8 ENV PATH="${CONDA_DIR}/bin:${PATH}" \ HOME="/home/${NB_USER}" @@ -123,34 +124,33 @@ RUN set -x && \ # Should be simpler, see arch="64"; \ fi && \ - wget --progress=dot:giga -O /tmp/micromamba.tar.bz2 \ - "https://micromamba.snakepit.net/api/micromamba/linux-${arch}/latest" && \ - tar -xvjf /tmp/micromamba.tar.bz2 --strip-components=1 bin/micromamba && \ - rm /tmp/micromamba.tar.bz2 && \ + # https://mamba.readthedocs.io/en/latest/installation/micromamba-installation.html#linux-and-macos + wget --progress=dot:giga -O - \ + "https://micro.mamba.pm/api/micromamba/linux-${arch}/latest" | tar -xvj bin/micromamba && \ PYTHON_SPECIFIER="python=${PYTHON_VERSION}" && \ if [[ "${PYTHON_VERSION}" == "default" ]]; then PYTHON_SPECIFIER="python"; fi && \ # Install the packages - ./micromamba install \ + ./bin/micromamba install \ --root-prefix="${CONDA_DIR}" \ --prefix="${CONDA_DIR}" \ --yes \ "${PYTHON_SPECIFIER}" \ 'mamba' \ 'jupyter_core' && \ - rm micromamba && \ + rm -rf /tmp/bin/ && \ # Pin major.minor version of python - mamba list python | grep '^python ' | tr -s ' ' | cut -d ' ' -f 1,2 >> "${CONDA_DIR}/conda-meta/pinned" && \ + # https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-pkgs.html#preventing-packages-from-updating-pinning + mamba list --full-name 'python' | tail -1 | tr -s ' ' | cut -d ' ' -f 1,2 | sed 's/\.[^.]*$/.*/' >> "${CONDA_DIR}/conda-meta/pinned" && \ mamba clean --all -f -y && \ fix-permissions "${CONDA_DIR}" && \ fix-permissions "/home/${NB_USER}" -# Configure container startup -ENTRYPOINT ["tini", "-g", "--"] -CMD ["start.sh"] - # Copy local files as late as possible to avoid cache busting COPY run-hooks.sh start.sh /usr/local/bin/ +# Configure container entrypoint +ENTRYPOINT ["tini", "-g", "--", "start.sh"] + USER root # Create dirs for startup hooks @@ -181,16 +181,18 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] USER root -# Install all OS dependencies for the Server that starts but lacks all -# features (e.g., download as all possible file formats) +# Install all OS dependencies for the Server that starts +# but lacks all features (e.g., download as all possible file formats) RUN apt-get update --yes && \ apt-get install --yes --no-install-recommends \ + # - Add necessary fonts for matplotlib/seaborn + # See https://github.com/jupyter/docker-stacks/pull/380 for details fonts-liberation \ - # - pandoc is used to convert notebooks to html files + # - `pandoc` is used to convert notebooks to html files # it's not present in the aarch64 Ubuntu image, so we install it here pandoc \ - # - run-one - a wrapper script that runs no more - # than one unique instance of some command with a unique set of arguments, + # - `run-one` - a wrapper script that runs no more + # than one unique instance of some command with a unique set of arguments, # we use `run-one-constantly` to support the `RESTARTABLE` option run-one && \ apt-get clean && rm -rf /var/lib/apt/lists/* @@ -234,7 +236,7 @@ RUN fix-permissions /etc/jupyter/ # HEALTHCHECK documentation: https://docs.docker.com/engine/reference/builder/#healthcheck # This healtcheck works well for `lab`, `notebook`, `nbclassic`, `server`, and `retro` jupyter commands # https://github.com/jupyter/docker-stacks/issues/915#issuecomment-1068528799 -HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=3 \ +HEALTHCHECK --interval=3s --timeout=1s --start-period=3s --retries=3 \ CMD /etc/jupyter/docker_healthcheck.py || exit 1 # Switch back to jovyan to avoid accidental container runs as root @@ -271,10 +273,10 @@ RUN apt-get update --yes && \ vim-tiny \ # git-over-ssh openssh-client \ - # less is needed to run help in R + # `less` is needed to run help in R # see: https://github.com/jupyter/docker-stacks/issues/1588 less \ - # nbconvert dependencies + # `nbconvert` dependencies # https://nbconvert.readthedocs.io/en/latest/install.html#installing-tex texlive-xetex \ texlive-fonts-recommended \ @@ -383,6 +385,13 @@ WORKDIR "${HOME}" LABEL maintainer="Christoph Schranz , Mathematical Michael " +# Install dependencies for e.g. PyTorch +RUN mamba install --quiet --yes \ + pyyaml setuptools cmake cffi typing && \ + mamba clean --all -f -y && \ + fix-permissions "${CONDA_DIR}" && \ + fix-permissions "/home/${NB_USER}" + # Install Tensorflow, check compatibility here: # https://www.tensorflow.org/install/source#gpu # installation via conda leads to errors in version 4.8.2 @@ -390,29 +399,22 @@ LABEL maintainer="Christoph Schranz , Mat # using device_lib.list_local_devices() the cudNN version is shown, adapt version to tested compat USER ${NB_UID} RUN pip install --upgrade pip && \ - pip install --no-cache-dir tensorflow==2.15.0 keras==2.15.0 && \ - fix-permissions "${CONDA_DIR}" && \ - fix-permissions "/home/${NB_USER}" - -# Install PyTorch with dependencies -RUN mamba install --quiet --yes \ - pyyaml setuptools cmake cffi typing && \ - mamba clean --all -f -y && \ + pip install --no-cache-dir tensorflow==2.16.1 keras==3.1.1 && \ fix-permissions "${CONDA_DIR}" && \ fix-permissions "/home/${NB_USER}" # Check compatibility here: # https://pytorch.org/get-started/locally/ # Installation via conda leads to errors installing cudatoolkit=11.1 -# RUN pip install --no-cache-dir torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 && \ -# torchviz==0.0.2 --extra-index-url https://download.pytorch.org/whl/cu118 +# RUN pip install --no-cache-dir torch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 \ +# && torchviz==0.0.2 --extra-index-url https://download.pytorch.org/whl/cu121 RUN set -ex \ && buildDeps=' \ - torch==2.1.2 \ - torchvision==0.16.2 \ - torchaudio==2.1.2 \ + torch==2.2.2 \ + torchvision==0.17.2 \ + torchaudio==2.2.2 \ ' \ - && pip install --no-cache-dir $buildDeps \ + && pip install --no-cache-dir $buildDeps --extra-index-url https://download.pytorch.org/whl/cu121 \ && fix-permissions "${CONDA_DIR}" \ && fix-permissions "/home/${NB_USER}" @@ -441,7 +443,8 @@ RUN pip install --no-cache-dir nvidia-pyindex && \ fix-permissions "${CONDA_DIR}" && \ fix-permissions "/home/${NB_USER}" -RUN mamba install -c nvidia cuda-nvcc=12.0.140 -y && \ +# Install cuda-nvcc with sepecific version, see here: https://anaconda.org/nvidia/cuda-nvcc/labels +RUN mamba install -c nvidia cuda-nvcc=12.3.107 -y && \ mamba clean --all -f -y && \ fix-permissions $CONDA_DIR && \ fix-permissions /home/$NB_USER @@ -467,39 +470,42 @@ RUN apt-get update \ USER $NB_UID RUN set -ex \ && buildDeps=' \ - graphviz==0.19.1 \ - pytest==7.2.2 \ -' \ + graphviz==0.20.3 \ + pytest==8.1.1 \ + ' \ && pip install --no-cache-dir $buildDeps \ && fix-permissions "${CONDA_DIR}" \ && fix-permissions "/home/${NB_USER}" # upgrade jupyter-server for compatibility -RUN pip install --no-cache-dir --upgrade \ - distributed==2023.3.0 \ - jupyter-server==2.4 \ - # fix permissions of conda +RUN set -ex \ + && buildDeps=' \ + distributed==2024.4.1 \ + jupyter-server==2.13 \ + ' \ + && pip install --no-cache-dir $buildDeps \ && fix-permissions "${CONDA_DIR}" \ && fix-permissions "/home/${NB_USER}" -RUN pip install --no-cache-dir \ +RUN set -ex \ + && buildDeps=' \ # install extension manager jupyter_contrib_nbextensions==0.7.0 \ - jupyter_nbextensions_configurator==0.6.1 \ + jupyter_nbextensions_configurator==0.6.3 \ # install git extension - jupyterlab-git==0.41.0 \ + jupyterlab-git==0.50.0 \ # install plotly extension - plotly==5.13.1 \ + plotly==5.20.0 \ # install drawio and graphical extensions - jupyterlab-drawio==0.9.0 \ - rise==5.7.1 \ - ipyleaflet==0.17.2 \ - ipywidgets==8.0.4 \ + ipydrawio==1.3.0 \ + ipyleaflet==0.18.2 \ + ipywidgets==8.1.2 \ # install spell checker - jupyterlab-spellchecker==0.7.3 && \ - # fix permissions of conda - fix-permissions "${CONDA_DIR}" && \ - fix-permissions "/home/${NB_USER}" + jupyterlab-spellchecker==0.7.3 \ + ' \ + && pip install --no-cache-dir $buildDeps \ + && fix-permissions "${CONDA_DIR}" \ + && fix-permissions "/home/${NB_USER}" # Switch back to jovyan to avoid accidental container runs as root USER $NB_UID diff --git a/.build/docker-stacks b/.build/docker-stacks index 1494233..e838ff3 160000 --- a/.build/docker-stacks +++ b/.build/docker-stacks @@ -1 +1 @@ -Subproject commit 1494233e27cdc70e3766ea2518e7153ee425fc4f +Subproject commit e838ff397a2d9c2ad0faae051ef0ec4f20732320 diff --git a/.build/docker_healthcheck.py b/.build/docker_healthcheck.py index 8f3338e..7dd3de0 100755 --- a/.build/docker_healthcheck.py +++ b/.build/docker_healthcheck.py @@ -3,6 +3,7 @@ # Distributed under the terms of the Modified BSD License. import json import os +import subprocess from pathlib import Path import requests @@ -10,7 +11,19 @@ # Several operations below deliberately don't check for possible errors # As this is a healthcheck, it should succeed or raise an exception on error -runtime_dir = Path("/home/") / os.environ["NB_USER"] / ".local/share/jupyter/runtime/" +# Docker runs healtchecks using an exec +# It uses the default user configured when running the image: root for the case of a custom NB_USER or jovyan for the case of the default image user. +# We manually change HOME to make `jupyter --runtime-dir` report a correct path +# More information: +result = subprocess.run( + ["jupyter", "--runtime-dir"], + check=True, + capture_output=True, + text=True, + env=dict(os.environ) | {"HOME": "/home/" + os.environ["NB_USER"]}, +) +runtime_dir = Path(result.stdout.rstrip()) + json_file = next(runtime_dir.glob("*server-*.json")) url = json.loads(json_file.read_bytes())["url"] diff --git a/.build/setup-scripts/setup-julia-packages.bash b/.build/setup-scripts/setup-julia-packages.bash index fa1421e..14a7740 100755 --- a/.build/setup-scripts/setup-julia-packages.bash +++ b/.build/setup-scripts/setup-julia-packages.bash @@ -3,7 +3,7 @@ set -exuo pipefail # Requirements: # - Run as a non-root user # - The JULIA_PKGDIR environment variable is set -# - Julia is already set up, with the setup-julia.bash command +# - Julia is already set up, with the setup_julia.py command # If we don't specify what CPUs the precompilation should be done for, it's @@ -11,20 +11,20 @@ set -exuo pipefail # container runs on a host that's the same architecture, but a *different* # generation of CPU than what the build host was, the precompilation is useless # and Julia takes a long long time to start up. This specific multitarget comes -# from https://github.com/JuliaCI/julia-buildkite/blob/70bde73f6cb17d4381b62236fc2d96b1c7acbba7/utilities/build_envs.sh#L20-L76, +# from https://github.com/JuliaCI/julia-buildkite/blob/9f354745a1f2bf31a5952462aa1ff2d869507cb8/utilities/build_envs.sh#L20-L82, # and may need to be updated as new CPU generations come out. # If the architecture the container runs on is different, # precompilation may still have to be re-done on first startup - but this # *should* catch most of the issues. See # https://github.com/jupyter/docker-stacks/issues/2015 for more information if [ "$(uname -m)" == "x86_64" ]; then - # See https://github.com/JuliaCI/julia-buildkite/blob/70bde73f6cb17d4381b62236fc2d96b1c7acbba7/utilities/build_envs.sh#L24 + # See https://github.com/JuliaCI/julia-buildkite/blob/9f354745a1f2bf31a5952462aa1ff2d869507cb8/utilities/build_envs.sh#L23 # for an explanation of these options - export JULIA_CPU_TARGET="generic;sandybridge,-xsaveopt,clone_all;haswell,-rdrnd,base(1)" + export JULIA_CPU_TARGET="generic;sandybridge,-xsaveopt,clone_all;haswell,-rdrnd,base(1);x86-64-v4,-rdrnd,base(1)" elif [ "$(uname -m)" == "aarch64" ]; then - # See https://github.com/JuliaCI/julia-buildkite/blob/70bde73f6cb17d4381b62236fc2d96b1c7acbba7/utilities/build_envs.sh#L54 + # See https://github.com/JuliaCI/julia-buildkite/blob/9f354745a1f2bf31a5952462aa1ff2d869507cb8/utilities/build_envs.sh#L56 # for an explanation of these options - export JULIA_CPU_TARGET="generic;cortex-a57;thunderx2t99;carmel" + export JULIA_CPU_TARGET="generic;cortex-a57;thunderx2t99;carmel,clone_all;apple-m1,base(3);neoverse-512tvb,base(3)" fi # Install base Julia packages diff --git a/.build/setup-scripts/setup_julia.py b/.build/setup-scripts/setup_julia.py index 0cdbe0c..114e64c 100755 --- a/.build/setup-scripts/setup_julia.py +++ b/.build/setup-scripts/setup_julia.py @@ -6,6 +6,7 @@ # - Run as the root user # - The JULIA_PKGDIR environment variable is set +import logging import os import platform import shutil @@ -14,6 +15,8 @@ import requests +LOGGER = logging.getLogger(__name__) + def unify_aarch64(platform: str) -> str: """ @@ -31,14 +34,19 @@ def get_latest_julia_url() -> tuple[str, str]: Get the last stable version of Julia Based on: https://github.com/JuliaLang/www.julialang.org/issues/878#issuecomment-749234813 """ - + LOGGER.info("Downloading Julia versions information") versions = requests.get( "https://julialang-s3.julialang.org/bin/versions.json" ).json() stable_versions = {k: v for k, v in versions.items() if v["stable"]} - latest_version_files = stable_versions[max(stable_versions)]["files"] + # Compare versions semantically + latest_stable_version = max( + stable_versions, key=lambda ver: [int(sub_ver) for sub_ver in ver.split(".")] + ) + latest_version_files = stable_versions[latest_stable_version]["files"] triplet = unify_aarch64(platform.machine()) + "-linux-gnu" file_info = [vf for vf in latest_version_files if vf["triplet"] == triplet][0] + LOGGER.info(f"Latest version: {file_info['version']} url: {file_info['url']}") return file_info["url"], file_info["version"] @@ -47,6 +55,7 @@ def download_julia(julia_url: str) -> None: Downloads and unpacks julia The resulting julia directory is "/opt/julia-VERSION/" """ + LOGGER.info("Downloading and unpacking Julia") tmp_file = Path("/tmp/julia.tar.gz") subprocess.check_call( ["curl", "--progress-bar", "--location", "--output", tmp_file, julia_url] @@ -55,12 +64,13 @@ def download_julia(julia_url: str) -> None: tmp_file.unlink() -def prepare_julia(julia_version: str) -> None: +def configure_julia(julia_version: str) -> None: """ Creates /usr/local/bin/julia symlink Make Julia aware of conda libraries Creates a directory for Julia user libraries """ + LOGGER.info("Configuring Julia") # Link Julia installed version to /usr/local/bin, so julia launches it subprocess.check_call( ["ln", "-fs", f"/opt/julia-{julia_version}/bin/julia", "/usr/local/bin/julia"] @@ -80,6 +90,8 @@ def prepare_julia(julia_version: str) -> None: if __name__ == "__main__": + logging.basicConfig(level=logging.INFO) + julia_url, julia_version = get_latest_julia_url() download_julia(julia_url=julia_url) - prepare_julia(julia_version=julia_version) + configure_julia(julia_version=julia_version) diff --git a/.build/start-notebook.py b/.build/start-notebook.py index b99ff31..973da5a 100755 --- a/.build/start-notebook.py +++ b/.build/start-notebook.py @@ -14,23 +14,25 @@ os.execvp(command[0], command) -# Wrap everything in start.sh, no matter what -command = ["/usr/local/bin/start.sh"] +# Entrypoint is start.sh +command = [] -# If we want to survive restarts, tell that to start.sh +# If we want to survive restarts, launch the command using `run-one-constantly` if os.environ.get("RESTARTABLE") == "yes": command.append("run-one-constantly") # We always launch a jupyter subcommand from this script command.append("jupyter") -# Launch the configured subcommand. Note that this should be a single string, so we don't split it -# We default to lab +# Launch the configured subcommand. +# Note that this should be a single string, so we don't split it. +# We default to `lab`. jupyter_command = os.environ.get("DOCKER_STACKS_JUPYTER_CMD", "lab") command.append(jupyter_command) -# Append any optional NOTEBOOK_ARGS we were passed in. This is supposed to be multiple args passed -# on to the notebook command, so we split it correctly with shlex +# Append any optional NOTEBOOK_ARGS we were passed in. +# This is supposed to be multiple args passed on to the notebook command, +# so we split it correctly with shlex if "NOTEBOOK_ARGS" in os.environ: command += shlex.split(os.environ["NOTEBOOK_ARGS"]) @@ -38,4 +40,5 @@ command += sys.argv[1:] # Execute the command! +print("Executing: " + " ".join(command)) os.execvp(command[0], command) diff --git a/.build/start-singleuser.py b/.build/start-singleuser.py index 2dcf6c0..c80339f 100755 --- a/.build/start-singleuser.py +++ b/.build/start-singleuser.py @@ -5,14 +5,16 @@ import shlex import sys -command = ["/usr/local/bin/start.sh", "jupyterhub-singleuser"] +# Entrypoint is start.sh +command = ["jupyterhub-singleuser"] # set default ip to 0.0.0.0 if "--ip=" not in os.environ.get("NOTEBOOK_ARGS", ""): command.append("--ip=0.0.0.0") -# Append any optional NOTEBOOK_ARGS we were passed in. This is supposed to be multiple args passed -# on to the notebook command, so we split it correctly with shlex +# Append any optional NOTEBOOK_ARGS we were passed in. +# This is supposed to be multiple args passed on to the notebook command, +# so we split it correctly with shlex if "NOTEBOOK_ARGS" in os.environ: command += shlex.split(os.environ["NOTEBOOK_ARGS"]) @@ -20,4 +22,5 @@ command += sys.argv[1:] # Execute the command! +print("Executing: " + " ".join(command)) os.execvp(command[0], command) diff --git a/.build/start.sh b/.build/start.sh index 76419b6..33d12d8 100755 --- a/.build/start.sh +++ b/.build/start.sh @@ -34,6 +34,17 @@ else cmd=( "$@" ) fi +# Backwards compatibility: `start.sh` is executed by default in ENTRYPOINT +# so it should no longer be specified in CMD +if [ "${_START_SH_EXECUTED}" = "1" ]; then + _log "WARNING: start.sh is the default ENTRYPOINT, do not include it in CMD" + _log "Executing the command:" "${cmd[@]}" + exec "${cmd[@]}" +else + export _START_SH_EXECUTED=1 +fi + + # NOTE: This hook will run as the user the container was started with! # shellcheck disable=SC1091 source /usr/local/bin/run-hooks.sh /usr/local/bin/start-notebook.d @@ -77,6 +88,13 @@ if [ "$(id -u)" == 0 ]; then userdel "${NB_USER}" useradd --no-log-init --home "/home/${NB_USER}" --shell /bin/bash --uid "${NB_UID}" --gid "${NB_GID}" --groups 100 "${NB_USER}" fi + # Update the home directory if the desired user (NB_USER) is root and the + # desired user id (NB_UID) is 0 and the desired group id (NB_GID) is 0. + if [ "${NB_USER}" = "root" ] && [ "${NB_UID}" = "$(id -u "${NB_USER}")" ] && [ "${NB_GID}" = "$(id -g "${NB_USER}")" ]; then + sed -i "s|/root|/home/root|g" /etc/passwd + # Do not preserve ownership in rootless mode + CP_OPTS="-a --no-preserve=ownership" + fi # Move or symlink the jovyan home directory to the desired user's home # directory if it doesn't already exist, and update the current working @@ -85,7 +103,8 @@ if [ "$(id -u)" == 0 ]; then if [[ ! -e "/home/${NB_USER}" ]]; then _log "Attempting to copy /home/jovyan to /home/${NB_USER}..." mkdir "/home/${NB_USER}" - if cp -a /home/jovyan/. "/home/${NB_USER}/"; then + # shellcheck disable=SC2086 + if cp ${CP_OPTS:--a} /home/jovyan/. "/home/${NB_USER}/"; then _log "Success!" else _log "Failed to copy data from /home/jovyan to /home/${NB_USER}!" @@ -125,7 +144,7 @@ if [ "$(id -u)" == 0 ]; then sed -r "s#Defaults\s+secure_path\s*=\s*\"?([^\"]+)\"?#Defaults secure_path=\"${CONDA_DIR}/bin:\1\"#" /etc/sudoers | grep secure_path > /etc/sudoers.d/path # Optionally grant passwordless sudo rights for the desired user - if [[ "$GRANT_SUDO" == "1" || "$GRANT_SUDO" == "yes" ]]; then + if [[ "${GRANT_SUDO}" == "1" || "${GRANT_SUDO}" == "yes" ]]; then _log "Granting ${NB_USER} passwordless sudo rights!" echo "${NB_USER} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/added-by-start-script fi diff --git a/custom/gpulibs.Dockerfile b/custom/gpulibs.Dockerfile index 4481775..0b75f55 100644 --- a/custom/gpulibs.Dockerfile +++ b/custom/gpulibs.Dockerfile @@ -1,5 +1,12 @@ LABEL maintainer="Christoph Schranz , Mathematical Michael " +# Install dependencies for e.g. PyTorch +RUN mamba install --quiet --yes \ + pyyaml setuptools cmake cffi typing && \ + mamba clean --all -f -y && \ + fix-permissions "${CONDA_DIR}" && \ + fix-permissions "/home/${NB_USER}" + # Install Tensorflow, check compatibility here: # https://www.tensorflow.org/install/source#gpu # installation via conda leads to errors in version 4.8.2 @@ -7,29 +14,22 @@ LABEL maintainer="Christoph Schranz , Mat # using device_lib.list_local_devices() the cudNN version is shown, adapt version to tested compat USER ${NB_UID} RUN pip install --upgrade pip && \ - pip install --no-cache-dir tensorflow==2.15.0 keras==2.15.0 && \ - fix-permissions "${CONDA_DIR}" && \ - fix-permissions "/home/${NB_USER}" - -# Install PyTorch with dependencies -RUN mamba install --quiet --yes \ - pyyaml setuptools cmake cffi typing && \ - mamba clean --all -f -y && \ + pip install --no-cache-dir tensorflow==2.16.1 keras==3.1.1 && \ fix-permissions "${CONDA_DIR}" && \ fix-permissions "/home/${NB_USER}" # Check compatibility here: # https://pytorch.org/get-started/locally/ # Installation via conda leads to errors installing cudatoolkit=11.1 -# RUN pip install --no-cache-dir torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 && \ -# torchviz==0.0.2 --extra-index-url https://download.pytorch.org/whl/cu118 +# RUN pip install --no-cache-dir torch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 \ +# && torchviz==0.0.2 --extra-index-url https://download.pytorch.org/whl/cu121 RUN set -ex \ && buildDeps=' \ - torch==2.1.2 \ - torchvision==0.16.2 \ - torchaudio==2.1.2 \ + torch==2.2.2 \ + torchvision==0.17.2 \ + torchaudio==2.2.2 \ ' \ - && pip install --no-cache-dir $buildDeps \ + && pip install --no-cache-dir $buildDeps --extra-index-url https://download.pytorch.org/whl/cu121 \ && fix-permissions "${CONDA_DIR}" \ && fix-permissions "/home/${NB_USER}" @@ -58,7 +58,8 @@ RUN pip install --no-cache-dir nvidia-pyindex && \ fix-permissions "${CONDA_DIR}" && \ fix-permissions "/home/${NB_USER}" -RUN mamba install -c nvidia cuda-nvcc=12.0.140 -y && \ +# Install cuda-nvcc with sepecific version, see here: https://anaconda.org/nvidia/cuda-nvcc/labels +RUN mamba install -c nvidia cuda-nvcc=12.3.107 -y && \ mamba clean --all -f -y && \ fix-permissions $CONDA_DIR && \ fix-permissions /home/$NB_USER diff --git a/custom/header.Dockerfile b/custom/header.Dockerfile index a4d9889..3d6ef22 100644 --- a/custom/header.Dockerfile +++ b/custom/header.Dockerfile @@ -1,6 +1,6 @@ # Use NVIDIA CUDA as base image and run the same installation as in the other packages. # The version of cuda must match those of the packages installed in src/Dockerfile.gpulibs -FROM nvidia/cuda:12.0.1-cudnn8-runtime-ubuntu22.04 +FROM nvidia/cuda:12.3.2-cudnn9-runtime-ubuntu22.04 LABEL authors="Christoph Schranz , Mathematical Michael " # This is a concatenated Dockerfile, the maintainers of subsequent sections may vary. RUN chmod 1777 /tmp && chmod 1777 /var/tmp diff --git a/custom/usefulpackages.Dockerfile b/custom/usefulpackages.Dockerfile index 6fd16dd..e2262fe 100644 --- a/custom/usefulpackages.Dockerfile +++ b/custom/usefulpackages.Dockerfile @@ -10,39 +10,42 @@ RUN apt-get update \ USER $NB_UID RUN set -ex \ && buildDeps=' \ - graphviz==0.19.1 \ - pytest==7.2.2 \ -' \ + graphviz==0.20.3 \ + pytest==8.1.1 \ + ' \ && pip install --no-cache-dir $buildDeps \ && fix-permissions "${CONDA_DIR}" \ && fix-permissions "/home/${NB_USER}" # upgrade jupyter-server for compatibility -RUN pip install --no-cache-dir --upgrade \ - distributed==2023.3.0 \ - jupyter-server==2.4 \ - # fix permissions of conda +RUN set -ex \ + && buildDeps=' \ + distributed==2024.4.1 \ + jupyter-server==2.13 \ + ' \ + && pip install --no-cache-dir $buildDeps \ && fix-permissions "${CONDA_DIR}" \ && fix-permissions "/home/${NB_USER}" -RUN pip install --no-cache-dir \ +RUN set -ex \ + && buildDeps=' \ # install extension manager jupyter_contrib_nbextensions==0.7.0 \ - jupyter_nbextensions_configurator==0.6.1 \ + jupyter_nbextensions_configurator==0.6.3 \ # install git extension - jupyterlab-git==0.41.0 \ + jupyterlab-git==0.50.0 \ # install plotly extension - plotly==5.13.1 \ + plotly==5.20.0 \ # install drawio and graphical extensions - jupyterlab-drawio==0.9.0 \ - rise==5.7.1 \ - ipyleaflet==0.17.2 \ - ipywidgets==8.0.4 \ + ipydrawio==1.3.0 \ + ipyleaflet==0.18.2 \ + ipywidgets==8.1.2 \ # install spell checker - jupyterlab-spellchecker==0.7.3 && \ - # fix permissions of conda - fix-permissions "${CONDA_DIR}" && \ - fix-permissions "/home/${NB_USER}" + jupyterlab-spellchecker==0.7.3 \ + ' \ + && pip install --no-cache-dir $buildDeps \ + && fix-permissions "${CONDA_DIR}" \ + && fix-permissions "/home/${NB_USER}" # Switch back to jovyan to avoid accidental container runs as root USER $NB_UID diff --git a/extra/Getting_Started/GPU-processing.ipynb b/extra/Getting_Started/GPU-processing.ipynb index 20fc6a8..0d293ef 100755 --- a/extra/Getting_Started/GPU-processing.ipynb +++ b/extra/Getting_Started/GPU-processing.ipynb @@ -15,7 +15,7 @@ "source": [ "## Test GPU connection\n", "\n", - "#### Using the following command, your GPU type and its NVIDIA-SMI driver version should be listed:" + "### Using the following command, your GPU type and its NVIDIA-SMI driver version should be listed:" ] }, { @@ -27,26 +27,26 @@ "name": "stdout", "output_type": "stream", "text": [ - "Tue Dec 19 15:20:27 2023 \n", - "+-----------------------------------------------------------------------------+\n", - "| NVIDIA-SMI 525.54 Driver Version: 526.56 CUDA Version: 12.0 |\n", - "|-------------------------------+----------------------+----------------------+\n", - "| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |\n", - "| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |\n", - "| | | MIG M. |\n", - "|===============================+======================+======================|\n", - "| 0 NVIDIA GeForce ... On | 00000000:01:00.0 Off | N/A |\n", - "| N/A 43C P0 19W / N/A | 0MiB / 6144MiB | 0% Default |\n", - "| | | N/A |\n", - "+-------------------------------+----------------------+----------------------+\n", - " \n", - "+-----------------------------------------------------------------------------+\n", - "| Processes: |\n", - "| GPU GI CI PID Type Process name GPU Memory |\n", - "| ID ID Usage |\n", - "|=============================================================================|\n", - "| No running processes found |\n", - "+-----------------------------------------------------------------------------+\n" + "Mon Apr 8 16:12:04 2024 \n", + "+---------------------------------------------------------------------------------------+\n", + "| NVIDIA-SMI 545.23.05 Driver Version: 545.84 CUDA Version: 12.3 |\n", + "|-----------------------------------------+----------------------+----------------------+\n", + "| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |\n", + "| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |\n", + "| | | MIG M. |\n", + "|=========================================+======================+======================|\n", + "| 0 NVIDIA GeForce RTX 3060 ... On | 00000000:01:00.0 Off | N/A |\n", + "| N/A 39C P8 10W / 60W | 105MiB / 6144MiB | 0% Default |\n", + "| | | N/A |\n", + "+-----------------------------------------+----------------------+----------------------+\n", + " \n", + "+---------------------------------------------------------------------------------------+\n", + "| Processes: |\n", + "| GPU GI CI PID Type Process name GPU Memory |\n", + "| ID ID Usage |\n", + "|=======================================================================================|\n", + "| No running processes found |\n", + "+---------------------------------------------------------------------------------------+\n" ] } ], @@ -58,7 +58,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "#### Now, test if PyTorch can access the GPU via CUDA:" + "### Now, test if PyTorch can access the GPU via CUDA:" ] }, { @@ -66,10 +66,21 @@ "execution_count": 2, "metadata": {}, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + }, { "data": { "text/plain": [ - "True" + "tensor([[0.3820, 0.9186, 0.0873],\n", + " [0.0677, 0.3465, 0.2376],\n", + " [0.3284, 0.1974, 0.0858],\n", + " [0.6180, 0.1698, 0.6550],\n", + " [0.8948, 0.0876, 0.5775]])" ] }, "execution_count": 2, @@ -78,8 +89,21 @@ } ], "source": [ + "from __future__ import print_function\n", + "import numpy as np\n", "import torch\n", - "torch.cuda.is_available()" + "\n", + "print(torch.cuda.is_available())\n", + "\n", + "a = torch.rand(5, 3)\n", + "a" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Now, test if Tensorflow can access the GPU via CUDA:" ] }, { @@ -91,76 +115,67 @@ "name": "stderr", "output_type": "stream", "text": [ - "2023-12-19 15:20:31.292167: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n", - "2023-12-19 15:20:31.292283: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n", - "2023-12-19 15:20:31.345027: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n", - "2023-12-19 15:20:31.405681: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n", - "To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n" + "2024-04-08 16:12:05.608277: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n", + "To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n", + "2024-04-08 16:12:06.372910: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "[]\n" + "True [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]\n", + "[name: \"/device:CPU:0\"\n", + "device_type: \"CPU\"\n", + "memory_limit: 268435456\n", + "locality {\n", + "}\n", + "incarnation: 5065807306722951698\n", + "xla_global_id: -1\n", + ", name: \"/device:GPU:0\"\n", + "device_type: \"GPU\"\n", + "memory_limit: 3774873600\n", + "locality {\n", + " bus_id: 1\n", + " links {\n", + " }\n", + "}\n", + "incarnation: 18240998582538193189\n", + "physical_device_desc: \"device: 0, name: NVIDIA GeForce RTX 3060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6\"\n", + "xla_global_id: 416903419\n", + "]\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "2023-12-19 15:20:33.437438: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:887] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", + "2024-04-08 16:12:07.257260: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", "Your kernel may have been built without NUMA support.\n", - "2023-12-19 15:20:33.438375: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:887] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", + "2024-04-08 16:12:07.258537: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", "Your kernel may have been built without NUMA support.\n", - "2023-12-19 15:20:33.438401: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:887] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", + "2024-04-08 16:12:07.258578: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", "Your kernel may have been built without NUMA support.\n", - "2023-12-19 15:20:33.439883: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:887] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", + "2024-04-08 16:12:07.261418: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", "Your kernel may have been built without NUMA support.\n", - "2023-12-19 15:20:33.439914: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:887] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", + "2024-04-08 16:12:07.261470: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", "Your kernel may have been built without NUMA support.\n", - "2023-12-19 15:20:33.439931: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:887] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", + "2024-04-08 16:12:07.261499: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", "Your kernel may have been built without NUMA support.\n", - "2023-12-19 15:20:35.742285: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:887] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", + "2024-04-08 16:12:07.390214: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", "Your kernel may have been built without NUMA support.\n", - "2023-12-19 15:20:35.742336: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:887] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", + "2024-04-08 16:12:07.390277: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", "Your kernel may have been built without NUMA support.\n", - "2023-12-19 15:20:35.742346: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2022] Could not identify NUMA node of platform GPU id 0, defaulting to 0. Your kernel may not have been built with NUMA support.\n", - "2023-12-19 15:20:35.742371: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:887] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", + "2024-04-08 16:12:07.390289: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2019] Could not identify NUMA node of platform GPU id 0, defaulting to 0. Your kernel may not have been built with NUMA support.\n", + "2024-04-08 16:12:07.390324: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", "Your kernel may have been built without NUMA support.\n", - "2023-12-19 15:20:35.742387: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1929] Created device /device:GPU:0 with 3007 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6\n" + "2024-04-08 16:12:07.390350: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1928] Created device /device:GPU:0 with 3600 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6\n" ] - }, - { - "data": { - "text/plain": [ - "[name: \"/device:CPU:0\"\n", - " device_type: \"CPU\"\n", - " memory_limit: 268435456\n", - " locality {\n", - " }\n", - " incarnation: 16132906446837489126\n", - " xla_global_id: -1,\n", - " name: \"/device:GPU:0\"\n", - " device_type: \"GPU\"\n", - " memory_limit: 3153068032\n", - " locality {\n", - " bus_id: 1\n", - " links {\n", - " }\n", - " }\n", - " incarnation: 13564847057713934038\n", - " physical_device_desc: \"device: 0, name: NVIDIA GeForce RTX 3060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6\"\n", - " xla_global_id: 416903419]" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" } ], "source": [ "import tensorflow as tf\n", + "# NUMA warnings are no problem\n", "print(tf.test.is_built_with_cuda(), tf.config.list_physical_devices('GPU'))\n", "\n", "from tensorflow.python.client import device_lib\n", @@ -170,16 +185,32 @@ { "cell_type": "code", "execution_count": 4, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 16:12:07.398413: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", + "Your kernel may have been built without NUMA support.\n", + "2024-04-08 16:12:07.398507: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", + "Your kernel may have been built without NUMA support.\n", + "2024-04-08 16:12:07.398537: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", + "Your kernel may have been built without NUMA support.\n", + "2024-04-08 16:12:07.398712: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", + "Your kernel may have been built without NUMA support.\n", + "2024-04-08 16:12:07.398727: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2019] Could not identify NUMA node of platform GPU id 0, defaulting to 0. Your kernel may not have been built with NUMA support.\n", + "2024-04-08 16:12:07.398755: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", + "Your kernel may have been built without NUMA support.\n", + "2024-04-08 16:12:07.398769: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1928] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 3600 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6\n" + ] + }, { "data": { "text/plain": [ - "tensor([[0.6527, 0.7924, 0.8878],\n", - " [0.7822, 0.0338, 0.4025],\n", - " [0.6130, 0.1177, 0.9255],\n", - " [0.0451, 0.7010, 0.0331],\n", - " [0.1705, 0.8165, 0.7323]])" + "24.57181" ] }, "execution_count": 4, @@ -188,13 +219,24 @@ } ], "source": [ - "from __future__ import print_function\n", - "import numpy as np\n", - "import torch\n", - "a = torch.rand(5, 3)\n", - "a" + "# Test GPU-calculation in TF\n", + "with tf.device('/gpu:0'):\n", + " a = tf.Variable(tf.random.uniform(shape=(100, 100)), name=\"a\")\n", + " b = tf.matmul(a, a)\n", + " del a\n", + "\n", + "np.mean(b)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -229,7 +271,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "559 ms ± 87.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" + "666 ms ± 75.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" ] } ], @@ -263,7 +305,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "200 ms ± 4.12 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" + "275 ms ± 12.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" ] } ], @@ -289,16 +331,16 @@ "name": "stdout", "output_type": "stream", "text": [ - "tensor([[0.4609, 0.7584, 0.4593, 0.0551, 0.1594],\n", - " [0.6063, 0.5960, 0.4197, 0.7962, 0.1542],\n", - " [0.5160, 0.4067, 0.6062, 0.1356, 0.8867],\n", - " [0.3636, 0.7090, 0.3487, 0.0552, 0.4904],\n", - " [0.6309, 0.0065, 0.8926, 0.0643, 0.6346]], device='cuda:0')\n", - "tensor([[0.4609, 0.7584, 0.4593, 0.0551, 0.1594],\n", - " [0.6063, 0.5960, 0.4197, 0.7962, 0.1542],\n", - " [0.5160, 0.4067, 0.6062, 0.1356, 0.8867],\n", - " [0.3636, 0.7090, 0.3487, 0.0552, 0.4904],\n", - " [0.6309, 0.0065, 0.8926, 0.0643, 0.6346]], dtype=torch.float64)\n" + "tensor([[0.3950, 0.1953, 0.3265, 0.5156, 0.5355],\n", + " [0.2038, 0.3776, 0.9295, 0.4246, 0.4888],\n", + " [0.4108, 0.8438, 0.9092, 0.9224, 0.2784],\n", + " [0.6929, 0.9316, 0.6724, 0.0748, 0.4366],\n", + " [0.4430, 0.9733, 0.1734, 0.9995, 0.0928]], device='cuda:0')\n", + "tensor([[0.3950, 0.1953, 0.3265, 0.5156, 0.5355],\n", + " [0.2038, 0.3776, 0.9295, 0.4246, 0.4888],\n", + " [0.4108, 0.8438, 0.9092, 0.9224, 0.2784],\n", + " [0.6929, 0.9316, 0.6724, 0.0748, 0.4366],\n", + " [0.4430, 0.9733, 0.1734, 0.9995, 0.0928]], dtype=torch.float64)\n" ] } ], @@ -322,8 +364,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "The slowest run took 5.26 times longer than the fastest. This could mean that an intermediate result is being cached.\n", - "90.5 ms ± 74.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" + "55.3 ms ± 161 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n" ] } ], @@ -370,11 +411,11 @@ "name": "stdout", "output_type": "stream", "text": [ - "tensor([[0.2782, 0.4737, 0.6745, 0.9081, 0.3480],\n", - " [0.1753, 0.6475, 0.3926, 0.3947, 0.9197],\n", - " [0.1747, 0.6550, 0.4903, 0.4221, 0.3066],\n", - " [0.8606, 0.6053, 0.0784, 0.1127, 0.2536],\n", - " [0.0236, 0.5264, 0.6400, 0.5198, 0.5281]], device='cuda:0')\n" + "tensor([[0.4825, 0.5817, 0.0127, 0.7462, 0.1225],\n", + " [0.5351, 0.1582, 0.7482, 0.5826, 0.0507],\n", + " [0.1559, 0.9457, 0.6242, 0.7610, 0.2080],\n", + " [0.6010, 0.4131, 0.8429, 0.5539, 0.0943],\n", + " [0.3711, 0.0609, 0.5242, 0.5414, 0.9859]], device='cuda:0')\n" ] } ], @@ -405,11 +446,11 @@ "name": "stdout", "output_type": "stream", "text": [ - "tensor([[ 6.5489e-04, 1.8794e-04, 2.2678e-04, -2.8653e-04, 1.9096e-04],\n", - " [ 1.8794e-04, 7.0443e-04, 2.0275e-04, -2.2673e-04, 2.6704e-04],\n", - " [ 2.2678e-04, 2.0275e-04, 6.8227e-04, -1.5024e-05, 3.2128e-04],\n", - " [-2.8653e-04, -2.2673e-04, -1.5024e-05, 1.1865e-03, 1.9364e-04],\n", - " [ 1.9096e-04, 2.6704e-04, 3.2128e-04, 1.9364e-04, 1.0109e-03]],\n", + "tensor([[ 1.2062e-03, -3.5245e-04, 6.0149e-04, 5.5662e-04, -5.2612e-04],\n", + " [-3.5245e-04, 1.0502e-03, -1.2980e-04, 7.1976e-05, 2.5712e-04],\n", + " [ 6.0149e-04, -1.2980e-04, 1.2645e-03, 4.9298e-04, -2.6166e-04],\n", + " [ 5.5662e-04, 7.1976e-05, 4.9298e-04, 9.1148e-04, -2.7401e-04],\n", + " [-5.2612e-04, 2.5712e-04, -2.6166e-04, -2.7401e-04, 1.0023e-03]],\n", " device='cuda:0')\n" ] } @@ -428,11 +469,11 @@ "name": "stdout", "output_type": "stream", "text": [ - "tensor([[ 6.5489e-04, 1.8794e-04, 2.2678e-04, -2.8653e-04, 1.9096e-04],\n", - " [ 1.8794e-04, 7.0443e-04, 2.0275e-04, -2.2673e-04, 2.6704e-04],\n", - " [ 2.2678e-04, 2.0275e-04, 6.8227e-04, -1.5024e-05, 3.2128e-04],\n", - " [-2.8653e-04, -2.2673e-04, -1.5024e-05, 1.1865e-03, 1.9364e-04],\n", - " [ 1.9096e-04, 2.6704e-04, 3.2128e-04, 1.9364e-04, 1.0109e-03]],\n", + "tensor([[ 1.2062e-03, -3.5245e-04, 6.0149e-04, 5.5662e-04, -5.2612e-04],\n", + " [-3.5245e-04, 1.0502e-03, -1.2980e-04, 7.1976e-05, 2.5712e-04],\n", + " [ 6.0149e-04, -1.2980e-04, 1.2645e-03, 4.9298e-04, -2.6166e-04],\n", + " [ 5.5662e-04, 7.1976e-05, 4.9298e-04, 9.1148e-04, -2.7401e-04],\n", + " [-5.2612e-04, 2.5712e-04, -2.6166e-04, -2.7401e-04, 1.0023e-03]],\n", " dtype=torch.float64)\n" ] } @@ -468,7 +509,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.7" + "version": "3.11.8" } }, "nbformat": 4, diff --git a/generate-Dockerfile.sh b/generate-Dockerfile.sh index d91de70..a4ef0d6 100755 --- a/generate-Dockerfile.sh +++ b/generate-Dockerfile.sh @@ -5,7 +5,7 @@ cd $(cd -P -- "$(dirname -- "$0")" && pwd -P) export DOCKERFILE=".build/Dockerfile" export STACKS_DIR=".build/docker-stacks" # please test the build of the commit in https://github.com/jupyter/docker-stacks/commits/main in advance -export HEAD_COMMIT="1494233e27cdc70e3766ea2518e7153ee425fc4f" +export HEAD_COMMIT="e838ff397a2d9c2ad0faae051ef0ec4f20732320" while [[ "$#" -gt 0 ]]; do case $1 in -p|--pw|--password) PASSWORD="$2" && USE_PASSWORD=1; shift;; From 198007d01592b633bcfcb6ab0c88e6d1a1a2f867 Mon Sep 17 00:00:00 2001 From: Christoph Schranz Date: Mon, 8 Apr 2024 18:17:11 +0200 Subject: [PATCH 2/4] header update --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 752fc9e..187251a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +# GPU-Jupyter + GPU-Jupyter From 7c293b55f22fc02a5bf41198d313fb11d3f424d0 Mon Sep 17 00:00:00 2001 From: Christoph Schranz Date: Mon, 8 Apr 2024 18:21:50 +0200 Subject: [PATCH 3/4] update to v1.7_cuda-12.3_ubuntu-22.04 --- README.md | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 187251a..3229869 100644 --- a/README.md +++ b/README.md @@ -45,19 +45,19 @@ for creating and maintaining a robust Python, R, and Julia toolstack for Data Sc 3. Get access to your GPU via CUDA drivers within Docker containers. For this, follow the installation steps in this [Medium article](https://medium.com/@christoph.schranz/set-up-your-own-gpu-based-jupyterlab-e0d45fcacf43). You can confirm that you can access your GPU within Docker if the command below returns a result similar to this one: ```bash - docker run --gpus all nvidia/cuda:12.0.1-cudnn8-runtime-ubuntu22.04 nvidia-smi + docker run --gpus all nvidia/cuda:12.3.2-cudnn9-runtime-ubuntu22.04 nvidia-smi ``` ```bash - Fri Mar 24 09:17:19 2023 + Mon Apr 8 16:19:10 2024 +---------------------------------------------------------------------------------------+ - | NVIDIA-SMI 530.30.02 Driver Version: 530.30.02 CUDA Version: 12.1 | + | NVIDIA-SMI 545.23.05 Driver Version: 545.84 CUDA Version: 12.3 | |-----------------------------------------+----------------------+----------------------+ - | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | - | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | + | GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC | + | Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |=========================================+======================+======================| - | 0 NVIDIA GeForce RTX 2070 S... On | 00000000:01:00.0 Off | N/A | - | 0% 36C P8 1W / 215W| 65MiB / 8192MiB | 0% Default | + | 0 NVIDIA GeForce RTX 3060 ... On | 00000000:01:00.0 Off | N/A | + | N/A 46C P8 10W / 60W | 105MiB / 6144MiB | 0% Default | | | | N/A | +-----------------------------------------+----------------------+----------------------+ @@ -66,6 +66,7 @@ for creating and maintaining a robust Python, R, and Julia toolstack for Data Sc | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=======================================================================================| + | No running processes found | +---------------------------------------------------------------------------------------+ ``` **It is important to keep your installed CUDA version in mind when you pull images. @@ -75,9 +76,9 @@ for creating and maintaining a robust Python, R, and Julia toolstack for Data Sc ```bash cd your-working-directory ll data # this path will be mounted by default - docker run --gpus all -d -it -p 8848:8888 -v $(pwd)/data:/home/jovyan/work -e GRANT_SUDO=yes -e JUPYTER_ENABLE_LAB=yes --user root cschranz/gpu-jupyter:v1.6_cuda-12.0_ubuntu-22.04 + docker run --gpus all -d -it -p 8848:8888 -v $(pwd)/data:/home/jovyan/work -e GRANT_SUDO=yes -e JUPYTER_ENABLE_LAB=yes --user root cschranz/gpu-jupyter:v1.7_cuda-12.3_ubuntu-22.04 ``` - This starts an instance of *GPU-Jupyter* with the tag `v1.6_cuda-12.0_ubuntu-22.04` at [http://localhost:8848](http://localhost:8848) (port `8848`). + This starts an instance of *GPU-Jupyter* with the tag `v1.7_cuda-12.3_ubuntu-22.04` at [http://localhost:8848](http://localhost:8848) (port `8848`). To log into Jupyterlab, you have to specify a token that you get from: ```bash docker exec -it [container-ID/name] jupyter server list @@ -88,6 +89,9 @@ for creating and maintaining a robust Python, R, and Julia toolstack for Data Sc Additionally, data within the host's `data` directory is shared with the container. The following images of GPU-Jupyter are available on [Dockerhub](https://hub.docker.com/r/cschranz/gpu-jupyter): + - `v1.7_cuda-12.3_ubuntu-22.04` (full image) + - `v1.7_cuda-12.3_ubuntu-22.04_python-only` (only with a python interpreter and without Julia and R) + - `v1.7_cuda-12.3_ubuntu-22.04_slim` (only with a python interpreter and without additional packages) - `v1.6_cuda-12.0_ubuntu-22.04` (full image) - `v1.6_cuda-12.0_ubuntu-22.04_python-only` (only with a python interpreter and without Julia and R) - `v1.6_cuda-12.0_ubuntu-22.04_slim` (only with a python interpreter and without additional packages) @@ -124,8 +128,8 @@ Additionally, data within the host's `data` directory is shared with the contain - `v1.4_cuda-10.1_ubuntu-18.04_slim` (only with a python interpreter and without additional packages) - The version, e.g. `v1.6`, declares the version of the generator setup. - The Cuda version, e.g. `cuda-12.0`, must match the CUDA driver version and be supported by the GPU libraries. + The version, e.g. `v1.7`, declares the version of the generator setup. + The Cuda version, e.g. `cuda-12.3`, must match the CUDA driver version and be supported by the GPU libraries. These and older versions of GPU-Jupyter are listed on [Dockerhub](https://hub.docker.com/r/cschranz/gpu-jupyter/tags?page=1&ordering=last_updated). In case you are using another version or the GPU libraries don't work on your hardware, please try to build the image on your own as described below. Note that the images built for Ubuntu 20.04 LTS work also on Ubuntu 22.04 LTS is currently not supported. @@ -141,14 +145,14 @@ we recommend checking out this [tutorial](https://www.youtube.com/watch?v=7wfPqA Building a custom Docker image is the recommended option if you have a different GPU architecture or if you want to customize the pre-installed packages. The Dockerfiles in `custom/` can be modified to achieve this. To use a custom base image, modify `custom/header.Dockerfile`. To install specific GPU-related libraries, modify `custom/gpulibs.Dockerfile`, and to add specific libraries, append them to `custom/usefulpackages.Dockerfile`. -After making the necessary modifications, regenerate the `Dockerfile` in `/.build`. Once you have confirmed that your GPU is accessible within Docker containers by running `docker run --gpus all nvidia/cuda:12.0.1-cudnn8-runtime-ubuntu22.04 nvidia-smi` and seeing the GPU statistics, you can generate, build, and run the Docker image. +After making the necessary modifications, regenerate the `Dockerfile` in `/.build`. Once you have confirmed that your GPU is accessible within Docker containers by running `docker run --gpus all nvidia/cuda:12.3.2-cudnn9-runtime-ubuntu22.04 nvidia-smi` and seeing the GPU statistics, you can generate, build, and run the Docker image. The following commands will start *GPU-Jupyter* on [localhost:8848](http://localhost:8848) with the default password `gpu-jupyter`. ```bash git clone https://github.com/iot-salzburg/gpu-jupyter.git cd gpu-jupyter git branch # Check for extisting branches -git checkout v1.6_cuda-11.8_ubuntu-22.04 # select or create a new version +git checkout v1.7_cuda-12.3_ubuntu-22.04 # select or create a new version # generate the Dockerfile with python and without Julia and R (see options: --help) ./generate-Dockerfile.sh --python-only docker build -t gpu-jupyter .build/ # will take a while From 2fe5f3cff1c22e24c8d0fd3a36b1467cf21bca06 Mon Sep 17 00:00:00 2001 From: Christoph Schranz Date: Tue, 9 Apr 2024 10:18:45 +0200 Subject: [PATCH 4/4] Omit drawio, Jupyterlab version 4.X --- .build/Dockerfile | 6 +- custom/usefulpackages.Dockerfile | 6 +- extra/Getting_Started/GPU-processing.ipynb | 249 ++++++--------------- 3 files changed, 75 insertions(+), 186 deletions(-) diff --git a/.build/Dockerfile b/.build/Dockerfile index bd89ef3..dd07a47 100755 --- a/.build/Dockerfile +++ b/.build/Dockerfile @@ -496,12 +496,12 @@ RUN set -ex \ jupyterlab-git==0.50.0 \ # install plotly extension plotly==5.20.0 \ - # install drawio and graphical extensions - ipydrawio==1.3.0 \ + # install drawio and graphical extensions, not compatible with Jupyterlab 4.X yet + # ipydrawio==1.3.0 \ ipyleaflet==0.18.2 \ ipywidgets==8.1.2 \ # install spell checker - jupyterlab-spellchecker==0.7.3 \ + jupyterlab-spellchecker==0.8.4 \ ' \ && pip install --no-cache-dir $buildDeps \ && fix-permissions "${CONDA_DIR}" \ diff --git a/custom/usefulpackages.Dockerfile b/custom/usefulpackages.Dockerfile index e2262fe..d7d2727 100644 --- a/custom/usefulpackages.Dockerfile +++ b/custom/usefulpackages.Dockerfile @@ -36,12 +36,12 @@ RUN set -ex \ jupyterlab-git==0.50.0 \ # install plotly extension plotly==5.20.0 \ - # install drawio and graphical extensions - ipydrawio==1.3.0 \ + # install drawio and graphical extensions, not compatible with Jupyterlab 4.X yet + # ipydrawio==1.3.0 \ ipyleaflet==0.18.2 \ ipywidgets==8.1.2 \ # install spell checker - jupyterlab-spellchecker==0.7.3 \ + jupyterlab-spellchecker==0.8.4 \ ' \ && pip install --no-cache-dir $buildDeps \ && fix-permissions "${CONDA_DIR}" \ diff --git a/extra/Getting_Started/GPU-processing.ipynb b/extra/Getting_Started/GPU-processing.ipynb index 0d293ef..2a43bda 100755 --- a/extra/Getting_Started/GPU-processing.ipynb +++ b/extra/Getting_Started/GPU-processing.ipynb @@ -9,6 +9,36 @@ "This Jupyterlab Instance is connected to the GPU via CUDA drivers. In this notebook, we test the installation and perform some basic operations on the GPU." ] }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Selected Jupyter core packages...\n", + "IPython : 8.22.2\n", + "ipykernel : 6.29.3\n", + "ipywidgets : 8.1.2\n", + "jupyter_client : 8.6.1\n", + "jupyter_core : 5.7.2\n", + "jupyter_server : 2.13.0\n", + "jupyterlab : 4.1.5\n", + "nbclient : 0.10.0\n", + "nbconvert : 7.16.3\n", + "nbformat : 5.10.4\n", + "notebook : 7.1.2\n", + "qtconsole : not installed\n", + "traitlets : 5.14.2\n" + ] + } + ], + "source": [ + "!jupyter --version" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -20,14 +50,14 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Mon Apr 8 16:12:04 2024 \n", + "Tue Apr 9 08:07:24 2024 \n", "+---------------------------------------------------------------------------------------+\n", "| NVIDIA-SMI 545.23.05 Driver Version: 545.84 CUDA Version: 12.3 |\n", "|-----------------------------------------+----------------------+----------------------+\n", @@ -36,7 +66,7 @@ "| | | MIG M. |\n", "|=========================================+======================+======================|\n", "| 0 NVIDIA GeForce RTX 3060 ... On | 00000000:01:00.0 Off | N/A |\n", - "| N/A 39C P8 10W / 60W | 105MiB / 6144MiB | 0% Default |\n", + "| N/A 38C P8 10W / 60W | 0MiB / 6144MiB | 0% Default |\n", "| | | N/A |\n", "+-----------------------------------------+----------------------+----------------------+\n", " \n", @@ -63,7 +93,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -76,14 +106,14 @@ { "data": { "text/plain": [ - "tensor([[0.3820, 0.9186, 0.0873],\n", - " [0.0677, 0.3465, 0.2376],\n", - " [0.3284, 0.1974, 0.0858],\n", - " [0.6180, 0.1698, 0.6550],\n", - " [0.8948, 0.0876, 0.5775]])" + "tensor([[0.3254, 0.9917, 0.7786],\n", + " [0.5244, 0.4340, 0.8261],\n", + " [0.7216, 0.0024, 0.3113],\n", + " [0.8638, 0.6087, 0.6495],\n", + " [0.2394, 0.2831, 0.6866]])" ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -108,16 +138,16 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "2024-04-08 16:12:05.608277: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n", + "2024-04-09 08:07:27.416927: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n", "To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n", - "2024-04-08 16:12:06.372910: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n" + "2024-04-09 08:07:28.663739: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n" ] }, { @@ -130,7 +160,7 @@ "memory_limit: 268435456\n", "locality {\n", "}\n", - "incarnation: 5065807306722951698\n", + "incarnation: 7894643083535347790\n", "xla_global_id: -1\n", ", name: \"/device:GPU:0\"\n", "device_type: \"GPU\"\n", @@ -140,7 +170,7 @@ " links {\n", " }\n", "}\n", - "incarnation: 18240998582538193189\n", + "incarnation: 9669600989926253149\n", "physical_device_desc: \"device: 0, name: NVIDIA GeForce RTX 3060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6\"\n", "xla_global_id: 416903419\n", "]\n" @@ -150,26 +180,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "2024-04-08 16:12:07.257260: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", - "Your kernel may have been built without NUMA support.\n", - "2024-04-08 16:12:07.258537: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", - "Your kernel may have been built without NUMA support.\n", - "2024-04-08 16:12:07.258578: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", - "Your kernel may have been built without NUMA support.\n", - "2024-04-08 16:12:07.261418: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", - "Your kernel may have been built without NUMA support.\n", - "2024-04-08 16:12:07.261470: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", - "Your kernel may have been built without NUMA support.\n", - "2024-04-08 16:12:07.261499: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", - "Your kernel may have been built without NUMA support.\n", - "2024-04-08 16:12:07.390214: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", - "Your kernel may have been built without NUMA support.\n", - "2024-04-08 16:12:07.390277: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", - "Your kernel may have been built without NUMA support.\n", - "2024-04-08 16:12:07.390289: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2019] Could not identify NUMA node of platform GPU id 0, defaulting to 0. Your kernel may not have been built with NUMA support.\n", - "2024-04-08 16:12:07.390324: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", - "Your kernel may have been built without NUMA support.\n", - "2024-04-08 16:12:07.390350: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1928] Created device /device:GPU:0 with 3600 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6\n" + "2024-04-09 08:07:30.376208: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1928] Created device /device:GPU:0 with 3600 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6\n" ] } ], @@ -184,7 +195,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": { "tags": [] }, @@ -193,27 +204,16 @@ "name": "stderr", "output_type": "stream", "text": [ - "2024-04-08 16:12:07.398413: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", - "Your kernel may have been built without NUMA support.\n", - "2024-04-08 16:12:07.398507: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", - "Your kernel may have been built without NUMA support.\n", - "2024-04-08 16:12:07.398537: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", - "Your kernel may have been built without NUMA support.\n", - "2024-04-08 16:12:07.398712: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", - "Your kernel may have been built without NUMA support.\n", - "2024-04-08 16:12:07.398727: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2019] Could not identify NUMA node of platform GPU id 0, defaulting to 0. Your kernel may not have been built with NUMA support.\n", - "2024-04-08 16:12:07.398755: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", - "Your kernel may have been built without NUMA support.\n", - "2024-04-08 16:12:07.398769: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1928] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 3600 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6\n" + "2024-04-09 08:07:30.385786: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1928] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 3600 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6\n" ] }, { "data": { "text/plain": [ - "24.57181" + "25.202852" ] }, - "execution_count": 4, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -255,7 +255,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -264,14 +264,14 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "666 ms ± 75.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" + "973 ms ± 151 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" ] } ], @@ -289,7 +289,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -298,14 +298,14 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "275 ms ± 12.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" + "290 ms ± 44.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" ] } ], @@ -324,23 +324,23 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "tensor([[0.3950, 0.1953, 0.3265, 0.5156, 0.5355],\n", - " [0.2038, 0.3776, 0.9295, 0.4246, 0.4888],\n", - " [0.4108, 0.8438, 0.9092, 0.9224, 0.2784],\n", - " [0.6929, 0.9316, 0.6724, 0.0748, 0.4366],\n", - " [0.4430, 0.9733, 0.1734, 0.9995, 0.0928]], device='cuda:0')\n", - "tensor([[0.3950, 0.1953, 0.3265, 0.5156, 0.5355],\n", - " [0.2038, 0.3776, 0.9295, 0.4246, 0.4888],\n", - " [0.4108, 0.8438, 0.9092, 0.9224, 0.2784],\n", - " [0.6929, 0.9316, 0.6724, 0.0748, 0.4366],\n", - " [0.4430, 0.9733, 0.1734, 0.9995, 0.0928]], dtype=torch.float64)\n" + "tensor([[0.3845, 0.0880, 0.5156, 0.4110, 0.5014],\n", + " [0.7350, 0.1050, 0.2858, 0.1222, 0.2921],\n", + " [0.3644, 0.0735, 0.8485, 0.8745, 0.8900],\n", + " [0.8959, 0.6109, 0.7280, 0.2928, 0.9440],\n", + " [0.0158, 0.1069, 0.9924, 0.0682, 0.6148]], device='cuda:0')\n", + "tensor([[0.3845, 0.0880, 0.5156, 0.4110, 0.5014],\n", + " [0.7350, 0.1050, 0.2858, 0.1222, 0.2921],\n", + " [0.3644, 0.0735, 0.8485, 0.8745, 0.8900],\n", + " [0.8959, 0.6109, 0.7280, 0.2928, 0.9440],\n", + " [0.0158, 0.1069, 0.9924, 0.0682, 0.6148]], dtype=torch.float64)\n" ] } ], @@ -357,14 +357,14 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "55.3 ms ± 161 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n" + "51.4 ms ± 121 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n" ] } ], @@ -374,117 +374,6 @@ "H = x.mm( (x.t().mm(x)).inverse() ).mm(x.t())" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Exhaustive Testing on GPU" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [], - "source": [ - "# let us run this cell only if CUDA is available\n", - "# We will use ``torch.device`` objects to move tensors in and out of GPU\n", - "import torch\n", - "if torch.cuda.is_available():\n", - " device = torch.device(\"cuda\") # a CUDA device object\n", - " x = torch.rand(10000, 10, device=device) # directly create a tensor on GPU" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "tensor([[0.4825, 0.5817, 0.0127, 0.7462, 0.1225],\n", - " [0.5351, 0.1582, 0.7482, 0.5826, 0.0507],\n", - " [0.1559, 0.9457, 0.6242, 0.7610, 0.2080],\n", - " [0.6010, 0.4131, 0.8429, 0.5539, 0.0943],\n", - " [0.3711, 0.0609, 0.5242, 0.5414, 0.9859]], device='cuda:0')\n" - ] - } - ], - "source": [ - "if torch.cuda.is_available():\n", - " y = x.to(device) # or just use strings ``.to(\"cuda\")``\n", - " print(x[0:5, 0:5])" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [], - "source": [ - "if torch.cuda.is_available():\n", - " # Here is the memory of the GPU a border.\n", - " # A matrix with 100000 lines requires 37 GB, but only 8 GB are available.\n", - " H = x.mm( (x.t().mm(x)).inverse() ).mm(x.t())" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "tensor([[ 1.2062e-03, -3.5245e-04, 6.0149e-04, 5.5662e-04, -5.2612e-04],\n", - " [-3.5245e-04, 1.0502e-03, -1.2980e-04, 7.1976e-05, 2.5712e-04],\n", - " [ 6.0149e-04, -1.2980e-04, 1.2645e-03, 4.9298e-04, -2.6166e-04],\n", - " [ 5.5662e-04, 7.1976e-05, 4.9298e-04, 9.1148e-04, -2.7401e-04],\n", - " [-5.2612e-04, 2.5712e-04, -2.6166e-04, -2.7401e-04, 1.0023e-03]],\n", - " device='cuda:0')\n" - ] - } - ], - "source": [ - "if torch.cuda.is_available():\n", - " print(H[0:5, 0:5])" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "tensor([[ 1.2062e-03, -3.5245e-04, 6.0149e-04, 5.5662e-04, -5.2612e-04],\n", - " [-3.5245e-04, 1.0502e-03, -1.2980e-04, 7.1976e-05, 2.5712e-04],\n", - " [ 6.0149e-04, -1.2980e-04, 1.2645e-03, 4.9298e-04, -2.6166e-04],\n", - " [ 5.5662e-04, 7.1976e-05, 4.9298e-04, 9.1148e-04, -2.7401e-04],\n", - " [-5.2612e-04, 2.5712e-04, -2.6166e-04, -2.7401e-04, 1.0023e-03]],\n", - " dtype=torch.float64)\n" - ] - } - ], - "source": [ - "if torch.cuda.is_available():\n", - " # This operation is difficult, as an symmetric matrix is transferred\n", - " # back to the CPU. Is possible up to 30000 rows.\n", - " print(H.to(\"cpu\", torch.double)[0:5, 0:5])" - ] - }, { "cell_type": "code", "execution_count": null,