LoginSignup
0
0

DeepRacer For CloudをWindows(WSL)上に構築する

Posted at

はじめに

DeepRacer For Cloudをローカルにインストールすることで、課金を気にせずDeepRacerのモデル作成を行うことが可能です。

ただしDeepRacer For Cloudのローカル構築記事は多くはなく、私が構築を行ったときには以下の記事が非常に助かりました。
詳細まで書かれており、非常にわかりやすかったです。

本記事では上記記事をベースに、構築部分について記事執筆時点での最新情報を加筆しています。(重複する箇所もございますがご容赦ください。)
最後にはトラブルシューティングもつけているので、少しでもご参考になればと思います。

必要スペック

ローカル環境へのインストールにあたり、以下のスペックが推奨されています。

項目 必要スペック
OS Ubuntu 20.04 (WindowsではWSL上のUbuntu 20.04でも可能)
CPU Intel CPU(筆者の環境ではAMDでも動きました)
4 core-CPU (8vCPU) 以上
RAM 32GB 以上

WSLの導入

Windows機能の有効化

コントロールパネル > プログラム > Windowsの機能の有効化または無効化から以下の項目を選択します。

  • Linux用Windowsサブシステム
  • 仮想マシンプラットフォーム
  • Hyper-V

有効化に伴って再起動が必要です。

windows.png

ディストリビューション(Ubuntu)インストール/起動

PowerShell Terminal
> wsl --install Ubuntu-20.04
> wsl -d Ubuntu-20.04

初回起動時にはログインするユーザーとパスワードの初期設定が求められます。こちらは自由に設定してください。

ちなみに終了するときはwsl -t <ディストリビューション名>あるいはwsl --shutdownを実行します。

DeepRacer For Cloudインストール準備

ユーザーの作成

terminal
# ユーザーの作成
$ sudo useradd deepracer -m -p <YOUR PASSWORD> -s /bin/bash -G sudo
$ sudo su - deepracer

"YOUR PASSWORD" 部分は自由に設定ください。

補足: sudoグループについて

sudoグループはUbuntu-20.04のデフォルトグループであり、sudo権限を持っています。

sudoers
:
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
:
terminal
$ sudo cat /etc/group | grep sudo
$ sudo:x:27:deepracer

Docker等の必要パッケージの準備

terminal
$ sudo apt-get update -y
$ sudo apt-get install jq awscli python3-boto3 docker-compose -y
terminal
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository    "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ sudo apt-get update && sudo apt-get install -y --no-install-recommends docker-ce docker-ce-cli containerd.io

GPUを使用する場合は別途設定が必要です。以下記事をご参照ください。

dockerグループに追加

Dockerのインストールに伴ってdockerグループが作成されます。docker関連の操作に必要な権限が付与されているため、前段で作成したdeepracerユーザーのセカンダリグループとして設定します。

terminal
$ usermod -aG docker deepracer

Dockerを起動

terminal
$ sudo service docker start

AWS CLIでminIOにアクセスするための設定

minIOとはAmazon S3をローカル環境に構築するためのオープンソースツールです。AWS CLIからアクセスできるように設定を行っていきます。

terminal
$ aws configure --profile minio
AWS Access Key ID [None]: minio <= なんでもいいです
AWS Secret Access Key [None]: miniokey <= なんでもいいです
Default region name [None]:
Default output format [None]:

DeepRacer For Cloudのインストール方法

リポジトリのクローン

terminal
$ git clone https://github.com/aws-deepracer-community/deepracer-for-cloud.git

Dockerの準備

このステップを踏まないと後続の有効化のタイミングでエラーが発生するので実施が必要です。

Swarmの初期設定

terminal
# IPの確認
$ ip addr show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1472 qdisc mq state UP group default qlen 1000
    link/ether xxxxxxxxxxxxx brd ff:ff:ff:ff:ff:ff
    inet 172.xxx.xxx.xxx/20 brd 172.xxx.xxx.xxx scope global eth0
       valid_lft forever preferred_lft forever
    :

# 確認したIPに対してswarmを作成
$ docker swarm init --advertise-addr="172.xxx.xxx.xxx"
Swarm initialized: current node (j690y7mgke7hq51nz833ndv5y) is now a manager.
:

ネットワークの作成

terminal
# ネットワークの作成
$ docker network create -d overlay sagemaker-local

# 確認
$ docker network ls
NETWORK ID     NAME              DRIVER    SCOPE
:              :                 :         :
qndldb1t6d83   sagemaker-local   overlay   swarm

初期インストール

terminal
$ cd deepracer-for-cloud/
$ bin/init.sh -a cpu -c local
:
Creating service s3_minio

GPUの場合は-a gpuとなります。

DeepRacer For Cloudの実行

terminal
# 有効化
$ source bin/activate.sh

# トレーニング実行
$ dr-start-training
:
[s3] Successfully uploaded .lock to                      s3 bucket bucket with s3 key rl-deepracer-sagemaker/model/.lock.
[s3] Successfully uploaded .ready to                      s3 bucket bucket with s3 key rl-deepracer-sagemaker/model/.ready.
DoorMan: installing SIGINT, SIGTERM
Training> Name=main_level/agent, Worker=0, Episode=1, Total reward=14.88, Steps=26, Training iteration=0
Training> Name=main_level/agent, Worker=0, Episode=2, Total reward=6.06, Steps=42, Training iteration=0
Training> Name=main_level/agent, Worker=0, Episode=3, Total reward=9.67, Steps=72, Training iteration=0
Training> Name=main_level/agent, Worker=0, Episode=4, Total reward=10.96, Steps=93, Training iteration=0
Training> Name=main_level/agent, Worker=0, Episode=5, Total reward=9.94, Steps=116, Training iteration=0
:

上記のようなログが出力されれば成功。

トラブルシューティング

Dockerでのエラー

could not choose an IP address to advertise since this system has multiple addresses on different interfaces

terminal
$ docker swarm init
Error response from daemon: could not choose an IP address to advertise since this system has multiple addresses on different interfaces (10.255.255.254 on lo and 172.20.232.14 on eth0) - specify one with --advertise-addr

対応
Docker準備(Swarmの初期設定)のようにIPを確認して--advertise-addrオプションを強した状態で実行する。

source bin/activate.shでのエラー

This node is not a swarm manager.

terminal
$ source bin/activate.sh
Status: Error response from daemon: This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again., Code: 1
Error response from daemon: This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.
Since --detach=false was not specified, tasks will be created in the background.
In a future release, --detach=false will become the default.
this node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again
deepracer@DESKTOP-EUM8PS4:~/deepracer-for-cloud$ docker swam init
docker: 'swam' is not a docker command.
See 'docker --help'

対応
Docker準備を実施する。

network "sagemaker-local" is declared as external, but could not be found.

terminal
$ source bin/activate.sh
Since --detach=false was not specified, tasks will be created in the background.
In a future release, --detach=false will become the default.
network "sagemaker-local" is declared as external, but could not be found. You need to create a swarm-scoped network before the stack is deployed

対応
Docker準備(ネットワークの作成)を実施する。

dr-start-training でのエラー

No Swarm Nodes labelled for placement of Robomaker.

terminal
$ dr-start-training
Training of model s3://bucket/rl-deepracer-sagemaker starting.
Using configuration files:
   s3://bucket/custom_files/reward_function.py
   s3://bucket/custom_files/model_metadata.json
   s3://bucket/custom_files/hyperparameters.json
Creating Robomaker configuration in s3://bucket/rl-deepracer-sagemaker/training_params.yaml
ERROR: No Swarm Nodes labelled for placement of Robomaker. Please add Robomaker node.
       Example: docker node update --label-add Robomaker=true j690y7mgke7hq51nz833ndv5y

対応
エラーメッセージに従ってラベル付与を行う

terminal
$ docker node update --label-add Robomaker=true j690y7mgke7hq51nz833ndv5y
j690y7mgke7hq51nz833ndv5y

Selected path s3://bucket/rl-deepracer-sagemaker exists.

terminal
$ dr-start-training
Training of model s3://bucket/rl-deepracer-sagemaker starting.
Using configuration files:
   s3://bucket/custom_files/reward_function.py
   s3://bucket/custom_files/model_metadata.json
   s3://bucket/custom_files/hyperparameters.json
Selected path s3://bucket/rl-deepracer-sagemaker exists. Delete it, or use -w option. Exiting.

対応
エラーメッセージに従って-wオプションをつけて実行する

terminal
$ dr-start-training -w
:

Sagemaker is not running.

terminal
$ dr-start-training
:
Sagemaker is not running.

対応
Docker Swarmを再構成する。

terminal
# swarmの再構成
$ docker swarm leave -f
$ docker swarm init

# 初期化
$ bin/init.sh -a cpu -c local

その他DeepRacer For Cloudに関する記事

以下の記事は

  • 各種コマンド

  • パラメータ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0