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

Add cpu only version #315

Merged
merged 18 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .azure-pipelines/scripts/ut/collect_log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ git fetch
git checkout main
rm -rf build dist *egg-info
echo y | pip uninstall auto_round
python setup.py bdist_wheel && rm -rf build && pip install dist/auto_round*.whl
pip install -r requirements.txt
pip install -vvv --no-build-isolation -e .[cpu]

coverage erase
cd /auto-round/log_dir
Expand Down
5 changes: 2 additions & 3 deletions .azure-pipelines/template/ut-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ steps:
- 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 install -vvv --no-build-isolation -e .[cpu] \
&& 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 install -vvv --no-build-isolation -e .[hpu] \
&& pip list"
displayName: "HPU Env Setup"

Expand Down
53 changes: 0 additions & 53 deletions .azure-pipelines/unit-test-hpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,56 +58,3 @@ stages:
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"
3 changes: 1 addition & 2 deletions .azure-pipelines/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ stages:
echo "--- collect logs ---"
docker exec collectLogs 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 install -vvv --no-build-isolation -e .[cpu] \
&& pip list"
docker exec collectLogs /bin/bash +x -c "cd /auto-round/.azure-pipelines/scripts \
&& bash ut/collect_log.sh"
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.vs
.vscode
__pycache__
auto_round.egg-info/
*.egg-info/
build/*
.eggs/
dist/
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,29 @@ more accuracy data and recipes across various models.
### Build from Source

```bash
pip install -r requirements.txt

# GPU
pip install -vvv --no-build-isolation -e .

# CPU
pip install -vvv --no-build-isolation -e .[cpu]

# HPU
pip install -vvv --no-build-isolation -e .[hpu]
```

### Install from pypi

```bash
# GPU
pip install auto-round

# CPU
pip install auto-round[cpu]

# HPU
pip install auto-round[hpu]
```

## Model Quantization
Expand Down
18 changes: 18 additions & 0 deletions requirements-cpu.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
accelerate
datasets
py-cpuinfo
sentencepiece
torch
transformers>=4.38
triton
numpy < 2.0
threadpoolctl
lm-eval>=0.4.2,<=0.4.5
tqdm
packaging
auto-gptq>=0.7.1
pillow
numba
tbb
intel-extension-for-pytorch
intel-extension-for-transformers
57 changes: 18 additions & 39 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,53 +181,32 @@ def detect_local_sm_architectures():
}

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"),
"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"),
"cpu": fetch_requirements("requirements-cpu.txt"),
},
}

if __name__ == "__main__":
# There are two ways to install hpu-only package:
# 1. pip install setup.py hpu.
# 1. pip install -vvv --no-build-isolation -e .[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", {})

include_packages = PKG_INSTALL_CFG.get("include_packages", {})
install_requires = PKG_INSTALL_CFG.get("install_requires", [])
extras_require = PKG_INSTALL_CFG.get("extras_require", {})

setup(
name=project_name,
name="auto_round",
author="Intel AIPT Team",
version=version,
author_email="[email protected], [email protected]",
Expand Down
9 changes: 7 additions & 2 deletions test/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ def test_autoround_format(self):
return

from auto_round.auto_quantizer import AutoHfQuantizer
model = AutoModelForCausalLM.from_pretrained(quantized_model_path, device_map="auto")
device = "auto" ##cpu, hpu, cuda
from auto_round import AutoRoundConfig
quantization_config = AutoRoundConfig(
backend=device
)
model = AutoModelForCausalLM.from_pretrained(quantized_model_path, device_map=device, quantization_config=quantization_config)
tokenizer = AutoTokenizer.from_pretrained(quantized_model_path)
text = "There is a girl who likes adventure,"
inputs = tokenizer(text, return_tensors="pt").to(model.device)
Expand Down Expand Up @@ -215,4 +220,4 @@ def test_autoawq_format(self):
# inputs = tokenizer(text, return_tensors="pt").to(model.device)
# print(tokenizer.decode(model.generate(**inputs, max_new_tokens=50)[0]))
# shutil.rmtree("./saved", ignore_errors=True)
#
#
4 changes: 2 additions & 2 deletions test/test_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_llm_generation_asym_qbits(self):
text = "There is a girl who likes adventure,"
inputs = tokenizer(text, return_tensors="pt").to(model.device)
res = tokenizer.decode(model.generate(**inputs, max_new_tokens=50)[0])
assert (
res == """</s>There is a girl who likes adventure, and I'm not sure if she's into it, but I'm sure she's into it.\nI'm not sure if she's into adventure, but I'm sure she's into it.\nI'm not sure if she's into adventure""")
assert ("!!!" not in res)



Loading