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

add retry when loss is NaN in train and finetune #672

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 8 additions & 6 deletions federatedscope/core/trainers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,10 @@ def _run_routine(self, mode, hooks_set, dataset_name=None):
return self.ctx.num_samples

@lifecycle(LIFECYCLE.EPOCH)
def _run_epoch(self, hooks_set):
for epoch_i in range(
getattr(self.ctx, f"num_{self.ctx.cur_split}_epoch")):
def _run_epoch(self, hooks_set, run_step=-1):
if run_step == -1:
run_step = getattr(self.ctx, f"num_{self.ctx.cur_split}_epoch")
for epoch_i in range(run_step):
self.ctx.cur_epoch_i = CtxVar(epoch_i, "epoch")

for hook in hooks_set["on_epoch_start"]:
Expand All @@ -293,9 +294,10 @@ def _run_epoch(self, hooks_set):
hook(self.ctx)

@lifecycle(LIFECYCLE.BATCH)
def _run_batch(self, hooks_set):
for batch_i in range(
getattr(self.ctx, f"num_{self.ctx.cur_split}_batch")):
def _run_batch(self, hooks_set, run_step=-1):
if run_step == -1:
run_step = getattr(self.ctx, f"num_{self.ctx.cur_split}_batch")
for batch_i in range(run_step):
self.ctx.cur_batch_i = CtxVar(batch_i, LIFECYCLE.BATCH)

for hook in hooks_set["on_batch_start"]:
Expand Down
7 changes: 6 additions & 1 deletion federatedscope/llm/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from federatedscope.register import register_trainer
from federatedscope.core.trainers import GeneralTorchTrainer
from federatedscope.core.trainers.context import CtxVar
from federatedscope.core.trainers.enums import LIFECYCLE
from federatedscope.core.trainers.enums import MODE, LIFECYCLE
from federatedscope.core.monitors.monitor import Monitor
from federatedscope.llm.model.adapter_builder import AdapterModel

Expand Down Expand Up @@ -54,6 +54,11 @@ def _hook_on_batch_backward(self, ctx):

def _hook_on_batch_end(self, ctx):
if ctx.skip_this_batch:
# Retry with new data in train and finetune
if ctx.cur_mode == MODE.TRAIN:
self._run_batch(self.hooks_in_train, run_step=1)
elif ctx.cur_mode == MODE.FINETUNE:
self._run_batch(self.hooks_in_ft, run_step=1)
return

ctx.num_samples += ctx.batch_size
Expand Down