Share
Embed
CyberAgent AI事業本部MLOps研修応用編
CybagerAgent AI事業本部 2023年度新卒研修 MLOps 応用編で使用したスライドです。
ハンズオンで使用したGitHub Repository: https://github.com/nsakki55/aws-mlops-handson
Satsuki Nagae
May 24, 2023
Transcript
140 slides
-
©2023 CyberAgent Inc. Distribution prohibited Today’s Schedule 10: 00 -
12: 30: Container編 13: 45 - 14: 45: MLOps基礎編 15: 00 - 18: 30: MLOps応用編 -
©2023 CyberAgent Inc. Distribution prohibited 自己紹介 長江五月 Dynalyst Data Scientist
業務 MLモデリング データ分析 MLOps 保有AWS認定証 5 @nsakki55 @nsakki55 -
©2023 CyberAgent Inc. Distribution prohibited 本講義のゴール 6 持続可能なMLシステム を Portableな実験環境
Scalableな推論App Container編 MLOps基礎編 を使って 作る MLOps応用編 -
©2023 CyberAgent Inc. Distribution prohibited 本日皆さんが触れる技術スタック 7 ML SGDClassifier Feature
Hashing Python静的解析 isort black flake8 mypy pytest CI/CD Docker GitHub Actions ECS ECR Fargate S3 StepFunctions Event Bridge Auto Scaling ALB AWS -
©2023 CyberAgent Inc. Distribution prohibited 目次 8 1. 前準備 2.
ローカルでML基盤を開発 3. CI/CD 4. MLパイプラインをAWS上で実行する 5. 推論サーバーをAWS上に立てる -
©2023 CyberAgent Inc. Distribution prohibited 目次 9 1. 前準備 2.
ローカルでML基盤を開発 3. CI/CD 4. MLパイプラインをAWS上で実行する 5. 推論サーバーをAWS上に立てる -
©2023 CyberAgent Inc. Distribution prohibited Prerequisites 10 1. Docker Desktop
2. pyenv 3. poetry 4. awscli (認証含む) 5. hey 6. direnv 7. terraform -
©2023 CyberAgent Inc. Distribution prohibited ハンズオンリポジトリ 11 $ git clone
https://github.com/nsakki55/aws-mlops-handson $ cd aws-mlops-handson ハンズオンリポジトリをクローン https://github.com/nsakki55/aws-mlops-handson -
©2023 CyberAgent Inc. Distribution prohibited 環境変数の設定 12 direnvの設定 $ cp
.env.example .env $ vi .env AWS_REGION=ap-northeast-1 AWS_ACCOUNT_ID=012345678901 AWS_PROFILE=mlops-handson TF_VAR_aws_region=${AWS_REGION} TF_VAR_aws_profile=${AWS_PROFILE} TF_VAR_aws_account_id=${AWS_ACCOUNT_ID} AWSリージョン名 $ direnv allow . AWSアカウントID 使用するAWS Profile名 使用するAWS Profile名 Terraform実行変数 (変更しない) -
©2023 CyberAgent Inc. Distribution prohibited 環境変数の設定 13 direnvの設定 $ echo
$TF_VAR_aws_region ap-northeast-1 $ eval "$(direnv hook zsh)" >> ~/.zshrc 環境変数が設定できているか確認 設定できていない場合 -
©2023 CyberAgent Inc. Distribution prohibited AWSリソースの作成 14 $ cd infra
$ terraform init TerraformでAWSリソースを作成する $ terraform apply $ cd .. -
©2023 CyberAgent Inc. Distribution prohibited Python環境構築 15 pyenvでPython 3.9.0の環境を用意する 依存関係のインストール
$ pyenv install 3.9.0 $ pyenv local 3.9.0 $ poetry install -
©2023 CyberAgent Inc. Distribution prohibited S3 16 Simple Storage Service
オブジェクトストレージサービス 非構造化データを低コストで保存できる -
©2023 CyberAgent Inc. Distribution prohibited 学習データの準備 18 S3 Bucket作成 バケット名
{name}-mlops-handson -
©2023 CyberAgent Inc. Distribution prohibited 環境変数の設定 22 direnvの設定 $ vi
.env AWS_BUCKET=nagae-mlops-handson USER_NAME=nagae 自分の名前 作成したS3 Bucket名 -
©2023 CyberAgent Inc. Distribution prohibited 目次 23 1. 前準備 2.
ローカルでML基盤を開発 3. CI/CD 4. MLパイプラインをAWS上で実行する 5. 推論サーバーをAWS上に立てる -
©2023 CyberAgent Inc. Distribution prohibited MLOpsの要件 25 データ kaggle avazu
ctr prediction dataset -
©2023 CyberAgent Inc. Distribution prohibited モデリングを行う 26 jupyter notebookで分析 $
poetry run jupyter lab -
©2023 CyberAgent Inc. Distribution prohibited スクリプトで管理する 27 /aws-mlops-handson ├ Dockerfile
- - - - - - - - - -MLパイプライン・推論サーバー用 Dockerfile ├ Makefile - - - - - - - - - - -ローカル実行コマンド ├ docker-compose.yaml - - -推論サーバー用 docker-compose.yaml ├ infra - - - - - - - - - - - - - MLシステムのインフラ用Terraform ├ ml - - - - - - - - - - - - - - -MLパイプラインの実装 ├ predictor - - - - - - - - - - 推論サーバーの実装 ├ pyproject.toml - - - - - - -poetry, pysen設定 └ tests - - - - - - - - - - - - -テストの実装 ファイル説明(全体) -
©2023 CyberAgent Inc. Distribution prohibited MLパイプラインをローカル実行する 28 /aws-mlops-handson └ ml
├ aws - - - - - - - - - - AWSリソース操作 ├ dataset - - - - - - - -データ読み込み操作 ├ logger- - - - - - - - - ロギング ├ model - - - - - - - - - MLモデル ├ path - - - - - - - - - - ディレクトリ操作 ├ preprocessor- - - - - 前処理 └ main.py - - - - - - - - MLパイプライン ファイル説明(MLパイプライン) -
©2023 CyberAgent Inc. Distribution prohibited 学習ワークフロー概略(MLOps基礎編再掲) 学習ワークフローを構成するstep • Extract step
• Validate data step • Preprocess step • Train step • Evaluate step • Validate model step 黄色step: ハンズオンで実行するstep -
©2023 CyberAgent Inc. Distribution prohibited MLパイプラインをローカル実行する 31 コマンド確認 $ make
$ make build-ml MLパイプラインのimage build MLパイプラインの実行 $ make run-ml -
©2023 CyberAgent Inc. Distribution prohibited 推論サーバーをローカル実行する 33 推論サーバーを起動 $ make
up $ make logs docker-composeのログを確認する -
©2023 CyberAgent Inc. Distribution prohibited デプロイ方法(MLOps基礎編再掲) 1. モデルビルドパターン a. Dockerのビルド時にモデルを含めてしまう
2. モデルロードパターン a. 外部ストレージから実行時に取得 -
©2023 CyberAgent Inc. Distribution prohibited 推論サーバーをローカル実行する 35 推論サーバーにリクエストを投げる $ make
predict $ make down 推論サーバーを停止する -
©2023 CyberAgent Inc. Distribution prohibited ローカル開発を体験する 36 Optunaでハイパラチューニングを行うモデルを追加する /3-mlops-handson └
ml └ model - - - - - - - - - MLモデル ├ sgd_classifier_ctr_model.py └ sgd_classifier_ctr_optuna_model.py MLパイプライン・推論サーバーに追加 -
©2023 CyberAgent Inc. Distribution prohibited ローカル開発を体験する 37 ローカル開発の流れ 1. 実装
2. 静的解析チェック 3. テストの追加 -
©2023 CyberAgent Inc. Distribution prohibited ローカル開発を体験する 38 実装 /3-mlops-handson/ml/model/__init__.py from
.base_model import BaseModel from .sgd_classifier_ctr_model import SGDClassifierCTRModel from .sgd_classifier_ctr_optuna_model import SGDClassifierCTROptunaModel __all__ = ["BaseModel", "SGDClassifierCTRModel", "SGDClassifierCTROptunaModel"] /3-mlops-handson/ml/model/models.py class MODELS(Enum): sgd_classifier_ctr_model = Model( …. ) sgd_classifier_ctr_optuna_model = Model( name="sgd_classifier_ctr_optuna_model", model=SGDClassifierCTROptunaModel, preprocessor=CTRModelPreprocessor, ) オレンジ線の実装を追加 -
©2023 CyberAgent Inc. Distribution prohibited ローカル開発を体験する 39 静的解析チェック $ make
lint pysenによって以下のチェックが実行されます ・isort - - - -import文チェック ・black - - - -コードスタイル整形 ・flake8 - - - コード品質チェック ・mypy - - - - 静的型チェック $ make format エラーが出た場合は... isort・blackによるコード整形が自動で行われます -
©2023 CyberAgent Inc. Distribution prohibited ローカル開発を体験する 40 テストの追加 $ make
test FAILED tests/ml/model/test_models.py::test_all_models_are_tested - AssertionError: assert ['sgd_classifier_ctr_model'] == ['sgd_classif...optuna_model'] 追加したモデルのテストがないエラーがでます テストを実行 -
©2023 CyberAgent Inc. Distribution prohibited ローカル開発を体験する 41 テストの追加 params =
{ "sgd_classifier_ctr_model": ("sgd_classifier_ctr_model", SGDClassifierCTRModel, CTRModelPreprocessor), "sgd_classifier_ctr_optuna_model": ("sgd_classifier_ctr_optuna_model", SGDClassifierCTROptunaModel, CTRModelPreprocessor), } /3-mlops-handson/ml/tests/ml/model/test_models.py $ make test テストが通るか確認 オレンジ線の実装を追加 -
©2023 CyberAgent Inc. Distribution prohibited ローカル開発を体験する 42 追加したモデルの学習を実行する $ make
build-ml $ vi .env $ make run-ml AWS_BUCKET=nagae-mlops-handson AWS_ACCOUNT_ID=012345678901 AWS_PROFILE=mlops-handson AWS_ALB_DNS= USER_NAME=nagae VERSION=2023-04-01 MODEL=sgd_classifier_ctr_optuna_model 追加したモデル名 -
©2023 CyberAgent Inc. Distribution prohibited ローカル開発を体験する 43 推論サーバーに複数モデルを乗せる model_candidates =
["sgd_classifier_ctr_model", "sgd_classifier_ctr_optuna_model"] model_preprocessor_list = [ get_model_preprocessor(bucket=BUCKET, model_name=model_name, version=VERSION) for model_name in model_candidates ] /3-mlops-handson/predictor/routers.py オレンジ線の実装を追加 -
©2023 CyberAgent Inc. Distribution prohibited ローカル開発を体験する 44 推論サーバーに複数モデルを乗せる $ make
up 推論サーバーを起動 $ make predict {"prediction":0.18150064819518077,"model":"sgd_classifier_ctr_optuna_model"} 推論リクエスト 複数のモデルの予測値を返す →ABテストが可能 -
©2023 CyberAgent Inc. Distribution prohibited A/B基盤(MLOps基礎編再掲) 何かの施策の効果検証の際、A/Bテストが使われるがA/Bの基盤パターンも いくつか存在 CTR予測モデルAとBのA/Bテストをしたい時 •
トラフィックレベルの振り分け • アプリケーションレベルの振り分け -
©2023 CyberAgent Inc. Distribution prohibited 目次 46 1. 前準備 2.
ローカルでML基盤を開発 3. CI/CD 4. MLパイプラインをAWS上で実行する 5. 推論サーバーをAWS上に立てる -
©2023 CyberAgent Inc. Distribution prohibited CI/CD 47 静的解析・テストがない場合 バグの混入 可読性の低下
誰も触れないMLシステム リリース自動化がない場合 手作業によるリリース MLシステムの属人化 -
©2023 CyberAgent Inc. Distribution prohibited CI/CD 48 GitHub Actionsの活用 ・静的解析チェック
・テスト実行 ・image build/push コードの品質管理・リリースの自動化 -
©2023 CyberAgent Inc. Distribution prohibited コード品質管理の自動化 49 /aws-mlops-handson/.github/workflows/test-mlops-handson.yml name: Run
tests and linters on: push: branches: - main jobs: tests: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Set up Python 3.9 uses: actions/setup-python@v2 with: python-version: 3.9 - name: Install dependencies run: | pip install --upgrade pip pip install poetry=="1.4.2" poetry install - name: Run pysen lint run: | poetry run pysen run lint - name: Run tests run: | poetry run pytest 実行環境の設定 pysen, pytestの実行 -
©2023 CyberAgent Inc. Distribution prohibited リリースの自動化 50 /aws-mlops-handson/.github/workflows/deploy-mlops-handson.yml name: Run
creating docker image on: push: branches: - main jobs: build: runs-on: ubuntu-latest permissions: id-token: write contents: read steps: - uses: actions/checkout@v3 - uses: aws-actions/configure-aws-credentials@v2 with: role-to-assume: ${{ secrets.GTIHUB_ACTIONS_AWS_ROLE }} aws-region: ap-northeast-1 - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v1 実行環境の設定 GitHub Action用のAWS Role名を GitHub RepositoryのSecret変数で管理 -
©2023 CyberAgent Inc. Distribution prohibited リリースの自動化 51 /aws-mlops-handson/.github/workflows/deploy-mlops-handson.yml - name:
Build, tag, and push image to Amazon ECR for ml env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: mlops-handson/ml-pipeline run: | IMAGE_TAG=$(git rev-parse --short "$GITHUB_SHA") docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --target ml . docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - name: Build, tag, and push image to Amazon ECR for predict-api env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: mlops-handson/predict-api run: | IMAGE_TAG=$(git rev-parse --short "$GITHUB_SHA") docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --target predictor ./ docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG image build/push -
©2023 CyberAgent Inc. Distribution prohibited 目次 53 1. 前準備 2.
ローカルでML基盤を開発 3. CI/CD 4. MLパイプラインをAWS上で実行する 5. 推論サーバーをAWS上に立てる -
©2023 CyberAgent Inc. Distribution prohibited 技術選定の前に... 54 ◦ MLを本当に使うべきかを考える ◦
ゴールはビジネス課題の解決であって、MLサービスを作ることではない ◦ MLを導入した時のコストと解決できるコストを評価する ◦ 小さく作り始める ◦ いきなり完成系を目指すのではなく、小さく作り始める ▪ デプロイは手動から ▪ 簡単な線形モデルから ◦ 人と向き合う ◦ 守備範囲が広く1人ではできないからこそ、チームメンバー(Biz、SWE、DS)と 適切にコミュニケーションを取り、すり合わせる (MLOps基礎編再掲)最後に -
©2023 CyberAgent Inc. Distribution prohibited 技術選定 55 ・チームにML/DSは1人 ・既存システムのサーバーはECSでホスティング ・既存システムのオフライン処理をECS
Taskで実行してる ・既存システムのワークフローツールにStepFunctionsを使用してる 前提状況 -
©2023 CyberAgent Inc. Distribution prohibited 技術選定 56 ・チームにML/DSは1人 ・既存システムのサーバーはECSでホスティング ・既存システムのオフライン処理をECS
Taskで実行してる ・ワークフローツールにStepFunctionsを既に使用してる 前提状況 → 他メンバーの協力が得られるように、既存システムに乗っかる → SageMakerよりチームナレッジがあるECSを優先する → 最初はシンプルに、コンテナを実行するだけの構成にする → チームで面倒をみるワークフローツールは1つにする -
©2023 CyberAgent Inc. Distribution prohibited MLパイプライン作成手順 60 ・ECRレポジトリの作成 ・ECRにMLパイプラインのimage push
・ECS Task定義作成 ・ECS Task実行 ・StepFunctionsの作成 ・EventBridgeの設定 -
©2023 CyberAgent Inc. Distribution prohibited MLパイプライン作成手順 61 ・ECRレポジトリの作成 ・ECRにMLパイプラインのimage push
・ECS Task定義作成 ・ECS Task実行 ・StepFunctionsの作成 ・EventBridgeの設定 -
©2023 CyberAgent Inc. Distribution prohibited ECR 62 Elastic Container Registory
Docker コンテナイメージを管理する マネージドサービス -
©2023 CyberAgent Inc. Distribution prohibited MLパイプライン作成手順 65 ・ECRレポジトリの作成 ・ECRにMLパイプラインのimage push
・ECS Task定義作成 ・ECS Task実行 ・StepFunctionsの作成 ・EventBridgeの設定 -
©2023 CyberAgent Inc. Distribution prohibited ECRにimageを保存 66 mlパイプラインのimageをECRにpush $ make
build-ml $ make push-ml ECRにimageが保存されていることを確認 -
©2023 CyberAgent Inc. Distribution prohibited MLパイプライン作成手順 67 ・ECRレポジトリの作成 ・ECRにMLパイプラインのimage push
・ECS Task定義作成 ・ECS Task実行 ・StepFunctionsの作成 ・EventBridgeの設定 -
©2023 CyberAgent Inc. Distribution prohibited ECS 68 Elastic Container Service
Docker コンテナを実行する マネージド型のコンテナ オーケストレーションサービス -
©2023 CyberAgent Inc. Distribution prohibited MLパイプライン作成手順 69 ECS Clusterの作成 クラスター名
mlops-handson-ecs VPC mlops-handson -
©2023 CyberAgent Inc. Distribution prohibited ECS Task定義を作成 71 タスク定義ファミリー {name}-ml-pipeline
コンテナ: 名前 ml-pipeline コンテナ: イメージURI 作成した自分のECRレポジトリのURI -
©2023 CyberAgent Inc. Distribution prohibited ECS Task定義を作成 72 環境変数 -
VERSION 2023-05-11 - MODEL sgd_classifier_ctr_model - AWS_BUCKET 作成した自分のS3バケット名 -
©2023 CyberAgent Inc. Distribution prohibited ECS Task定義を作成 73 アプリケーション環境 AWS
Fargate タスクロール mlops-handson-ecs-task-role タスク実行ロール mlops-handson-ecs-task-execution-role -
©2023 CyberAgent Inc. Distribution prohibited MLパイプライン作成手順 75 ・ECRレポジトリの作成 ・ECRにMLパイプラインのimage push
・ECS Task定義作成 ・ECS Task実行 ・StepFunctionsの作成 ・EventBridgeの設定 -
©2023 CyberAgent Inc. Distribution prohibited ECS Taskを実行 78 タスク定義: ファミリー
作成した自分のECS Task定義 {name}-ml-pipeline -
©2023 CyberAgent Inc. Distribution prohibited ECS Taskを実行 79 VPC mlops-handson
サブネット mlops-handson-private-subnet-1a セキュリティグループ mlops-handson-ml-pipeline-sg パブリックIP オフに変更 -
©2023 CyberAgent Inc. Distribution prohibited MLパイプライン作成手順 82 ・ECRレポジトリの作成 ・ECRにMLパイプラインのimage push
・ECS Task定義作成 ・ECS Task実行 ・StepFunctionsの作成 ・EventBridgeの設定 -
©2023 CyberAgent Inc. Distribution prohibited StepFunctionsを作成 87 { "LaunchType": "FARGATE",
"Cluster": "arn:aws:ecs:ap-northeast-1:123456789101:cluster/mlops-handson-ecs", "TaskDefinition": "arn:aws:ecs:ap-northeast-1:123456789101:task-definition/nagae-ml-pipeline:2", "NetworkConfiguration": { "AwsvpcConfiguration": { "AssignPublicIp": "DISABLED", "SecurityGroups": [ "sg-0076849cc3bc59502" ], "Subnets": [ "subnet-0afd71e0a510d7b94" ] } } } APIパラメータ 作成した自分の ClusterのARNに変更 ECS Task定義のARNに変更 mlops-handson-ml-pipeline-sg セキュリティグループ mlops-handson-ml-pipeline-sg のID サブネット mlops-handson-private-subnet-1a のID -
©2023 CyberAgent Inc. Distribution prohibited StepFunctionsを作成 91 名前 {name}-mlops-pipeline 実行ロール
mlops-handson-step-functions-role 設定したら画面下にある「ステートマシンの作成」をクリック -
©2023 CyberAgent Inc. Distribution prohibited MLパイプライン作成手順 94 ・ECRレポジトリの作成 ・ECRにMLパイプラインのimage push
・ECS Task定義作成 ・ECS Task実行 ・StepFunctionsの作成 ・EventBridgeの設定 -
©2023 CyberAgent Inc. Distribution prohibited EventBridgeを作成 98 頻度 定期的なスケジュール スケジュールの種類
cronベースのスケジュール cron式 */2 * * * ? * フレックスタイムウィンドウ オフ -
©2023 CyberAgent Inc. Distribution prohibited EventBridgeを作成 99 ターゲットAPI AWS StepFunctions
StartExecution ステートマシン 作成した自分のステートマシンを選択 {name}-ml-pipeline -
©2023 CyberAgent Inc. Distribution prohibited 目次 102 1. 前準備 2.
ローカルでML基盤を開発 3. CI/CD 4. MLパイプラインをAWS上で実行する 5. 推論サーバーをAWS上に立てる -
©2023 CyberAgent Inc. Distribution prohibited 推論サーバー作成手順 106 ・ECRレポジトリの作成 ・ECRに推論サーバーのimage push
・ECS Task定義作成 ・Load Balancerの作成 ・ECS Service作成 -
©2023 CyberAgent Inc. Distribution prohibited 推論サーバー作成手順 107 ・ECRレポジトリの作成 ・ECRに推論サーバーのimage push
・ECS Task定義作成 ・Load Balancerの作成 ・ECS Service作成 -
©2023 CyberAgent Inc. Distribution prohibited 推論サーバー作成手順 109 ・ECRレポジトリの作成 ・ECRに推論サーバーのimage push
・ECS Task定義作成 ・Load Balancerの作成 ・ECS Service作成 -
©2023 CyberAgent Inc. Distribution prohibited ECRにimageを保存 110 推論サーバーのimageをECRにpush $ make
build-predictor $ make push-predictor ECRにimageが保存されていることを確認 -
©2023 CyberAgent Inc. Distribution prohibited 推論サーバー作成手順 111 ・ECRレポジトリの作成 ・ECRに推論サーバーのimage push
・ECS Task定義作成 ・Load Balancerの作成 ・ECS Service作成 -
©2023 CyberAgent Inc. Distribution prohibited ECS Task定義を作成 113 タスク定義ファミリー {name}-predict-api
コンテナ: 名前 prdict-api コンテナ: イメージURI 作成した自分のECRレポジトリのURI ポートマッピング 8080 -
©2023 CyberAgent Inc. Distribution prohibited ECS Task定義を作成 114 環境変数 -
VERSION 2023-05-11 - AWS_BUCKET 作成した自分のS3バケット名 -
©2023 CyberAgent Inc. Distribution prohibited ECS Task定義を作成 115 アプリケーション環境 AWS
Fargate タスクロール mlops-handson-ecs-task-role タスク実行ロール mlops-handson-ece-task-execution-role -
©2023 CyberAgent Inc. Distribution prohibited 推論サーバー作成手順 117 ・ECRレポジトリの作成 ・ECRに推論サーバーのimage push
・ECS Task定義作成 ・Load Balancerの作成 ・ECS Service作成 -
©2023 CyberAgent Inc. Distribution prohibited ALB 118 Application Load Balancer
アプリケーションレイヤーで負荷分散を 行うマネージドサービス -
©2023 CyberAgent Inc. Distribution prohibited Target Groupの作成 120 Target type
IP addresses Target group name {name}-mlops-handson-tg Protocol Port HTTP : 8080 -
©2023 CyberAgent Inc. Distribution prohibited Target Groupの作成 121 VPC mlops-handson
Health check path /healthcheck 他の設定は変更せず 「Create Target」をクリック -
©2023 CyberAgent Inc. Distribution prohibited Load Balancerの作成 123 Load balancer
types Application Load Balcanerを選択 -
©2023 CyberAgent Inc. Distribution prohibited Load Balancerの作成 124 Load balancer
name {name}-mlops-hanson-alb -
©2023 CyberAgent Inc. Distribution prohibited Load Balancerの作成 125 VPC mlops-handson
Mappings ap-northeast-1a → mlops-handson-public-subnet-1a ap-northeast-1c → mlops-handson-public-subnet-1c -
©2023 CyberAgent Inc. Distribution prohibited Load Balancerの作成 126 Security Group
mlops-handson-alb-sg Listeners and routing Protocol: HTTP Port: 8080 Foward to: 作成した自分のtaget group {name}-mlops-handson-tg 他の設定は変更せず 「Create Load Balancer」 をクリック -
©2023 CyberAgent Inc. Distribution prohibited 推論サーバー作成手順 127 ・ECRレポジトリの作成 ・ECRに推論サーバーのimage push
・ECS Task定義作成 ・Load Balancerの作成 ・ECS Service作成 -
©2023 CyberAgent Inc. Distribution prohibited ECS Serviceの作成 129 アプリケーションタイプ サービス
ファミリー 作成した自分のECS Task定義 {name}-predict-api サービス名 {name}-predict-api-service 必要タスク 2 -
©2023 CyberAgent Inc. Distribution prohibited ECS Serviceの作成 130 VPC mlops-handson
サブネット mlops-handson-private-subnet-1a mlops-handson-private-subnet-1c セキュリティグループ mlops-handson-predict-api-sg パブリックIP オフ -
©2023 CyberAgent Inc. Distribution prohibited ECS Serviceの作成 131 ロードバランサーの種類 Application
Load Balancer ロードバランサー 作成した自分のALB {name}-mlops-handson-alb ターゲットグループ 作成した自分のTarget Group {name}-mlops-handson-tg -
©2023 CyberAgent Inc. Distribution prohibited ECS Serviceの作成 132 サービスのオートスケーリングを使用 ONに変更
タスクの最小数 2 タスクの最大数 6 ポリシー名 {name}-auto-scaling-policy ECSサービスメトリクス ALBRequestCountPerTarget 他の設定は変更せず「作成」をクリック -
©2023 CyberAgent Inc. Distribution prohibited 推論リクエストを送る 135 $ vi .env
AWS_ALB_DNS=nagae-mlops-handson-alb-354533381.ap-northeast-1.elb.amazonaws.com ローカルからECS Serviceにリクエストを送る ALBのDNS名 $ make predict-ecs -
©2023 CyberAgent Inc. Distribution prohibited オートスケーリングを確認する 136 $ make check-scale
heyでリクエストを送る (注意) リクエストを送りすぎるとIP バンされる可能性があります -
©2023 CyberAgent Inc. Distribution prohibited 139 MLOpsとしてまだできることは? 推論サーバーの自動更新 複数モデルの学習 モデル監視
データ監視 インフラ監視 実験管理 A/Bテスト基盤 インフラのコード管理 レイテンシーの改善 閉鎖網での推論APIの提供 ドキュメント作成 …