Skip to content

Commit

Permalink
adamround bugfix, refine import (#275)
Browse files Browse the repository at this point in the history
Signed-off-by: Zhang, Weiwei1 <[email protected]>
  • Loading branch information
WeiweiZhang1 authored Oct 12, 2024
1 parent 98a9c75 commit a633aa7
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 74 deletions.
147 changes: 76 additions & 71 deletions auto_round/autoround.py
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ class AutoOPTRound(AutoRound):
act_group_size (int): Group size for activation quantization. Default is None.
act_sym (bool): Whether to use symmetric activation quantization. Default is None.
act_dynamic (bool): Whether to use dynamic activation quantization. Default is True.
quant_block_list (list): A list whose elements are list of block's layer names to be quantized.
**kwargs: Additional keyword arguments.
Returns:
Expand Down Expand Up @@ -1418,44 +1418,46 @@ def __init__(
act_sym: bool = None,
act_dynamic: bool = True,
enable_norm_bias_tuning: bool = False,
quant_block_list: list = None,
optimizer="AdamW",
**kwargs,
):
super(AutoOPTRound, self).__init__(
model,
tokenizer,
bits,
group_size,
sym,
layer_config,
enable_full_range,
batch_size,
amp,
device,
lr_scheduler,
dataset,
enable_quanted_input,
enable_minmax_tuning,
lr,
minmax_lr,
low_gpu_mem_usage,
low_cpu_mem_usage,
iters,
seqlen,
nsamples,
sampler,
seed,
nblocks,
gradient_accumulate_steps,
not_use_best_mse,
dynamic_max_gap,
data_type,
scale_dtype,
act_bits,
act_group_size,
act_sym,
act_dynamic,
enable_norm_bias_tuning,
model=model,
tokenizer=tokenizer,
bits=bits,
group_size=group_size,
sym=sym,
layer_config=layer_config,
enable_full_range=enable_full_range,
batch_size=batch_size,
amp=amp,
device=device,
lr_scheduler=lr_scheduler,
dataset=dataset,
enable_quanted_input=enable_quanted_input,
enable_minmax_tuning=enable_minmax_tuning,
lr=lr,
minmax_lr=minmax_lr,
low_gpu_mem_usage=low_gpu_mem_usage,
low_cpu_mem_usage=low_cpu_mem_usage,
iters=iters,
seqlen=seqlen,
nsamples=nsamples,
sampler=sampler,
seed=seed,
nblocks=nblocks,
gradient_accumulate_steps=gradient_accumulate_steps,
not_use_best_mse=not_use_best_mse,
dynamic_max_gap=dynamic_max_gap,
data_type=data_type,
scale_dtype=scale_dtype,
act_bits=act_bits,
act_group_size=act_group_size,
act_sym=act_sym,
act_dynamic=act_dynamic,
enable_norm_bias_tuning=enable_norm_bias_tuning,
quant_block_list=quant_block_list,
**kwargs,
)

Expand Down Expand Up @@ -1544,7 +1546,7 @@ class AutoAdamRound(AutoOPTRound):
act_group_size (int): Group size for activation quantization. Default is None.
act_sym (bool): Whether to use symmetric activation quantization. Default is None.
act_dynamic (bool): Whether to use dynamic activation quantization. Default is True.
quant_block_list (list): A list whose elements are list of block's layer names to be quantized.
Returns:
The quantized model.
"""
Expand Down Expand Up @@ -1585,45 +1587,48 @@ def __init__(
act_sym: bool = None,
act_dynamic: bool = True,
enable_norm_bias_tuning: bool = False,
quant_block_list: list = None,
optimizer="AdamW",
**kwargs,
):
super(AutoAdamRound, self).__init__(
model,
tokenizer,
bits,
group_size,
sym,
layer_config,
enable_full_range,
batch_size,
amp,
device,
lr_scheduler,
dataset,
enable_quanted_input,
enable_minmax_tuning,
lr,
minmax_lr,
low_gpu_mem_usage,
low_cpu_mem_usage,
iters,
seqlen,
nsamples,
sampler,
seed,
nblocks,
gradient_accumulate_steps,
not_use_best_mse,
dynamic_max_gap,
data_type,
scale_dtype,
act_bits,
act_group_size,
act_sym,
act_dynamic,
enable_norm_bias_tuning,
optimizer,
model=model,
tokenizer=tokenizer,
bits=bits,
group_size=group_size,
sym=sym,
layer_config=layer_config,
enable_full_range=enable_full_range,
batch_size=batch_size,
amp=amp,
device=device,
lr_scheduler=lr_scheduler,
dataset=dataset,
enable_quanted_input=enable_quanted_input,
enable_minmax_tuning=enable_minmax_tuning,
lr=lr,
minmax_lr=minmax_lr,
low_gpu_mem_usage=low_gpu_mem_usage,
low_cpu_mem_usage=low_cpu_mem_usage,
iters=iters,
seqlen=seqlen,
nsamples=nsamples,
sampler=sampler,
seed=seed,
nblocks=nblocks,
gradient_accumulate_steps=gradient_accumulate_steps,
not_use_best_mse=not_use_best_mse,
dynamic_max_gap=dynamic_max_gap,
data_type=data_type,
scale_dtype=scale_dtype,
act_bits=act_bits,
act_group_size=act_group_size,
act_sym=act_sym,
act_dynamic=act_dynamic,
enable_norm_bias_tuning=enable_norm_bias_tuning,
quant_block_list=quant_block_list,
optimizer=optimizer,
**kwargs,
)


7 changes: 4 additions & 3 deletions auto_round/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,11 +891,11 @@ def get_library_version(library_name):
except pkg_resources.DistributionNotFound:
return f"{library_name} is not installed"
else:
import importlib_metadata # pylint: disable=E0401
import importlib.metadata # pylint: disable=E0401
try:
version = importlib_metadata.version(library_name)
version = importlib.metadata.version(library_name)
return version
except importlib_metadata.PackageNotFoundError:
except importlib.metadata.PackageNotFoundError:
return f"{library_name} is not installed"


Expand Down Expand Up @@ -972,3 +972,4 @@ def get_autogptq_packing_qlinear(backend, bits=4, group_size=128, sym=False):
)
return QuantLinear


0 comments on commit a633aa7

Please sign in to comment.