PTQ-Level Efficiency, QAT-Level Accuracy | 训练后量化的效率,量化感知训练的精度
HPU only release binary (#302)
Yi Liu5cd255edbb5b
diff --git a/.azure-pipelines/scripts/ut/run_ut.sh b/.azure-pipelines/scripts/ut/run_ut.shindex 5c4289f56..d9ccaebf7 100644--- a/.azure-pipelines/scripts/ut/run_ut.sh+++ b/.azure-pipelines/scripts/ut/run_ut.sh@@ -18,7 +18,7 @@ LOG_DIR=/auto-round/log_dirmkdir -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.shcat run.shbash run.sh 2>&1 | tee ${ut_log_name}@@ -33,4 +33,4 @@ fi# if ut pass, collect the coverage file into artifactscp .coverage ${LOG_DIR}/.coverage-echo "UT finished successfully! "\ No newline at end of file+echo "UT finished successfully! "diff --git a/.azure-pipelines/scripts/ut/run_ut_hpu.sh b/.azure-pipelines/scripts/ut/run_ut_hpu.shnew file mode 100644index 000000000..77619df96--- /dev/null+++ b/.azure-pipelines/scripts/ut/run_ut_hpu.sh@@ -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! "\ No newline at end of filediff --git a/.azure-pipelines/template/docker-template.yml b/.azure-pipelines/template/docker-template.ymlindex cbde3680c..f71123fa3 100644--- a/.azure-pipelines/template/docker-template.yml+++ b/.azure-pipelines/template/docker-template.yml@@ -16,6 +16,9 @@ parameters:- name: repotype: stringdefault: "https://github.com/intel/auto-round"+ - name: imageSource+ type: string+ default: "build"steps:- task: Bash@3@@ -24,7 +27,7 @@ steps:script: |docker ps -aif [[ $(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@@ -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 prunedisplayName: "Clean workspace"- checkout: self@@ -45,7 +47,6 @@ steps:rm -fr ${BUILD_SOURCESDIRECTORY} || sudo rm -fr ${BUILD_SOURCESDIRECTORY} || truemkdir ${BUILD_SOURCESDIRECTORY}chmod 777 ${BUILD_SOURCESDIRECTORY}- echo y | docker system prunedisplayName: "Clean workspace"- checkout: none@@ -57,20 +58,26 @@ steps:git checkout maindisplayName: "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 }} || trueenv | sortdisplayName: "Clean docker container"@@ -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+ fiecho "Show the container list after docker run ... "docker ps -adisplayName: "Docker run - ${{ parameters.containerName }} Container"diff --git a/.azure-pipelines/template/ut-template.yml b/.azure-pipelines/template/ut-template.ymlindex 46addafa8..2464da86f 100644--- a/.azure-pipelines/template/ut-template.yml+++ b/.azure-pipelines/template/ut-template.yml@@ -17,6 +17,9 @@ parameters:- name: utContainerNametype: stringdefault: "AutoRoundUnitTest"+ - name: imageSource+ type: string+ default: "build"steps:- template: docker-template.yml@@ -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 \@@ -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 }} || truedisplayName: "Docker clean up"diff --git a/.azure-pipelines/unit-test-hpu.yml b/.azure-pipelines/unit-test-hpu.ymlnew file mode 100644index 000000000..b0b6bf3d5--- /dev/null+++ b/.azure-pipelines/unit-test-hpu.yml@@ -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"diff --git a/.azure-pipelines/unit-test.yml b/.azure-pipelines/unit-test.ymlindex eff997208..e0cca55cd 100644--- a/.azure-pipelines/unit-test.yml+++ b/.azure-pipelines/unit-test.yml@@ -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-16Cdiff --git a/auto_round/auto_quantizer.py b/auto_round/auto_quantizer.pyindex 0cfbf0729..a91cf589c 100644--- a/auto_round/auto_quantizer.py+++ b/auto_round/auto_quantizer.py@@ -46,10 +46,6 @@ from auto_round.utils import get_module, set_module, is_hpu_supportedfrom 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_awqfrom auto_round.backend import BackendInfosfrom transformers.utils.versions import require_versionfrom enum import Enum@@ -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]):@@ -588,12 +581,14 @@ class AutoRoundQuantizer(HfQuantizer):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@@ -702,7 +697,7 @@ class AutoRoundQuantizer(HfQuantizer):"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_initmodel = 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":diff --git a/auto_round/autoround.py b/auto_round/autoround.pyindex 86dd36d46..2401a732b 100644--- a/auto_round/autoround.py+++ b/auto_round/autoround.py@@ -1216,7 +1216,7 @@ class AutoRound(object):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(diff --git a/auto_round/export/__init__.py b/auto_round/export/__init__.pyindex ec3047930..149ede560 100644--- a/auto_round/export/__init__.py+++ b/auto_round/export/__init__.py@@ -12,9 +12,39 @@# See the License for the specific language governing permissions and# limitations under the License.-from .register import EXPORT_FORMAT-from auto_round.export.export_to_autogptq.export import save_quantized_as_autogptq-from .export_to_itrex import save_quantized_as_itrex, QuantConfig-from .export_to_autoround.export import save_quantized_as_autoround-from .export_to_awq.export import save_quantized_as_autoawq+from auto_round.export.register import EXPORT_FORMAT, register_format++@register_format("auto_gptq")+def _save_quantized_as_autogptq(*args, **kwargs):+ from auto_round.export.export_to_autogptq.export import save_quantized_as_autogptq++ return save_quantized_as_autogptq(*args, **kwargs)+++@register_format("itrex")+def _save_quantized_as_itrex(*args, **kwargs):+ from auto_round.export.export_to_itrex.export import save_quantized_as_itrex++ return save_quantized_as_itrex(*args, **kwargs)+++@register_format("itrex_xpu")+def _save_quantized_as_itrex_xpu(*args, **kwargs):+ from auto_round.export.export_to_itrex.export import save_quantized_as_itrex_xpu++ return save_quantized_as_itrex_xpu(*args, **kwargs)+++@register_format("auto_round")+def _save_quantized_as_autoround(*args, **kwargs):+ from auto_round.export.export_to_autoround.export import save_quantized_as_autoround++ return save_quantized_as_autoround(*args, **kwargs)+++@register_format("auto_awq")+def _save_quantized_as_autoawq(*args, **kwargs):+ from auto_round.export.export_to_awq.export import save_quantized_as_autoawq++ return save_quantized_as_autoawq(*args, **kwargs)diff --git a/auto_round/export/export_to_autogptq/export.py b/auto_round/export/export_to_autogptq/export.pyindex 2ca99b123..6e8e1c90b 100644--- a/auto_round/export/export_to_autogptq/export.py+++ b/auto_round/export/export_to_autogptq/export.py@@ -114,7 +114,6 @@ def pack_layer(name, model, layer_config, backend, pbar):pbar.update(1)-@register_format("auto_gptq")def save_quantized_as_autogptq(output_dir, inplace=True, backend="auto_gptq:exllamav2",**kwargs):"""Export the model to autogptq format to easily leverage cuda kernel."""diff --git a/auto_round/export/export_to_autoround/export.py b/auto_round/export/export_to_autoround/export.pyindex aa0ce85a3..f8e769e2c 100644--- a/auto_round/export/export_to_autoround/export.py+++ b/auto_round/export/export_to_autoround/export.py@@ -153,7 +153,6 @@ def pack_layer(name, model, layer_config, backend, pbar):pbar.update(1)-@register_format("auto_round")def save_quantized_as_autoround(output_dir, inplace=True, backend="auto_round:exllamav2", **kwargs):"""Saves a quantized model in the auto-round format.diff --git a/auto_round/export/export_to_awq/export.py b/auto_round/export/export_to_awq/export.pyindex d191f3442..bba2423a1 100644--- a/auto_round/export/export_to_awq/export.py+++ b/auto_round/export/export_to_awq/export.py@@ -77,7 +77,6 @@ def pack_layer(name, model, layer_config, backend, pbar):pbar.update(1)-@register_format("auto_awq")def save_quantized_as_autoawq(output_dir, inplace=True, **kwargs):"""Export the model to autogptq format to easily leverage cuda kernel."""model = kwargs["model"]diff --git a/auto_round/export/export_to_itrex/export.py b/auto_round/export/export_to_itrex/export.pyindex 950d9d8e0..d0bbb5618 100644--- a/auto_round/export/export_to_itrex/export.py+++ b/auto_round/export/export_to_itrex/export.py@@ -60,7 +60,6 @@ def quant_weight_w_scale(weight, scale, zp, group_size=-1, device="cpu"):return int_weight-@register_format("itrex")def save_quantized_as_itrex(output_dir, inplace=True, **kwargs):"""Save configure file and weights for CPU backend inference."""model = kwargs["model"]@@ -107,7 +106,7 @@ def save_quantized_as_itrex(output_dir, inplace=True, **kwargs):return compressed_model-@register_format("itrex_xpu")+def save_quantized_as_itrex_xpu(output_dir, inplace=True, **kwargs):"""Save configure file and weights for XPU backend inference."""model = kwargs["model"]diff --git a/auto_round_extension/ipex/__init__.py b/auto_round_extension/ipex/__init__.pyindex e69de29bb..2d32570d3 100644--- a/auto_round_extension/ipex/__init__.py+++ b/auto_round_extension/ipex/__init__.py@@ -0,0 +1,6 @@+from auto_round_extension.ipex.qlinear_ipex_awq import QuantLinear as IpexAWQQuantLinear+from auto_round_extension.ipex.qlinear_ipex_gptq import (+ QuantLinear as IpexGPTQQuantLinear,+)++ipex_qlinear_classes = (IpexAWQQuantLinear, IpexGPTQQuantLinear)diff --git a/auto_round_extension/qbits/__init__.py b/auto_round_extension/qbits/__init__.pyindex e69de29bb..416f1dfed 100644--- a/auto_round_extension/qbits/__init__.py+++ b/auto_round_extension/qbits/__init__.py@@ -0,0 +1,6 @@+from auto_round_extension.qbits.qlinear_qbits import QuantLinear as QBitsQuantLinear+from auto_round_extension.qbits.qlinear_qbits_gptq import (+ QuantLinear as QBitsGPTQQuantLinear,+)++qbits_qlinear_classes = (QBitsQuantLinear, QBitsGPTQQuantLinear)diff --git a/requirements-hpu.txt b/requirements-hpu.txtnew file mode 100644index 000000000..e3f9cc9db--- /dev/null+++ b/requirements-hpu.txt@@ -0,0 +1,11 @@+accelerate+datasets+py-cpuinfo+sentencepiece+transformers+numpy < 2.0+tqdm+packaging+pillow+numba+tbb\ No newline at end of filediff --git a/setup.py b/setup.pyindex fac699380..cfef6a99b 100644--- a/setup.py+++ b/setup.py@@ -3,7 +3,7 @@ from io import openimport osfrom setuptools import find_packages, setupimport sys-+from functools import lru_cacheos.environ["CC"] = "g++"os.environ["CXX"] = "g++"try:@@ -18,6 +18,19 @@ version = __version__BUILD_CUDA_EXT = int(os.environ.get('BUILD_CUDA_EXT', '1')) == 1PYPI_RELEASE = os.environ.get('PYPI_RELEASE', None)+BUILD_HPU_ONLY = os.environ.get('BUILD_HPU_ONLY', '0') == '1'++@lru_cache(None)+def is_hpu_available():+ try:+ import habana_frameworks.torch.core as htcore # pylint: disable=E0401+ return True+ except ImportError:+ return False++if is_hpu_available():+ # When HPU is available, we build HPU only by default+ BUILD_HPU_ONLY = Truedef is_cpu_env():try:@@ -167,9 +180,54 @@ if BUILD_CUDA_EXT:"cmdclass": {'build_ext': cpp_extension.BuildExtension}}+PKG_INSTALL_CFG = {+ # overall installation config, pip install neural-compressor+ "auto_round": {+ "project_name": "auto_round",+ "include_packages": find_packages(+ include=[+ "auto_round",+ "auto_round.*",+ "auto_round_extension",+ "auto_round_extension.*",+ ],+ ),+ "install_requires": fetch_requirements("requirements.txt"),+ "extras_require": {+ "hpu": fetch_requirements("requirements-hpu.txt"),+ },+ },+ "auto_round_hpu": {+ "project_name": "auto_round_hpu",+ "include_packages": find_packages(+ include=["auto_round", "auto_round.*"],+ exclude=[+ "auto_round.export.export_to_autogptq",+ "auto_round.export.export_to_awq",+ ],+ ),+ "install_requires": fetch_requirements("requirements-hpu.txt"),+ },+}+if __name__ == "__main__":+ # There are two ways to install hpu-only package:+ # 1. pip install setup.py hpu.+ # 2. Within the gaudi docker where the HPU is available, we install the hpu package by default.+ cfg_key = "auto_round"+ if "hpu" in sys.argv:+ sys.argv.remove("hpu")+ cfg_key = "auto_round_hpu"+ if BUILD_HPU_ONLY:+ cfg_key = "auto_round_hpu"++ project_name = PKG_INSTALL_CFG[cfg_key].get("project_name")+ include_packages = PKG_INSTALL_CFG[cfg_key].get("include_packages", {})+ install_requires = PKG_INSTALL_CFG[cfg_key].get("install_requires", [])+ extras_require = PKG_INSTALL_CFG[cfg_key].get("extras_require", {})+setup(- name="auto_round",+ name=project_name,author="Intel AIPT Team",version=version,author_email="[email protected], [email protected]",@@ -179,10 +237,11 @@ if __name__ == "__main__":keywords="quantization,auto-around,LLM,SignRound",license="Apache 2.0",url="https://github.com/intel/auto-round",- packages=find_packages(),+ packages=include_packages,include_dirs=include_dirs,##include_package_data=False,- install_requires=fetch_requirements("requirements.txt"),+ install_requires=install_requires,+ extras_require=extras_require,python_requires=">=3.7.0",classifiers=["Intended Audience :: Science/Research",@@ -192,5 +251,5 @@ if __name__ == "__main__":],include_package_data=True,package_data={"": ["mllm/templates/*.json"]},- **additional_setup_kwargs+ **additional_setup_kwargs,)diff --git a/test/test_auto_round_hpu_only.py b/test/test_auto_round_hpu_only.pynew file mode 100644index 000000000..0e9e0680f--- /dev/null+++ b/test/test_auto_round_hpu_only.py@@ -0,0 +1,3 @@+def test_import():+ from auto_round import AutoRound+ from auto_round.export.export_to_itrex.export import save_quantized_as_itrex, WeightOnlyLinear\ No newline at end of filediff --git a/test/test_autoround_export_to_itrex.py b/test/test_autoround_export_to_itrex.pyindex e2b1fe1e5..502b4d2c6 100644--- a/test/test_autoround_export_to_itrex.py+++ b/test/test_autoround_export_to_itrex.py@@ -81,7 +81,7 @@ class TestAutoroundExport(unittest.TestCase):self.assertTrue(torch.all(torch.isclose(out4[0], out5[0], atol=1e-3)))def test_config(self):- from auto_round.export import QuantConfig+ from auto_round.export.export_to_itrex import QuantConfigconfig = QuantConfig.from_pretrained("TheBloke/Llama-2-7B-Chat-GPTQ")config.save_pretrained("quantization_config_dir")