atsushi@AT-GPU-NOTE:~/projects$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.4 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
atsushi@AT-GPU-NOTE:~/projects$ nvidia-smi
Wed Mar 6 22:57:25 2024
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.133 Driver Version: 537.79 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| 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 T550 Laptop GPU On | 00000000:03:00.0 Off | N/A |
| N/A 0C P5 5W / 15W | 0MiB / 4096MiB | 0% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| No running processes found |
+---------------------------------------------------------------------------------------+
cf. Win11 WSL2/Docker及Nvidia GPU
$ docker run --runtime=nvidia --gpus all -it --rm tensorflow/tensorflow:2.14.0-gpu-jupyter python -c \
"import tensorflow as tf; \
print(tf.config.list_physical_devices('GPU')); \
physical_devices = tf.config.list_physical_devices('GPU'); \
print(tf.config.experimental.get_device_details(physical_devices[0]))"
2024-03-09 06:50:06.625119: I tensorflow/core/util/port.cc:111] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-03-09 06:50:06.648882: E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:9342] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
2024-03-09 06:50:06.648962: E tensorflow/compiler/xla/stream_executor/cuda/cuda_fft.cc:609] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
2024-03-09 06:50:06.648992: E tensorflow/compiler/xla/stream_executor/cuda/cuda_blas.cc:1518] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2024-03-09 06:50:06.653614: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-03-09 06:50:08.600246: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:880] could not open file to read NUMA node: /sys/bus/pci/devices/0000:03:00.0/numa_node
Your kernel may have been built without NUMA support.
2024-03-09 06:50:08.608037: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:880] could not open file to read NUMA node: /sys/bus/pci/devices/0000:03:00.0/numa_node
Your kernel may have been built without NUMA support.
2024-03-09 06:50:08.608193: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:880] could not open file to read NUMA node: /sys/bus/pci/devices/0000:03:00.0/numa_node
Your kernel may have been built without NUMA support.
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
2024-03-09 06:50:08.608538: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:880] could not open file to read NUMA node: /sys/bus/pci/devices/0000:03:00.0/numa_node
Your kernel may have been built without NUMA support.
{'compute_capability': (7, 5), 'device_name': 'NVIDIA T550 Laptop GPU'}
ふぅ、実際やってみるといろいろあるねFROM tensorflow/tensorflow:2.14.0-gpu-jupyter
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Tokyo
# update the ubuntu os image and install mandatory libs.
# CAUTION: Don't upgrade packages, especially the CUDA and CuDNN.
RUN apt update && \
apt install -y \
sudo wget curl apt-utils locales bash-completion fonts-noto-cjk graphviz && \
apt clean && \
rm -rf /var/lib/apt/lists/*
# install python library
RUN /usr/local/bin/pip3 install --upgrade pip && \
/usr/local/bin/pip3 install \
autopep8 black yapf bandit flake8 mypy pycodestyle pydocstyle pylint \
jupyterlab-language-pack-ja-JP keras-tqdm pydot pillow pandas bokeh matplotlib && \
/usr/local/bin/pip3 cache purge
# create vscode user
ARG USERNAME=vscode
ARG GROUPNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN groupadd -g 1000 ${GROUPNAME} && \
useradd -m -s /bin/bash -u ${USER_UID} -g ${USER_GID} ${USERNAME} && \
echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} && \
chmod 0440 /etc/sudoers.d/${USERNAME} && \
localedef -f UTF-8 -i ja_JP ja_JP.UTF-8
# install poerty for vscode user
USER vscode
ARG WORKDIR
RUN curl -sSL https://install.python-poetry.org | python3 -
RUN echo "export PATH=/home/vscode/.local/bin:$PATH" >> /home/vscode/.bashrc
RUN /home/vscode/.local/bin/poetry completions bash | sudo tee /etc/bash_completion.d/poerty.bash-completion > /dev/null
{
"name": "KerasExam",
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python3.11",
"python.formatting.autopep8Path": "/usr/local/bin/autopep8",
"python.formatting.blackPath": "/usr/local/bin/black",
"python.formatting.yapfPath": "/usr/local/bin/yapf"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-azuretools.vscode-docker", // To avoid the vscode on the devcontaier recommends it.
"oderwat.indent-rainbow",
"github.copilot",
"github.copilot-chat"
]
}
},
"runArgs" : [
"--runtime=nvidia",
"--gpus","all",
"--add-host=host.docker.internal:host-gateway"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// 8888 : jupyter notebook
// 6006 : TensorBoard
"forwardPorts": [6006, 8888],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
"--runtime=nvidia",
"--gpus","all",
"--add-host=host.docker.internal:host-gateway"
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
]
}
import tensorflow as tf;
from tensorflow.python.platform import build_info as tf_build_info
for physical_device in tf.config.list_physical_devices('GPU') :
print(tf.config.experimental.get_device_details(physical_device))
print("cudnn_version",tf_build_info.build_info['cudnn_version'])
print("cuda_version",tf_build_info.build_info['cuda_version'])
vscode@a976b6555d9c:/workspaces/KerasExam$ python3 list_gpu.py
2024-03-13 14:57:28.335052: I tensorflow/core/util/port.cc:111] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-03-13 14:57:29.023909: E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:9342] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
2024-03-13 14:57:29.023980: E tensorflow/compiler/xla/stream_executor/cuda/cuda_fft.cc:609] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
2024-03-13 14:57:29.027485: E tensorflow/compiler/xla/stream_executor/cuda/cuda_blas.cc:1518] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2024-03-13 14:57:29.299870: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-03-13 14:57:34.610492: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:880] could not open file to read NUMA node: /sys/bus/pci/devices/0000:03:00.0/numa_node
Your kernel may have been built without NUMA support.
2024-03-13 14:57:34.672764: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:880] could not open file to read NUMA node: /sys/bus/pci/devices/0000:03:00.0/numa_node
Your kernel may have been built without NUMA support.
2024-03-13 14:57:34.672926: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:880] could not open file to read NUMA node: /sys/bus/pci/devices/0000:03:00.0/numa_node
Your kernel may have been built without NUMA support.
2024-03-13 14:57:34.673118: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:880] could not open file to read NUMA node: /sys/bus/pci/devices/0000:03:00.0/numa_node
Your kernel may have been built without NUMA support.
{'compute_capability': (7, 5), 'device_name': 'NVIDIA T550 Laptop GPU'}
良かろうと思います。Devcontainer の Terminal から
$ jupyter notebook
で Jupter Note を起動
これでよかろうと思います。
import tensorflow as tf
print("TensorFlow version:", tf.__version__)
mnist = tf.keras.datasets.mnist
(x_train, y_train),(x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(512, activation=tf.nn.relu),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10, activation=tf.nn.softmax)
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test)
2024-03-16 15:28:23.538492: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1886] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 2080 MB memory: -> device: 0, name: NVIDIA T550 Laptop GPU, pci bus id: 0000:03:00.0, compute capability: 7.5
Epoch 1/5
2024-03-16 15:28:26.145357: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7ff77c242340 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2024-03-16 15:28:26.145404: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): NVIDIA T550 Laptop GPU, Compute Capability 7.5
2024-03-16 15:28:26.149143: I tensorflow/compiler/mlir/tensorflow/utils/dump_mlir_util.cc:269] disabling MLIR crash reproducer, set env var `MLIR_CRASH_REPRODUCER_DIRECTORY` to enable.
2024-03-16 15:28:26.310207: I tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:442] Loaded cuDNN version 8600
2024-03-16 15:28:26.399600: I ./tensorflow/compiler/jit/device_compiler.h:186] Compiled cluster using XLA! This line is logged at most once for the lifetime of the process.
1875/1875 [==============================] - 12s 5ms/step - loss: 0.2176 - accuracy: 0.9352
Epoch 2/5
1875/1875 [==============================] - 11s 6ms/step - loss: 0.0967 - accuracy: 0.9702
Epoch 3/5
1875/1875 [==============================] - 11s 6ms/step - loss: 0.0677 - accuracy: 0.9786
Epoch 4/5
1875/1875 [==============================] - 10s 6ms/step - loss: 0.0533 - accuracy: 0.9829
Epoch 5/5
1875/1875 [==============================] - 12s 6ms/step - loss: 0.0431 - accuracy: 0.9864
313/313 [==============================] - 1s 4ms/step - loss: 0.0650 - accuracy: 0.9810