Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPU only release binary #302

Merged
merged 27 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .azure-pipelines/scripts/ut/run_ut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ LOG_DIR=/auto-round/log_dir
mkdir -p ${LOG_DIR}
ut_log_name=${LOG_DIR}/ut.log

find . -name "test*.py" | sed "s,\.\/,python -m pytest --cov=\"${auto_round_path}\" --cov-report term --html=report.html --self-contained-html --cov-report xml:coverage.xml --cov-append -vs --disable-warnings ,g" > run.sh
find . -name "test*.py" ! -name "*hpu_only*.py" | sed "s,\.\/,python -m pytest --cov=\"${auto_round_path}\" --cov-report term --html=report.html --self-contained-html --cov-report xml:coverage.xml --cov-append -vs --disable-warnings ,g" > run.sh
cat run.sh
bash run.sh 2>&1 | tee ${ut_log_name}

Expand All @@ -33,4 +33,4 @@ fi
# if ut pass, collect the coverage file into artifacts
cp .coverage ${LOG_DIR}/.coverage

echo "UT finished successfully! "
echo "UT finished successfully! "
36 changes: 36 additions & 0 deletions .azure-pipelines/scripts/ut/run_ut_hpu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
set -xe

# install requirements
echo "set up UT env..."
pip install pytest-cov pytest-html
pip list

cd /auto-round/test || exit 1
find . -type f -exec sed -i '/sys\.path\.insert(0, "\.\.")/d' {} +

export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
export FORCE_BF16=1
export COVERAGE_RCFILE=/auto-round/.azure-pipelines/scripts/ut/.coverage
auto_round_path=$(python -c 'import auto_round; print(auto_round.__path__[0])')

LOG_DIR=/auto-round/log_dir
mkdir -p ${LOG_DIR}
ut_log_name=${LOG_DIR}/ut.log

find . -name "test*hpu_only.py" | sed "s,\.\/,python -m pytest --cov=\"${auto_round_path}\" --cov-report term --html=report.html --self-contained-html --cov-report xml:coverage.xml --cov-append -vs --disable-warnings ,g" > run.sh
cat run.sh
bash run.sh 2>&1 | tee ${ut_log_name}

cp report.html ${LOG_DIR}/
cp coverage.xml ${LOG_DIR}/

if [ $(grep -c '== FAILURES ==' ${ut_log_name}) != 0 ] || [ $(grep -c '== ERRORS ==' ${ut_log_name}) != 0 ] || [ $(grep -c ' passed' ${ut_log_name}) == 0 ]; then
echo "Find errors in pytest case, please check the output..."
exit 1
fi

# if ut pass, collect the coverage file into artifacts
cp .coverage ${LOG_DIR}/.coverage

echo "UT finished successfully! "
48 changes: 31 additions & 17 deletions .azure-pipelines/template/docker-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ parameters:
- name: repo
type: string
default: "https://github.com/intel/auto-round"
- name: imageSource
type: string
default: "build"

steps:
- task: Bash@3
Expand All @@ -24,7 +27,7 @@ steps:
script: |
docker ps -a
if [[ $(docker ps -a | grep -i '${{ parameters.containerName }}'$) ]]; then
docker start $(docker ps -aq)
docker start ${{ parameters.containerName }}
echo "remove left files through container ..."
docker exec ${{ parameters.containerName }} bash -c "ls -a /auto-round && rm -fr /auto-round/* && rm -fr /auto-round/.* && ls -a /auto-round || true"
fi
Expand All @@ -33,7 +36,6 @@ steps:
- ${{ if eq(parameters.dockerConfigName, 'commonDockerConfig') }}:
- script: |
rm -fr ${BUILD_SOURCESDIRECTORY} || sudo rm -fr ${BUILD_SOURCESDIRECTORY} || true
echo y | docker system prune
displayName: "Clean workspace"

- checkout: self
Expand All @@ -45,7 +47,6 @@ steps:
rm -fr ${BUILD_SOURCESDIRECTORY} || sudo rm -fr ${BUILD_SOURCESDIRECTORY} || true
mkdir ${BUILD_SOURCESDIRECTORY}
chmod 777 ${BUILD_SOURCESDIRECTORY}
echo y | docker system prune
displayName: "Clean workspace"

- checkout: none
Expand All @@ -57,20 +58,26 @@ steps:
git checkout main
displayName: "Checkout out main"

- script: |
if [[ ! $(docker images | grep -i ${{ parameters.repoName }}:${{ parameters.repoTag }}) ]]; then
cd ${BUILD_SOURCESDIRECTORY}
docker build -f .azure-pipelines/docker/${{parameters.dockerFileName}}.devel -t ${{ parameters.repoName }}:${{ parameters.repoTag }} .
fi
docker images | grep -i ${{ parameters.repoName }}
if [[ $? -ne 0 ]]; then
echo "NO Such Repo"
exit 1
fi
displayName: "Build develop docker image"
- ${{ if eq(parameters.imageSource, 'build') }}:
- script: |
docker image prune -a -f
if [[ ! $(docker images | grep -i ${{ parameters.repoName }}:${{ parameters.repoTag }}) ]]; then
docker build -f ${BUILD_SOURCESDIRECTORY}/.azure-pipelines/docker/${{parameters.dockerFileName}}.devel -t ${{ parameters.repoName }}:${{ parameters.repoTag }} .
fi
docker images | grep -i ${{ parameters.repoName }}
if [[ $? -ne 0 ]]; then
echo "NO Such Repo"
exit 1
fi
displayName: "Build develop docker image"

- ${{ if eq(parameters.imageSource, 'pull') }}:
- script: |
docker pull vault.habana.ai/gaudi-docker/1.18.0/ubuntu22.04/habanalabs/pytorch-installer-2.4.0:latest
displayName: "Pull habana docker image"

- script: |
docker stop $(docker ps -aq)
docker stop ${{ parameters.containerName }}
docker rm -vf ${{ parameters.containerName }} || true
env | sort
displayName: "Clean docker container"
Expand All @@ -80,8 +87,15 @@ steps:
inputs:
targetType: "inline"
script: |
docker run -dit --disable-content-trust --privileged --name=${{ parameters.containerName }} --shm-size="2g" \
-v ${BUILD_SOURCESDIRECTORY}:/auto-round -v /tf_dataset:/tf_dataset -v /tf_dataset2:/tf_dataset2 ${{ parameters.repoName }}:${{ parameters.repoTag }}
if [[ "${{ parameters.imageSource }}" == "build" ]]; then
docker run -dit --disable-content-trust --privileged --name=${{ parameters.containerName }} --shm-size="2g" \
-v ${BUILD_SOURCESDIRECTORY}:/auto-round -v /tf_dataset:/tf_dataset -v /tf_dataset2:/tf_dataset2 \
${{ parameters.repoName }}:${{ parameters.repoTag }}
else
docker run -dit --disable-content-trust --privileged --name=${{ parameters.containerName }} --shm-size="2g" \
--runtime=habana -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --net=host --ipc=host \
-v ${BUILD_SOURCESDIRECTORY}:/auto-round vault.habana.ai/gaudi-docker/1.18.0/ubuntu22.04/habanalabs/pytorch-installer-2.4.0:latest
fi
echo "Show the container list after docker run ... "
docker ps -a
displayName: "Docker run - ${{ parameters.containerName }} Container"
28 changes: 21 additions & 7 deletions .azure-pipelines/template/ut-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ parameters:
- name: utContainerName
type: string
default: "AutoRoundUnitTest"
- name: imageSource
type: string
default: "build"

steps:
- template: docker-template.yml
Expand All @@ -27,14 +30,23 @@ steps:
dockerFileName: "Dockerfile"
containerName: ${{ parameters.utContainerName }}
repo: ${{ parameters.repo }}
imageSource: ${{ parameters.imageSource }}

- script: |
docker exec ${{ parameters.utContainerName }} bash -c "cd /auto-round \
&& pip install -r requirements.txt \
&& python setup.py bdist_wheel && rm -rf build \
&& pip install dist/auto_round*.whl \
&& pip list"
displayName: "Env Setup"
- ${{ if eq(parameters.imageSource, 'build') }}:
- script: |
docker exec ${{ parameters.utContainerName }} bash -c "cd /auto-round \
&& pip install -r requirements.txt \
&& python setup.py bdist_wheel && rm -rf build \
&& pip install dist/auto_round*.whl \
&& pip list"
displayName: "Env Setup"

- ${{ if eq(parameters.imageSource, 'pull') }}:
- script: |
docker exec ${{ parameters.utContainerName }} bash -c "cd /auto-round \
&& python setup.py install hpu \
&& pip list"
displayName: "HPU Env Setup"

- script: |
docker exec ${{ parameters.utContainerName }} bash -c "cd /auto-round/.azure-pipelines/scripts \
Expand All @@ -54,4 +66,6 @@ steps:
targetType: "inline"
script: |
docker exec ${{ parameters.utContainerName }} bash -c "rm -rf /auto-round/* && rm -rf /auto-round/.* || true"
docker stop ${{ parameters.utContainerName }}
docker rm -vf ${{ parameters.utContainerName }} || true
displayName: "Docker clean up"
113 changes: 113 additions & 0 deletions .azure-pipelines/unit-test-hpu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
trigger: none

pr:
autoCancel: true
drafts: false
branches:
include:
- main
paths:
include:
- auto_round
- test/test*hpu*'
- setup.py
- requirements-hpu.txt
- .azure-pipelines/scripts/ut
exclude:
- auto_round/export/export_to_autogptq
- auto_round/export/export_to_awq

pool: GAUDI

variables:
IMAGE_NAME: "auto-round"
IMAGE_TAG: "py310"
UPLOAD_PATH: $(Build.SourcesDirectory)/log_dir
DOWNLOAD_PATH: $(Build.SourcesDirectory)/log_dir
ARTIFACT_NAME: "UT_coverage_report"
REPO: $(Build.Repository.Uri)

stages:
- stage: Unit_test
displayName: Unit Test
dependsOn: []
jobs:
- job:
displayName: Unit Test
steps:
- template: template/ut-template.yml
parameters:
imageSource: "pull"
dockerConfigName: "commonDockerConfig"
utScriptFileName: "run_ut_hpu"
uploadPath: $(UPLOAD_PATH)
utArtifact: "ut"

- stage: Unit_test_baseline
displayName: Unit Test Baseline
dependsOn: []
jobs:
- job:
displayName: Unit Test
steps:
- template: template/ut-template.yml
parameters:
imageSource: "pull"
dockerConfigName: "gitCloneDockerConfig"
utScriptFileName: "run_ut_hpu"
uploadPath: $(UPLOAD_PATH)
utArtifact: "ut_baseline"
repo: $(REPO)

- stage: Coverage
displayName: "Coverage Compare"
pool:
vmImage: "ubuntu-latest"
dependsOn: [Unit_test, Unit_test_baseline]
jobs:
- job: CollectDatafiles
steps:
- script: |
if [[ ! $(docker images | grep -i ${IMAGE_NAME}:${IMAGE_TAG}) ]]; then
docker build -f ${BUILD_SOURCESDIRECTORY}/.azure-pipelines/docker/Dockerfile.devel -t ${IMAGE_NAME}:${IMAGE_TAG} .
fi
docker images | grep -i ${IMAGE_NAME}
if [[ $? -ne 0 ]]; then
echo "NO Such Repo"
exit 1
fi
displayName: "Build develop docker image"

- task: DownloadPipelineArtifact@2
inputs:
artifact:
patterns: "*_coverage/.coverage"
path: $(DOWNLOAD_PATH)

- script: |
echo "--- create container ---"
docker run -d -it --name="collectLogs" -v ${BUILD_SOURCESDIRECTORY}:/auto-round ${IMAGE_NAME}:${IMAGE_TAG} /bin/bash
echo "--- docker ps ---"
docker ps
echo "--- collect logs ---"
docker exec collectLogs bash -c "cd /auto-round \
&& python setup.py install hpu \
&& pip list"
docker exec collectLogs /bin/bash +x -c "cd /auto-round/.azure-pipelines/scripts \
&& bash ut/collect_log.sh"
displayName: "Collect UT Coverage"

- task: PublishPipelineArtifact@1
condition: succeededOrFailed()
inputs:
targetPath: $(UPLOAD_PATH)
artifact: $(ARTIFACT_NAME)
publishLocation: "pipeline"

- task: Bash@3
condition: always()
inputs:
targetType: "inline"
script: |
docker exec collectLogs bash -c "rm -fr /auto-round/* && rm -fr /auto-round/.* || true"
displayName: "Docker clean up"
4 changes: 3 additions & 1 deletion .azure-pipelines/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ pr:
- auto_round_extension
- test
- setup.py
- requirements_pt.txt
- requirements.txt
- .azure-pipelines/scripts/ut
exclude:
- test/test*hpu*

pool: ICX-16C

Expand Down
15 changes: 5 additions & 10 deletions auto_round/auto_quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@

from auto_round.backend import get_layer_backend, dynamic_import_inference_linear

import auto_round_extension.qbits.qlinear_qbits as qlinear_qbits
import auto_round_extension.qbits.qlinear_qbits_gptq as qlinear_qbits_gptq
import auto_round_extension.ipex.qlinear_ipex_gptq as qlinear_ipex_gptq
import auto_round_extension.ipex.qlinear_ipex_awq as qlinear_ipex_awq
from auto_round.backend import BackendInfos
from transformers.utils.versions import require_version
from enum import Enum
Expand Down Expand Up @@ -110,9 +106,6 @@ def is_auto_round_available():
)


if is_auto_round_available():
from auto_round_extension.cuda.post_init import autoround_post_init


#
def get_device(obj: Union[torch.Tensor, nn.Module]):
Expand Down Expand Up @@ -588,12 +581,14 @@ def cpu_post_init(self, model):

for n, layer in tqdm(layers, desc=message, total=len(layers),
leave=True):
if isinstance(layer, (qlinear_qbits.QuantLinear, qlinear_qbits_gptq.QuantLinear)):
from auto_round_extension.qbits import qbits_qlinear_classes
from auto_round_extension.ipex import ipex_qlinear_classes
if isinstance(layer, qbits_qlinear_classes):
if dep_check:
layer.req_check()
layer.post_init()
dep_check = False
if isinstance(layer, (qlinear_ipex_gptq.QuantLinear, qlinear_ipex_awq.QuantLinear)):
if isinstance(layer, ipex_qlinear_classes):
layer.post_init()

return model
Expand Down Expand Up @@ -702,7 +697,7 @@ class StoreAttr(object):
"marlin format requires gptqmodel to be installed, "
"`pip install -v gptqmodel --no-build-isolation `")
self.repack_marlin(model)

from auto_round_extension.cuda.post_init import autoround_post_init
model = autoround_post_init(model)
# there are no side-effects after call qbits_post_init when model quant-type not equal to qbits.
if self.target_device == "cpu":
Expand Down
2 changes: 1 addition & 1 deletion auto_round/autoround.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ def save_quantized(self, output_dir=None, format="auto_round", inplace=True, **k
format = format.split(":")[0]
if format not in EXPORT_FORMAT:
logger.error(f"export format only supports {EXPORT_FORMAT.keys()}")
exit(-1)
raise ValueError(f"export format only supports {EXPORT_FORMAT.keys()}, but got {format}")
save_quantized_as_format = EXPORT_FORMAT.get(format)
if "gptq" in format and not self.sym:
logger.warning(
Expand Down
Loading
Loading