Skip to content
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
8 changes: 7 additions & 1 deletion tico/quantization/recipes/data/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ def build_wikitext_calibration_inputs(

random.seed(seed)
samples: list[torch.Tensor] = []
bos = getattr(tokenizer, "bos_token_id", None)
for _ in range(n_samples):
i = random.randint(0, token_ids.shape[1] - seq_len - 1)
samples.append(token_ids[:, i : i + seq_len].cpu())
w = token_ids[:, i : i + seq_len]
if bos is not None:
w = torch.cat(
[torch.tensor([[bos]], device=w.device), w[:, : seq_len - 1]], dim=1
)
samples.append(w.cpu())
return samples
Original file line number Diff line number Diff line change
Expand Up @@ -1295,10 +1295,16 @@ def build_calibration_inputs(

random.seed(args.seed)
calib_inputs = []
bos = getattr(tokenizer, "bos_token_id", None)
for _ in range(nsamples):
i = random.randint(0, train_ids.shape[1] - seqlen - 1)
j = i + seqlen
calib_inputs.append(train_ids[:, i:j].cpu())
w = train_ids[:, i : i + seqlen].cpu()
if bos is not None:
w = torch.cat(
[torch.tensor([[bos]], device=w.device), w[:, : seqlen - 1]], dim=1
)

calib_inputs.append(w)

return calib_inputs

Expand Down
Loading