autogluon.timeseries 1.4.1b20250821__py3-none-any.whl → 1.4.1b20250825__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of autogluon.timeseries might be problematic. Click here for more details.

Files changed (44) hide show
  1. autogluon/timeseries/dataset/ts_dataframe.py +9 -9
  2. autogluon/timeseries/learner.py +14 -14
  3. autogluon/timeseries/metrics/__init__.py +5 -5
  4. autogluon/timeseries/metrics/abstract.py +9 -9
  5. autogluon/timeseries/models/abstract/abstract_timeseries_model.py +39 -41
  6. autogluon/timeseries/models/abstract/tunable.py +6 -6
  7. autogluon/timeseries/models/autogluon_tabular/mlforecast.py +30 -30
  8. autogluon/timeseries/models/autogluon_tabular/per_step.py +12 -12
  9. autogluon/timeseries/models/chronos/model.py +10 -10
  10. autogluon/timeseries/models/chronos/pipeline/base.py +8 -8
  11. autogluon/timeseries/models/chronos/pipeline/chronos.py +12 -12
  12. autogluon/timeseries/models/chronos/pipeline/chronos_bolt.py +12 -12
  13. autogluon/timeseries/models/chronos/pipeline/utils.py +12 -12
  14. autogluon/timeseries/models/ensemble/abstract.py +19 -19
  15. autogluon/timeseries/models/ensemble/basic.py +8 -8
  16. autogluon/timeseries/models/ensemble/greedy.py +13 -13
  17. autogluon/timeseries/models/gluonts/abstract.py +24 -24
  18. autogluon/timeseries/models/gluonts/dataset.py +2 -2
  19. autogluon/timeseries/models/gluonts/models.py +7 -7
  20. autogluon/timeseries/models/local/abstract_local_model.py +12 -12
  21. autogluon/timeseries/models/local/statsforecast.py +11 -11
  22. autogluon/timeseries/models/multi_window/multi_window_model.py +4 -4
  23. autogluon/timeseries/models/presets.py +14 -14
  24. autogluon/timeseries/models/registry.py +3 -3
  25. autogluon/timeseries/predictor.py +35 -35
  26. autogluon/timeseries/regressor.py +13 -13
  27. autogluon/timeseries/splitter.py +6 -6
  28. autogluon/timeseries/trainer.py +50 -49
  29. autogluon/timeseries/transforms/covariate_scaler.py +3 -3
  30. autogluon/timeseries/transforms/target_scaler.py +7 -7
  31. autogluon/timeseries/utils/datetime/lags.py +2 -2
  32. autogluon/timeseries/utils/datetime/time_features.py +2 -2
  33. autogluon/timeseries/utils/features.py +31 -31
  34. autogluon/timeseries/version.py +1 -1
  35. {autogluon.timeseries-1.4.1b20250821.dist-info → autogluon.timeseries-1.4.1b20250825.dist-info}/METADATA +5 -5
  36. autogluon.timeseries-1.4.1b20250825.dist-info/RECORD +72 -0
  37. autogluon.timeseries-1.4.1b20250821.dist-info/RECORD +0 -72
  38. /autogluon.timeseries-1.4.1b20250821-py3.9-nspkg.pth → /autogluon.timeseries-1.4.1b20250825-py3.9-nspkg.pth +0 -0
  39. {autogluon.timeseries-1.4.1b20250821.dist-info → autogluon.timeseries-1.4.1b20250825.dist-info}/LICENSE +0 -0
  40. {autogluon.timeseries-1.4.1b20250821.dist-info → autogluon.timeseries-1.4.1b20250825.dist-info}/NOTICE +0 -0
  41. {autogluon.timeseries-1.4.1b20250821.dist-info → autogluon.timeseries-1.4.1b20250825.dist-info}/WHEEL +0 -0
  42. {autogluon.timeseries-1.4.1b20250821.dist-info → autogluon.timeseries-1.4.1b20250825.dist-info}/namespace_packages.txt +0 -0
  43. {autogluon.timeseries-1.4.1b20250821.dist-info → autogluon.timeseries-1.4.1b20250825.dist-info}/top_level.txt +0 -0
  44. {autogluon.timeseries-1.4.1b20250821.dist-info → autogluon.timeseries-1.4.1b20250825.dist-info}/zip-safe +0 -0
@@ -3,7 +3,7 @@ import logging
3
3
  import math
4
4
  import time
5
5
  import warnings
6
- from typing import Any, Callable, Collection, Dict, List, Optional, Tuple, Type, Union
6
+ from typing import Any, Callable, Collection, Optional, Type, Union
7
7
 
8
8
  import numpy as np
9
9
  import pandas as pd
@@ -68,7 +68,7 @@ class AbstractMLForecastModel(AbstractTimeSeriesModel):
68
68
  path: Optional[str] = None,
69
69
  name: Optional[str] = None,
70
70
  eval_metric: Optional[Union[str, TimeSeriesScorer]] = None,
71
- hyperparameters: Optional[Dict[str, Any]] = None,
71
+ hyperparameters: Optional[dict[str, Any]] = None,
72
72
  **kwargs,
73
73
  ):
74
74
  super().__init__(
@@ -86,12 +86,12 @@ class AbstractMLForecastModel(AbstractTimeSeriesModel):
86
86
  self._sum_of_differences: int = 0 # number of time steps removed from each series by differencing
87
87
  self._max_ts_length: Optional[int] = None
88
88
  self._target_lags: np.ndarray
89
- self._date_features: List[Callable]
89
+ self._date_features: list[Callable]
90
90
  self._mlf: MLForecast
91
91
  self._scaler: Optional[BaseTargetTransform] = None
92
92
  self._residuals_std_per_item: pd.Series
93
93
  self._train_target_median: Optional[float] = None
94
- self._non_boolean_real_covariates: List[str] = []
94
+ self._non_boolean_real_covariates: list[str] = []
95
95
 
96
96
  def _initialize_transforms_and_regressor(self):
97
97
  super()._initialize_transforms_and_regressor()
@@ -99,7 +99,7 @@ class AbstractMLForecastModel(AbstractTimeSeriesModel):
99
99
  self.target_scaler = None
100
100
 
101
101
  @property
102
- def allowed_hyperparameters(self) -> List[str]:
102
+ def allowed_hyperparameters(self) -> list[str]:
103
103
  return super().allowed_hyperparameters + [
104
104
  "lags",
105
105
  "date_features",
@@ -117,7 +117,7 @@ class AbstractMLForecastModel(AbstractTimeSeriesModel):
117
117
  known_covariates: Optional[TimeSeriesDataFrame] = None,
118
118
  is_train: bool = False,
119
119
  **kwargs,
120
- ) -> Tuple[TimeSeriesDataFrame, Optional[TimeSeriesDataFrame]]:
120
+ ) -> tuple[TimeSeriesDataFrame, Optional[TimeSeriesDataFrame]]:
121
121
  if is_train:
122
122
  # All-NaN series are removed; partially-NaN series in train_data are handled inside _generate_train_val_dfs
123
123
  all_nan_items = data.item_ids[data[self.target].isna().groupby(ITEMID, sort=False).all()]
@@ -130,7 +130,7 @@ class AbstractMLForecastModel(AbstractTimeSeriesModel):
130
130
  data[self.target] = data[self.target].fillna(value=self._train_target_median)
131
131
  return data, known_covariates
132
132
 
133
- def _process_deprecated_hyperparameters(self, model_params: Dict[str, Any]) -> Dict[str, Any]:
133
+ def _process_deprecated_hyperparameters(self, model_params: dict[str, Any]) -> dict[str, Any]:
134
134
  if "tabular_hyperparameters" in model_params:
135
135
  logger.warning(
136
136
  f"Hyperparameter 'tabular_hyperparameters' for {self.name} is deprecated and will be removed in v1.5. "
@@ -155,7 +155,7 @@ class AbstractMLForecastModel(AbstractTimeSeriesModel):
155
155
  )
156
156
  return model_params
157
157
 
158
- def _get_default_hyperparameters(self) -> Dict[str, Any]:
158
+ def _get_default_hyperparameters(self) -> dict[str, Any]:
159
159
  return {
160
160
  "max_num_items": 20_000,
161
161
  "max_num_samples": 1_000_000,
@@ -163,12 +163,12 @@ class AbstractMLForecastModel(AbstractTimeSeriesModel):
163
163
  "model_hyperparameters": {},
164
164
  }
165
165
 
166
- def _create_tabular_model(self, model_name: str, model_hyperparameters: Dict[str, Any]) -> TabularModel:
166
+ def _create_tabular_model(self, model_name: str, model_hyperparameters: dict[str, Any]) -> TabularModel:
167
167
  raise NotImplementedError
168
168
 
169
169
  def _get_mlforecast_init_args(
170
- self, train_data: TimeSeriesDataFrame, model_params: Dict[str, Any]
171
- ) -> Dict[str, Any]:
170
+ self, train_data: TimeSeriesDataFrame, model_params: dict[str, Any]
171
+ ) -> dict[str, Any]:
172
172
  from mlforecast.target_transforms import Differences
173
173
 
174
174
  from .transforms import MLForecastScaler
@@ -236,7 +236,7 @@ class AbstractMLForecastModel(AbstractTimeSeriesModel):
236
236
 
237
237
  def _generate_train_val_dfs(
238
238
  self, data: TimeSeriesDataFrame, max_num_items: Optional[int] = None, max_num_samples: Optional[int] = None
239
- ) -> Tuple[pd.DataFrame, pd.DataFrame]:
239
+ ) -> tuple[pd.DataFrame, pd.DataFrame]:
240
240
  # Exclude items that are too short for chosen differences - otherwise exception will be raised
241
241
  if self._sum_of_differences > 0:
242
242
  ts_lengths = data.num_timesteps_per_item()
@@ -400,16 +400,16 @@ class AbstractMLForecastModel(AbstractTimeSeriesModel):
400
400
  self,
401
401
  data: TimeSeriesDataFrame,
402
402
  known_covariates: Optional[TimeSeriesDataFrame] = None,
403
- ) -> Tuple[TimeSeriesDataFrame, Optional[TimeSeriesDataFrame], Optional[TimeSeriesDataFrame]]:
403
+ ) -> tuple[TimeSeriesDataFrame, Optional[TimeSeriesDataFrame], Optional[TimeSeriesDataFrame]]:
404
404
  """Remove series that are too short for chosen differencing from data and generate naive forecast for them.
405
405
 
406
406
  Returns
407
407
  -------
408
- data_long : TimeSeriesDataFrame
408
+ data_long
409
409
  Data containing only time series that are long enough for the model to predict.
410
- known_covariates_long : TimeSeriesDataFrame or None
410
+ known_covariates_long
411
411
  Future known covariates containing only time series that are long enough for the model to predict.
412
- forecast_for_short_series : TimeSeriesDataFrame or None
412
+ forecast_for_short_series
413
413
  Seasonal naive forecast for short series, if there are any in the dataset.
414
414
  """
415
415
  ts_lengths = data.num_timesteps_per_item()
@@ -468,7 +468,7 @@ class AbstractMLForecastModel(AbstractTimeSeriesModel):
468
468
  predictions[str(q)] = predictions["mean"] + norm.ppf(q) * std_per_timestep.to_numpy()
469
469
  return predictions
470
470
 
471
- def _more_tags(self) -> Dict[str, Any]:
471
+ def _more_tags(self) -> dict[str, Any]:
472
472
  return {"allow_nan": True, "can_refit_full": True}
473
473
 
474
474
 
@@ -493,13 +493,13 @@ class DirectTabularModel(AbstractMLForecastModel):
493
493
 
494
494
  Other Parameters
495
495
  ----------------
496
- lags : List[int], default = None
496
+ lags : list[int], default = None
497
497
  Lags of the target that will be used as features for predictions. If None, will be determined automatically
498
498
  based on the frequency of the data.
499
- date_features : List[Union[str, Callable]], default = None
499
+ date_features : list[Union[str, Callable]], default = None
500
500
  Features computed from the dates. Can be pandas date attributes or functions that will take the dates as input.
501
501
  If None, will be determined automatically based on the frequency of the data.
502
- differences : List[int], default = []
502
+ differences : list[int], default = []
503
503
  Differences to take of the target before computing the features. These are restored at the forecasting step.
504
504
  Defaults to no differencing.
505
505
  target_scaler : {"standard", "mean_abs", "min_max", "robust", None}, default = "mean_abs"
@@ -508,7 +508,7 @@ class DirectTabularModel(AbstractMLForecastModel):
508
508
  Name of the tabular regression model. See ``autogluon.tabular.registry.ag_model_registry`` or
509
509
  `the documentation <https://auto.gluon.ai/stable/api/autogluon.tabular.models.html>`_ for the list of available
510
510
  tabular models.
511
- model_hyperparameters : Dict[str, Any], optional
511
+ model_hyperparameters : dict[str, Any], optional
512
512
  Hyperparameters passed to the tabular regression model.
513
513
  max_num_items : int or None, default = 20_000
514
514
  If not None, the model will randomly select this many time series for training and validation.
@@ -523,7 +523,7 @@ class DirectTabularModel(AbstractMLForecastModel):
523
523
  def is_quantile_model(self) -> bool:
524
524
  return self.eval_metric.needs_quantile
525
525
 
526
- def get_hyperparameters(self) -> Dict[str, Any]:
526
+ def get_hyperparameters(self) -> dict[str, Any]:
527
527
  model_params = super().get_hyperparameters()
528
528
  # We don't set 'target_scaler' if user already provided 'scaler' to avoid overriding the user-provided value
529
529
  if "scaler" not in model_params:
@@ -634,7 +634,7 @@ class DirectTabularModel(AbstractMLForecastModel):
634
634
  column_order = ["mean"] + [col for col in predictions_df.columns if col != "mean"]
635
635
  return predictions_df[column_order]
636
636
 
637
- def _create_tabular_model(self, model_name: str, model_hyperparameters: Dict[str, Any]) -> TabularModel:
637
+ def _create_tabular_model(self, model_name: str, model_hyperparameters: dict[str, Any]) -> TabularModel:
638
638
  model_class = ag_model_registry.key_to_cls(model_name)
639
639
  if self.is_quantile_model:
640
640
  problem_type = ag.constants.QUANTILE
@@ -673,25 +673,25 @@ class RecursiveTabularModel(AbstractMLForecastModel):
673
673
 
674
674
  Other Parameters
675
675
  ----------------
676
- lags : List[int], default = None
676
+ lags : list[int], default = None
677
677
  Lags of the target that will be used as features for predictions. If None, will be determined automatically
678
678
  based on the frequency of the data.
679
- date_features : List[Union[str, Callable]], default = None
679
+ date_features : list[Union[str, Callable]], default = None
680
680
  Features computed from the dates. Can be pandas date attributes or functions that will take the dates as input.
681
681
  If None, will be determined automatically based on the frequency of the data.
682
- differences : List[int], default = None
682
+ differences : list[int], default = None
683
683
  Differences to take of the target before computing the features. These are restored at the forecasting step.
684
684
  If None, will be set to ``[seasonal_period]``, where seasonal_period is determined based on the data frequency.
685
685
  target_scaler : {"standard", "mean_abs", "min_max", "robust", None}, default = "standard"
686
686
  Scaling applied to each time series. Scaling is applied after differencing.
687
- lag_transforms : Dict[int, List[Callable]], default = None
687
+ lag_transforms : dict[int, list[Callable]], default = None
688
688
  Dictionary mapping lag periods to transformation functions applied to lagged target values (e.g., rolling mean).
689
689
  See `MLForecast documentation <https://nixtlaverse.nixtla.io/mlforecast/lag_transforms.html>`_ for more details.
690
690
  model_name : str, default = "GBM"
691
691
  Name of the tabular regression model. See ``autogluon.tabular.registry.ag_model_registry`` or
692
692
  `the documentation <https://auto.gluon.ai/stable/api/autogluon.tabular.models.html>`_ for the list of available
693
693
  tabular models.
694
- model_hyperparameters : Dict[str, Any], optional
694
+ model_hyperparameters : dict[str, Any], optional
695
695
  Hyperparameters passed to the tabular regression model.
696
696
  max_num_items : int or None, default = 20_000
697
697
  If not None, the model will randomly select this many time series for training and validation.
@@ -702,7 +702,7 @@ class RecursiveTabularModel(AbstractMLForecastModel):
702
702
 
703
703
  ag_priority = 90
704
704
 
705
- def get_hyperparameters(self) -> Dict[str, Any]:
705
+ def get_hyperparameters(self) -> dict[str, Any]:
706
706
  model_params = super().get_hyperparameters()
707
707
  # We don't set 'target_scaler' if user already provided 'scaler' to avoid overriding the user-provided value
708
708
  if "scaler" not in model_params:
@@ -756,7 +756,7 @@ class RecursiveTabularModel(AbstractMLForecastModel):
756
756
  predictions = pd.concat([predictions, forecast_for_short_series]) # type: ignore
757
757
  return predictions.reindex(original_item_id_order, level=ITEMID)
758
758
 
759
- def _create_tabular_model(self, model_name: str, model_hyperparameters: Dict[str, Any]) -> TabularModel:
759
+ def _create_tabular_model(self, model_name: str, model_hyperparameters: dict[str, Any]) -> TabularModel:
760
760
  model_class = ag_model_registry.key_to_cls(model_name)
761
761
  return TabularModel(
762
762
  model_class=model_class,
@@ -2,7 +2,7 @@ import logging
2
2
  import math
3
3
  import os
4
4
  import time
5
- from typing import Any, Callable, Dict, List, Literal, Optional, Type
5
+ from typing import Any, Callable, Literal, Optional, Type
6
6
 
7
7
  import numpy as np
8
8
  import pandas as pd
@@ -49,15 +49,15 @@ class PerStepTabularModel(AbstractTimeSeriesModel):
49
49
 
50
50
  Other Parameters
51
51
  ----------------
52
- trailing_lags : List[int], default = None
52
+ trailing_lags : list[int], default = None
53
53
  Trailing window lags of the target that will be used as features for predictions.
54
54
  Trailing lags are shifted per forecast step: model for step ``h`` uses ``[lag+h for lag in trailing_lags]``.
55
55
  If None, defaults to ``[1, 2, ..., 12]``.
56
- seasonal_lags: List[int], default = None
56
+ seasonal_lags : list[int], default = None
57
57
  Seasonal lags of the target used as features. Unlike trailing lags, seasonal lags are not shifted
58
58
  but filtered by availability: model for step ``h`` uses ``[lag for lag in seasonal_lags if lag > h]``.
59
59
  If None, determined automatically based on data frequency.
60
- date_features : List[Union[str, Callable]], default = None
60
+ date_features : list[Union[str, Callable]], default = None
61
61
  Features computed from the dates. Can be pandas date attributes or functions that will take the dates as input.
62
62
  If None, will be determined automatically based on the frequency of the data.
63
63
  target_scaler : {"standard", "mean_abs", "min_max", "robust", None}, default = "mean_abs"
@@ -66,7 +66,7 @@ class PerStepTabularModel(AbstractTimeSeriesModel):
66
66
  Name of the tabular regression model. See ``autogluon.tabular.registry.ag_model_registry`` or
67
67
  `the documentation <https://auto.gluon.ai/stable/api/autogluon.tabular.models.html>`_ for the list of available
68
68
  tabular models.
69
- model_hyperparameters : Dict[str, Any], optional
69
+ model_hyperparameters : dict[str, Any], optional
70
70
  Hyperparameters passed to the tabular regression model.
71
71
  validation_fraction : float or None, default = 0.1
72
72
  Fraction of the training data to use for validation. If None or 0.0, no validation set is created.
@@ -94,11 +94,11 @@ class PerStepTabularModel(AbstractTimeSeriesModel):
94
94
  self._date_features: list[Callable]
95
95
  self._model_cls: Type[AbstractTabularModel]
96
96
  self._n_jobs: int
97
- self._non_boolean_real_covariates: List[str] = []
97
+ self._non_boolean_real_covariates: list[str] = []
98
98
  self._max_ts_length: Optional[int] = None
99
99
 
100
100
  @property
101
- def allowed_hyperparameters(self) -> List[str]:
101
+ def allowed_hyperparameters(self) -> list[str]:
102
102
  # TODO: Differencing is currently not supported because it greatly complicates the preprocessing logic
103
103
  return super().allowed_hyperparameters + [
104
104
  "trailing_lags",
@@ -285,10 +285,10 @@ class PerStepTabularModel(AbstractTimeSeriesModel):
285
285
 
286
286
  @staticmethod
287
287
  def _get_lags_for_step(
288
- trailing_lags: List[int],
289
- seasonal_lags: List[int],
288
+ trailing_lags: list[int],
289
+ seasonal_lags: list[int],
290
290
  step: int,
291
- ) -> List[int]:
291
+ ) -> list[int]:
292
292
  """Get the list of lags that can be used by the model for the given step."""
293
293
  shifted_trailing_lags = [lag + step for lag in trailing_lags]
294
294
  # Only keep lags that are available for model predicting `step` values ahead at prediction time
@@ -417,7 +417,7 @@ class PerStepTabularModel(AbstractTimeSeriesModel):
417
417
 
418
418
  Returns
419
419
  -------
420
- predictions :
420
+ predictions
421
421
  Predictions of the model for the given step. Shape: (num_items, len(quantile_levels)).
422
422
  """
423
423
  from mlforecast import MLForecast
@@ -498,5 +498,5 @@ class PerStepTabularModel(AbstractTimeSeriesModel):
498
498
  predictions["mean"] = predictions["0.5"]
499
499
  return TimeSeriesDataFrame(predictions)
500
500
 
501
- def _more_tags(self) -> Dict[str, Any]:
501
+ def _more_tags(self) -> dict[str, Any]:
502
502
  return {"allow_nan": True, "can_refit_full": True}
@@ -3,7 +3,7 @@ import os
3
3
  import shutil
4
4
  import warnings
5
5
  from pathlib import Path
6
- from typing import Any, Dict, Optional, Union
6
+ from typing import Any, Optional, Union
7
7
 
8
8
  import numpy as np
9
9
  import pandas as pd
@@ -110,7 +110,7 @@ class ChronosModel(AbstractTimeSeriesModel):
110
110
 
111
111
  Other Parameters
112
112
  ----------------
113
- model_path: str, default = "autogluon/chronos-bolt-small"
113
+ model_path : str, default = "autogluon/chronos-bolt-small"
114
114
  Model path used for the model, i.e., a HuggingFace transformers ``name_or_path``. Can be a
115
115
  compatible model name on HuggingFace Hub or a local path to a model directory. Original
116
116
  Chronos models (i.e., ``autogluon/chronos-t5-{model_size}``) can be specified with aliases
@@ -144,7 +144,7 @@ class ChronosModel(AbstractTimeSeriesModel):
144
144
  for more information.
145
145
  fine_tune : bool, default = False
146
146
  If True, the pretrained model will be fine-tuned
147
- fine_tune_lr: float, default = 1e-5
147
+ fine_tune_lr : float, default = 1e-5
148
148
  The learning rate used for fine-tuning. This default is suitable for Chronos-Bolt models; for the original
149
149
  Chronos models, we recommend using a higher learning rate such as ``1e-4``
150
150
  fine_tune_steps : int, default = 1000
@@ -162,7 +162,7 @@ class ChronosModel(AbstractTimeSeriesModel):
162
162
  during fine-tuning. If None, the entire validation dataset will be used.
163
163
  fine_tune_trainer_kwargs : dict, optional
164
164
  Extra keyword arguments passed to ``transformers.TrainingArguments``
165
- keep_transformers_logs: bool, default = False
165
+ keep_transformers_logs : bool, default = False
166
166
  If True, the logs generated by transformers will NOT be removed after fine-tuning
167
167
  """
168
168
 
@@ -181,7 +181,7 @@ class ChronosModel(AbstractTimeSeriesModel):
181
181
  path: Optional[str] = None,
182
182
  name: Optional[str] = None,
183
183
  eval_metric: Optional[str] = None,
184
- hyperparameters: Optional[Dict[str, Any]] = None,
184
+ hyperparameters: Optional[dict[str, Any]] = None,
185
185
  **kwargs, # noqa
186
186
  ):
187
187
  hyperparameters = hyperparameters if hyperparameters is not None else {}
@@ -242,7 +242,7 @@ class ChronosModel(AbstractTimeSeriesModel):
242
242
  return self._model_pipeline
243
243
 
244
244
  @property
245
- def ag_default_config(self) -> Dict[str, Any]:
245
+ def ag_default_config(self) -> dict[str, Any]:
246
246
  """The default configuration of the model used by AutoGluon if the model is one of those
247
247
  defined in MODEL_CONFIGS. For now, these are ``autogluon/chronos-t5-*`` family of models.
248
248
  """
@@ -272,8 +272,8 @@ class ChronosModel(AbstractTimeSeriesModel):
272
272
  """
273
273
  return self.ag_default_config.get("default_torch_dtype", "auto")
274
274
 
275
- def get_minimum_resources(self, is_gpu_available: bool = False) -> Dict[str, Union[int, float]]:
276
- minimum_resources: Dict[str, Union[int, float]] = {"num_cpus": 1}
275
+ def get_minimum_resources(self, is_gpu_available: bool = False) -> dict[str, Union[int, float]]:
276
+ minimum_resources: dict[str, Union[int, float]] = {"num_cpus": 1}
277
277
  # if GPU is available, we train with 1 GPU per trial
278
278
  if is_gpu_available:
279
279
  minimum_resources["num_gpus"] = self.min_num_gpus
@@ -323,7 +323,7 @@ class ChronosModel(AbstractTimeSeriesModel):
323
323
 
324
324
  return init_args.copy()
325
325
 
326
- def _get_default_hyperparameters(self) -> Dict:
326
+ def _get_default_hyperparameters(self) -> dict:
327
327
  return {
328
328
  "batch_size": self.default_batch_size,
329
329
  "num_samples": self.default_num_samples,
@@ -688,7 +688,7 @@ class ChronosModel(AbstractTimeSeriesModel):
688
688
 
689
689
  return TimeSeriesDataFrame(df)
690
690
 
691
- def _more_tags(self) -> Dict:
691
+ def _more_tags(self) -> dict:
692
692
  do_fine_tune = self.get_hyperparameters()["fine_tune"]
693
693
  return {
694
694
  "allow_nan": True,
@@ -2,7 +2,7 @@
2
2
 
3
3
  from enum import Enum
4
4
  from pathlib import Path
5
- from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union
5
+ from typing import TYPE_CHECKING, Optional, Union
6
6
 
7
7
  import torch
8
8
 
@@ -18,7 +18,7 @@ class ForecastType(Enum):
18
18
 
19
19
 
20
20
  class PipelineRegistry(type):
21
- REGISTRY: Dict[str, "PipelineRegistry"] = {}
21
+ REGISTRY: dict[str, "PipelineRegistry"] = {}
22
22
 
23
23
  def __new__(cls, name, bases, attrs):
24
24
  """See, https://github.com/faif/python-patterns."""
@@ -43,13 +43,13 @@ class BaseChronosPipeline(metaclass=PipelineRegistry):
43
43
  """
44
44
  Parameters
45
45
  ----------
46
- inner_model : PreTrainedModel
46
+ inner_model
47
47
  A hugging-face transformers PreTrainedModel, e.g., T5ForConditionalGeneration
48
48
  """
49
49
  # for easy access to the inner HF-style model
50
50
  self.inner_model = inner_model
51
51
 
52
- def _prepare_and_validate_context(self, context: Union[torch.Tensor, List[torch.Tensor]]):
52
+ def _prepare_and_validate_context(self, context: Union[torch.Tensor, list[torch.Tensor]]):
53
53
  if isinstance(context, list):
54
54
  context = left_pad_and_stack_1D(context)
55
55
  assert isinstance(context, torch.Tensor)
@@ -61,7 +61,7 @@ class BaseChronosPipeline(metaclass=PipelineRegistry):
61
61
 
62
62
  def predict(
63
63
  self,
64
- context: Union[torch.Tensor, List[torch.Tensor]],
64
+ context: Union[torch.Tensor, list[torch.Tensor]],
65
65
  prediction_length: Optional[int] = None,
66
66
  **kwargs,
67
67
  ):
@@ -88,8 +88,8 @@ class BaseChronosPipeline(metaclass=PipelineRegistry):
88
88
  raise NotImplementedError()
89
89
 
90
90
  def predict_quantiles(
91
- self, context: torch.Tensor, prediction_length: int, quantile_levels: List[float], **kwargs
92
- ) -> Tuple[torch.Tensor, torch.Tensor]:
91
+ self, context: torch.Tensor, prediction_length: int, quantile_levels: list[float], **kwargs
92
+ ) -> tuple[torch.Tensor, torch.Tensor]:
93
93
  """
94
94
  Get quantile and mean forecasts for given time series. All
95
95
  predictions are returned on the CPU.
@@ -104,7 +104,7 @@ class BaseChronosPipeline(metaclass=PipelineRegistry):
104
104
  prediction_length
105
105
  Time steps to predict. Defaults to a model-dependent
106
106
  value if not given.
107
- quantile_levels: List[float]
107
+ quantile_levels
108
108
  Quantile levels to compute
109
109
 
110
110
  Returns
@@ -7,7 +7,7 @@
7
7
  import logging
8
8
  import warnings
9
9
  from dataclasses import dataclass
10
- from typing import Any, Dict, List, Literal, Optional, Tuple, Union
10
+ from typing import Any, Literal, Optional, Union
11
11
 
12
12
  import torch
13
13
  import torch.nn as nn
@@ -29,7 +29,7 @@ class ChronosConfig:
29
29
  """
30
30
 
31
31
  tokenizer_class: str
32
- tokenizer_kwargs: Dict[str, Any]
32
+ tokenizer_kwargs: dict[str, Any]
33
33
  n_tokens: int
34
34
  n_special_tokens: int
35
35
  pad_token_id: int
@@ -66,7 +66,7 @@ class ChronosTokenizer:
66
66
  def context_input_transform(
67
67
  self,
68
68
  context: torch.Tensor,
69
- ) -> Tuple:
69
+ ) -> tuple:
70
70
  """
71
71
  Turn a batch of time series into token IDs, attention mask, and tokenizer_state.
72
72
 
@@ -95,7 +95,7 @@ class ChronosTokenizer:
95
95
  """
96
96
  raise NotImplementedError()
97
97
 
98
- def label_input_transform(self, label: torch.Tensor, tokenizer_state: Any) -> Tuple:
98
+ def label_input_transform(self, label: torch.Tensor, tokenizer_state: Any) -> tuple:
99
99
  """
100
100
  Turn a batch of label slices of time series into token IDs and attention mask
101
101
  using the ``tokenizer_state`` provided by ``context_input_transform``.
@@ -171,7 +171,7 @@ class MeanScaleUniformBins(ChronosTokenizer):
171
171
 
172
172
  def _input_transform(
173
173
  self, context: torch.Tensor, scale: Optional[torch.Tensor] = None
174
- ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
174
+ ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
175
175
  attention_mask = ~torch.isnan(context)
176
176
 
177
177
  if scale is None:
@@ -196,7 +196,7 @@ class MeanScaleUniformBins(ChronosTokenizer):
196
196
 
197
197
  def _append_eos_token(
198
198
  self, token_ids: torch.Tensor, attention_mask: torch.Tensor
199
- ) -> Tuple[torch.Tensor, torch.Tensor]:
199
+ ) -> tuple[torch.Tensor, torch.Tensor]:
200
200
  batch_size = token_ids.shape[0]
201
201
  eos_tokens = torch.full((batch_size, 1), fill_value=self.config.eos_token_id)
202
202
  token_ids = torch.concat((token_ids, eos_tokens), dim=1)
@@ -205,7 +205,7 @@ class MeanScaleUniformBins(ChronosTokenizer):
205
205
 
206
206
  return token_ids, attention_mask
207
207
 
208
- def context_input_transform(self, context: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
208
+ def context_input_transform(self, context: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
209
209
  length = context.shape[-1]
210
210
 
211
211
  if length > self.config.context_length:
@@ -218,7 +218,7 @@ class MeanScaleUniformBins(ChronosTokenizer):
218
218
 
219
219
  return token_ids, attention_mask, scale
220
220
 
221
- def label_input_transform(self, label: torch.Tensor, scale: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
221
+ def label_input_transform(self, label: torch.Tensor, scale: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
222
222
  token_ids, attention_mask, _ = self._input_transform(context=label, scale=scale)
223
223
 
224
224
  if self.config.use_eos_token:
@@ -371,7 +371,7 @@ class ChronosPipeline(BaseChronosPipeline):
371
371
  self.model = model
372
372
 
373
373
  @torch.no_grad()
374
- def embed(self, context: Union[torch.Tensor, List[torch.Tensor]]) -> Tuple[torch.Tensor, Any]:
374
+ def embed(self, context: Union[torch.Tensor, list[torch.Tensor]]) -> tuple[torch.Tensor, Any]:
375
375
  """
376
376
  Get encoder embeddings for the given time series.
377
377
 
@@ -404,7 +404,7 @@ class ChronosPipeline(BaseChronosPipeline):
404
404
 
405
405
  def predict(
406
406
  self,
407
- context: Union[torch.Tensor, List[torch.Tensor]],
407
+ context: Union[torch.Tensor, list[torch.Tensor]],
408
408
  prediction_length: Optional[int] = None,
409
409
  num_samples: Optional[int] = None,
410
410
  temperature: Optional[float] = None,
@@ -494,10 +494,10 @@ class ChronosPipeline(BaseChronosPipeline):
494
494
  self,
495
495
  context: torch.Tensor,
496
496
  prediction_length: int,
497
- quantile_levels: List[float],
497
+ quantile_levels: list[float],
498
498
  num_samples: Optional[int] = None,
499
499
  **kwargs,
500
- ) -> Tuple[torch.Tensor, torch.Tensor]:
500
+ ) -> tuple[torch.Tensor, torch.Tensor]:
501
501
  num_samples = num_samples or self.model.config.num_samples
502
502
  prediction_samples = (
503
503
  self.predict(
@@ -7,7 +7,7 @@ import copy
7
7
  import logging
8
8
  import warnings
9
9
  from dataclasses import dataclass, fields
10
- from typing import List, Optional, Tuple, Union
10
+ from typing import Optional, Union
11
11
 
12
12
  import torch
13
13
  import torch.nn as nn
@@ -32,7 +32,7 @@ class ChronosBoltConfig:
32
32
  prediction_length: int
33
33
  input_patch_size: int
34
34
  input_patch_stride: int
35
- quantiles: List[float]
35
+ quantiles: list[float]
36
36
  use_reg_token: bool = False
37
37
 
38
38
 
@@ -77,8 +77,8 @@ class InstanceNorm(nn.Module):
77
77
  def forward(
78
78
  self,
79
79
  x: torch.Tensor,
80
- loc_scale: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
81
- ) -> Tuple[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:
80
+ loc_scale: Optional[tuple[torch.Tensor, torch.Tensor]] = None,
81
+ ) -> tuple[torch.Tensor, tuple[torch.Tensor, torch.Tensor]]:
82
82
  if loc_scale is None:
83
83
  loc = torch.nan_to_num(torch.nanmean(x, dim=-1, keepdim=True), nan=0.0)
84
84
  scale = torch.nan_to_num((x - loc).square().nanmean(dim=-1, keepdim=True).sqrt(), nan=1.0)
@@ -88,7 +88,7 @@ class InstanceNorm(nn.Module):
88
88
 
89
89
  return (x - loc) / scale, (loc, scale)
90
90
 
91
- def inverse(self, x: torch.Tensor, loc_scale: Tuple[torch.Tensor, torch.Tensor]) -> torch.Tensor:
91
+ def inverse(self, x: torch.Tensor, loc_scale: tuple[torch.Tensor, torch.Tensor]) -> torch.Tensor:
92
92
  loc, scale = loc_scale
93
93
  return x * scale + loc
94
94
 
@@ -343,11 +343,11 @@ class ChronosBoltModelForForecasting(T5PreTrainedModel):
343
343
  """
344
344
  Parameters
345
345
  ----------
346
- input_embeds: torch.Tensor
346
+ input_embeds
347
347
  Patched and embedded inputs. Shape (batch_size, patched_context_length, d_model)
348
- attention_mask: torch.Tensor
348
+ attention_mask
349
349
  Attention mask for the patched context. Shape (batch_size, patched_context_length), type: torch.int64
350
- hidden_states: torch.Tensor
350
+ hidden_states
351
351
  Hidden states returned by the encoder. Shape (batch_size, patched_context_length, d_model)
352
352
 
353
353
  Returns
@@ -385,12 +385,12 @@ class ChronosBoltPipeline(BaseChronosPipeline):
385
385
  self.model_prediction_length: int = self.model.config.chronos_config["prediction_length"]
386
386
 
387
387
  @property
388
- def quantiles(self) -> List[float]:
388
+ def quantiles(self) -> list[float]:
389
389
  return self.model.config.chronos_config["quantiles"]
390
390
 
391
391
  def predict( # type: ignore[override]
392
392
  self,
393
- context: Union[torch.Tensor, List[torch.Tensor]],
393
+ context: Union[torch.Tensor, list[torch.Tensor]],
394
394
  prediction_length: Optional[int] = None,
395
395
  limit_prediction_length: bool = False,
396
396
  ):
@@ -458,8 +458,8 @@ class ChronosBoltPipeline(BaseChronosPipeline):
458
458
  return torch.cat(predictions, dim=-1)[..., :prediction_length]
459
459
 
460
460
  def predict_quantiles(
461
- self, context: torch.Tensor, prediction_length: int, quantile_levels: List[float], **kwargs
462
- ) -> Tuple[torch.Tensor, torch.Tensor]:
461
+ self, context: torch.Tensor, prediction_length: int, quantile_levels: list[float], **kwargs
462
+ ) -> tuple[torch.Tensor, torch.Tensor]:
463
463
  # shape (batch_size, prediction_length, len(training_quantile_levels))
464
464
  predictions = (
465
465
  self.predict(