From 232d6c9f7ae0106b3059bf94d19adffa5fcb0945 Mon Sep 17 00:00:00 2001 From: LRL2-ModelCloud Date: Thu, 16 Oct 2025 14:35:53 +0800 Subject: [PATCH] not log token numbers if not support batch --- gptqmodel/models/base.py | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/gptqmodel/models/base.py b/gptqmodel/models/base.py index 4a1437e62..bfffa308c 100644 --- a/gptqmodel/models/base.py +++ b/gptqmodel/models/base.py @@ -735,29 +735,31 @@ def _maybe_resolve_length(value, source_name): collate_data(sorted_dataset[start: start + batch_size], self.tokenizer.pad_token_id) for start in range(0, len(sorted_dataset), batch_size) ] - else: - new_calibration_dataset_batched = [ - {"input_ids": torch.tensor(block["input_ids"], dtype=torch.long)} - for block in sorted_dataset - ] - # total tokens counters - total_padded = 0 - total_non_padded = 0 + # total tokens counters + total_padded = 0 + total_non_padded = 0 - for batch in new_calibration_dataset_batched: - # attention_mask is shape [batch_size, seq_len] - mask = batch["attention_mask"] + for batch in new_calibration_dataset_batched: + # attention_mask is shape [batch_size, seq_len] + mask = batch["attention_mask"] - # count where mask == 0 (padded tokens) - total_padded += (mask == 0).sum().item() + # count where mask == 0 (padded tokens) + total_padded += (mask == 0).sum().item() - # count where mask == 1 (non-padded tokens) - total_non_padded += (mask == 1).sum().item() + # count where mask == 1 (non-padded tokens) + total_non_padded += (mask == 1).sum().item() - log.info(f"Calibration: Total padded tokens: {total_padded}") - log.info(f"Calibration: Total non-padded tokens: {total_non_padded}") - log.info(f"Calibration: Total tokens: {total_non_padded + total_padded}") + log.info(f"Calibration: Total padded tokens: {total_padded}") + log.info(f"Calibration: Total non-padded tokens: {total_non_padded}") + log.info(f"Calibration: Total tokens: {total_non_padded + total_padded}") + else: + new_calibration_dataset_batched = [ + { + "input_ids": torch.tensor(block["input_ids"], dtype=torch.long), + } + for block in sorted_dataset + ] return new_calibration_dataset_batched