Skip to content

Commit

Permalink
add an extra validation that loss should not vary too much
Browse files Browse the repository at this point in the history
  • Loading branch information
techkang committed Jan 13, 2025
1 parent 163cab6 commit f5040b2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/trainer/test_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,13 @@ def tokenize_function(examples):
# max diff broken should be very off
self.assertGreater(max(diff_broken), 2, f"Difference {max(diff_broken)} is not greater than 2")

loss_base = sum(base_loss_callback.losses)
loss_broken = sum(broken_loss_callback.losses)

# mean/sum loss should not vary too much.
relative_diff = abs(loss_base - loss_broken) / max(loss_base, loss_broken)
self.assertLess(relative_diff, 0.1, f"Relative difference {relative_diff} is not within 0.1")

@slow
def test_gradient_accumulation_loss_alignment_with_loss_func(self):
set_seed(42)
Expand Down

0 comments on commit f5040b2

Please sign in to comment.