Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
SageMaker Dive Deep Workshop 動かして理解する SageMaker...
Search
kmotohas
July 14, 2022
Technology
0
82
SageMaker Dive Deep Workshop 動かして理解する SageMaker Training Job の仕組み
2022年4月26日に実施したワークショップのスライドです。
kmotohas
July 14, 2022
Tweet
Share
More Decks by kmotohas
See All by kmotohas
AWS re:Invent直前!2021年のアップデートを振り返ろう AI/MLサービス編
kmotohas
0
900
論文解説 150 Successful Machine Learning Models: 6 Lessons Learned at Booking.com
kmotohas
0
1.3k
konduit-servingとSpring Cloud Data Flowを用いたMLアプリケーション開発
kmotohas
0
600
Deep Learningによる画像認識の基礎・CNNの仕組み
kmotohas
0
1.1k
詳説Deep LearningとDL4JとMLOps入門
kmotohas
0
650
オートエンコーダーと異常検知入門
kmotohas
1
1.3k
20190515 RNNと自然言語処理 RNNの基礎からAttention〜BERTの概要まで
kmotohas
0
730
20190417 畳み込みニューラル ネットワークの基礎と応用
kmotohas
0
170
20190407 第7章 事例研究:自然言語処理における素性
kmotohas
0
60
Other Decks in Technology
See All in Technology
ビジネスと現場活動をつなぐソフトウェアエンジニアリング~とあるスタートアッププロダクトの成長記録より~
mizunori
0
130
Amazon GuardDuty Malware Protection for Amazon S3のここがすごい!
ryder472
1
120
飲食店予約台帳を支えるインタラクティブ UI 設計と実装
siropaca
5
1.1k
Data-centric AI入門第6章:Data-centric AIの実践例
x_ttyszk
1
280
FastConnect の冗長性
ocise
1
9.5k
実践!OpenTelemetry
oracle4engineer
PRO
0
210
Bounded Context: Problem or Solution?
ewolff
1
200
スタートアップ1人目QAエンジニアが QAチームを立ち上げ、“個”からチーム、 そして“組織”に成長するまで / How to set up QA team at reiwatravel
mii3king
1
340
What's New in OpenShift 4.18
redhatlivestreaming
0
1.2k
Nekko Cloud、 これまでとこれから ~学生サークルが作る、 小さなクラウド
logica0419
2
140
第13回 Data-Centric AI勉強会, 画像認識におけるData-centric AI
ksaito_osx
0
290
自動と手動の両輪で開発するデータクレンジング
estie
2
190
Featured
See All Featured
Code Review Best Practice
trishagee
66
17k
Embracing the Ebb and Flow
colly
84
4.6k
Designing Experiences People Love
moore
139
23k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.2k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
GraphQLとの向き合い方2022年版
quramy
44
13k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
620
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.3k
Producing Creativity
orderedlist
PRO
343
39k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
530
Transcript
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. SageMaker Dive Deep Workshop 動かして理解する SageMaker Training Job の仕組み 本橋 和貴 機械学習パートナー ソリューション アーキテクト 呉 和仁 機械学習ソリューション アーキテクト アマゾン ウェブ サービス ジャパン合同会社
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. 本ワークショップの対象者 • これまで SageMaker の概要の説明を聞いたりハンズオンイベント に参加したものの、⾃前のモデルをどう SageMaker 上で学習する かイメージがつかなかった⽅々 • これから SageMaker を活⽤していきたい⽅々 前提条件 • 【必須】Python の基礎知識 • 【望ましい】TensorFlow/PyTorch での実装経験 *SageMaker Training Job 以外の機能にはほぼ触れません 2
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. Agenda • SageMaker Training Job 座学 • SageMaker の全体像 • SageMaker Notebooks と SageMaker Studio • SageMaker Training Job と SageMaker Python SDK • SageMaker Training Job ハンズオン • Toy コードを⽤いた SageMaker Training Job の動作の理解 • TensorFlow / PyTorch の学習コードを SageMaker ⽤に書き換える 3
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. 機械学習を取り巻く状況 AI による変⾰ 2025年までに新しいエン タープライズ アプリケー ションの 90% 以上に AI が組み込まれる –IDC 2024年までに、⼈⼯知能に 対する投資は1100億ドルに 到達する –IDC 加速する投資 機械学習と DevOps の統合 機械学習はすでにメイン ストリームの DevOps プロセスの⼀部であり、 独⽴したプロジェクトで はない ̶Gartner あらゆるものが「賢く」 なる時代
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. お客様にとって、AI/ML はすでに最重要課題 お客様は急速なペースで ML を導⼊しています。2024年には75%のお客様が ML を運⽤するようになります(出典︓Gartner) より多くのビジネスグループにリーチを広げる ML は、マーケティング、法務、サプライチェーン、⼈事、財務、さらには IT など、 ビジネスライン全体で使⽤されています。ML のワークロードは、お客様のアカウント での活動範囲を増やすための⾜がかりとなります。 お客様には⽀援が必要 お客様は ML を重視していますが、ほとんどの場合、実⾏するための専⾨的なスキルを 社内に持ち合わせていません。お客様は、ML プラットフォームの構築からビジネス ユースケースの解決、技術⼒の拡張まで、ML のライフサイクル全体にわたって⽀援を 必要としています。 AI & 機械学習 なぜパートナーに とって重要か
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. お客様の ML の障壁を SageMaker で克服 ଟذʹΘͨΔσʔλαΠΤϯε πʔϧ ୯ҰΠϯλʔϑΣʔεͷ౷߹ .-πʔϧ *%&Λར༻ͯ͠ϞσϧΛߏஙɺֶशɺσϓϩΠ .-ͷͨΊͷେྔͷσʔλ ͷॲཧͱϥϕϦϯά ઐ༻ͷσʔλ४උπʔϧ .- ͷͨΊͷσʔλͷϥϕϦϯάͱ४උ .-։ൃऀͷෆ ϊʔίʔυ .-πʔϧ .-ͷઐ͕ࣝͳͯ͘༧ଌΛੜ ୀ۶ͳखಈͷ .-ΦϖϨʔγϣϯ ΈࠐΈͷ .-0QT ػೳ .-0QT ϓϥΫςΟεΛ࣮ͯ͠ .-ϥΠϑαΠΫϧΛޮԽ
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. 7 https://gitlab.com/juliensimon/awsmlmap/-/blob/master/map-sagemaker.png データ準備 モデル構築 モデル学習 最適化 ⾃動化 モニタリング デプロイ
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. クラウド上に機械学習開発 プラットフォームを構築 SageMaker Training Job を活⽤して学習コストの最適化 ⾃動ハイパーパラメータ 最適化や分散学習を⽤いて ⼤規模に学習を実⾏ MLOps パイプラインを構築して モデルの再学習プロセスを⾃動化 移⾏ 最適化 ⼤規模化 ⾃動化 モデル学習の Modernization SageMaker Experiments Managed Spot Training SageMaker Debugger SageMaker Autopilot SageMaker Studio SageMaker Pipelines SageMaker Clarify SageMaker Data Wrangler
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. クラウド上に機械学習開発 プラットフォームを構築 SageMaker Training Job を活⽤して学習コストの最適化 ⾃動ハイパーパラメータ 最適化や分散学習を⽤いて ⼤規模に学習を実⾏ MLOps パイプラインを構築して モデルの再学習プロセスを⾃動化 移⾏ 最適化 ⼤規模化 ⾃動化 モデル学習の Modernization SageMaker Experiments Managed Spot Training SageMaker Debugger SageMaker Autopilot SageMaker Studio SageMaker Pipelines SageMaker Clarify SageMaker Data Wrangler
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. Amazon SageMaker の基本構成要素 学習スクリプト ML 実⾏環境 学習データ … Amazon SageMaker Amazon ECR Amazon S3 SageMaker Python SDK
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. Jupyter ノートブック環境でモデルを構築 The Jupyter Trademark is registered with the U.S. Patent & Trademark Office.
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. Amazon SageMaker Notebooks Jupyter Notebook JupyterLab
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. Amazon SageMaker Studio
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. SageMaker Studio / Notebooks 14
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. EBS Volume SageMaker Notebooks のアーキテクチャー 15 🧑💻 Browser EC2 instance Notebook Server Kernel Kernel HTTPS/ WSS 0MQ Jupyter / JupyterLab UI User 機械学習開発⽤にセットアップされた シンプルなマネージド Jupyter 環境 組み込みのカーネル
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. SageMaker Studio のアーキテクチャー 16 Amazon Elastic File System (EFS) 👩💻 User 1 🧑💻 User 2 User Profile User Profile Studio UI Studio UI EC2 instance Notebook Server JupyterServer App System Terminal docker container KernelGateway Kernel Kernel Image Terminal docker container KernelGateway App KernelGateway KernelGateway KernelGateway ... ... ... ... ...
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. SageMaker Studio のアーキテクチャー 17 Amazon Elastic File System (EFS) 👩💻 User 1 🧑💻 User 2 User Profile User Profile Studio UI Studio UI EC2 instance Notebook Server JupyterServer App System Terminal docker container KernelGateway Kernel Kernel Image Terminal docker container KernelGateway App KernelGateway KernelGateway KernelGateway ... ... ... ... ...
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. SageMaker Studio のアーキテクチャー 18 Amazon Elastic File System (EFS) 👩💻 User 1 🧑💻 User 2 User Profile User Profile Studio UI Studio UI EC2 instance Notebook Server JupyterServer App System Terminal docker container KernelGateway Kernel Kernel Image Terminal docker container KernelGateway App KernelGateway KernelGateway KernelGateway ... ... ... ... ...
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. SageMaker Notebooks と SageMaker Studio の機能⽐較 19 SageMaker Notebooks SageMaker Studio UI Jupyter / JupyterLab JupyterLab を拡張した SageMaker IDE ストレージ EBS EFS 環境分離 Anaconda Docker インスタンスの変更 インスタンス⾃体の 停⽌ → 切り替え → 起動 Studio UI 上で切り替え ローカルモード 使⽤可能 不可 AWS SSO 連携不可 連携可能
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. Cloud9 に EFS をマウントするという選択肢 20 Amazon Elastic File System AWS Cloud9 Amazon SageMaker
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. SageMaker Training Job 21
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. ノートブック環境と学習環境の分離 The Jupyter Trademark is registered with the U.S. Patent & Trademark Office.
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. ノートブック環境と学習環境の分離 The Jupyter Trademark is registered with the U.S. Patent & Trademark Office.
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. ノートブック環境と学習環境の分離 The Jupyter Trademark is registered with the U.S. Patent & Trademark Office. 学習が終わると削除 学習時間のみ秒単位で課⾦
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. 推論環境をコンテナで素早く構築 The Jupyter Trademark is registered with the U.S. Patent & Trademark Office. エンドポイント
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. SageMaker Python SDK • SageMaker でのモデル学習とかデプロイを簡素化する OSS の SDK 26 👩💻 Amazon SageMaker AWS SDK for Python (Boto3) SageMaker Python SDK ⼤変なことは SageMaker に やらせよう Estimator 学習コード ハイパーパラメータ コンテナ URI … Estimator.fit(学習データ) create_training_job(...) インスタンスタイプ わかる Estimator.deploy(...) create_model(...) create_endpoint_config(...) create_endpoint(...)
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. SageMaker でモデルをトレーニングする⽅法 • Jupyter Notebook 上で直接実⾏ § 任意のライブラリ • SageMaker Traning Job で実⾏ § 組み込みアルゴリズム – Linear Learner, XGBoost, k-NN, Random Cut Forest, ResNet, BrazingText, ... § スクリプトモード – TensorFlow, MXNet, PyTorch, HuggingFace, SKLearn, etc § 独⾃コンテナの持ち込み (Bring Your Own Container) § AWS Marketplace アルゴリズム 27
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. Estimator – SageMaker Python SDK • エンドツーエンドの学習とモデルのデプロイを制御するクラス 28 EstimatorBase Estimator Framework MXNet XGBoost SKLearn TensorFlow HuggingFace PyTorch Chainer 汎⽤的な Estimator クラス • 組み込みアルゴリズム • コンテナ持ち込み (BYOC) 各フレームワーク⽤にカスタマイズされた Estimator クラス • スクリプトモード AlgorithmEstimator • AWS Marketplace アルゴリズム
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. TensorFlow Estimator の使⽤例 29 from sagemaker.tensorflow import TensorFlow tensorflow_estimator = TensorFlow( entry_point='train.py', hyperparameters={ 'epochs': 20, 'batch-size': 64, 'learning-rate': 0.1 }, framework_version='2.6', py_version='py38', instance_type='ml.p3.2xlarge', instance_count=1, ) tensorflow_estimator.fit({ 'train': 's3://my-bucket/path/to/training/data', 'test': 's3://my-bucket/path/to/test/data' }) 学習コードの指定 学習コードに渡すハイパーパラメータの設定 学習コンテナの指定 学習インスタンスの指定 学習データの指定 e.g.) 763104351884.dkr.ecr.us-east-1.amazonaws.com/tensorflow-training:2.6-gpu-py38
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. ⼀般的な学習コードの構成 SageMaker Training Job § [ジョブ開始時]: 学習データは S3 から⾃動ダウンロード § [ジョブ終了時]: 学習済みモデルは S3 に⾃動アップロード コードの書き換えが最低限必要なのは § データをどのパスからロードするか § モデルをどのパスに保存するか § (*ハイパーパラメータは引数として argparse で取得可能) § (*分散学習する場合はトレーニング部分も) 30 データのロード モデルの定義 トレーニング* モデルの保存 ▼ ▼ ▼
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. コード × コンテナ × SageMaker Python SDK 31 データのロード モデルの定義 トレーニング* モデルの保存 ▼ ▼ ▼ /opt/ml ├── │ ├── data │ │ ├── <channel_name_train> │ │ │ └── <input data> │ │ ├── <channel_name_validation> │ │ │ └── <input data> │ │ └── <channel_name_test> │ │ └── <input data> │ └── config │ ├── hyperparameters.json │ └── resourceConfig.json │ ├── code │ ├── <code files> │ └── <train>.py ├── output │ └── <success or failure> └── model └── <model files> データ モデル コード fit( ={ 'train': '<S3 URI>’, 'validation': '<S3 URI>’, 'test': '<S3 URI>’, }) hyperparameters={ 'epochs': 20, 'batch-size': 64, 'learning-late': 0.1 } Estimator 学習コンテナのファイルシステム [source_dir] entry_point
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. 学習コンテナ(学習コード)で使える便利な環境変数* • SM_CHANNEL_{channel_name} § Estimator.fit() の引数で指定したチャンネルのデータが配置されるディレクトリ – SM_CHANNEL_TRAIN=/opt/ml/input/data/train – SM_CHANNEL_TEST=/opt/ml/input/data/test • SM_HPS § Estimator に渡したハイパーパラメータを JSON エンコードした辞書 – SM_HPS=‘{“epochs”: “20”, “batch-size”: “64”, “learning-rate”: “0.1”}’ • SM_NUM_GPUS / SM_NUM_CPUS § コンテナで利⽤可能な GPU / CPU の数 • SM_MODEL_DIR § S3 にアップロードされることになるモデルの置き場所 – SM_MODEL_DIR=/opt/ml/model 32 *その他多数あり https://zenn.dev/kmotohas/articles/7bfe313eab01ea
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. (おまけ)学習済みモデルのデプロイ • fit を呼び出すと Estimator の self.latest_training_job にジョブ の情報が格納され、その情報をもとにモデルをデプロイできる 33 predictor = estimator.deploy( instance_type="ml.c5.xlarge", initial_instance_count=1, ) result = predictor.predict(data) create_model() create_endpoint_config() create_endpoint() invoke_endpoint()
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. (おまけ)Estimator.deploy() がやっていること 34 Inference Container Image Model Artifact Advanced Configurations SageMaker Model IAM Role SageMaker Endpoint インスタンスタイプ / 数 / リクエストの割合 / ... invoke_endpoint() create_model create_endpoint_config create_endpoint ① ② ③
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. (おまけ)A/B テストの仕組みも簡単に作れる 35 SageMaker Endpoint invoke_endpoint() 95% 5% Variant 1 Variant 2
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. まとめ • SageMaker は機械学習ライフサイクル全体をエンドツーエンドで サポートすることができる • まずは、SageMaker Training Job を利⽤してモデル学習を modernize していくところから始めるのがおすすめ • SageMaker Python SDK を⽤いるとモデルの学習からデプロイまで の⼿順を簡素化できる • スクリプトモードを⽤いる場合も学習コードの書き換えは最⼩限 36
AWS パートナー様限定 SageMaker Dive Deep Workshop 〜 動かして理解する SageMaker Training
Job の仕組み © 2022, Amazon Web Services, Inc. or its affiliates. Thank you! © 2022, Amazon Web Services, Inc. or its affiliates.