Skip to main content

Weights & Biases에서 웹훅 자동화를 활용한 모델 CI/CD

조직에서 지속적 통합과 배포를 위해 자동화를 활용하는 방법 이 글은 AI로 번역되었습니다. 오역이 의심되면 댓글로 알려주세요.
Created on September 15|Last edited on September 15

ML을 위한 CI/CD란 무엇일까?

전통적인 소프트웨어에서 코드에 변경 사항이 생기면, 보통 사용자는 변경 내용을 git 리포지토리에 커밋하고 풀 리퀘스트를 제출합니다. 그러면 새 코드 변경에 대한 테스트가 트리거되어 정상 동작하는지 확인하며, 최종 승인 전에 팀원이 풀 리퀘스트를 검토하는 경우가 많습니다. 이후 코드는 메인 브랜치에 머지됩니다.

ML 개발에서는 배포되는 주요 자산이 코드에만 국한되지 않습니다. 아티팩트, 특히 모델 가중치가 훨씬 더 중요한 역할을 합니다. 모델을 테스트하고 배포하는 과정에서는 종종 해당 가중치를 별도의 팀에 인계해야 하며, 그 팀은 테스트를 수행하고 모델을 컨테이너화한 뒤 프로덕션에 배포해야 합니다.
이런 인계 절차에는 문제가 많습니다. 맥락이 자주 사라지고, 파일이 이리저리 옮겨 다니며, 배포에 필요한 파일을 찾기 위해 보물찾기처럼 뒤져야 하는 상황이 되곤 합니다.
ML을 위한 시스템 오브 레코드로서 W&B는 모델이 만들어진 전 과정에 대한 모든 컨텍스트를 제공합니다. 학습 및 평가 지표, 데이터셋 의존성, 그리고 기타 중요한 메타데이터까지 W&B에서 확인할 수 있습니다. W&B를 사용하면 Model Registry 그리고 Webhooks를 통해 이제 ML 엔지니어링과 DevOps 간에 깔끔한 인계 지점을 구현할 수 있습니다.
오늘 바로 그 방법을 보여드리겠습니다. 이번 글에서 다룰 내용은 다음과 같습니다:


Weights & Biases에서 Webhook Automation 사용하기

Webhook 자동화 DevOps 팀이 개발 단계에서 테스트와 배포 단계로 모델 체크포인트를 손쉽게 자동 인계할 수 있도록 합니다. 새로운 모델이 W&B Model Registry에 연결되면, 웹훅 POST 요청이 자동으로 GitHub Actions 워크플로를 트리거하여 해당 모델을 가져오고, 테스트를 실행하고, 추론 서버로 컨테이너화하거나, 나아가 배포까지 수행할 수 있습니다.
다음은 설정 방법입니다 Webhook 자동화 W&B에서 GitHub Actions에 연결하기:"

1. GitHub 세분화된 Personal Access Token(PAT) 생성하기

먼저 다음을 확인하세요 여기에서 문서 보기 그리고 PAT에 웹훅 이벤트를 트리거할 수 있는 적절한 권한이 있는지 확인하세요. repo dispatch를 트리거하기 위해 필요한 권한은 다음과 같습니다 Read and write 으로 Contents 저장소의

다른 권한도 추가하는 것이 좋습니다.

2. 팀 설정으로 이동하세요


페이지를 아래로 약 3분의 2 지점까지 스크롤하면 “Team secrets”와 “Webhooks” 항목을 찾을 수 있습니다.



3. GitHub PAT을 팀 시크릿에 추가하세요




4. 웹훅 만들기

GitHub Actions에서는 Access token에 PAT을 추가하고, repo dispatch에 사용할 저장소 URL을 추가해야 합니다. 일반적으로 다음과 같습니다. https://api.github.com/repos/<org>/<repo_name>/dispatches


관련 정보를 모두 입력했다면 “Create webhook” 버튼을 클릭하세요.

5. W&B Model Registry로 이동하여 Automation을 생성하세요

Webhook Automation을 생성하려는 등록된 모델에서 “View details”를 클릭하세요:

“New Automation”을 클릭하세요:

트리거할 이벤트를 선택하세요. 레지스트리에 새 모델 버전이 추가되거나 기존 버전에 별칭이 추가될 때 등에서 선택할 수 있습니다:

작업 유형으로 “Webhooks”를 선택하세요:

작업 유형으로 “Webhooks”를 선택하세요:

앞에서 생성한 GitHub Actions Webhook을 선택하고 payload를 추가하세요. 나중에 사용할 수 있도록 GitHub Actions에 W&B 컨텍스트를 전달하기 위해 템플릿 문자열을 추가할 수 있습니다.


참고: 반드시 …하도록 하세요 "event_type" 필드가 GitHub Actions YAML 필드와 일치해야 합니다 "type" repo dispatch에서
💡
on:
repository_dispatch:
types: "test-and-report" # Should match the Automation payload's "event_type"
마지막으로 자동화의 이름과 설명을 입력하면 설정이 완료됩니다:

CI/CD에서 Model Registry 모범 사례를 구현할 때 참고할 수 있는 GitHub Actions 워크플로우 YAML 예시 두 가지를 소개합니다.

6. CI/CD를 수행하는 GitHub Actions 워크플로우 YAML 작성하기

시작하는 데 도움이 되는 예시를 아래에 소개합니다:

예시: 모델 테스트와 리포팅 자동화

name: Test ML Model

on:
repository_dispatch:
types: "test-and-report"

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
test_and_report:
# The type of runner that the job will run on
runs-on: ubuntu-latest
env:
WANDB_API_KEY: ${{ secrets.WANDB_API_KEY }}

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.7.13'
cache: 'pip'
- name: Install Dependencies
run: pip install wandb
# run: pip install -r ./.github/workflows/requirements.txt

- name: Login to W&B
run: wandb login


# Use the payload to pull down relevant artifacts, test and deploy them!
- name: Echo Template Strings from W&B Webhook
run: |
echo -e "${{ github.event.client_payload.my_custom_string1 }}\n\
${{ github.event.client_payload.my_custom_string2 }}\n\
${{ github.event.client_payload.event_type }}\n\
${{ github.event.client_payload.event_author }}\n\
${{ github.event.client_payload.artifact_version }}\n\
${{ github.event.client_payload.artifact_version_string }}\n\
${{ github.event.client_payload.artifact_collection_name }}\n\
${{ github.event.client_payload.project_name }}\n\
${{ github.event.client_payload.entity_name }}"
- name: Retrieve Artifacts
run: python .github/workflows/retrieve_artifacts.py --registered_model_name "${{ github.event.client_payload.artifact_version_string }}"

- name: Test Model Loading and Inference
run: pytest -s --artifact_path ./wandb_artifact_cache

- name: Generate W&B Report with Reports API

예시: 모델 배포 자동화

name: Containerize Model in Inference Server

on:
repository_dispatch:
types: "build-inference-server"

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build_inference_server:
# The type of runner that the job will run on
runs-on: ubuntu-latest
env:
WANDB_API_KEY: ${{ secrets.WANDB_API_KEY }}

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.7.13'
cache: 'pip'
- name: Install Dependencies
run: pip install wandb
# run: pip install -r ./.github/workflows/requirements.txt

- name: Login to W&B
run: wandb login


# Use the payload to pull down relevant artifacts, test and deploy them!
- name: Echo Template Strings from W&B Webhook
run: |
echo -e "${{ github.event.client_payload.my_custom_string1 }}\n\
${{ github.event.client_payload.my_custom_string2 }}\n\
${{ github.event.client_payload.event_type }}\n\
${{ github.event.client_payload.event_author }}\n\
${{ github.event.client_payload.artifact_version }}\n\
${{ github.event.client_payload.artifact_version_string }}\n\
${{ github.event.client_payload.artifact_collection_name }}\n\
${{ github.event.client_payload.project_name }}\n\
${{ github.event.client_payload.entity_name }}"
- name: Retrieve Artifacts
run: python .github/workflows/retrieve_artifacts.py --registered_model_name "${{ github.event.client_payload.artifact_version_string }}"

- name: Containerize the artifact in our inference server
uses: docker/build-push-action@v4
with:
context: ./docker_context
file: src/torchserve/Dockerfile
push: true
tags: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }}

CI/CD 도구에서 W&B 아티팩트 가져오기

API

CLI

wandb CLI를 사용해 아티팩트를 가져올 수 있습니다. wandb artifact get <entity>/<project>/<name>:<alias> --root <target_dir> . 이는 편리하지만, 그 아티팩트가 다운스트림에서 어떻게 사용되었는지 계보를 확인할 수 없다는 단점이 있습니다. 예를 들어 GitHub Actions 워크플로우 YAML에서 사용할 수 있습니다.
run: |
ARG="${{ github.event.client_payload.artifact_version_string }}" # This avoids space escaping in registered model name
wandb artifact get "$ARG" --root ./wandb_artifact_cache

결론

Weights & Biases에서 CI/CD를 위해 Webhook Automation을 사용하는 간단한 소개를 마칩니다. 플랫폼에서의 동작 방식에 대해 더 알아보고 싶다면, 다음을 확인해 보시길 권장합니다. 문서 확인하기또한 모델 CI/CD에 관한 무료 인터랙티브 과정을 새로 제공하고 있으며, 여기서 웹훅을 비롯한 다양한 주제를 더 깊이 있게 다룹니다. 여기에서 무료로 등록할 수 있습니다.


이 글은 AI로 번역되었습니다. 오역이 의심되는 부분이 있으면 댓글로 알려주세요. 원문 보고서는 다음 링크에서 확인할 수 있습니다: 원문 보고서 보기