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

[FIX] Batching of calibration data in .quantize() #70

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 7 additions & 3 deletions gptqmodel/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,18 @@ def _convert_tensor_to_list(tensor):
if not pad_token_id:
pad_token_id = self.config.eos_token_id

new_calibration_dataset = [
if pad_token_id is None:
raise ValueError("Calibration data requires model's `pad_token_id` or `eos_token_id` to be set: actual = `None`.")

new_calibration_dataset_batched = [
collate_data(new_calibration_dataset[start: start + batch_size], pad_token_id)
for start in range(0, len(new_calibration_dataset), batch_size)
]
for new_example in new_calibration_dataset:

for new_example in new_calibration_dataset_batched:
del new_example["labels"]

return new_calibration_dataset
return new_calibration_dataset_batched

@torch.inference_mode()
def quantize(
Expand Down
2 changes: 1 addition & 1 deletion gptqmodel/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def make_data_block(

def collate_data(blocks: List[Dict[str, List[List[int]]]], pad_token_id: int) -> Dict[str, LongTensor]:
def pad_block(block, pads):
return torch.cat((pads.to(block.device), block), dim=-1)
return torch.cat((block, pads.to(block.device)), dim=-1)

input_ids_blocks = [LongTensor(block["input_ids"]) for block in blocks]
attention_mask_blocks = [LongTensor(block["attention_mask"]) for block in blocks]
Expand Down
Loading