def predict_from_dataset(
        self,
        n: int,
        dataset: TorchInferenceDataset,
        trainer: Optional[pl.Trainer] = None,
        batch_size: Optional[int] = None,
        verbose: Optional[bool] = None,
        n_jobs: int = 1,
        roll_size: Optional[int] = None,
        num_samples: int = 1,
        dataloader_kwargs: Optional[dict[str, Any]] = None,
        mc_dropout: bool = False,
        predict_likelihood_parameters: bool = False,
        random_state: Optional[int] = None,
        values_only: bool = False,
    ) -> Sequence[TimeSeries]:
        """
        This method allows for predicting with a specific :class:`darts.utils.data.TorchInferenceDataset` instance.
        These datasets implement a PyTorch ``Dataset``, and specify how the target and covariates are sliced
        for inference. In most cases, you'll rather want to call :func:`predict()` instead, which will create an
        appropriate :class:`TorchInferenceDataset` for you.

        Prediction is performed with a PyTorch Lightning Trainer. It uses a default Trainer object from presets and
        ``pl_trainer_kwargs`` used at model creation. You can also use a custom Trainer with optional parameter
        ``trainer``. For more information on PyTorch Lightning Trainers check out `this link
        <https://pytorch-lightning.readthedocs.io/en/stable/common/trainer.html>`_ .

        Parameters
        ----------
        n
            The number of time steps after the end of the training time series for which to produce predictions
        dataset
            Optionally, a series or sequence of series, representing the history of the target series' whose
            future is to be predicted. If specified, the method returns the forecasts of these
            series. Otherwise, the method returns the forecast of the (single) training series.
        trainer
            Optionally, a custom PyTorch-Lightning Trainer object to perform prediction.  Using a custom ``trainer``
            will override Darts' default trainer.
        batch_size
            Size of batches during prediction. Defaults to the models ``batch_size`` value.
        verbose
            Whether to print the progress. Ignored if there is a `ProgressBar` callback in
            `pl_trainer_kwargs`.
        n_jobs
            The number of jobs to run in parallel. ``-1`` means using all processors. Defaults to ``1``.
        roll_size
            For self-consuming predictions, i.e. ``n > output_chunk_length``, determines how many
            outputs of the model are fed back into it at every iteration of feeding the predicted target
            (and optionally future covariates) back into the model. If this parameter is not provided,
            it will be set ``output_chunk_length`` by default.
        num_samples
            Number of times a prediction is sampled from a probabilistic model. Must be `1` for deterministic models.
        dataloader_kwargs
            Optionally, a dictionary of keyword arguments used to create the PyTorch `DataLoader` instance for the
            inference/prediction dataset. For more information on `DataLoader`, check out `this link
            <https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader>`_.
            By default, Darts configures parameters ("batch_size", "shuffle", "drop_last", "collate_fn", "pin_memory")
            for seamless forecasting. Changing them should be done with care to avoid unexpected behavior.
        mc_dropout
            Optionally, enable monte carlo dropout for predictions using neural network based models.
            This allows bayesian approximation by specifying an implicit prior over learned models.
        predict_likelihood_parameters
            If set to `True`, the model predicts the parameters of its `likelihood` instead of the target. Only
            supported for probabilistic models with a likelihood, `num_samples = 1` and `n<=output_chunk_length`.
            Default: ``False``
        random_state
            Controls the randomness of probabilistic predictions.
        values_only
            Whether to return the predicted values only. If `False`, will return `TimeSeries` objects. Otherwise, will
            return a tuple of `(np.ndarray, list[dict[str, Any]], list[Union[pd.Timestamp, int]])`. The first element
            represents the predictions with shape `(num_predictions, n, columns, num_samples)`. The second element
            represents the schemas of forecasted target `TimeSeries`. The third element represents the prediction start
            times.

        Returns
        -------
        Sequence[TimeSeries]
            Returns one or more forecasts for time series.
        """

        # we need to call super's super's method directly, because GlobalForecastingModel expects series:
        ForecastingModel.predict(self, n, num_samples)

        self._verify_inference_dataset_type(dataset)

        # check that covariates and dimensions are matching what we had during training
        self._validate_predict_sample(
            train_sample=self.train_sample, predict_sample=dataset[0]
        )

        if roll_size is None:
            roll_size = self.output_chunk_length
        else:
            raise_if_not(
                0 < roll_size <= self.output_chunk_length,
                "`roll_size` must be an integer between 1 and `self.output_chunk_length`.",
            )

        # prevent auto-regression when prediction the likelihood parameters
        raise_if(
            predict_likelihood_parameters and n > self.output_chunk_length,
            "`n` must be smaller than or equal to `output_chunk_length` when `predict_likelihood_parameters=True`.",
            logger,
        )

        # check that `num_samples` is a positive integer
        raise_if_not(num_samples > 0, "`num_samples` must be a positive integer.")

        # iterate through batches to produce predictions
        batch_size = batch_size or self.batch_size

        # set prediction parameters
        self.model.set_predict_parameters(
            n=n,
            num_samples=num_samples,
            roll_size=roll_size,
            batch_size=batch_size,
            predict_likelihood_parameters=predict_likelihood_parameters,
            mc_dropout=mc_dropout,
        )

        dataloader_kwargs = dict(
            {
                "batch_size": batch_size,
                "pin_memory": True,
                "drop_last": False,
                "collate_fn": self._batch_collate_fn,
            },
            **(dataloader_kwargs or {}),
            **{"shuffle": False},
        )

        pred_loader = DataLoader(
            dataset,
            **dataloader_kwargs,
        )

        # set up trainer. use user supplied trainer or create a new trainer from scratch
        self.trainer = self._setup_trainer(
            trainer=trainer, model=self.model, verbose=verbose, epochs=self.n_epochs
        )

        # prediction output comes as list of batch tuples
        out = self.trainer.predict(model=self.model, dataloaders=pred_loader)
        # each batch tuple has elements (prediction np.ndarray, series schema, prediction start time)
        predictions, series_schemas, pred_starts = [], [], []

        # flatten output for parallelization
        for pred, ss, ps in out:
            predictions.append(pred)
            series_schemas += ss
            pred_starts += ps

        # concatenate to shape: (num_samples, n forecasts, forecast horizon, n components)
        predictions = np.concatenate(predictions, axis=1)
        # reshape to: (n forecasts, forecast horizon, n components, num_samples)
        predictions = np.transpose(predictions, axes=(1, 2, 3, 0))

        if values_only:
            return predictions, series_schemas, pred_starts

        # create forecast `TimeSeries`
        iterator = _build_tqdm_iterator(
            iterable=zip(predictions, series_schemas, pred_starts),
            verbose=verbose,
            total=len(predictions),
            desc="Generating TimeSeries",
        )
        ts_forecasts = _parallel_apply(
            iterator=iterator,
            fn=_build_forecast_series_from_schema,
            n_jobs=n_jobs,
            fn_args=tuple(),
            fn_kwargs={
                "predict_likelihood_parameters": predict_likelihood_parameters,
                "likelihood_component_names_fn": (
                    self.likelihood.component_names
                    if predict_likelihood_parameters
                    else None
                ),
            },
        )
        return ts_forecasts

        This method allows for predicting with a specific :class:`darts.utils.data.TorchInferenceDataset` instance.
        These datasets implement a PyTorch ``Dataset``, and specify how the target and covariates are sliced
        for inference. In most cases, you'll rather want to call :func:`predict()` instead, which will create an
        appropriate :class:`TorchInferenceDataset` for you.

        Prediction is performed with a PyTorch Lightning Trainer. It uses a default Trainer object from presets and
        ``pl_trainer_kwargs`` used at model creation. You can also use a custom Trainer with optional parameter
        ``trainer``. For more information on PyTorch Lightning Trainers check out `this link
        <https://pytorch-lightning.readthedocs.io/en/stable/common/trainer.html>`_ .

        Parameters
        ----------
        n
            The number of time steps after the end of the training time series for which to produce predictions
        dataset
            Optionally, a series or sequence of series, representing the history of the target series' whose
            future is to be predicted. If specified, the method returns the forecasts of these
            series. Otherwise, the method returns the forecast of the (single) training series.
        trainer
            Optionally, a custom PyTorch-Lightning Trainer object to perform prediction.  Using a custom ``trainer``
            will override Darts' default trainer.
        batch_size
            Size of batches during prediction. Defaults to the models ``batch_size`` value.
        verbose
            Whether to print the progress. Ignored if there is a `ProgressBar` callback in
            `pl_trainer_kwargs`.
        n_jobs
            The number of jobs to run in parallel. ``-1`` means using all processors. Defaults to ``1``.
        roll_size
            For self-consuming predictions, i.e. ``n > output_chunk_length``, determines how many
            outputs of the model are fed back into it at every iteration of feeding the predicted target
            (and optionally future covariates) back into the model. If this parameter is not provided,
            it will be set ``output_chunk_length`` by default.
        num_samples
            Number of times a prediction is sampled from a probabilistic model. Must be `1` for deterministic models.
        dataloader_kwargs
            Optionally, a dictionary of keyword arguments used to create the PyTorch `DataLoader` instance for the
            inference/prediction dataset. For more information on `DataLoader`, check out `this link
            <https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader>`_.
            By default, Darts configures parameters ("batch_size", "shuffle", "drop_last", "collate_fn", "pin_memory")
            for seamless forecasting. Changing them should be done with care to avoid unexpected behavior.
        mc_dropout
            Optionally, enable monte carlo dropout for predictions using neural network based models.
            This allows bayesian approximation by specifying an implicit prior over learned models.
        predict_likelihood_parameters
            If set to `True`, the model predicts the parameters of its `likelihood` instead of the target. Only
            supported for probabilistic models with a likelihood, `num_samples = 1` and `n<=output_chunk_length`.
            Default: ``False``
        random_state
            Controls the randomness of probabilistic predictions.
        values_only
            Whether to return the predicted values only. If `False`, will return `TimeSeries` objects. Otherwise, will
            return a tuple of `(np.ndarray, list[dict[str, Any]], list[Union[pd.Timestamp, int]])`. The first element
            represents the predictions with shape `(num_predictions, n, columns, num_samples)`. The second element
            represents the schemas of forecasted target `TimeSeries`. The third element represents the prediction start
            times.

        Returns
        -------
        Sequence[TimeSeries]
            Returns one or more forecasts for time series.
        
darts/models/forecasting/torch_forecasting_model.py