Tutorial Lengkap Azure DevOps untuk MLOps: CI/CD untuk Machine Learning
Azure DevOps menyediakan kemampuan CI/CD komprehensif untuk proyek machine learning. Tutorial ini mencakup pembangunan pipeline ML otomatis, deployment model, dan continuous delivery menggunakan Azure DevOps.
Mengapa Azure DevOps untuk MLOps?
Manfaat Utama:- Automasi end-to-end: Dari kode hingga deployment
- Version control: Git repos untuk kode dan data
- Orkestrasi pipeline: Workflow ML multi-stage
- Integration: Integrasi native Azure ML
- Collaboration: Pengembangan berbasis tim
- Azure Repos: Git repositories
- Azure Pipelines: Automasi CI/CD
- Azure Artifacts: Package management
- Azure Boards: Work tracking
Prerequisites
pip install azure-devops azure-ai-ml
Azure CLI
az login
az extension add --name azure-devops
az devops configure --defaults organization=https://dev.azure.com/myorg
Setup Proyek
1. Buat DevOps Project
# Buat project
az devops project create --name "MLOps-Project" --org https://dev.azure.com/myorg
Buat repository
az repos create --name "ml-models" --project "MLOps-Project"
2. Struktur Repository
ml-models/
├── src/
│ ├── train.py
│ ├── evaluate.py
│ └── score.py
├── tests/
│ └── testmodel.py
├── pipelines/
│ ├── train-pipeline.yml
│ ├── deploy-pipeline.yml
│ └── cd-pipeline.yml
├── infrastructure/
│ └── arm-templates/
├── environment.yml
├── requirements.txt
└── azure-pipelines.yml
3. Service Connection
# Buat service connection ke Azure
az devops service-endpoint azurerm create \
--azure-rm-service-principal-id "your-sp-id" \
--azure-rm-subscription-id "your-subscription-id" \
--azure-rm-subscription-name "Your Subscription" \
--azure-rm-tenant-id "your-tenant-id" \
--name "azure-ml-connection"
CI Pipeline untuk ML
1. Basic CI Pipeline
# azure-pipelines.yml
trigger:
branches:
include:
- main
- develop
paths:
include:
- src/
- tests/
pool:
vmImage: 'ubuntu-latest'
variables:
pythonVersion: '3.9'
stages:
- stage: Build
displayName: 'Build dan Test'
jobs:
- job: BuildJob
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(pythonVersion)'
displayName: 'Gunakan Python $(pythonVersion)'
- script: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest pytest-cov
displayName: 'Install dependencies'
- script: |
python -m pytest tests/ --cov=src --cov-report=xml
displayName: 'Jalankan tests'
- task: PublishTestResults@2
inputs:
testResultsFiles: '*/test-.xml'
testRunTitle: 'Python Tests'
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/*/coverage.xml'
2. Linting dan Code Quality
# Tambahkan ke azure-pipelines.yml
- script: |
pip install flake8 black mypy
flake8 src/ --max-line-length=100
black --check src/
mypy src/
displayName: 'Pemeriksaan kualitas kode'
Training Pipeline
1. ML Training Pipeline
# pipelines/train-pipeline.yml
trigger:
branches:
include:
- main
paths:
include:
- src/
- data/
variables:
- group: ml-variables
- name: resourceGroup
value: 'ml-rg'