class_docstr: Buketized BatchSampler for sequential data with different lengths to reduce number of paddings.
  
  Args:
      lengths (List[int]): The lengths of the samples in the dataset.
      num_buckets (int): The number of buckets to split the data samples.
      min_len (int, optional): The minimum sample lengths to keep.
          (Default: 0)
      max_len (int or None, optional): The maximum sample lengths to keep. Inferred if not provided.
          (Default ``None``)
      max_token_count (int or None, optional): The max number of tokens in one mini-batch.
          (Default: ``None``)
      batch_size (int or None, optional): The number of samples in one mini-batch.
          (Default: ``None``)
      shuffle (bool, optional): Whether to shuffle buckets for non-monotonic length sampling.
          (Default: True)
      seed (int, optional): The seed for initialzing RNG. Only used when `shuffle` is True. (Default: 0)
      drop_last (bool, optional): If ``True``, the sampler will drop the last batch if
          its size would be less than ``batch_size``
          (Default: False)
  
  Note:
      ``max_token_count`` and ``batch_size`` are mutually exclusive. Only one argument of the two
      should have value.
  
  Note:
      ``drop_last`` is only valid when ``batch_size`` argument is given.
  
  Note:
      if ``shuffle`` is True, it will only shuffle the data once. Please set ``reload_dataloaders_every_n_epochs=1``
      in pytorch_lightning Trainer and set ``seed`` to ``self.trainer.current_epoch`` to enable shuffling every epoch.
class_docstr_tok: ["Buketized","BatchSampler","for","sequential","data","with","different","lengths","to","reduce","number","of","paddings",".","Args",":","lengths","(","List","[","int","]",")",":","The","lengths","of","the","samples","in","the","dataset",".","num_buckets","(","int",")",":","The","number","of","buckets","to","split","the","data","samples",".","min_len","(","int",",","optional",")",":","The","minimum","sample","lengths","to","keep",".","(","Default",":","0",")","max_len","(","int","or","None",",","optional",")",":","The","maximum","sample","lengths","to","keep",".","Inferred","if","not","provided",".","(","Default","``","None","``",")","max_token_count","(","int","or","None",",","optional",")",":","The","max","number","of","tokens","in","one","mini-batch",".","(","Default",":","``","None","``",")","batch_size","(","int","or","None",",","optional",")",":","The","number","of","samples","in","one","mini-batch",".","(","Default",":","``","None","``",")","shuffle","(","bool",",","optional",")",":","Whether","to","shuffle","buckets","for","non-monotonic","length","sampling",".","(","Default",":","True",")","seed","(","int",",","optional",")",":","The","seed","for","initialzing","RNG",".","Only","used","when","`","shuffle","`","is","True",".","(","Default",":","0",")","drop_last","(","bool",",","optional",")",":","If","``","True","``",",","the","sampler","will","drop","the","last","batch","if","its","size","would","be","less","than","``","batch_size","``","(","Default",":","False",")","Note",":","``","max_token_count","``","and","``","batch_size","``","are","mutually","exclusive",".","Only","one","argument","of","the","two","should","have","value",".","Note",":","``","drop_last","``","is","only","valid","when","``","batch_size","``","argument","is","given",".","Note",":","if","``","shuffle","``","is","True",",","it","will","only","shuffle","the","data","once",".","Please","set","``","reload_dataloaders_every_n_epochs=1","``","in","pytorch_lightning","Trainer","and","set","``","seed","``","to","``","self.trainer.current_epoch","``","to","enable","shuffling","every","epoch","."]
code: def __init__(
      self,
      lengths: List[int],
      num_buckets: int,
      min_len: int = 0,
      max_len: Optional[int] = None,
      max_token_count: Optional[int] = None,
      batch_size: Optional[int] = None,
      shuffle: bool = True,
      seed: int = 0,
      drop_last: bool = False,
  ) -> None:
      if max_len is None:
          max_len = max(lengths)
  
      if not (0 <= min_len <= max_len):
          raise AssertionError(
              "``min_len`` should be non-negative and smaller than ``max_len``"
          )
      if max_token_count is not None and batch_size is not None:
          raise AssertionError(
              "The ``max_token_count`` and ``batch_size`` can't be both set."
          )
      if max_token_count is None and batch_size is None:
          raise AssertionError(
              "One of ``max_token_count`` or ``batch_size`` must be set."
          )
      if max_token_count is not None:
          assert (
              max_len <= max_token_count
          ), "The  ``max_token_count`` must be greater than or equal to the maximum value of ``lengths``."
      # Filter out samples which are outside the bounds of [min_len, max_len]
      filtered_length_idx = [
          (length, i)
          for i, length in enumerate(lengths)
          if min_len <= length <= max_len
      ]
      if len(filtered_length_idx) == 0:
          raise AssertionError(
              "``lengths`` cannot be empty after filtering."
          )
      sorted_filtered_length_idx = sorted(
          filtered_length_idx, key=lambda x: x[0]
      )
      self.lengths = [e[0] for e in sorted_filtered_length_idx]
      self.indices = [e[1] for e in sorted_filtered_length_idx]
      self.max_token_count = max_token_count
      self.batch_size = batch_size
      self.shuffle = shuffle
      self.seed = seed
      if self.shuffle:
          self.g = torch.Generator()
          self.g.manual_seed(self.seed)
      self.drop_last = drop_last
      self.buckets = self._get_buckets(
          self.lengths, num_buckets, min_len, max_len
      )
      self._update_iter_list()
  
imports: import math
  import os
  import sys
  from pathlib import Path
  from typing import Dict, Iterator, List, Optional, Tuple, Union
  import numpy
  import torch
  import torch.distributed
  import torchaudio
  from torch import Tensor
  from torch.utils.data import BatchSampler, Dataset, DistributedSampler
  from utils import _get_label2id
label_desc: Use image node_id 1 to create a new BucketizeBatchSampler object from inherited base classes: BatchSampler with example: obj = BucketizeBatchSampler(lengths, num_buckets, min_len, max_len, max_token_count, batch_size, shuffle, seed, drop_last)