class_docstr: Data loader that balances data from multiple datasets.
class_docstr_tok: ["Data","loader","that","balances","data","from","multiple","datasets","."]
docstr: Data loader that balances data from multiple datasets.
  
  Mini-batches emitted by this dataloader are created by collating
  together mini-batches from each group. It may be used to balance data
  among classes, experiences, tasks, and so on.
  
  If `oversample_small_groups == True` smaller groups are oversampled to
  match the largest group. Otherwise, once data from a group is
  completely iterated, the group will be skipped.
  
  :param datasets: an instance of `AvalancheDataset`.
  :param oversample_small_groups: whether smaller groups should be
      oversampled to match the largest one.
  :param batch_size: the size of the batch. It must be greater than or
      equal to the number of groups.
  :param distributed_sampling: If True, apply the PyTorch
      :class:`DistributedSampler`. Defaults to True.
      Note: the distributed sampler is not applied if not running
      a distributed training, even when True is passed.
  :param kwargs: data loader arguments used to instantiate the loader for
      each group separately. See pytorch :class:`DataLoader`.
docstr_tok: ["Data","loader","that","balances","data","from","multiple","datasets",".","Mini-batches","emitted","by","this","dataloader","are","created","by","collating","together","mini-batches","from","each","group",".","It","may","be","used","to","balance","data","among","classes",",","experiences",",","tasks",",","and","so","on",".","If","`","oversample_small_groups","==","True","`","smaller","groups","are","oversampled","to","match","the","largest","group",".","Otherwise",",","once","data","from","a","group","is","completely","iterated",",","the","group","will","be","skipped",".",":","param","datasets",":","an","instance","of","`","AvalancheDataset","`",".",":","param","oversample_small_groups",":","whether","smaller","groups","should","be","oversampled","to","match","the","largest","one",".",":","param","batch_size",":","the","size","of","the","batch",".","It","must","be","greater","than","or","equal","to","the","number","of","groups",".",":","param","distributed_sampling",":","If","True",",","apply","the","PyTorch",":","class",":","`","DistributedSampler","`",".","Defaults","to","True",".","Note",":","the","distributed","sampler","is","not","applied","if","not","running","a","distributed","training",",","even","when","True","is","passed",".",":","param","kwargs",":","data","loader","arguments","used","to","instantiate","the","loader","for","each","group","separately",".","See","pytorch",":","class",":","`","DataLoader","`","."]
code: def __init__(
      self,
      datasets: Sequence[AvalancheDataset],
      oversample_small_groups: bool = False,
      batch_size: int = 32,
      distributed_sampling: bool = True,
      **kwargs,
  ):
      """Data loader that balances data from multiple datasets.
  
      Mini-batches emitted by this dataloader are created by collating
      together mini-batches from each group. It may be used to balance data
      among classes, experiences, tasks, and so on.
  
      If `oversample_small_groups == True` smaller groups are oversampled to
      match the largest group. Otherwise, once data from a group is
      completely iterated, the group will be skipped.
  
      :param datasets: an instance of `AvalancheDataset`.
      :param oversample_small_groups: whether smaller groups should be
          oversampled to match the largest one.
      :param batch_size: the size of the batch. It must be greater than or
          equal to the number of groups.
      :param distributed_sampling: If True, apply the PyTorch
          :class:`DistributedSampler`. Defaults to True.
          Note: the distributed sampler is not applied if not running
          a distributed training, even when True is passed.
      :param kwargs: data loader arguments used to instantiate the loader for
          each group separately. See pytorch :class:`DataLoader`.
      """
  
      # check if batch_size is larger than or equal to the number of datasets
      assert batch_size >= len(datasets)
  
      # divide the batch between all datasets in the group
      ds_batch_size = batch_size // len(datasets)
      remaining = batch_size % len(datasets)
  
      batch_sizes = []
      for _ in datasets:
          bs = ds_batch_size
          if remaining > 0:
              bs += 1
              remaining -= 1
          batch_sizes.append(bs)
  
      super().__init__(
          datasets,
          batch_sizes,
          oversample_small_datasets=oversample_small_groups,
          distributed_sampling=distributed_sampling,
          **kwargs,
      )
  
imports: from typing import Any, Dict, Iterator, List, Optional, Sequence, Sized, Union
  import numpy
  from torch.utils.data import DistributedSampler, Dataset
  from torch.utils.data.dataloader import DataLoader
  from avalanche.benchmarks.utils.data import AvalancheDataset
  from avalanche.benchmarks.utils.data_attribute import DataAttribute
  from avalanche.benchmarks.utils.ffcv_support.ffcv_components import HybridFfcvLoader, has_ffcv_support
  from avalanche.distributed.distributed_helper import DistributedHelper
  from torch.utils.data.sampler import Sampler, BatchSampler
  from torch.utils.data import ConcatDataset
label_desc: Use image node_id 1 to create a new GroupBalancedDataLoader object from inherited base classes: MultiDatasetDataLoader with example: obj = GroupBalancedDataLoader(datasets, oversample_small_groups, batch_size, distributed_sampling)