Fix inaccurate train_tokens_per_second when resuming from checkpoint
Author: lilin-1
Pull request: yes

# Fix inaccurate `train_tokens_per_second` when resuming from checkpoint

## What does this PR do?
This PR addresses the issue where `train_tokens_per_second` calculates incorrectly when resuming training from a checkpoint. 

### Problem Background
Previously, `speed_metrics` used the **cumulative total token count** (`self.state.num_input_tokens_seen`) to compute training speed. However, when resuming from a checkpoint:
1. The cumulative token count includes tokens processed in prior sessions.
2. `start_time` is reset to the current session’s start time.
This mismatch led to abnormally high initial `train_tokens_per_second` values (as the cumulative tokens were divided by a short new time window), which gradually decreased but never accurately reflected the current session’s real throughput (reported in #40560).


### Solution
To ensure speed metrics reflect only the current training session:
1. **Capture baseline token count**: In the `_inner_training_loop` method (right after `start_time = time.time()`), save the initial token count of the current session as `initial_num_input_tokens_seen_for_session`.
2. **Calculate session-specific token increment**: When updating logs with `speed_metrics`, compute the number of tokens processed *in the current session* (via `self.state.num_input_tokens_seen - initial_num_input_tokens_seen_for_session`), and pass this increment to `speed_metrics` instead of the cumulative total.


This change ensures `train_tokens_per_second` consistently represents the real-time throughput of the active training session—whether starting fresh or resuming from a checkpoint.

Fixes #40560


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request), Pull Request section?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link to it if that's the case.  
  Links: #40560
- [ ] Did you make sure to update the documentation with your changes? Here are the [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and here are tips on formatting docstrings.  
- [ ] Did you write any new necessary tests?  


## Who can review?


Comments:
cc @sunmarc

Tests keep failing. Only modified training speed calculation in logs，without touching previously failed core modules. Why do failed test cases differ each time and seem unrelated to this change? @SunMarc 

> Tests keep failing. Only modified training speed calculation in logs，without touching previously failed core modules. Why do failed test cases differ each time and seem unrelated to this change? @SunMarc

Some tests are flaky unfortunately ! Don't worry, i will make sure to merge this PR 

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_41156). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.