[Trainer] Deeper length checks for IterableDatasetShard
# What does this PR do?

As discussed in https://github.com/huggingface/transformers/pull/15309#discussion_r795553017 , in cases where `IterableDatasetShard` wraps a non-sized dataset, the check for `isinstance(dataset, Sized)` passes, while `len(dataset)` fails. 
This PR adds a universal `has_length(dataset)` that tries to get the dataset's length explicitly without relying on type checking.
_The documentation is not available anymore as the PR was closed or merged._