code: def __init__(self, data_source: PersonalizedBase, batch_size: int):
      super().__init__(data_source)
  
      n = len(data_source)
      self.groups = data_source.groups
      self.len = n_batch = n // batch_size
      expected = [
          len(g) / n * n_batch * batch_size for g in data_source.groups
      ]
      self.base = [int(e) // batch_size for e in expected]
      self.n_rand_batches = nrb = n_batch - sum(self.base)
      self.probs = [
          e % batch_size / nrb / batch_size if nrb > 0 else 0
          for e in expected
      ]
      self.batch_size = batch_size
  
imports: import os
  import numpy
  import PIL
  import torch
  from PIL import Image
  from torch.utils.data import Dataset, DataLoader, Sampler
  from torchvision import transforms
  from collections import defaultdict
  from random import shuffle, choices
  import random
  import tqdm
  from modules import devices, shared
  import re
  from ldm.modules.distributions.distributions import DiagonalGaussianDistribution
label_desc: Use image node_id 1 to create a new GroupedBatchSampler object from inherited base classes: Sampler with example: obj = GroupedBatchSampler(data_source, batch_size)