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

Port torch GPTQ to 3.x #1408

Merged
merged 30 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4a1735a
rename rtn_quantize to weight_only_algos
yiliu30 Nov 21, 2023
4cbcdde
copied gpt into 3.x
yiliu30 Nov 21, 2023
814a3f4
add gptq entry (WIP)
yiliu30 Nov 21, 2023
fd3d27f
add gptq config
yiliu30 Nov 22, 2023
5009c52
port gptq
yiliu30 Nov 22, 2023
cb1f48b
add args palceholder for double quant
yiliu30 Nov 22, 2023
4233e9d
clean entry
yiliu30 Nov 22, 2023
928304c
Merge branch 'master' into gptq
yiliu30 Nov 22, 2023
102b950
fixed the import issue of lwq
yiliu30 Nov 22, 2023
49ef348
clean entry
yiliu30 Nov 22, 2023
219e02b
complete gptq config
yiliu30 Nov 23, 2023
5fb6e31
Merge branch 'master' into gptq
yiliu30 Nov 23, 2023
8a7b571
add UTs
yiliu30 Nov 24, 2023
88e709a
add more UTs for GPTQ
yiliu30 Nov 24, 2023
a5c6427
remove attrs for double quant
yiliu30 Nov 24, 2023
af82d64
clean code
yiliu30 Nov 24, 2023
9980d88
add more UTs
yiliu30 Nov 24, 2023
aa4e8d8
revert change
yiliu30 Nov 24, 2023
9fbafa9
remove lwy
yiliu30 Nov 24, 2023
5e0910a
print itrex commit
chensuyue Nov 24, 2023
8e89da9
Merge branch 'ly/gptq_3x' of https://github.com/intel/neural-compress…
yiliu30 Nov 24, 2023
7596137
remove calib_dataloader
yiliu30 Nov 24, 2023
1f02346
rename calib_func to run_fn, calib_func_args to run_args
yiliu30 Nov 24, 2023
c6ee04a
Merge branch 'master' into ly/gptq_3x
chensuyue Nov 25, 2023
42a07d9
refactor gptq
yiliu30 Nov 26, 2023
a209074
Merge branch 'ly/gptq_3x' of https://github.com/intel/neural-compress…
yiliu30 Nov 26, 2023
e913b04
add UTs
yiliu30 Nov 26, 2023
b6a57ce
fix ut
yiliu30 Nov 26, 2023
ac0aeea
add more UTs
yiliu30 Nov 27, 2023
d78fd78
remove unused test
yiliu30 Nov 27, 2023
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
34 changes: 22 additions & 12 deletions neural_compressor/common/base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,16 @@ def from_dict(cls, config_dict, str2operator=None):
Returns:
The constructed config.
"""
config = cls(**config_dict.get(GLOBAL, {}))
operator_config = config_dict.get(LOCAL, {})
if operator_config:
for op_name, op_config in operator_config.items():
config.set_local(op_name, cls(**op_config))
return config
if GLOBAL not in config_dict and LOCAL not in config_dict:
config = cls(**config_dict)
return config
else:
config = cls(**config_dict.get(GLOBAL, {}))
operator_config = config_dict.get(LOCAL, {})
if operator_config:
for op_name, op_config in operator_config.items():
config.set_local(op_name, cls(**op_config))
return config

@classmethod
def to_diff_dict(cls, instance) -> Dict[str, Any]:
Expand Down Expand Up @@ -201,11 +205,11 @@ def to_config_mapping(
global_config = config.global_config
op_type_config_dict, op_name_config_dict = config._get_op_name_op_type_config()
for op_name, op_type in model_info:
config_mapping.setdefault(op_type, OrderedDict())[op_name] = global_config
config_mapping[(op_type, op_name)] = global_config
if op_type in op_type_config_dict:
config_mapping[op_type][op_name] = op_name_config_dict[op_type]
config_mapping[(op_type, op_name)] = op_name_config_dict[op_type]
if op_name in op_name_config_dict:
config_mapping[op_type][op_name] = op_name_config_dict[op_name]
config_mapping[(op_type, op_name)] = op_name_config_dict[op_name]
return config_mapping

@staticmethod
Expand Down Expand Up @@ -234,9 +238,15 @@ def to_dict(self, params_list=[], operator2str=None):
return result

@classmethod
def from_dict(cls, config_dict, str2operator=None):
# TODO(Yi)
pass
def from_dict(cls, config_dict: OrderedDict[str, Dict], config_registry: Dict[str, BaseConfig]):
assert len(config_dict) >= 1, "The config dict must include at least one configuration."
num_configs = len(config_dict)
name, value = next(iter(config_dict.items()))
config = config_registry[name].from_dict(value)
for _ in range(num_configs - 1):
name, value = next(iter(config_dict.items()))
config += config_registry[name].from_dict(value)
return config

def to_json_string(self, use_diff: bool = False) -> str:
return json.dumps(self.to_dict(), indent=2) + "\n"
Expand Down
1 change: 1 addition & 0 deletions neural_compressor/common/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
BASE_CONFIG = "base_config"
COMPOSABLE_CONFIG = "composable_config"
RTN_WEIGHT_ONLY_QUANT = "rtn_weight_only_quant"
GPTQ = "gptq"
DUMMY_CONFIG = "dummy_config"
4 changes: 3 additions & 1 deletion neural_compressor/torch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
# limitations under the License.

from neural_compressor.torch.utils import register_algo
from neural_compressor.torch.algorithms import rtn_quantize_entry
from neural_compressor.torch.algorithms import rtn_quantize_entry, gptq_quantize_entry

from neural_compressor.torch.quantization import (
quantize,
RTNWeightQuantConfig,
get_default_rtn_config,
DummyConfig,
get_default_dummy_config,
GPTQConfig,
get_default_gptq_config,
)
3 changes: 2 additions & 1 deletion neural_compressor/torch/algorithms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
# limitations under the License.


from neural_compressor.torch.algorithms.rtn_quantize import rtn_quantize_entry
from neural_compressor.torch.algorithms.weight_only_algos import rtn_quantize_entry
from neural_compressor.torch.algorithms.weight_only_algos import gptq_quantize_entry
Loading
Loading