LoginSignup
0
0

More than 3 years have passed since last update.

SageMakerで使われるビルトインコンテナを探す

Last updated at Posted at 2020-05-08

はじめに

データサイエンティストがSageMakerを覚えていくのに、大きな障壁になるのがdockerの理解。
SageMakerで使われている built-in container の中身をみてみる。

[2020/05/11 追記]公式に場所書かれていた
https://docs.aws.amazon.com/ja_jp/sagemaker/latest/dg/sagemaker-algo-docker-registry-paths.html

どこにあるの?

AWSのgithubにて、

image.png

「container」と検索
image.png

image.png

見つかった。

sagemaker-xgboost-container の中身をみていく

この指示にしたがって進めていく。
ローカルのMacBook Proのdocker上に展開していく。

baseのコンテナをbuild

$ git clone 
$ cd sagemaker-xgboost-container

$ docker build -t xgboost-container-base:1.0-1-cpu-py3 -f docker/1.0-1/base/Dockerfile.cpu .

Successfully built が出力された。

# 確認
$ docker images
# 起動して、コンテナの中に入る。
$ docker run -it xgboost-container-base:1.0-1-cpu-py3 /bin/bash

以下、baseのDockerfileにある記載

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONIOENCODING='utf-8'

以下、finalのDockerfileにある記載

# Set SageMaker training environment variables
ENV SM_INPUT /opt/ml/input
ENV SM_INPUT_TRAINING_CONFIG_FILE $SM_INPUT/config/hyperparameters.json
ENV SM_INPUT_DATA_CONFIG_FILE $SM_INPUT/config/inputdataconfig.json
ENV SM_CHECKPOINT_CONFIG_FILE $SM_INPUT/config/checkpointconfig.json

# Set SageMaker serving environment variables
ENV SM_MODEL_DIR /opt/ml/model
#環境確認
$ set | grep -e 'PYTHON\|SM'
PYTHONDONTWRITEBYTECODE=1
PYTHONIOENCODING=utf-8
PYTHONUNBUFFERED=1

baseのDockerfileをもとにしたコンテナが正しく作られている模様。(finalにある、SM_ がヒットしないことから)

ちなみに、/opt配下は空だった。

finalのコンテナをbuild

$ python setup.py bdist_wheel --universal
$ docker build -t preprod-xgboost-container:1.0-1-cpu-py3 -f docker/1.0-1/final/Dockerfile.cpu .

なんか途中でエラーが出た。が大丈夫のようだ。

ERROR: boto3 1.13.5 has requirement botocore<1.17.0,>=1.16.5, but you'll have botocore 1.13.14 which is incompatible.
ERROR: aioboto3 6.4.1 has requirement aiobotocore[boto3]~=0.10.2, but you'll have aiobotocore 0.11.0 which is incompatible.
ERROR: smdebug 0.4.13 has requirement boto3==1.10.14, but you'll have boto3 1.13.5 which is incompatible.

Successfully built
Successfully tagged preprod-xgboost-container:1.0-1-cpu-py3

# 確認
$ docker images
$ docker run -it preprod-xgboost-container:1.0-1-cpu-py3 /bin/bash
$ set | grep -e 'PYTHON\|SM'
PYTHONDONTWRITEBYTECODE=1
PYTHONIOENCODING=utf-8
PYTHONPATH=:/miniconda3/lib/python3.6/site-packages/xgboost/dmlc-core/tracker
PYTHONUNBUFFERED=1
SM_CHECKPOINT_CONFIG_FILE=/opt/ml/input/config/checkpointconfig.json
SM_INPUT=/opt/ml/input
SM_INPUT_DATA_CONFIG_FILE=/opt/ml/input/config/inputdataconfig.json
SM_INPUT_TRAINING_CONFIG_FILE=/opt/ml/input/config/hyperparameters.json
SM_MODEL_DIR=/opt/ml/model

/opt配下は空だった。
SageMaker側で制御しているようだ。なので、/opt/mlなどのディレクトリ構成ルールは従うしかなさそう。

finalのDockerfileの中身

FROM xgboost-container-base:1.0-1-cpu-py3

LABEL com.amazonaws.sagemaker.capabilities.accept-bind-to-port=true

# Set SageMaker training environment variables
ENV SM_INPUT /opt/ml/input
ENV SM_INPUT_TRAINING_CONFIG_FILE $SM_INPUT/config/hyperparameters.json
ENV SM_INPUT_DATA_CONFIG_FILE $SM_INPUT/config/inputdataconfig.json
ENV SM_CHECKPOINT_CONFIG_FILE $SM_INPUT/config/checkpointconfig.json

# Set SageMaker serving environment variables
ENV SM_MODEL_DIR /opt/ml/model

ENV SAGEMAKER_TRAINING_MODULE sagemaker_xgboost_container.training:main
ENV SAGEMAKER_SERVING_MODULE sagemaker_xgboost_container.serving:main

# Include DMLC python code in PYTHONPATH to use RabitTracker
ENV PYTHONPATH=$PYTHONPATH:/miniconda3/lib/python3.6/site-packages/xgboost/dmlc-core/tracker

COPY requirements.txt /requirements.txt
RUN pip install -r /requirements.txt && rm /requirements.txt

# DMLC patches; TODO: remove after making contributions back to xgboost for tracker.py
COPY src/sagemaker_xgboost_container/dmlc_patch/tracker.py \
   /miniconda3/lib/python3.6/site-packages/xgboost/dmlc-core/tracker/dmlc_tracker/tracker.py

COPY dist/sagemaker_xgboost_container-2.0-py2.py3-none-any.whl /sagemaker_xgboost_container-2.0-py2.py3-none-any.whl
RUN pip install --no-cache /sagemaker_xgboost_container-2.0-py2.py3-none-any.whl && \
    rm /sagemaker_xgboost_container-2.0-py2.py3-none-any.whl

参考

Amazon SageMakerで独自の学習/推論用コンテナイメージを作ってみる
https://dev.classmethod.jp/articles/sagemaker-container-image-custom/
trainの置き場所は自分で決められるらしい。(要調査)

Dockerコマンド よく使うやつ
https://qiita.com/Esfahan/items/52141a2ad741933d7d4c

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