class_docstr: Sampler that samples indices in a way that groups together features of the dataset of roughly the same length while
  keeping a bit of randomness.
class_docstr_tok: ["Sampler","that","samples","indices","in","a","way","that","groups","together","features","of","the","dataset","of","roughly","the","same","length","while","keeping","a","bit","of","randomness","."]
code: def __iter__(self):
      if self.group_by_modality:
          indices = get_modality_length_grouped_indices(
              self.lengths,
              self.batch_size,
              self.world_size,
              generator=self.generator,
          )
      else:
          indices = get_length_grouped_indices(
              self.lengths,
              self.batch_size,
              self.world_size,
              generator=self.generator,
          )
      return iter(indices)
  
imports: import os
  import torch
  import torch.nn
  from fairscale.optim import OSS
  from torch.utils.data import Sampler
  from transformers import Trainer
  from transformers.pytorch_utils import ALL_LAYERNORM_LAYERS
  from transformers.trainer_pt_utils import get_parameter_names
  from transformers.trainer_utils import ShardedDDPOption, has_length
  from transformers.utils import is_sagemaker_mp_enabled, logging
  from typing import List, Optional, Union, Dict, Any
label_desc: Use image node_id 3 for calling the LengthGroupedSampler obj's underlying member method code with example usage: obj.__iter__() and returns: iter