docker
コマンドが実行できる。
tensorflow 1.x では、keras も別途インストールする必要があることに注意する。
pip install keras
[本のサンプルで使用されている主要パッケージのバージョン (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
nVidia の公式 Release Notes が以下の URL にある。
https://docs.nvidia.com/deeplearning/frameworks/tensorflow-release-notes/index.html
tf1 の最終バージョンは 23.03-tf1-py3 のようだ。
Container TensorFlow Python -------------------------------- 23.03 1.15.5 3.8 23.02 1.15.5 3.8 23.01 1.15.5 22.12 1.15.5 22.11 1.15.5 22.10 1.15.5 22.09 1.15.5 22.08 1.15.5 22.07 1.15.5 22.06 1.15.5 22.05 1.15.5 22.04 1.15.5 3.8 22.03 1.15.5 22.02 1.15.5 22.01 1.15.5 21.12 1.15.5 21.11 1.15.5 21.10 1.15.5 3.8 21.09 1.15.5 21.08 1.15.5 21.07 1.15.5 21.06 1.15.5 3.8 21.05 1.15.5 21.04 1.15.5 21.03 1.15.5 3.8 21.02 1.15.5 3.8 20.12 1.15.4 3.8 20.11 1.15.4 3.6 20.10 1.15.4 20.09 1.15.3 20.08 1.15.3 20.07 1.15.3 20.06 1.15.2 20.05 1.15.2 20.04 1.15.2 20.03 1.15.2 20.02 1.15.2 20.01 1.15.0 19.12 1.15.0 19.11 1.15.0 19.10 1.14.0 19.09 1.14.0 19.08 1.14.0 3.6 19.07 1.14.0 3.6 19.06 1.13.1 3.5 19.05 1.13.1 3.5 19.04 1.13.1 3.5 19.03 1.13.1 3.5「f文字列」は python3.6 以降でサポートされている。 tensorflow 1.x 系の最終版 1.15.5 を含んでいる 23.03 を使ってみる。
(例) 緑色の文字部分は環境に合わせて変更すること docker run --gpus all -it --rm -v local_dir:container_dir nvcr.io/nvidia/tensorflow:23.03-tf1-py3
割当 | コンテナ名 | ポート1 (22へ転送) | ポート2 (8888へ転送) | /root/doc マウント先 | Docker Image |
---|---|---|---|---|---|
- | tf1_15_5 | 7076 | 8086 | /home/docker/tf1_15_5 | nvcr.io/nvidia/tensorflow:23.03-tf1-py3 |
docker run --name tf1_15_5 --shm-size=1g --ulimit memlock=-1 --ulimit stack=67108864 --gpus all \ -p 7076:22 -p 8086:8888 \ -v /home/docker/tf1_15_5:/root/doc \ -it nvcr.io/nvidia/tensorflow:23.03-tf1-py3
Docker Host の Windows 上で動作する Ubuntu (WSL2) において、docker コマンドを用いて tf1_15_5 コンテナに接続する。
docker attach tf1_15_5
Docker Desktop から tf1_15_5 を選択して、"Exec" タブを選択するとシェルが起動して、対話環境が手に入る。
root@ea8c1fabfe70:/workspace# nvidia-smi Sun Apr 13 14:25:41 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 73C P0 111W / 125W | 7069MiB / 8192MiB | 78% Default | | | | N/A | +-----------------------------------------+------------------------+----------------------+ +-----------------------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=========================================================================================| | 0 N/A N/A 14596 C /python3.6 N/A | +-----------------------------------------------------------------------------------------+ root@ea8c1fabfe70:/workspace# nvcc --version nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2023 NVIDIA Corporation Built on Tue_Feb__7_19:32:13_PST_2023 Cuda compilation tools, release 12.1, V12.1.66 Build cuda_12.1.r12.1/compiler.32415258_0
root@ea8c1fabfe70:~# python Python 3.8.10 (default, Nov 14 2022, 12:59:47) [GCC 9.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf 2025-04-13 14:30:13.535393: I tensorflow/stream_executor/platform/default/dso_loader.cc:50] Successfully opened dynamic library libcudart.so.12 WARNING:tensorflow:Deprecation warnings have been disabled. Set TF_ENABLE_DEPRECATION_WARNINGS=1 to re-enable them. >>> print(tf.__version__) 1.15.5 >>> exit()
apt-get update apt-get upgrade -y 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 7076 [email protected]
apt-get install libssl-dev apt-get install -y openssh ← openssh パッケージのインストールがなぜか失敗する。
rsync -avr -e "ssh -p 7076" sample [email protected]:/root/doc
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@ea8c1fabfe70:~# python Python 3.8.10 (default, Mar 18 2025, 20:04:55) [GCC 9.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>>python は 3.8.10 のようだ。 本のpython のバージョンは 3.6.7 (p.67) だが大丈夫だろう。
>>> import tensorflow as tf 2025-04-13 14:39:36.899438: I tensorflow/stream_executor/platform/default/dso_loader.cc:50] Successfully opened dynamic library libcudart.so.12 WARNING:tensorflow:Deprecation warnings have been disabled. Set TF_ENABLE_DEPRECATION_WARNINGS=1 to re-enable them. pr>>> print(tf.__version__) 1.15.5
>>> import numpy as np >>> print(np.__version__) 1.22.2
>>> import matplotlib >>> print(matplotlib.__version__) 3.7.0
>>> import pandas as pd >>> print(pd.__version__) 1.5.2
>>> import PIL >>> print(PIL.__version__) 9.4.0
>>> import h5py >>> print(h5py.__version__) 2.10.0
>>> import gym Traceback (most recent call last): File "", line 1, in ImportError: No module named 'gym'
pip install gym==0.10.11
>>> import tensorflow.keras 2025-04-13 08:52:03.276548: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.1 >>> print(tensorflow.keras.__version__) 2.2.4-tf
[注意] tensorflow.keras でアクセスされることに注意。 4_4_dqn_carpole.ipynb で keras を import しているのでコードの変更が必要。
from keras.models import Sequential → from tensorflow.keras.models import Sequential
pip install ipywidgets
jupyter notebook --allow-root --ip=0.0.0.0 --no-browser他のマシンからアクセスするには "--ip=0.0.0.0" の指定が必要であることに注意。
(動作中の jupyter notebook の token を知る) jupyter notebook list
http://133.99.41.195:8086/?token=a62e....e0ab