code: def _split_dataset_by_attribute(
      data: TCLDataset, attr_name: str
  ) -> Dict[int, TCLDataset]:
      """Helper to split a dataset by attribute.
  
      :param data: an Avalanche dataset.
      :param attr_name: the name of the attribute of `data` to use for splitting `data`.
      """
      da = getattr(data, attr_name)
      dds = {}
      for el in da.uniques:
          idxs = da.val_to_idx[el]
          dds[el] = data.subset(idxs)
      return dds
  
imports: import random
  from avalanche.benchmarks.utils.data import AvalancheDataset
  import torch
  from itertools import tee
  from typing import Callable, Generator, Generic, List, Sequence, TypeVar, Union, Tuple, Optional, Iterable, Dict
  from .generic_scenario import EagerCLStream, CLScenario, CLExperience, make_stream
  from ..utils import TaskAwareSupervisedClassificationDataset
label_desc: Use image node_id 2 for calling a global function with example usage: _split_dataset_by_attribute(data, attr_name) and returns: dds