From f8aa28174e961a23ccb635442029808b2c49c7e4 Mon Sep 17 00:00:00 2001 From: hemu Date: Tue, 23 Apr 2024 17:04:09 +0800 Subject: [PATCH] fix bug for less data then grad acc --- swift/trainers/trainers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/swift/trainers/trainers.py b/swift/trainers/trainers.py index 4ef06733b..6ec04a5f3 100644 --- a/swift/trainers/trainers.py +++ b/swift/trainers/trainers.py @@ -287,7 +287,8 @@ def __next__(self): if not use_torchacc(): origin_loader = super().get_train_dataloader() grad_acc_steps = self.args.gradient_accumulation_steps - if grad_acc_steps is None or grad_acc_steps <= 1: + if grad_acc_steps is None or grad_acc_steps <= 1 or len( + origin_loader) < grad_acc_steps: return origin_loader length = len(origin_loader) // grad_acc_steps * grad_acc_steps