docker
コマンドが実行できる。[本のサンプルで使用されている主要パッケージのバージョン (p.55)] python 3.6.7 tensorflow 1.13.1 numpy 1.14.6 matplotlib 3.0.3 pandas 0.22.0 Pillow(PIL) 4.1.1 h5py 2.8.0 gym 0.10.11
tensorflow/tensorflow:1.13.1-gpu tensorflow/tensorflow:1.13.1-gpu-py3 これらのイメージは、TensorFlow 1.13.1 と CUDA 10 を組み合わせており、NVIDIA ドライバのバージョンが CUDA 10 をサポートしている必要があります。
tensorflow/tensorflow:1.13.1-gpu-py3-jupyter
docker pull tensorflow/tensorflow:1.13.1-gpu-py3-jupyter
(例) 緑色の文字部分は環境に合わせて変更すること docker run --gpus all -it --rm -v local_dir:container_dir tensorflow/tensorflow:1.13.1-gpu-py3-jupyter
割当 | コンテナ名 | ポート1 (22へ転送) | ポート2 (8888へ転送) | /root/doc マウント先 | Docker Image |
---|---|---|---|---|---|
- | alphazero | 7075 | 8085 | /home/docker/alphazero | tensorflow/tensorflow:1.13.1-gpu-py3-jupyter |
docker run --name alphazero --shm-size=1g --ulimit memlock=-1 --ulimit stack=67108864 --gpus all \ -p 7075:22 -p 8085:8888 \ -v /home/docker/alphazero:/root/doc \ -it tensorflow/tensorflow:1.13.1-gpu-py3-jupyter
Docker Host の Windows 上で動作する Ubuntu (WSL2) において、docker コマンドを用いて alphazero コンテナに接続する。
docker attach alphazero
Docker Desktop から alphazero を選択して、"Exec" タブを選択するとシェルが起動して、対話環境が手に入る。
(動作中の jupyter notebook の token を知る) jupyter notebook listjupyter notebook のルートは /tf のようだ。 sampleをそちらに移動する。
# python Python 3.5.2 (default, Jan 26 2021, 13:30:48) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf >>> print(tf.config.list_physical_devices('GPU')) Traceback (most recent call last): File "", line 1, in AttributeError: module 'tensorflow' has no attribute 'config' >>> print(tf.config) Traceback (most recent call last): File " ", line 1, in AttributeError: module 'tensorflow' has no attribute 'config' >>> from tensorflow.python.client import device_lib >>> print(device_lib.list_local_devices()) 2025-04-12 05:15:52.134689: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 AVX512F FMA 2025-04-12 05:15:52.314537: E tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node Your kernel may have been built without NUMA support. 2025-04-12 05:15:52.314798: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x47e2fa0 executing computations on platform CUDA. Devices: 2025-04-12 05:15:52.314846: I tensorflow/compiler/xla/service/service.cc:158] StreamExecutor device (0): NVIDIA GeForce RTX 3070 Laptop GPU, Compute Capability 8.6 2025-04-12 05:15:52.318474: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2304010000 Hz 2025-04-12 05:15:52.334564: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x493a180 executing computations on platform Host. Devices: 2025-04-12 05:15:52.334623: I tensorflow/compiler/xla/service/service.cc:158] StreamExecutor device (0): , 2025-04-12 05:15:52.335763: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1433] Found device 0 with properties: name: NVIDIA GeForce RTX 3070 Laptop GPU major: 8 minor: 6 memoryClockRate(GHz): 1.62 pciBusID: 0000:01:00.0 totalMemory: 8.00GiB freeMemory: 6.95GiB 2025-04-12 05:15:52.335811: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 0 2025-04-12 05:15:52.336088: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix: 2025-04-12 05:15:52.336112: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990] 0 2025-04-12 05:15:52.336118: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0: N 2025-04-12 05:15:52.336246: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1194] Could not identify NUMA node of platform GPU id 0, defaulting to 0. Your kernel may not have been built with NUMA support. 2025-04-12 05:15:52.336320: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/device:GPU:0 with 6762 MB memory) -> physical GPU (device: 0, name: NVIDIA GeForce RTX 3070 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6) [name: "/device:CPU:0" device_type: "CPU" memory_limit: 268435456 locality { } incarnation: 1455752447322421804 , name: "/device:XLA_GPU:0" device_type: "XLA_GPU" memory_limit: 17179869184 locality { } incarnation: 15660618604836127656 physical_device_desc: "device: XLA_GPU device" , name: "/device:XLA_CPU:0" device_type: "XLA_CPU" memory_limit: 17179869184 locality { } incarnation: 14919214141591377901 physical_device_desc: "device: XLA_CPU device" , name: "/device:GPU:0" device_type: "GPU" memory_limit: 7090575770 locality { bus_id: 1 links { } } incarnation: 18121662368334831392 physical_device_desc: "device: 0, name: NVIDIA GeForce RTX 3070 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6" ] >>>
apt-get update apt-get upgrade -y --allow-unauthenticated apt-get install -y openssh-server echo 'root:パスワード' | chpasswd sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/" /etc/ssh/sshd_config service ssh start
ssh -p 7075 root@133.99.41.195
apt install rsync
apt-get install libssl-dev apt-get install -y openssh ← openssh パッケージのインストールがなぜか失敗する。
rsync -avr -e "ssh -p 7075" sample root@133.99.41.195:/root/doc
(問題発生) 実行すると、次のエラーメッセージが表示されて、ファイルがコピーできない。
protocol version mismatch -- is your shell clean?
(see the rsync manpage for an explanation)
rsync error: protocol incompatibility (code 2) at compat.c(622) [sender=3.2.7]
(原因究明) これは、ssh ログイン時にシェルから不要な出力(バナーなど)がある場合に起きるエラーと考えられる。
確かに /etc/bash.bashrc で余分な出力がある。
その部分を以下のコードで囲んで対話環境でのみ実行されるように変更する。
if [[ $- == *i* ]]; then # echo を実行する行 fi
/etc/bash/bashrc の変更 |
*** bash.bashrc.org Sat Apr 12 01:15:25 2025 --- bash.bashrc Sat Apr 12 01:22:43 2025 *************** *** 19,24 **** --- 19,27 ---- alias grep="grep --color=auto" alias ls="ls --color=auto" + # added by nitta 2025/04/12 + if [[ $- == *i* ]]; then + echo -e "\e[1;31m" cat<<TF ________ _______________ *************** *** 48,50 **** --- 51,56 ---- # Turn off colors echo -e "\e[m" + + fi + # till here by nitta |
$ ssh -p 7075 root@133.99.41.195 echo ok(解決) rsync によるコピーが動作するようになった。
requirements.txt |
tensorflow_gpu==1.13.1 numpy==1.14.6 matplotlib==3.0.3 panas==0.22.0 Pillow==4.1.1 h5py==2.8.0 gym==0.10.11 |
root@4206f815ce4d:~# python Python 3.5.2 (default, Jan 26 2021, 13:30:48) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information.python は 3.5.2 のようだ。本にはpython のバージョンは 3.6.7 (p.67) なのでこのまま進め、 エラーがでる場合は変更する。← 3_1の ipynb でエラーが出たので 3.6.7 に変更すべし。
pip uninstall python pip install python==3.6.7
>>> import tensorflow as tf >>> print(tf.__version__) 1.13.1
>>> import numpy as np >>> print(np.__version__) 1.16.3
>>> import matplotlib >>> print(matplotlib.__version__) 3.0.3
>>> import pandas as pd Traceback (most recent call last): File "", line 1, in ImportError: No module named 'pandas' >>> import PIL Traceback (most recent call last): File " ", line 1, in ImportError: No module named 'PIL' >>> import Pillow Traceback (most recent call last): File " ", line 1, in ImportError: No module named 'Pillow' >>> import h5py >>> print(h5py.__version__) 2.9.0 >>> import gym Traceback (most recent call last): File " ", line 1, in ImportError: No module named 'gym' >>> from openai import gym Traceback (most recent call last): File " ", line 1, in ImportError: No module named 'openai' >>>
pip install pandas=0.22.0
pip install pillow==4.1.1
pip install h5py==2.8.0
pip install gym==0.10.11
自動的にjupyter nnotebookが起動している。 さらに、ssh 経由で入ると、相手は jupyter notebook のようだ。
(他のマシンから) ssh -p 7005 root@133.99.41.195 ← 反応なし ^C-c をタイプすると Serving notebooks from local directory: /tf 0 active kernels The Jupyter Notebook is running at: http://(4206f815ce4d or 127.0.0.1):8888/?token=c53633f5e846d47bf88103c6649065357720b3e020ef39cf Shutdown this notebook server (y/[n])? No answer for 5s: resuming operation...
http://133.99.41.195:8085/?token=a62e....e0ab3_1_classification.ipynb でエラーがでる。
# cat /usr/local/cuda/version.txt CUDA Version 10.0.130 # nvcc --version nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2018 NVIDIA Corporation Built on Sat_Aug_25_21:08:01_CDT_2018 Cuda compilation tools, release 10.0, V10.0.130 # nvidia-smi Sat Apr 12 05:36:02 2025 +-----------------------------------------------------------------------------------------+ | NVIDIA-SMI 565.72 Driver Version: 566.14 CUDA Version: 12.7 | |-----------------------------------------+------------------------+----------------------+ | 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 3070 ... On | 00000000:01:00.0 Off | N/A | | N/A 44C P8 20W / 125W | 7037MiB / 8192MiB | 0% Default | | | | N/A | +-----------------------------------------+------------------------+----------------------+ +-----------------------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=========================================================================================| | 0 N/A N/A 55 C /python3.5 N/A | +-----------------------------------------------------------------------------------------+
NVIDIAドライバは docker ホストにだけ必要であるが、docker コンテナは 自分の中に CUDA ランタイプやライブラリを含んでいる 必要がある。そのうえで、コンテナからホストの NVIDIA カーネルモジュールにアクセスできるようにするのが nvidia-container-toolkit の役割。
nvidia-container-toolkit はインストールされていないようだ。 何なら、使用している docker Container は昔の NVIDIA ドライバがインストールされているような気がする。 nvidia の公式サイトからダウンロードすべき。 https://catalog.ngc.nvidia.com/orgs/nvidia/containers/tensorflow
tensorflow-1.13.1 を含むコンテナは nvcr.io/nvidia/tensorflow:19.03-py3
# python Python 3.5.2 (default, Jan 26 2021, 13:30:48) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf >>> print(tf.test.is_gpu_available()) 2025-04-12 06:25:39.058560: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 AVX512F FMA 2025-04-12 06:25:40.821502: E tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node Your kernel may have been built without NUMA support. 2025-04-12 06:25:40.821722: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x44331b0 executing computations on platform CUDA. Devices: 2025-04-12 06:25:40.821796: I tensorflow/compiler/xla/service/service.cc:158] StreamExecutor device (0): NVIDIA GeForce RTX 3070 Laptop GPU, Compute Capability 8.6 2025-04-12 06:25:40.827096: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2304010000 Hz 2025-04-12 06:25:40.837139: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x458a370 executing computations on platform Host. Devices: 2025-04-12 06:25:40.837194: I tensorflow/compiler/xla/service/service.cc:158] StreamExecutor device (0):, 2025-04-12 06:25:40.838116: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1433] Found device 0 with properties: name: NVIDIA GeForce RTX 3070 Laptop GPU major: 8 minor: 6 memoryClockRate(GHz): 1.62 pciBusID: 0000:01:00.0 totalMemory: 8.00GiB freeMemory: 6.95GiB 2025-04-12 06:25:40.838163: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 0 2025-04-12 06:25:40.838401: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix: 2025-04-12 06:25:40.838425: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990] 0 2025-04-12 06:25:40.838445: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0: N 2025-04-12 06:25:40.838552: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1194] Could not identify NUMA node of platform GPU id 0, defaulting to 0. Your kernel may not have been built with NUMA support. 2025-04-12 06:25:40.838627: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/device:GPU:0 with 6762 MB memory) -> physical GPU (device: 0, name: NVIDIA GeForce RTX 3070 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6) True
ssh -p 7077 root@133.99.41.195
ssh-keygen -R '[133.99.41.195]:7077'
ssh -p 7077 root@133.99.41.195
jupyter notebook
http://localhost:8888/?token=...(略) or http://127.0.0.1:8888/?token=...(略)
(例) jupyter が表示したURL: http://127.0.0.1:8888/?token=64b6f850fc2a1b9fb52c71b7cd3240d59870619b32a4b4e7 (変更点) IPアドレス: 127.0.0.1 (または localhost) → 133.99.41.195 ポート番号: 8888 → 8087 (アクセスするURL) http://133.99.41.195:8087/?token=64b6f850fc2a1b9fb52c71b7cd3240d59870619b32a4b4e7
jupyter notebook が異常終了したときに、しばらく(5分程度) 8888 番ポートをつかんだままになることがある。 そのような状態で jupyter notebook 再起動すると、8888番ポート以外のポート番号を使って起動し、 外部からアクセスできなくなる。しばらく(5分程度)待ってから jupyter notebook を起動すること。