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

Support LayerWise for RTN/GPTQ #1883

Merged
merged 42 commits into from
Jul 16, 2024
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4cf0620
support rtn & gptq(draft)
Kaihui-intel Jun 25, 2024
a1d9e10
clean code
Kaihui-intel Jun 25, 2024
b4e93f3
clean gptq
Kaihui-intel Jun 25, 2024
a3a061e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 25, 2024
02ee1f8
del unused line
Kaihui-intel Jun 25, 2024
060ea50
fix load import
Kaihui-intel Jun 26, 2024
1a60731
fix rtn model_path
Kaihui-intel Jun 26, 2024
04e1923
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 26, 2024
8f27d47
update rtn model
Kaihui-intel Jun 26, 2024
263c581
Merge branch 'kaihui/lw' of https://github.com/intel/neural-compresso…
Kaihui-intel Jun 26, 2024
5a3f090
fix clean module
Kaihui-intel Jun 26, 2024
14bd733
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 26, 2024
4ce74db
fix layerwise woq forward
Kaihui-intel Jun 26, 2024
199fe4c
Merge branch 'kaihui/lw' of https://github.com/intel/neural-compresso…
Kaihui-intel Jun 26, 2024
b700d39
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 26, 2024
96d0e05
fix import
Kaihui-intel Jun 26, 2024
4337eac
Merge branch 'kaihui/lw' of https://github.com/intel/neural-compresso…
Kaihui-intel Jun 26, 2024
7b2d326
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 26, 2024
77cde5c
update clean module & add timestep
Jul 3, 2024
6cf8ff3
add numba pack
Jul 11, 2024
0e388c0
mimor fix numba
Jul 11, 2024
b0ccd62
apply mask
Jul 11, 2024
0f7de68
support gptq
Jul 11, 2024
83c6a9b
keep q_model in memory
Jul 12, 2024
483c219
merge master
Jul 12, 2024
c543783
fix master conflict
Jul 12, 2024
159aa34
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 12, 2024
809c0fb
update numba requirements_pt
Jul 12, 2024
308c7fc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 12, 2024
5d80e9b
fix awq config
Jul 12, 2024
c4af344
remove pack_with_reshpe
Jul 12, 2024
e99ee19
recover ar
Jul 12, 2024
1dd01a0
revert eg
Jul 12, 2024
8dbf793
install py 3x deps
chensuyue Jul 12, 2024
0ea77fd
enhance import&add pack ut
Kaihui-intel Jul 16, 2024
eec87ac
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 16, 2024
36a4a29
add pack ut file
Kaihui-intel Jul 16, 2024
86008f4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 16, 2024
93a86f2
move load_empty_model to torch.utils
Kaihui-intel Jul 16, 2024
19b1c4d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 16, 2024
f17c640
remove torch import
Kaihui-intel Jul 16, 2024
fa39f6f
fix ut import
Kaihui-intel Jul 16, 2024
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
Prev Previous commit
Next Next commit
clean gptq
Signed-off-by: Kaihui-intel <kaihui.tang@intel.com>
Kaihui-intel committed Jun 25, 2024
commit b4e93f3625d240ff93e7e143c5739d2ed9c88d08
12 changes: 0 additions & 12 deletions neural_compressor/torch/algorithms/weight_only/gptq.py
Original file line number Diff line number Diff line change
@@ -573,18 +573,6 @@ def tmp(_, inp, out):
set_module_tensor_to_device,
)

# sub_layer = sub_layers[layer_name]
# full_layer_name = self.get_full_layer_name(layer_name, block_idx)
# for n, p in sub_layer.named_parameters():
# param_name = full_layer_name + "." + n
# # breakpoint()
# if n == "weight":
# set_module_tensor_to_device(self.model, param_name, self.device, Q)
# else:
# value = load_value(self.model, param_name, model_path)
# set_module_tensor_to_device(self.model, param_name, self.device, value)
# sub_layer.weight.data = Q
# torch.save(sub_layer.state_dict(), LWQ_WORKSPACE + f"/{full_layer_name}.pt")
torch.save(new_module.state_dict(), LWQ_WORKSPACE + f"/{full_layer_name}.pt")
clean_module_weight(new_module)
del Q
13 changes: 6 additions & 7 deletions test/3x/torch/quantization/weight_only/test_gptq.py
Original file line number Diff line number Diff line change
@@ -28,10 +28,8 @@ def run_fn(model):
# GPTQ uses ValueError to reduce computation when collecting input data of the first block
# It's special for UTs, no need to add this wrapper in examples.
with pytest.raises(ValueError):
# model(torch.tensor([[10, 20, 30]], dtype=torch.long).to(device))
# model(torch.tensor([[40, 50, 60]], dtype=torch.long).to(device))
model(torch.tensor([[10, 20, 30]], dtype=torch.long))
model(torch.tensor([[40, 50, 60]], dtype=torch.long))
model(torch.tensor([[10, 20, 30]], dtype=torch.long).to(device))
model(torch.tensor([[40, 50, 60]], dtype=torch.long).to(device))


class TestGPTQQuant:
@@ -182,14 +180,15 @@ def test_layer_wise(self):
q_label = model(self.example_inputs)[0]

from neural_compressor.torch.algorithms.layer_wise import load_empty_model
model = load_empty_model("hf-internal-testing/tiny-random-GPTJForCausalLM", torchscript=True)

model = load_empty_model("hf-internal-testing/tiny-random-GPTJForCausalLM")

quant_config = GPTQConfig(
use_layer_wise=True,
model_path="hf-internal-testing/tiny-random-GPTJForCausalLM"
)
model = quantize(model, quant_config, run_fn=run_fn)
model = prepare(model, quant_config)
run_fn(model)
model = convert(model)
out = model(self.example_inputs)[0]
assert torch.equal(out, q_label), "use_layer_wise=True output should be same. Please double check."