(Distributed)LengthGroupedSampler: allow only providing lengths but not a dataset
# 🚀 Feature request

Currently `LengthGroupedSampler` & `DistributedLengthGroupedSampler` require a `dataset` and optionally `lengths`. However, the sole purpose of `dataset` here is to get the lengths, so these classes should allow providing `lengths` only but not a `dataset`. This is easily doable for `LengthGroupedSampler` by giving `None` as a `dataset` (though not very elegant). However, `DistributedLengthGroupedSampler` actually calls `len(dataset)` even when `lengths` is provided (this can be easily circumvented by calling `len(lengths)` instead if provided). I think it'd be great if both classes make `dataset` an optional parameter but check that at least one of `dataset` and `lengths` is provided.

## Motivation

Sometimes people do not use a HuggingFace Dataset instance, but find the functionality provided by `LengthGroupedSampler` convenient to use. So they can manually provided `lengths`.

## Your contribution

I can submit a PR, if needed.

cc @sgugger <|||||>This would be a nice addition indeed. If you want to work on this, don't hesitate to submit a PR!<|||||>Submitted: #13820