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
110
0
Share
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
45
OpenAI gpt-oss ファインチューニング入門
kmotohas
3
3.3k
AWS re:Invent直前!2021年のアップデートを振り返ろう AI/MLサービス編
kmotohas
0
980
論文解説 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
740
オートエンコーダーと異常検知入門
kmotohas
1
1.6k
20190515 RNNと自然言語処理 RNNの基礎からAttention〜BERTの概要まで
kmotohas
0
880
Other Decks in Technology
See All in Technology
[Scram Fest Niigata2026]Quality as Code〜AIにQAの思考を再現させる試み〜
masamiyajiri
1
140
AIが自律的に働く時代へ Amazon Quick で実現するAIエージェント紹介
koheiyoshikawa
0
170
国内外の生成AIセキュリティの最新動向 & AIガードレール製品「chakoshi」のご紹介 / Latest Trends in Generative AI Security (Domestic & International) & Introduction to AI Guardrail Product "chakoshi"
nttcom
4
1.7k
Google Cloud Next '26 の裏でこっそりリリースされたCloud Number Registry & Cloud Hub コスト分析 を試してみた
hikaru1001
0
150
Fabric MCPの紹介と使い分け
ryomaru0825
1
110
AIが盛んな時代に 技術記事を書き始めて起きた私の中での小さな変化
peintangos
0
340
Claude Code を安全に使おう勉強会 / Claude Code Security Basics
masahirokawahara
12
39k
ハーネスエンジニアリングをやりすぎた話 ~そのハーネスは解体された~
gotalab555
5
2k
AI時代の品質はテストプロセスの作り直し #scrumniigata
kyonmm
PRO
4
1k
自動テストだけで リリース判断できるチームへ - 鍵はテストの量ではなくリリース判断基準の再設計にあった / Redesigning Release Criteria for Lightweight Releases
ewa
6
3k
AI時代に越境し、 組織を変えるQAスキルの正体 / QA Skills for Transforming an Organization
mii3king
3
2.9k
Building Production-Ready Agents Microsoft Agent Framework
_mertmetin
0
140
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
28
2.6k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
130
30 Presentation Tips
portentint
PRO
1
280
The Cost Of JavaScript in 2023
addyosmani
55
9.9k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
350
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
680
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.2k
AI: The stuff that nobody shows you
jnunemaker
PRO
6
620
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
110
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
130
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.