Skip to content

Commit

Permalink
add optimization for group-by-len (#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
winglian authored Sep 13, 2023
1 parent e625338 commit 60c32b0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/axolotl/utils/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,14 @@ def create_scheduler(


def add_position_ids(sample):
sample_len = len(sample["input_ids"])
sample["position_ids"] = torch.arange(len(sample["input_ids"]))
sample["length"] = sample_len
return sample


def add_length(sample):
sample["length"] = len(sample["input_ids"])
return sample


Expand All @@ -382,6 +389,9 @@ def process_datasets_for_packing(cfg, train_dataset, eval_dataset):
if eval_dataset:
eval_dataset = eval_dataset.filter(drop_long, num_proc=os.cpu_count())

if cfg.group_by_length:
train_dataset = train_dataset.map(add_length, num_proc=os.cpu_count())

if cfg.sample_packing:
train_dataset = train_dataset.map(add_position_ids, num_proc=os.cpu_count())
if eval_dataset:
Expand Down

0 comments on commit 60c32b0

Please sign in to comment.