def load_all_experiences(self, to_exp: Optional[int] = None) -> None:
        """
        Load all experiences up to a certain experience ID (inclusive).

        Beware that this won't re-load any already dropped experience.

        :param to_exp: The ID of the last exp to load (inclusive). If None,
            the whole stream will be loaded.
        :return: None
        """
        if to_exp is None:
            to_exp = len(self) - 1
        else:
            to_exp = int(to_exp)  # Handle single element tensors

        if to_exp >= len(self):
            raise IndexError(f"The stream doesn't contain {to_exp+1}" f"experiences")

        if self._next_exp_id > to_exp:
            # Nothing to do
            return

        exp_gen = self._exp_generator
        assert exp_gen is not None

        for exp_id in range(self._next_exp_id, to_exp + 1):
            try:
                generated_exp: TCLDataset = next(exp_gen)
            except StopIteration:
                raise RuntimeError(
                    f"Unexpected end of stream. The generator was supposed to "
                    f"generate {len(self)} experiences, but an error occurred "
                    f"while generating experience {exp_id}."
                )

            if not isinstance(generated_exp, AvalancheDataset):
                raise ValueError(
                    "All experience datasets must be subclasses of" " AvalancheDataset"
                )

            self._loaded_experiences[exp_id] = generated_exp
            self.targets_field_sequence[exp_id] = list(
                getattr(generated_exp, "targets")
            )
            self.task_labels_field_sequence[exp_id] = list(
                getattr(generated_exp, "targets_task_labels")
            )
            self._next_exp_id += 1

        if self._next_exp_id >= len(self):
            # Release all references to the generator
            self._exp_generator = None
            self._exp_source = None

        Load all experiences up to a certain experience ID (inclusive).

        Beware that this won't re-load any already dropped experience.

        :param to_exp: The ID of the last exp to load (inclusive). If None,
            the whole stream will be loaded.
        :return: None
        
avalanche/benchmarks/scenarios/deprecated/lazy_dataset_sequence.py