Skip to content

Commit e3359eb

Browse files
committed
Merge remote-tracking branch 'origin' into kylesayrs/reduce-quantized-compression-memory
2 parents 37da099 + ed3ac7c commit e3359eb

File tree

16 files changed

+272
-135
lines changed

16 files changed

+272
-135
lines changed

.github/workflows/build-test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ on:
2121
build_label:
2222
description: "requested runner label for build (specifies instance)"
2323
type: string
24-
default: ubuntu-24.04
24+
default: ubuntu-22.04
2525

2626
# test related parameters
2727
test_configs:
@@ -67,6 +67,7 @@ jobs:
6767

6868
REPORT:
6969
needs: [BUILD, TEST]
70+
if: success() || failure()
7071
uses: ./.github/workflows/report.yml
7172
with:
7273
label: rh-reporter

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ jobs:
7070
id: checkout
7171
uses: actions/checkout@v4
7272
with:
73+
fetch-depth: 0
74+
fetch-tags: true
7375
ref: ${{ inputs.gitref }}
7476

7577
- name: build
7678
id: build
77-
uses: neuralmagic/nm-actions/actions/build-ml-whl@v1.12.0
79+
uses: neuralmagic/nm-actions/actions/build-ml-whl@v1.18.0
7880
with:
7981
dev: false
8082
release: ${{ inputs.wf_category == 'RELEASE' }}

.github/workflows/upload.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,28 +97,36 @@ jobs:
9797
run_id: ${{ inputs.run_id }}
9898
asset_identifier: 'compressed*.whl'
9999

100+
- name: check if whl is new
101+
id: check-whl
102+
uses: neuralmagic/nm-actions/actions/check-whl-on-pypi@v1.19.0
103+
with:
104+
whl: ${{ steps.find-asset-whl.outputs.asset }}
105+
100106
- name: upload whl to "nm-pypi"
101-
if: ${{ inputs.push_to_pypi }}
107+
if: ${{ steps.check-whl.outputs.status == '0' && inputs.push_to_pypi }}
102108
uses: neuralmagic/nm-actions/actions/gcp-upload-asset@v1.1.0
103109
with:
104110
bucket_target: ${{ secrets.GCP_NM_PYPI_DIST }}
105111
asset: ${{ steps.find-asset-whl.outputs.asset }}
106112

107113
- name: find tar.gz
114+
if: ${{ steps.check-whl.outputs.status == '0' && inputs.push_to_pypi }}
108115
id: find-asset-targz
109116
uses: neuralmagic/nm-actions/actions/find-asset@v1.1.0
110117
with:
111118
run_id: ${{ inputs.run_id }}
112119
asset_identifier: 'compressed*.tar.gz'
113120

114121
- name: upload tar.gz to "nm-pypi"
115-
if: ${{ inputs.push_to_pypi }}
122+
if: ${{ steps.check-whl.outputs.status =='0' && inputs.push_to_pypi }}
116123
uses: neuralmagic/nm-actions/actions/gcp-upload-asset@v1.1.0
117124
with:
118125
bucket_target: ${{ secrets.GCP_NM_PYPI_DIST }}
119126
asset: ${{ steps.find-asset-targz.outputs.asset }}
120127

121128
- name: update "nm-pypi" index
129+
if: ${{ steps.check-whl.outputs.status == '0' && inputs.push_to_pypi }}
122130
uses: actions/github-script@v6
123131
with:
124132
github-token: ${{ secrets.NM_PYPI_WORKFLOW }}
@@ -133,7 +141,7 @@ jobs:
133141
134142
# publish the wheel file to public pypi
135143
- name: push wheel to pypi.org
136-
if: ${{ inputs.push_to_pypi }}
144+
if: ${{ steps.check-whl.outputs.status == '0' && inputs.push_to_pypi }}
137145
uses: neuralmagic/nm-actions/actions/publish-whl@v1.0.0
138146
with:
139147
username: ${{ secrets.PYPI_PUBLIC_USER }}
@@ -142,7 +150,7 @@ jobs:
142150

143151
# publish the tar.gz file to public pypi
144152
- name: push wheel to pypi.org
145-
if: ${{ inputs.push_to_pypi }}
153+
if: ${{ steps.check-whl.outputs.status == '0' && inputs.push_to_pypi }}
146154
uses: neuralmagic/nm-actions/actions/publish-whl@v1.0.0
147155
with:
148156
username: ${{ secrets.PYPI_PUBLIC_USER }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ share/python-wheels/
2525
.installed.cfg
2626
*.egg
2727
MANIFEST
28+
src/compressed_tensors/version.py
2829

2930
# PyInstaller
3031
# Usually these files are written by a python script from a template

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.PHONY: build docs test
22

3-
BUILD_ARGS := # set nightly to build nightly release
3+
BUILD_TYPE ?= dev # set nightly to build nightly release
44
PYCHECKDIRS := src tests
55
PYCHECKGLOBS := 'src/**/*.py' 'tests/**/*.py' 'utils/**/*.py' 'examples/**/*.py' setup.py
66
# run checks on all files for the repo
@@ -28,10 +28,10 @@ test:
2828
# creates wheel file
2929
build:
3030
@echo "Building the wheel for the repository";
31-
python3 setup.py sdist bdist_wheel $(BUILD_ARGS);
31+
BUILD_TYPE=$(BUILD_TYPE) python3 setup.py sdist bdist_wheel;
3232

3333
# clean package
3434
clean:
3535
@echo "Cleaning up";
3636
rm -rf .pytest_cache;
37-
find $(PYCHECKDIRS) | grep -E "(__pycache__|\.pyc|\.pyo)" | xargs rm -rf;
37+
find $(PYCHECKDIRS) | grep -E "(__pycache__|\.pyc|\.pyo)" | xargs rm -rf;

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pip install compressed-tensors
3131

3232
Nightly release:
3333
```bash
34-
pip install compressed-tensors-nightly
34+
pip install --pre compressed-tensors
3535
```
3636

3737
### From Source

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
[build-system]
2+
requires = ["setuptools", "wheel", "setuptools_scm>8"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.setuptools_scm]
6+
version_file = "src/compressed_tensors/version.py"
7+
18
[tool.black]
29
line-length = 88
310
target-version = ['py36']

setup.py

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,50 +17,66 @@
1717
from typing import List, Dict, Tuple
1818

1919

20-
def get_release_and_version(package_path: str) -> Tuple[bool, bool, str, str, str, str]:
21-
"""
22-
Load version and release info from compressed-tensors package
23-
"""
24-
# compressed-tensors/src/compressed_tensors/version.py always exists, default source of truth
25-
version_path = os.path.join(package_path, "version.py")
26-
27-
# exec() cannot set local variables so need to manually
28-
locals_dict = {}
29-
exec(open(version_path).read(), globals(), locals_dict)
30-
is_release = locals_dict.get("is_release", False)
31-
version = locals_dict.get("version", "unknown")
32-
version_major = locals_dict.get("version_major", "unknown")
33-
version_minor = locals_dict.get("version_minor", "unknown")
34-
version_bug = locals_dict.get("version_bug", "unknown")
35-
36-
print(f"Loaded version {version} from {version_path}")
37-
38-
return (
39-
is_release,
40-
version,
41-
version_major,
42-
version_minor,
43-
version_bug,
20+
# Set the build type using an environment variable to give us
21+
# different package names based on the reason for the build.
22+
VALID_BUILD_TYPES = {"release", "nightly", "dev"}
23+
BUILD_TYPE = os.environ.get("BUILD_TYPE", "dev")
24+
if BUILD_TYPE not in VALID_BUILD_TYPES:
25+
raise ValueError(
26+
f"Unsupported build type {BUILD_TYPE!r}, must be one of {VALID_BUILD_TYPES}"
4427
)
4528

29+
from setuptools_scm import ScmVersion
30+
31+
def version_func(version: ScmVersion) -> str:
32+
from setuptools_scm.version import guess_next_version
33+
34+
if BUILD_TYPE == "nightly":
35+
# Nightly builds use alpha versions to ensure they are marked
36+
# as pre-releases on pypi.org.
37+
return version.format_next_version(
38+
guess_next=guess_next_version,
39+
fmt="{guessed}.a{node_date:%Y%m%d}",
40+
)
41+
42+
if (
43+
BUILD_TYPE == "release"
44+
and not version.dirty
45+
and (version.exact or version.node is None)
46+
):
47+
# When we have a tagged version, use that without modification.
48+
return version.format_with("{tag}")
49+
50+
# In development mode or when the local repository is dirty, treat
51+
# it is as local development version.
52+
return version.format_next_version(
53+
guess_next=guess_next_version,
54+
fmt="{guessed}.dev{distance}",
55+
)
4656

47-
package_path = os.path.join(
48-
os.path.dirname(os.path.realpath(__file__)), "src", "compressed_tensors"
49-
)
50-
(
51-
is_release,
52-
version,
53-
version_major,
54-
version_minor,
55-
version_bug,
56-
) = get_release_and_version(package_path)
5757

58-
version_nm_deps = f"{version_major}.{version_minor}.0"
58+
def localversion_func(version: ScmVersion) -> str:
59+
from setuptools_scm.version import get_local_node_and_date
60+
61+
# When we are building nightly versions, we guess the next release
62+
# and add the date as an alpha version. We cannot publish packages
63+
# with local versions, so we do not add one.
64+
if BUILD_TYPE == "nightly":
65+
return ""
66+
67+
# When we have an exact tag, with no local changes, do not append
68+
# anything to the local version field.
69+
if (
70+
BUILD_TYPE == "release"
71+
and not version.dirty
72+
and (version.exact or version.node is None)
73+
):
74+
return ""
5975

60-
if is_release:
61-
_PACKAGE_NAME = "compressed-tensors"
62-
else:
63-
_PACKAGE_NAME = "compressed-tensors-nightly"
76+
# In development mode or when the local repository is dirty,
77+
# return a string that includes the git SHA (node) and a date,
78+
# formatted as a local version tag.
79+
return get_local_node_and_date(version)
6480

6581

6682
def _setup_long_description() -> Tuple[str, str]:
@@ -81,8 +97,11 @@ def _setup_extras() -> Dict:
8197
}
8298

8399
setup(
84-
name=_PACKAGE_NAME,
85-
version=version,
100+
name="compressed-tensors",
101+
use_scm_version={
102+
"version_scheme": version_func,
103+
"local_scheme": localversion_func,
104+
},
86105
author="Neuralmagic, Inc.",
87106
author_email="support@neuralmagic.com",
88107
license="Apache 2.0",

src/compressed_tensors/compressors/quantized_compressors/base.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import torch
2020
from compressed_tensors.compressors.base import BaseCompressor
21-
from compressed_tensors.quantization import QuantizationScheme
21+
from compressed_tensors.quantization import QuantizationStrategy
2222
from compressed_tensors.utils import (
2323
get_nested_mappings_from_state_dict,
2424
get_nested_weight_mappings,
@@ -134,6 +134,17 @@ def compress(
134134

135135
return compressed_dict
136136

137+
def _check_if_zp_pack_quantized(self, quant_args):
138+
from compressed_tensors.compressors import PackedQuantizationCompressor
139+
140+
if isinstance(self, PackedQuantizationCompressor):
141+
if not quant_args.symmetric and quant_args.strategy in [
142+
QuantizationStrategy.GROUP.value,
143+
QuantizationStrategy.CHANNEL.value,
144+
]:
145+
return True
146+
return False
147+
137148
def decompress(
138149
self,
139150
path_to_model_or_tensors: Union[str, Path, Dict[str, Any]],

0 commit comments

Comments
 (0)