Skip to content
Merged
Show file tree
Hide file tree
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
fix layerwise woq forward
Signed-off-by: Kaihui-intel <[email protected]>
  • Loading branch information
Kaihui-intel committed Jun 26, 2024
commit 4ce74db461e8eb6d34462084e388b8ba113773a6
25 changes: 15 additions & 10 deletions neural_compressor/torch/algorithms/layer_wise/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
from accelerate.utils import set_module_tensor_to_device
from transformers import AutoConfig, AutoModelForCausalLM
from transformers.models.auto.auto_factory import _BaseAutoModelClass
from neural_compressor.torch.algorithms.weight_only.modules import WeightOnlyLinear

from neural_compressor.common import options

from .load import load

LWQ_WORKSPACE = os.path.join(options.workspace, "layer_wise_tmp")
LWQ_WORKSPACE = os.path.join(options.workspace, "lwq_tmpdir")


class QDQLayer(torch.nn.Module):
Expand Down Expand Up @@ -250,13 +251,17 @@ def hook(module, input):
state_dict = None
if os.path.exists(os.path.join(LWQ_WORKSPACE, f"{name}.pt")):
state_dict = torch.load(os.path.join(LWQ_WORKSPACE, f"{name}.pt"))
for n, p in module.named_parameters():
param_name = name + "." + n
if state_dict:
value = state_dict[n]
else:
value = load_value(model, param_name, path)
set_module_tensor_to_device(model, param_name, device, value)
if isinstance(module, WeightOnlyLinear):
for n, p in module._buffers.items():
setattr(module, n, state_dict[n])
else:
for n, p in module.named_parameters():
param_name = name + "." + n
if state_dict:
value = state_dict[n]
else:
value = load_value(model, param_name, path)
set_module_tensor_to_device(model, param_name, device, value)

return hook

Expand All @@ -278,13 +283,13 @@ def hook(module, input, output):
return handle


def clean_module_weight(module, woq_type=False):
def clean_module_weight(module):
if isinstance(module, QDQLayer):
submodule = module.module
else:
submodule = module

if woq_type is True:
if isinstance(module, WeightOnlyLinear):
for n, m in submodule._buffers.items():
old_value = getattr(submodule, n)
with torch.no_grad():
Expand Down
2 changes: 1 addition & 1 deletion neural_compressor/torch/algorithms/weight_only/rtn.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def convert(
from neural_compressor.torch.algorithms.layer_wise.utils import clean_module_weight

torch.save(new_module.state_dict(), os.path.join(lwq_workspace, f"{name}.pt"))
clean_module_weight(new_module, woq_type=True)
clean_module_weight(new_module)
clean_module_weight(m)
del m
gc.collect()
Expand Down