def get_rand_mem_grads(self, strategy, grad_dims, gss_batch_size):
        """
        Args:
            buffer: memory buffer
            grad_dims: gradient dimensions
        Returns: gradient from memory subsets
        """
        temp_gss_batch_size = min(gss_batch_size, self.ext_mem_list_current_index)
        num_mem_subs = min(
            self.mem_strength, self.ext_mem_list_current_index // gss_batch_size
        )
        mem_grads = torch.zeros(
            num_mem_subs,
            sum(grad_dims),
            dtype=torch.float32,
            device=self.device,
        )
        shuffeled_inds = torch.randperm(
            self.ext_mem_list_current_index, device=self.device
        )
        for i in range(num_mem_subs):
            random_batch_inds = shuffeled_inds[
                i * temp_gss_batch_size : i * temp_gss_batch_size + temp_gss_batch_size
            ]
            batch_x = self.ext_mem_list_x[random_batch_inds].to(strategy.device)
            batch_y = self.ext_mem_list_y[random_batch_inds].to(strategy.device)
            strategy.model.zero_grad()

            loss = strategy._criterion(strategy.model.forward(batch_x), batch_y)
            loss.backward()
            mem_grads[i].data.copy_(
                self.get_grad_vector(strategy.model.parameters, grad_dims)
            )
        return mem_grads

        Args:
            buffer: memory buffer
            grad_dims: gradient dimensions
        Returns: gradient from memory subsets
        
avalanche/training/plugins/gss_greedy.py