Skip to content

Commit ced3b9c

Browse files
author
Griffin Adams
committed
Release of Cold Compress 1.0.
1 parent e2cfa34 commit ced3b9c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+6516
-2177
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ wandb
1313

1414
# downloaded by our tests
1515
original_model.py
16-
original_adapter.py
16+
original_adapter.py
17+
18+
.vscode
19+
20+
torch_compile_debug
21+
results

CODE_OF_CONDUCT.md

Lines changed: 0 additions & 76 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 0 additions & 32 deletions
This file was deleted.

DISCLAIMER.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Cold Compress Disclaimer & Attribution
2+
3+
This toolkit, "Cold Compress," is provided for research purposes only and is not intended for commercial use. It builds upon the open-source project GPT-Fast, which is copyright © 2023 Meta. The original source code from GPT-Fast is redistributed under the terms of its original BSD-style license, which permits use and redistribution with or without modification under the conditions listed in the license.
4+
5+
The Cold Compress toolkit includes additional code that is the original work of the contributors to this toolkit. All new contributions made specifically for the Cold Compress toolkit are subject to the same BSD-style license as the GPT-Fast project to maintain consistency and compliance with the original work's licensing terms.
6+
7+
Users of the Cold Compress toolkit should adhere to the following conditions:
8+
- Redistributions of the original source code must retain the copyright notice, this list of conditions, and the following disclaimer as provided by the GPT-Fast project.
9+
- Redistributions in binary form must reproduce the original copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution.
10+
- Neither the name of the Cold Compress toolkit nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11+
12+
THE COLD COMPRESS TOOLKIT IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION WITH THE TOOLKIT OR THE USE OR OTHER DEALINGS IN THE TOOLKIT.
13+
14+
By using the Cold Compress toolkit, you acknowledge and agree to the terms of this disclaimer.
15+
16+
-----------------------------
17+
Make sure to also include the license below in in a file named “LICENSE” in the root directory of your project repo.
18+
19+
## BSD 3-Clause License
20+
21+
```
22+
Copyright 2023 Meta
23+
24+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
25+
26+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
27+
28+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
29+
30+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
31+
32+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
```

GPTQ.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from eval import (
1717
setup_cache_padded_seq_input_pos_max_seq_length_for_prefill,
18-
GPTFastEvalWrapper
18+
GPTFastEvalWrapper,
1919
)
2020

2121

@@ -63,7 +63,6 @@ def __init__(
6363
)
6464
self.pad_calibration_inputs = False
6565

66-
6766
def add_input(self, args):
6867
if self.inputs is None:
6968
self.inputs = [MultiInput([arg]) for arg in args]
@@ -113,7 +112,6 @@ def _model_call(self, inps):
113112
)
114113

115114

116-
117115
class MultiInput:
118116
def __init__(self, inputs):
119117
self.values = list(inputs)
@@ -126,7 +124,9 @@ def __getitem__(self, slice):
126124
return MultiInput(self.values[slice])
127125

128126
def cuda(self):
129-
self.values = [val.cuda() if isinstance(val, torch.Tensor) else val for val in self.values]
127+
self.values = [
128+
val.cuda() if isinstance(val, torch.Tensor) else val for val in self.values
129+
]
130130

131131

132132
class GenericGPTQRunner(fx.Interpreter):
@@ -235,7 +235,12 @@ def tensors_to_cuda(args):
235235
)
236236
transposed_args = list(
237237
zip(
238-
*[x.values if isinstance(x, MultiInput) else [x] * multi_input_count for x in flat_args]
238+
*[
239+
x.values
240+
if isinstance(x, MultiInput)
241+
else [x] * multi_input_count
242+
for x in flat_args
243+
]
239244
)
240245
)
241246
else:
@@ -244,8 +249,8 @@ def tensors_to_cuda(args):
244249

245250
# check whether we apply GPTQ to this module
246251
quantize_linear = (
247-
(target == aten.linear.default) # if its a linear
248-
and id(args[1]) in self.id_to_name # and if we know the layer name
252+
(target == aten.linear.default) # if its a linear
253+
and id(args[1]) in self.id_to_name # and if we know the layer name
249254
and not skip_quant # and if we weren't told to skip quantization
250255
# and if the skip_layer_func doesn't say we should skip
251256
and not (self.skip_layer_func is not None and self.skip_layer_func(args[1]))
@@ -259,9 +264,7 @@ def tensors_to_cuda(args):
259264
inp = tensors_to_cuda(inp)
260265
cur_args, cur_kwargs = tree_unflatten(inp, spec)
261266

262-
if (
263-
quantize_linear
264-
): # calculate H instead of output (will run the linear eventually with updated weight)
267+
if quantize_linear: # calculate H instead of output (will run the linear eventually with updated weight)
265268
x = cur_args[0].float()
266269
shape = x.shape
267270
n = 1 if len(shape) == 2 else shape[0]
@@ -333,11 +336,14 @@ def SQNR(x, y):
333336
target, (args[0][:2], DQ2, *args[2:]), kwargs, skip_quant=True
334337
)
335338

336-
print("SQNR for output without GPTQ (should be less than above)",
337-
torch.cat([
339+
print(
340+
"SQNR for output without GPTQ (should be less than above)",
341+
torch.cat(
342+
[
338343
SQNR(old.cpu(), old_q.cpu()).unsqueeze(0)
339344
for (old, old_q) in zip(old_out.values, old_q_out.values)
340-
]).mean(),
345+
]
346+
).mean(),
341347
)
342348
return new_out
343349

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ Redistribution and use in source and binary forms, with or without modification,
88

99
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
1010

11-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)