Skip to content

Instantly share code, notes, and snippets.

@hariby
Last active November 22, 2021 13:52
Show Gist options
  • Save hariby/4691d1c0563df0e5cffc089e7db862b2 to your computer and use it in GitHub Desktop.
Save hariby/4691d1c0563df0e5cffc089e7db862b2 to your computer and use it in GitHub Desktop.

Amazon SageMaker JumpStart を使ったハンズオン

(2021-11-22 更新) こちらのコンテンツからのアップデート版です https://gist.github.com/hariby/1da937a98b82274d13e724cc921f0b57

概要

Amazon SageMaker の使い方を、SageMaker JumpStart のサンプルノートブック (英語) に従って説明します。

1. 導入

2. ハンズオンワークショップ

2.1. ハンズオン環境

AWS マネージメントコンソールにログインし、SageMaker Studio (Oregon Region) を開いて下さい。 その後、各自で SageMaker Studio のユーザーを作成します。Studio にログイン後、ハンズオンでは SageMaker JumpStart を利用します。

2.2. コンテンツ

  • Notebook1: Managed Spot Training for XGBoost
    • SageMaker Managed Spot Training によるコスト削減 (40分)
  • Notebook2: Training and Hosting a PyTorch Model
    • Amazon SageMaker で Python スクリプトを用いた機械学習モデルのトレーニングと推論エンドポイントへのデプロイ (40分)
2.2.1. Managed Spot Training for XGBoost

SageMaker JumpStart 下部の "Example Notebooks" から "How to Use Spot Training" のノートブックを開きます。右上の "Import notebook" (オレンジ色のボタン) を押し、Notebook をコピーします。順にセルを実行します (Mac であれば、shift+return)。

2.2.2. Training and Hosting a PyTorch Model

ノートブックを開きます。 Kernel は Python 3 (PyTorch 1.4 Python 3.6 CPU Optimized), Instance は ml.t3.medium が選ばれていることを確認します。

少々書き換えが必要です。

  1. データセットのダウンロードスクリプト wget https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz --quiet--no-check-certificate オプションを付け足す。
  2. estimator を作っているセルを以下のように書き換えます (SageMaker Python SDK の v1 → v2 アップデートに伴い、py_version='py3' を追記し、引数名を instance_count, instance_type に変更)。
from sagemaker.pytorch import PyTorch

estimator = PyTorch(entry_point='./cifar10.py',
                    role=role,
                    framework_version='1.4.0',
                    py_version='py3',
                    instance_count=1,
                    instance_type='ml.c5.xlarge')

estimator.fit(inputs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment