[Trainer] Deeper length checks for IterableDatasetShard (#15539)
* Unused import
* Make `has_length()` torch-independent to use in callbacks
* Update src/transformers/trainer_utils.py
Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>