PTQ-Level Efficiency, QAT-Level Accuracy | 训练后量化的效率,量化感知训练的精度
trigger: none
pr:
autoCancel: true
drafts: false
branches:
include:
- main
- "*rc"
paths:
include:
- auto_round
- auto_round_extension
- test/unit/test_cuda
- setup.py
- requirements.txt
- .azure-pipelines/scripts/cuda_unit_test
- .azure-pipelines/scripts/ut/detect_changed_tests.sh
- .azure-pipelines/unit-test-cuda.yml
exclude:
- "*.md"
- "**/*.md"
- auto_round_extension/ark
variables:
- name: POOL_NAME
value: "RunPod-GPU-Pool"
- name: AGENT_NAME
value: "runpod-agent-$(Build.BuildId)"
parameters:
- name: matrix
type: object
default:
part0:
PART: 0
part1:
PART: 1
part2:
PART: 2
stages:
- ${{ each pair in parameters.matrix }}:
# Pod creation, GPU tests and cleanup live in ONE stage as three jobs so a
# "Rerun failed stage" reruns every job (including Start_Pod_Job) and thus
# recreates the ephemeral pod. Separate stages would leave the already
# succeeded Start_Pod stage un-rerun, so the retry would find no agent.
- stage: GPU_Test_${{ pair.key }}
displayName: "GPU Test ${{ pair.value.PART }}"
dependsOn: []
jobs:
- job: Start_Pod_Job
displayName: "Launch Pod ${{ pair.value.PART }}"
timeoutInMinutes: 60
pool:
vmImage: "ubuntu-latest"
steps:
- checkout: self
- task: UsePythonVersion@0
inputs:
versionSpec: "3.14"
displayName: "Use Python 3.14"
- task: Bash@3
displayName: "Install dependencies"
inputs:
targetType: "inline"
script: |
pip install requests
- task: Bash@3
displayName: "Create RunPod Instance"
name: create_runpod
inputs:
targetType: "inline"
script: |
python .azure-pipelines/scripts/cuda_unit_test/runpod_manager.py \
--action create \
--api_key $(RUNPOD_API_KEY) \
--name "ci-$(Build.BuildId)-${{ pair.value.PART }}" \
--container_disk_size "100" \
--part ${{ pair.value.PART }} \
--env AZP_URL=$(System.CollectionUri) AZP_TOKEN=$(AZP_DEVOPS_PAT) AZP_POOL=$(POOL_NAME) AZP_AGENT_NAME="$(AGENT_NAME)-part${{ pair.value.PART }}"
env:
PYTHONUNBUFFERED: '1'
- task: Bash@3
displayName: "Wait for Pod to be Online"
name: wait_for_pod
inputs:
targetType: "inline"
script: |
python .azure-pipelines/scripts/cuda_unit_test/runpod_manager.py \
--action wait \
--api_key $(RUNPOD_API_KEY) \
--name "ci-$(Build.BuildId)-${{ pair.value.PART }}"
env:
PYTHONUNBUFFERED: '1'
- task: Bash@3
displayName: "Wait for Agent to be Online"
name: wait_for_agent
inputs:
targetType: "inline"
script: |
python .azure-pipelines/scripts/cuda_unit_test/azure_agent.py \
--action wait \
--url "$(System.CollectionUri)" \
--pat "$(AZP_DEVOPS_PAT)" \
--pool "$(POOL_NAME)" \
--agent "$(AGENT_NAME)-part${{ pair.value.PART }}"
env:
PYTHONUNBUFFERED: '1'
- job: GpuTests
dependsOn: Start_Pod_Job
variables:
- group: auto-round-bot-secrets
timeoutInMinutes: 60
pool:
name: "$(POOL_NAME)"
demands: Agent.Name -equals runpod-agent-$(Build.BuildId)-part${{ pair.value.PART }}
steps:
- checkout: self
clean: true
displayName: "Checkout Repo"
- script: |
echo "Running on GPU Agent: $(Agent.Name)"
nvidia-smi
lscpu
cd .azure-pipelines/scripts/cuda_unit_test
nohup uv run monitor_gpu.py daemon > monitor.log 2>&1 &
displayName: "Verify GPU Access"
- script: |
echo "##[group]Installing Python dependencies..."
uv pip install -U "pytest-cov" "requests" "huggingface_hub"
hf auth login --token "$(HF_TOKEN)"
echo "##[endgroup]"
displayName: "Install Python Dependencies"
# On a "Rerun failed jobs" retry the container is a clean environment, so pull
# the previous attempt's failed_tests.list to rerun only the failed cases.
# A cancelled previous attempt never publishes its failed-logs artifact, so
# probe for it first and skip the download when absent.
- task: Bash@3
condition: gt(variables['System.JobAttempt'], 1)
displayName: "Check previous attempt artifact exists"
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
inputs:
targetType: "inline"
script: |
set -eo pipefail
prev_attempt=$((SYSTEM_JOBATTEMPT - 1))
echo "##vso[task.setvariable variable=prevAttempt]${prev_attempt}"
artifact="ut-${{ pair.value.PART }}-${prev_attempt}"
url="${SYSTEM_COLLECTIONURI}${SYSTEM_TEAMPROJECT}/_apis/build/builds/${BUILD_BUILDID}/artifacts?api-version=7.1"
resp=$(curl -fsS -H "Authorization: Bearer ${SYSTEM_ACCESSTOKEN}" "${url}" || echo "")
if echo "${resp}" | grep -q "\"name\":\"${artifact}\""; then
echo "Found previous artifact ${artifact}."
echo "##vso[task.setvariable variable=prevArtifactExists]true"
else
echo "Previous artifact ${artifact} not found, skip retry download."
echo "##vso[task.setvariable variable=prevArtifactExists]false"
fi
- task: DownloadPipelineArtifact@2
condition: and(gt(variables['System.JobAttempt'], 1), eq(variables['prevArtifactExists'], 'true'))
continueOnError: true
inputs:
artifact: "ut-${{ pair.value.PART }}-$(prevAttempt)"
patterns: |
failed_tests.list
.coverage
path: $(Build.SourcesDirectory)/log_dir
displayName: "Download previous failed_tests.list and coverage (retry)"
- script: |
export UV_NO_CACHE=0
export FILTER_CHANGED_TESTS=true
bash .azure-pipelines/scripts/cuda_unit_test/run_cuda_ut.sh \
--test_case=ci \
--test_part=${{ pair.value.PART }}
displayName: "Run GPU Tests"
env:
GITHUB_TOKEN: $(AUTO_ROUND_BOT_TOKEN)
- task: PublishPipelineArtifact@1
condition: succeeded()
inputs:
targetPath: $(Build.SourcesDirectory)/log_dir
artifact: "ut-${{ pair.value.PART }}_coverage"
publishLocation: "pipeline"
displayName: "Publish UT coverage artifact"
# Publish only the failed logs (and seeded .coverage) so the next
# retry attempt can download and rerun exactly those cases.
- task: PublishPipelineArtifact@1
condition: failed()
inputs:
targetPath: $(Build.SourcesDirectory)/log_dir/failed_logs
artifact: "ut-${{ pair.value.PART }}-$(System.JobAttempt)"
publishLocation: "pipeline"
displayName: "Publish failed UT logs"
- script: |
cd .azure-pipelines/scripts/cuda_unit_test
uv run monitor_gpu.py stop
condition: always()
displayName: "GPU Monitor"
- job: Verify_Cleanup
displayName: "Verify Pod Cleanup ${{ pair.value.PART }}"
dependsOn:
- Start_Pod_Job
- GpuTests
condition: always()
pool:
vmImage: "ubuntu-latest"
steps:
- checkout: self
- task: UsePythonVersion@0
inputs:
versionSpec: "3.14"
displayName: "Use Python 3.14"
- task: Bash@3
displayName: "Install dependencies"
condition: always()
inputs:
targetType: "inline"
script: |
pip install requests
- task: Bash@3
displayName: "Terminate RunPod Instance"
condition: always()
inputs:
targetType: "inline"
script: |
echo "Terminating Pod: ci-$(Build.BuildId)-${{ pair.value.PART }}"
python .azure-pipelines/scripts/cuda_unit_test/runpod_manager.py \
--action terminate \
--api_key $(RUNPOD_API_KEY) \
--name "ci-$(Build.BuildId)-${{ pair.value.PART }}"
env:
PYTHONUNBUFFERED: '1'
- task: Bash@3
displayName: "Deregister Agent from Pool"
condition: always()
inputs:
targetType: "inline"
script: |
cd ${BUILD_SOURCESDIRECTORY}
python .azure-pipelines/scripts/cuda_unit_test/azure_agent.py \
--action deregister \
--url "$(System.CollectionUri)" \
--pat "$(AZP_DEVOPS_PAT)" \
--pool "$(POOL_NAME)" \
--agent "$(AGENT_NAME)-part${{ pair.value.PART }}"
env:
PYTHONUNBUFFERED: '1'
- template: template/ai-stage-template.yml
parameters:
dependsOn:
- ${{ each pair in parameters.matrix }}:
- GPU_Test_${{ pair.key }}
enableAiAnalysis: true
postComment: true
- stage: Coverage
displayName: "Collect Coverage"
pool:
vmImage: "ubuntu-latest"
dependsOn:
- ${{ each pair in parameters.matrix }}:
- GPU_Test_${{ pair.key }}
variables:
UPLOAD_PATH: $(Build.SourcesDirectory)/log_dir
DOWNLOAD_PATH: $(Build.SourcesDirectory)/log_dir
ARTIFACT_NAME: "UT_coverage_report"
jobs:
- job: CollectDatafiles
steps:
- checkout: self
- task: DownloadPipelineArtifact@2
inputs:
patterns: 'ut-*_coverage/.coverage.*'
path: $(DOWNLOAD_PATH)
- task: UsePythonVersion@0
inputs:
versionSpec: '3.14'
displayName: 'Use Python 3.14'
- script: |
cd ${BUILD_SOURCESDIRECTORY}
pip install -U pip setuptools uv
uv pip install -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu
uv pip install .
pip list
bash .azure-pipelines/scripts/ut/collect_log.sh cuda
env:
PYTHONUNBUFFERED: '1'
UV_NO_PROGRESS: '1'
UV_SYSTEM_PYTHON: '1'
displayName: "Collect UT Coverage"
- task: PublishPipelineArtifact@1
condition: succeededOrFailed()
inputs:
targetPath: $(UPLOAD_PATH)/coverage_PR
artifact: $(ARTIFACT_NAME)
publishLocation: "pipeline"
- task: PublishCodeCoverageResults@2
inputs:
summaryFileLocation: $(Build.SourcesDirectory)/log_dir/coverage_PR/coverage.xml