Group_texts in run_clm.py will add shorter than block_size groups on intermediately sized training sets.
### System Info

SageMaker using transformers 4.17 and attempting to fine-tune GPT2 and GPT-Neo. 

### Who can help?

@sgugger

### Information

- [X] The official example scripts
- [ ] 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

Steps to reproduce:

1: Use a dataset of about 10MB
2: Run run_clm.py on SageMaker using the latest supported version (4.17 at the time of writing)
3: Part way through training receive error stating: [ValueError: expected sequence of length 1024 at dim 1 (got 507)](https://discuss.huggingface.co/t/valueerror-expected-sequence-of-length-1024-at-dim-1-got-507/20390)

### Expected behavior

group_texts in run_clm should drop all sequences that are not the correct blocksize to prevent such an error. 

Additional context: This bug appears to be introduced by commit: 6f1adc43344a4ebe6fb1ecc018df9d6c092370cf
Removing the check for total_length < block_size resolves the issue and training completes without issue.
If you remove that line, you will get no training at all, since there is going to be 0 batches left. It is there to ensure a small dataset yields exactly one batch.<|||||>It looks like I must have hit some sort of an edge case. I think what happened was that it got to the end of my file and no longer had 1000 examples to provide the function `group_texts`. So in the case where the dataset lines up wrong, it won't work.

Perhaps the `drop_last_batch` flag should be set by default during the group_texts phase and a parse_flag for "small datasets" should be introduced?<|||||>Using run_clm.py from the commit by @spanglies solved this issue (I am forever grateful, this has been frustrating). You have to remove references to telemetrics and to check_min_version() to make it work on Sagemaker with estimator/fit.

However the same error shows up in evaluation, which I am disabling for now. Happy to finally have made it to a saved model, as that was my goal for this summer...<|||||>Hey glad that helped you @nittonfemton It wouldn't be hard to apply the same filter to the evaluation data. I hadn't because it was also my goal to have a trained model and I was less concerned with validating it. The way I had gotten it to work on sage maker was to apply the commit to v4.17.<|||||>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.