Skip to content

Commit

Permalink
Release of Cold Compress 1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Griffin Adams committed Jul 22, 2024
1 parent e2cfa34 commit ced3b9c
Show file tree
Hide file tree
Showing 68 changed files with 6,516 additions and 2,177 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ wandb

# downloaded by our tests
original_model.py
original_adapter.py
original_adapter.py

.vscode

torch_compile_debug
results
76 changes: 0 additions & 76 deletions CODE_OF_CONDUCT.md

This file was deleted.

32 changes: 0 additions & 32 deletions CONTRIBUTING.md

This file was deleted.

33 changes: 33 additions & 0 deletions DISCLAIMER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Cold Compress Disclaimer & Attribution

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.

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.

Users of the Cold Compress toolkit should adhere to the following conditions:
- 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.
- 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.
- 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.

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.

By using the Cold Compress toolkit, you acknowledge and agree to the terms of this disclaimer.

-----------------------------
Make sure to also include the license below in in a file named “LICENSE” in the root directory of your project repo.

## BSD 3-Clause License

```
Copyright 2023 Meta
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
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.
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.
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.
```
32 changes: 19 additions & 13 deletions GPTQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from eval import (
setup_cache_padded_seq_input_pos_max_seq_length_for_prefill,
GPTFastEvalWrapper
GPTFastEvalWrapper,
)


Expand Down Expand Up @@ -63,7 +63,6 @@ def __init__(
)
self.pad_calibration_inputs = False


def add_input(self, args):
if self.inputs is None:
self.inputs = [MultiInput([arg]) for arg in args]
Expand Down Expand Up @@ -113,7 +112,6 @@ def _model_call(self, inps):
)



class MultiInput:
def __init__(self, inputs):
self.values = list(inputs)
Expand All @@ -126,7 +124,9 @@ def __getitem__(self, slice):
return MultiInput(self.values[slice])

def cuda(self):
self.values = [val.cuda() if isinstance(val, torch.Tensor) else val for val in self.values]
self.values = [
val.cuda() if isinstance(val, torch.Tensor) else val for val in self.values
]


class GenericGPTQRunner(fx.Interpreter):
Expand Down Expand Up @@ -235,7 +235,12 @@ def tensors_to_cuda(args):
)
transposed_args = list(
zip(
*[x.values if isinstance(x, MultiInput) else [x] * multi_input_count for x in flat_args]
*[
x.values
if isinstance(x, MultiInput)
else [x] * multi_input_count
for x in flat_args
]
)
)
else:
Expand All @@ -244,8 +249,8 @@ def tensors_to_cuda(args):

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

if (
quantize_linear
): # calculate H instead of output (will run the linear eventually with updated weight)
if quantize_linear: # calculate H instead of output (will run the linear eventually with updated weight)
x = cur_args[0].float()
shape = x.shape
n = 1 if len(shape) == 2 else shape[0]
Expand Down Expand Up @@ -333,11 +336,14 @@ def SQNR(x, y):
target, (args[0][:2], DQ2, *args[2:]), kwargs, skip_quant=True
)

print("SQNR for output without GPTQ (should be less than above)",
torch.cat([
print(
"SQNR for output without GPTQ (should be less than above)",
torch.cat(
[
SQNR(old.cpu(), old_q.cpu()).unsqueeze(0)
for (old, old_q) in zip(old_out.values, old_q_out.values)
]).mean(),
]
).mean(),
)
return new_out

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Redistribution and use in source and binary forms, with or without modification,

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.

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.
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.
Loading

0 comments on commit ced3b9c

Please sign in to comment.