Skip to content

Commit

Permalink
Sum gathered input tokens (#34554)
Browse files Browse the repository at this point in the history
* sum gathered input tokens

* ruff line-length is 119, format the code

---------

Co-authored-by: kangsheng <[email protected]>
  • Loading branch information
techkang and kangsheng authored Nov 25, 2024
1 parent 1e492af commit 4dc1a69
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2489,7 +2489,9 @@ def _inner_training_loop(
else:
input_tokens = inputs[main_input_name].numel()
input_tokens = torch.tensor(input_tokens, device=self.args.device, dtype=torch.int64)
self.state.num_input_tokens_seen += self.accelerator.gather(input_tokens).cpu().item()
self.state.num_input_tokens_seen += (
self.accelerator.gather(input_tokens).sum().cpu().item()
)
if rng_to_sync:
self._load_rng_state(resume_from_checkpoint)
rng_to_sync = False
Expand Down

0 comments on commit 4dc1a69

Please sign in to comment.