GitHub Actions Workflow สำหรับการปรับ Hyperparameter

CI/CD สำหรับ Machine Learning

Ravi Bhadauria

Machine Learning Instructor

Branching workflow

  • แยก feature branch สำหรับการเทรนและการปรับ hyperparameter
    • งานที่ต้องการควรทริกเกอร์
    • งานอื่นไม่ควรทริกเกอร์
    • ใช้เงื่อนไข if
  • การปรับ hyperparameter
    • แสดงตารางสถิติเพื่อวิเคราะห์
    • เปิด PR ใหม่พร้อมการเปลี่ยนแปลงพารามิเตอร์โดยอัตโนมัติ
  • การเทรน
    • อ่านไฟล์พารามิเตอร์ใหม่ใน training PR
CI/CD สำหรับ Machine Learning

การตั้งค่าเงื่อนไข

การปรับ Hyperparameter
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
CI/CD สำหรับ Machine Learning

ตั้งค่าสิทธิ์ workflow

Repository Settings > Actions > General

ภาพหน้าจอการตั้งค่าสิทธิ์การทำงานของ workflow

CI/CD สำหรับ Machine Learning

เริ่มต้น Hyperparameter Tuning Job

  • ตรวจสอบให้แน่ใจว่าชื่อ branch ขึ้นต้นด้วย hp_tune/

ภาพหน้าจอ GHA workflow แสดงการรัน hyperparameter tuning job และข้าม training job

CI/CD สำหรับ Machine Learning

เมตริกของ Hyperparameter Tuning Job

ภาพหน้าจอ PR แสดงผลลัพธ์ GridSearch เป็นคอมเมนต์

CI/CD สำหรับ Machine Learning

การสร้าง Training PR จาก Hyperparameter Run

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
CI/CD สำหรับ Machine Learning

PR ของ Training Branch ใหม่

ภาพหน้าจอส่วนบนของ PR เทรนโมเดลใหม่ที่สร้างจาก GHA workflow

ภาพหน้าจอส่วนล่างของ PR เทรนโมเดลใหม่ที่สร้างจาก GHA workflow

CI/CD สำหรับ Machine Learning

PR ของ Training Branch ใหม่

ภาพหน้าจอ diff ของไฟล์พารามิเตอร์ที่ดีที่สุดใน PR เทรนโมเดลใหม่

CI/CD สำหรับ Machine Learning

เริ่มต้น Training Run ด้วยตนเอง

  • GITHUB_TOKEN ไม่สามารถทริกเกอร์ workflow บน PR ที่สร้างเอง

    • ป้องกันการรันแบบวนซ้ำ
  • วิธีแก้ปัญหา

    • ใช้ Personal access token ที่มีสิทธิ์เหมาะสม
      steps:
        - env:
            GITHUB_TOKEN: ${{ secrets.MY_TOKEN }}
      
    • รัน training job ต่อจาก hyperparameter tuning ใน GHA pipeline โดยตรง
    • 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
CI/CD สำหรับ Machine Learning

เริ่มต้น Training Job

ภาพหน้าจอ GHA workflow แสดงการรัน training job และข้าม hyperparameter tuning job

CI/CD สำหรับ Machine Learning

มาฝึกกันเถอะ!

CI/CD สำหรับ Machine Learning

Preparing Video For Download...