想定環境

やらないこと

OSに直接 CUDA CuDNN Tensorflow をインストールしない

不用意にNvidiaのドライバをインストールしない

Docker と nvidia-container-toolkit のインストール

cf. Win11 WSL2/Docker及Nvidia GPU

ベースイメージの選定

VSCode DevContainer の作成

Dockerfile

https://github.com/kagyuu/KerasExam/blob/main/.devcontainer/Dockerfile

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

devcontainer.json

https://github.com/kagyuu/KerasExam/blob/main/.devcontainer/devcontainer.json

{
	"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"
}

launch.json

https://github.com/kagyuu/KerasExam/blob/main/.vscode/launch.json

{
    // 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": [
    ]
}

VSCode DevContainer に入る

  1. WSL2に入る [F1]-[WSL:Connect to WSL]
    r1.png
  2. 右下に WSL:Ubuntu と接続しているアイコンが表示される
    r2.png
  3. WSL2で、KerasExam? フォルダを開く
    r3.png
  4. DevContaienr?に入る [F1]-[Dev Containers:Reopen in Container]
    r4.png
    • ここで必要があれば docker build が自動的に走る
  5. DevContainerに入った#ref(r1.png)
    r5.png

VSCode DevContainer を使ってみる

Junpyter note を使ってみる

Devcontainer の Terminal から

 $ jupyter notebook

で Jupter Note を起動

gpulist.png

これでよかろうと思います。

なんか Unable to register cuDNN とか出てるのはイイの?


Deep Learning#Keras


添付ファイル: filegpu.png 227件 [詳細] filegpulist.png 251件 [詳細] filer5.png 250件 [詳細] filer4.png 279件 [詳細] filer3.png 258件 [詳細] filer2.png 247件 [詳細] filer1.png 257件 [詳細] filedevcontainer1.png 253件 [詳細] filegdriver.png 278件 [詳細] filecuda.png 194件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS   sitemap
Last-modified: 2024-03-17 (日) 00:59:03 (265d)
Short-URL: http://at-sushi.com/pukiwiki/index.php?cmd=s&k=1232a09943
ISBN10
ISBN13
9784061426061