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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
kmotohas
July 14, 2022
Technology
120
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
SageMaker Dive Deep Workshop 動かして理解する SageMaker Training Job の仕組み
2022年4月26日に実施したワークショップのスライドです。
kmotohas
July 14, 2022
More Decks by kmotohas
See All by kmotohas
AWS の最新生成 AI 開発基盤サービスAmazon Bedrock AgentCore ご紹介
kmotohas
0
52
OpenAI gpt-oss ファインチューニング入門
kmotohas
3
3.4k
AWS re:Invent直前!2021年のアップデートを振り返ろう AI/MLサービス編
kmotohas
0
990
論文解説 150 Successful Machine Learning Models: 6 Lessons Learned at Booking.com
kmotohas
0
1.4k
konduit-servingとSpring Cloud Data Flowを用いたMLアプリケーション開発
kmotohas
0
700
Deep Learningによる画像認識の基礎・CNNの仕組み
kmotohas
0
1.2k
詳説Deep LearningとDL4JとMLOps入門
kmotohas
0
750
オートエンコーダーと異常検知入門
kmotohas
1
1.7k
20190515 RNNと自然言語処理 RNNの基礎からAttention〜BERTの概要まで
kmotohas
0
890
Other Decks in Technology
See All in Technology
Kiro Ambassador を目指す話
k_adachi_01
0
110
Claude Codeをどのように キャッチアップしているか
oikon48
13
8.5k
自分が詳しくない領域でAIを使う #プロヒス2026
konifar
6
1.6k
AIネイティブな開発のサプライチェーンリスク対策 〜激動の開発現場でリスクに立ち向かう〜【ZennFes】
cscengineer
PRO
2
140
【NRUG vol.18】KubernetesにおけるNew Relicデータ取得量削減の考え方
nrug_member
0
160
AIソロプレナー時代に2ヶ月で20人増員した事業創造会社の開発組織の話
miyatakoji
0
690
Chainlitで作るお手軽チャットUI
ynt0485
0
270
脆弱性対応、どこで線を引くか
rymiyamoto
1
410
20260619 私の日常業務での生成 AI 活用
masaruogura
1
230
AI-DLCを “そのまま導入しなかった”話 ~組織に合わせてアジャストした 私たちの実践共有~
hiroramos4
PRO
0
110
Flow 不死:AI 時代 DevOps 的不變本質
cheng_wei_chen
2
210
Bucharest Tech Week 2026 - Guardians of the Cloud-Native Galaxy
edeandrea
PRO
0
120
Featured
See All Featured
The Curious Case for Waylosing
cassininazir
1
390
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
ラッコキーワード サービス紹介資料
rakko
1
3.7M
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.9k
Discover your Explorer Soul
emna__ayadi
2
1.1k
Optimising Largest Contentful Paint
csswizardry
37
3.7k
Code Review Best Practice
trishagee
74
20k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
630
First, design no harm
axbom
PRO
2
1.2k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
310
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
780
Building an army of robots
kneath
306
46k
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.