checkpoints_to_be_deleted = checkpoints_sorted[:number_of_checkpoints_to_delete] TypeError: slice indices must be integers or None or have an __index__ method
### System Info

transformers.__version__==4.9.2



### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [x] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [x] My own task or dataset (give details below)

### Reproduction

1. use **trainer** to train your model

2. specify argument `resume_from_checkpoint`

### Expected behavior

if you use **trainer** to train your model and specify argument `resume_from_checkpoint`
`trainer.train(resume_from_checkpoint=checkpoint)`

you may encounter an error like this:
checkpoints_to_be_deleted = checkpoints_sorted[:number_of_checkpoints_to_delete]
TypeError: slice indices must be integers or None or have an __index__ method

this results from this line in **trainer.py**
```
number_of_checkpoints_to_delete = max(0, len(checkpoints_sorted) - save_total_limit)
checkpoints_to_be_deleted = checkpoints_sorted[:number_of_checkpoints_to_delete]
```
resolution:
add a conversion to int type for variable `number_of_checkpoints_to_delete`
```
number_of_checkpoints_to_delete = int(max(0, len(checkpoints_sorted) - save_total_limit))
checkpoints_to_be_deleted = checkpoints_sorted[:number_of_checkpoints_to_delete]
```


This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.<|||||>cc @sgugger <|||||>This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.