ハイパーパラメータチューニングのための GitHub Actions ワークフロー

Machine Learning のための CI/CD

Ravi Bhadauria

Machine Learning Instructor

ブランチ分岐ワークフロー

  • トレーニングとハイパーパラメータチューニングで別々の feature ブランチを使用
    • 対象のジョブはトリガーされる必要がある
    • 他方のジョブはトリガーされてはいけない
    • if 条件で実装
  • ハイパーパラメータチューニング
    • 分析用に統計テーブルを出力
    • パラメータ変更を含む新しい PR を自動で作成
  • トレーニング
    • トレーニング PR で新しいパラメータファイルを読み込み
Machine Learning のための CI/CD

条件分岐の設定

ハイパーパラメータチューニング
jobs:
  hp_tune_and_publish_report:
    # Run when branch name starts with hp_tune/
    if: startsWith(github.head_ref, 'hp_tune/')

steps: ... - name: | DVC pipeline for hyperparameter tuning run: dvc repro -f hp_tune
トレーニング
jobs:
  train_and_publish_report:
    # Run when branch name starts with train/
    if: startsWith(github.head_ref, 'train/')

steps: ... - name: Run DVC pipeline for training run: dvc repro train
Machine Learning のための CI/CD

ワークフローの権限を設定

Repository Settings > Actions > General

ワークフローの権限を設定する設定ページのスクリーンショット

Machine Learning のための CI/CD

ハイパーパラメータチューニングジョブの開始

  • ブランチ名の先頭に hp_tune/ を付けてください

ハイパーパラメータチューニングジョブが実行され、トレーニングジョブがスキップされている GHA ワークフローのスクリーンショット

Machine Learning のための CI/CD

ハイパーパラメータチューニングジョブのメトリクス

GridSearch の結果をコメントとして表示する PR のスクリーンショット

Machine Learning のための CI/CD

ハイパーパラメータ実行からトレーニング PR を作成

steps:
  - name: Create training branch
    env:
      REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    run: |
      # Branch name begins with train/
      export BRANCH_NAME=train/$(git rev-parse --short "${{ github.sha }}")

# Create PR for training cml pr create \ --user-email [email protected] \ --user-name HPBot \ --message "Hyperparameter tuning" \ --branch $BRANCH_NAME \ --target-branch main \ rfc_best_params.json
Machine Learning のための CI/CD

新しいトレーニングブランチの PR

GHA ワークフローの結果として作成された新しいモデルトレーニング PR の上部スクリーンショット

GHA ワークフローの結果として作成された新しいモデルトレーニング PR の下部スクリーンショット

Machine Learning のための CI/CD

新しいトレーニングブランチの PR

新しいモデルトレーニング PR 内の最適パラメータファイルの差分スクリーンショット

Machine Learning のための CI/CD

トレーニング実行を手動で開始

  • GITHUB_TOKEN は自分自身が作成した PR ではワークフローをトリガーできない

    • 再帰的な実行を防ぐため
  • 回避策

    • 適切な権限を持つ Personal access token を使用
      steps:
        - env:
            GITHUB_TOKEN: ${{ secrets.MY_TOKEN }}
      
    • GHA パイプラインでハイパーパラメータチューニングの直後にトレーニングジョブを実行
    • コードを force push して実行をトリガー(強制的に検査させる)
      -> git checkout train/1f34fs
      -> git commit --amend --no-edit && git push -f
      
1 https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow
Machine Learning のための CI/CD

トレーニングジョブの開始

トレーニングジョブが実行され、ハイパーパラメータチューニングジョブがスキップされている GHA ワークフローのスクリーンショット

Machine Learning のための CI/CD

練習しましょう!

Machine Learning のための CI/CD

Preparing Video For Download...