Skip to content

PTQ-Level Efficiency, QAT-Level Accuracy | 训练后量化的效率,量化感知训练的精度

rm unnecessary forward to improve speed (#593)

Wenhua Cheng23d40a0dceb6
diff --git a/auto_round/autoround.py b/auto_round/autoround.py
index 03acf72cc..76a5f9320 100644
--- a/auto_round/autoround.py
+++ b/auto_round/autoround.py
@@ -117,7 +117,7 @@ class AutoRound(object):
to_quant_block_names (str|list): A string or list whose elements are list of
block's layer names to be quantized.
enable_norm_bias_tuning (bool): Whether to enable fast norm/layer_bias tuning
- enable_torch_compile (bool): Whether to enable torch compile to optimize quant_block/layer, torch>=2.6 True.
+ enable_torch_compile (bool): Whether to enable torch compile to optimize quant_block/layer (default it False).
device_map (str|dict): device map for each block
Returns:
The quantized model.
@@ -1399,8 +1399,9 @@ class AutoRound(object):
device,
self.cache_device)
hook_handles = self.register_act_max_hook(block)
- self.get_block_outputs(block, q_input, input_others, self.batch_size * self.infer_bs_coeff,
- device, self.cache_device, save_output=False)
+ if hook_handles:
+ self.get_block_outputs(block, q_input, input_others, self.batch_size * self.infer_bs_coeff,
+ device, self.cache_device, save_output=False)
for handle in hook_handles:
handle.remove()
diff --git a/auto_round/script/mllm.py b/auto_round/script/mllm.py
index 768f7c394..621d974d1 100644
--- a/auto_round/script/mllm.py
+++ b/auto_round/script/mllm.py
@@ -370,7 +370,7 @@ def tune(args):
logger.warning(f"mixed precision exporting does not support {format} currently")
for n, m in model.named_modules():
- if isinstance(m, torch.nn.Linear) or isinstance(m, transformers.pytorch_utils.Conv1D):
+ if isinstance(m, (torch.nn.Linear, transformers.pytorch_utils.Conv1D)):
if m.weight.shape[0] % 32 != 0 or m.weight.shape[1] % 32 != 0:
layer_config[n] = {"bits": 32}
logger.info(