Skip to content

Commit

Permalink
Fix step iteration bug in finetuning scripts (#1794)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasbt authored Oct 21, 2024
1 parent 3ea3d93 commit e14e39f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion litgpt/finetune/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,13 @@ def fit(
total_lengths = 0
total_t0 = time.perf_counter()

while step_count < max_steps and train_iterator.epoch < train.epochs:
while step_count < max_steps:
iter_num += 1
iter_t0 = time.perf_counter()
batch = next(train_iterator)
if train_iterator.epoch >= train.epochs:
break

input_ids, targets = batch["input_ids"], batch["labels"]

is_accumulating = iter_num % train.gradient_accumulation_iters(devices) != 0
Expand Down
5 changes: 4 additions & 1 deletion litgpt/finetune/adapter_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,13 @@ def fit(
total_lengths = 0
total_t0 = time.perf_counter()

while step_count < max_steps and train_iterator.epoch < train.epochs:
while step_count < max_steps:
iter_num += 1
iter_t0 = time.perf_counter()
batch = next(train_iterator)
if train_iterator.epoch >= train.epochs:
break

input_ids, targets = batch["input_ids"], batch["labels"]

is_accumulating = iter_num % train.gradient_accumulation_iters(devices) != 0
Expand Down
4 changes: 3 additions & 1 deletion litgpt/finetune/full.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,12 @@ def fit(
)
fabric.barrier()

while state["step_count"] < max_steps and train_iterator.epoch < train.epochs:
while state["step_count"] < max_steps:
state["iter_num"] += 1
iter_t0 = time.perf_counter()
batch = next(train_iterator)
if train_iterator.epoch >= train.epochs:
break
input_ids, targets = batch["input_ids"], batch["labels"]

is_accumulating = state["iter_num"] % train.gradient_accumulation_iters(devices) != 0
Expand Down
4 changes: 3 additions & 1 deletion litgpt/finetune/lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,12 @@ def fit(
total_lengths = 0
total_t0 = time.perf_counter()

while step_count < max_steps and train_iterator.epoch < train.epochs:
while step_count < max_steps:
iter_num += 1
iter_t0 = time.perf_counter()
batch = next(train_iterator)
if train_iterator.epoch >= train.epochs:
break
input_ids, targets = batch["input_ids"], batch["labels"]

is_accumulating = iter_num % train.gradient_accumulation_iters(devices) != 0
Expand Down

0 comments on commit e14e39f

Please sign in to comment.