autogluon.timeseries 1.3.2b20250712__py3-none-any.whl → 1.4.1b20251116__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.
Files changed (90) hide show
  1. autogluon/timeseries/configs/__init__.py +3 -2
  2. autogluon/timeseries/configs/hyperparameter_presets.py +62 -0
  3. autogluon/timeseries/configs/predictor_presets.py +84 -0
  4. autogluon/timeseries/dataset/ts_dataframe.py +98 -72
  5. autogluon/timeseries/learner.py +19 -18
  6. autogluon/timeseries/metrics/__init__.py +5 -5
  7. autogluon/timeseries/metrics/abstract.py +17 -17
  8. autogluon/timeseries/metrics/point.py +1 -1
  9. autogluon/timeseries/metrics/quantile.py +2 -2
  10. autogluon/timeseries/metrics/utils.py +4 -4
  11. autogluon/timeseries/models/__init__.py +4 -0
  12. autogluon/timeseries/models/abstract/abstract_timeseries_model.py +52 -75
  13. autogluon/timeseries/models/abstract/tunable.py +6 -6
  14. autogluon/timeseries/models/autogluon_tabular/mlforecast.py +72 -76
  15. autogluon/timeseries/models/autogluon_tabular/per_step.py +104 -46
  16. autogluon/timeseries/models/autogluon_tabular/transforms.py +9 -7
  17. autogluon/timeseries/models/chronos/model.py +115 -78
  18. autogluon/timeseries/models/chronos/{pipeline/utils.py → utils.py} +76 -44
  19. autogluon/timeseries/models/ensemble/__init__.py +29 -2
  20. autogluon/timeseries/models/ensemble/abstract.py +16 -52
  21. autogluon/timeseries/models/ensemble/array_based/__init__.py +3 -0
  22. autogluon/timeseries/models/ensemble/array_based/abstract.py +247 -0
  23. autogluon/timeseries/models/ensemble/array_based/models.py +50 -0
  24. autogluon/timeseries/models/ensemble/array_based/regressor/__init__.py +10 -0
  25. autogluon/timeseries/models/ensemble/array_based/regressor/abstract.py +87 -0
  26. autogluon/timeseries/models/ensemble/array_based/regressor/per_quantile_tabular.py +133 -0
  27. autogluon/timeseries/models/ensemble/array_based/regressor/tabular.py +141 -0
  28. autogluon/timeseries/models/ensemble/weighted/__init__.py +8 -0
  29. autogluon/timeseries/models/ensemble/weighted/abstract.py +41 -0
  30. autogluon/timeseries/models/ensemble/{basic.py → weighted/basic.py} +8 -18
  31. autogluon/timeseries/models/ensemble/{greedy.py → weighted/greedy.py} +13 -13
  32. autogluon/timeseries/models/gluonts/abstract.py +26 -26
  33. autogluon/timeseries/models/gluonts/dataset.py +4 -4
  34. autogluon/timeseries/models/gluonts/models.py +27 -12
  35. autogluon/timeseries/models/local/abstract_local_model.py +14 -14
  36. autogluon/timeseries/models/local/naive.py +4 -0
  37. autogluon/timeseries/models/local/npts.py +1 -0
  38. autogluon/timeseries/models/local/statsforecast.py +30 -14
  39. autogluon/timeseries/models/multi_window/multi_window_model.py +34 -23
  40. autogluon/timeseries/models/registry.py +65 -0
  41. autogluon/timeseries/models/toto/__init__.py +3 -0
  42. autogluon/timeseries/models/toto/_internal/__init__.py +9 -0
  43. autogluon/timeseries/models/toto/_internal/backbone/__init__.py +3 -0
  44. autogluon/timeseries/models/toto/_internal/backbone/attention.py +197 -0
  45. autogluon/timeseries/models/toto/_internal/backbone/backbone.py +262 -0
  46. autogluon/timeseries/models/toto/_internal/backbone/distribution.py +70 -0
  47. autogluon/timeseries/models/toto/_internal/backbone/kvcache.py +136 -0
  48. autogluon/timeseries/models/toto/_internal/backbone/rope.py +94 -0
  49. autogluon/timeseries/models/toto/_internal/backbone/scaler.py +306 -0
  50. autogluon/timeseries/models/toto/_internal/backbone/transformer.py +333 -0
  51. autogluon/timeseries/models/toto/_internal/dataset.py +165 -0
  52. autogluon/timeseries/models/toto/_internal/forecaster.py +423 -0
  53. autogluon/timeseries/models/toto/dataloader.py +108 -0
  54. autogluon/timeseries/models/toto/hf_pretrained_model.py +119 -0
  55. autogluon/timeseries/models/toto/model.py +236 -0
  56. autogluon/timeseries/predictor.py +94 -107
  57. autogluon/timeseries/regressor.py +31 -27
  58. autogluon/timeseries/splitter.py +7 -31
  59. autogluon/timeseries/trainer/__init__.py +3 -0
  60. autogluon/timeseries/trainer/ensemble_composer.py +250 -0
  61. autogluon/timeseries/trainer/model_set_builder.py +256 -0
  62. autogluon/timeseries/trainer/prediction_cache.py +149 -0
  63. autogluon/timeseries/{trainer.py → trainer/trainer.py} +182 -307
  64. autogluon/timeseries/trainer/utils.py +18 -0
  65. autogluon/timeseries/transforms/covariate_scaler.py +4 -4
  66. autogluon/timeseries/transforms/target_scaler.py +14 -14
  67. autogluon/timeseries/utils/datetime/lags.py +2 -2
  68. autogluon/timeseries/utils/datetime/time_features.py +2 -2
  69. autogluon/timeseries/utils/features.py +41 -37
  70. autogluon/timeseries/utils/forecast.py +5 -5
  71. autogluon/timeseries/utils/warning_filters.py +3 -1
  72. autogluon/timeseries/version.py +1 -1
  73. autogluon.timeseries-1.4.1b20251116-py3.9-nspkg.pth +1 -0
  74. {autogluon.timeseries-1.3.2b20250712.dist-info → autogluon_timeseries-1.4.1b20251116.dist-info}/METADATA +32 -17
  75. autogluon_timeseries-1.4.1b20251116.dist-info/RECORD +96 -0
  76. {autogluon.timeseries-1.3.2b20250712.dist-info → autogluon_timeseries-1.4.1b20251116.dist-info}/WHEEL +1 -1
  77. autogluon/timeseries/configs/presets_configs.py +0 -79
  78. autogluon/timeseries/evaluator.py +0 -6
  79. autogluon/timeseries/models/chronos/pipeline/__init__.py +0 -10
  80. autogluon/timeseries/models/chronos/pipeline/base.py +0 -160
  81. autogluon/timeseries/models/chronos/pipeline/chronos.py +0 -544
  82. autogluon/timeseries/models/chronos/pipeline/chronos_bolt.py +0 -530
  83. autogluon/timeseries/models/presets.py +0 -358
  84. autogluon.timeseries-1.3.2b20250712-py3.9-nspkg.pth +0 -1
  85. autogluon.timeseries-1.3.2b20250712.dist-info/RECORD +0 -71
  86. {autogluon.timeseries-1.3.2b20250712.dist-info → autogluon_timeseries-1.4.1b20251116.dist-info/licenses}/LICENSE +0 -0
  87. {autogluon.timeseries-1.3.2b20250712.dist-info → autogluon_timeseries-1.4.1b20251116.dist-info/licenses}/NOTICE +0 -0
  88. {autogluon.timeseries-1.3.2b20250712.dist-info → autogluon_timeseries-1.4.1b20251116.dist-info}/namespace_packages.txt +0 -0
  89. {autogluon.timeseries-1.3.2b20250712.dist-info → autogluon_timeseries-1.4.1b20251116.dist-info}/top_level.txt +0 -0
  90. {autogluon.timeseries-1.3.2b20250712.dist-info → autogluon_timeseries-1.4.1b20251116.dist-info}/zip-safe +0 -0
@@ -0,0 +1,236 @@
1
+ import logging
2
+ import os
3
+ from typing import TYPE_CHECKING, Any, Optional, Sequence, Union
4
+
5
+ import numpy as np
6
+ import pandas as pd
7
+ from typing_extensions import Self
8
+
9
+ from autogluon.common.loaders import load_pkl
10
+ from autogluon.timeseries import TimeSeriesDataFrame
11
+ from autogluon.timeseries.models.abstract import AbstractTimeSeriesModel
12
+ from autogluon.timeseries.utils.features import CovariateMetadata
13
+
14
+ if TYPE_CHECKING:
15
+ from ._internal import TotoForecaster
16
+
17
+ logger = logging.getLogger(__name__)
18
+
19
+
20
+ class TotoModel(AbstractTimeSeriesModel):
21
+ """Toto (Time-Series-Optimized Transformer for Observability) [CohenKhwajaetal2025]_ pretrained time series forecasting model.
22
+
23
+ Toto is a 151M parameter model trained on over 1T data points from DataDog's internal observability systems, as well as
24
+ the GIFT-eval pretrain, Chronos pretraining, and synthetically generated time series corpora. It is a decoder-only
25
+ architecture that autoregressively outputs parametric distribution forecasts. More details can be found on
26
+ `Hugging Face <https://huggingface.co/Datadog/Toto-Open-Base-1.0>`_ and `GitHub <https://github.com/DataDog/toto>`_.
27
+
28
+ The AutoGluon implementation of Toto is on a port of the original implementation. AutoGluon supports Toto for
29
+ **inference only**, i.e., the model will not be trained or fine-tuned on the provided training data. Toto is optimized
30
+ for easy maintenance with the rest of the AutoGluon model zoo, and does not feature some important optimizations such
31
+ as xformers and flash-attention available in the original model repository. The AutoGluon implementation of Toto
32
+ requires a CUDA-compatible GPU.
33
+
34
+ References
35
+ ----------
36
+ .. [CohenKhwajaetal2025] Cohen, Ben, Khwaja, Emaad et al.
37
+ "This Time is Different: An Observability Perspective on Time Series Foundation Models."
38
+ https://arxiv.org/abs/2505.14766
39
+
40
+
41
+ Other Parameters
42
+ ----------------
43
+ model_path : str, default = "Datadog/Toto-Open-Base-1.0"
44
+ Model path used for the model, i.e., a HuggingFace transformers ``name_or_path``. Can be a
45
+ compatible model name on HuggingFace Hub or a local path to a model directory.
46
+ batch_size : int, default = 24
47
+ Size of batches used during inference.
48
+ num_samples : int, default = 256
49
+ Number of samples used during inference.
50
+ device : str, default = "cuda"
51
+ Device to use for inference. Toto requires a CUDA-compatible GPU to run.
52
+ context_length : int or None, default = 4096
53
+ The context length to use in the model. Shorter context lengths will decrease model accuracy, but result
54
+ in faster inference.
55
+ compile_model : bool, default = True
56
+ Whether to compile the model using torch.compile() for faster inference. May increase initial loading time
57
+ but can provide speedups during inference.
58
+ """
59
+
60
+ default_model_path: str = "Datadog/Toto-Open-Base-1.0"
61
+
62
+ def __init__(
63
+ self,
64
+ path: Optional[str] = None,
65
+ name: Optional[str] = None,
66
+ hyperparameters: Optional[dict[str, Any]] = None,
67
+ freq: Optional[str] = None,
68
+ prediction_length: int = 1,
69
+ covariate_metadata: Optional[CovariateMetadata] = None,
70
+ target: str = "target",
71
+ quantile_levels: Sequence[float] = (0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9),
72
+ eval_metric: Any = None,
73
+ ):
74
+ hyperparameters = hyperparameters if hyperparameters is not None else {}
75
+
76
+ self.model_path = hyperparameters.get("model_path", self.default_model_path)
77
+
78
+ super().__init__(
79
+ path=path,
80
+ name=name,
81
+ hyperparameters=hyperparameters,
82
+ freq=freq,
83
+ prediction_length=prediction_length,
84
+ covariate_metadata=covariate_metadata,
85
+ target=target,
86
+ quantile_levels=quantile_levels,
87
+ eval_metric=eval_metric,
88
+ )
89
+
90
+ self._forecaster: Optional[TotoForecaster] = None
91
+
92
+ def save(self, path: Optional[str] = None, verbose: bool = True) -> str:
93
+ forecaster = self._forecaster
94
+ self._forecaster = None
95
+ path = super().save(path=path, verbose=verbose)
96
+ self._forecaster = forecaster
97
+
98
+ return str(path)
99
+
100
+ @classmethod
101
+ def load(cls, path: str, reset_paths: bool = True, load_oof: bool = False, verbose: bool = True) -> Self:
102
+ model = load_pkl.load(path=os.path.join(path, cls.model_file_name), verbose=verbose)
103
+ if reset_paths:
104
+ model.set_contexts(path)
105
+
106
+ return model
107
+
108
+ def _is_gpu_available(self) -> bool:
109
+ import torch.cuda
110
+
111
+ return torch.cuda.is_available()
112
+
113
+ def get_minimum_resources(self, is_gpu_available: bool = False) -> dict[str, Union[int, float]]:
114
+ return {"num_cpus": 1, "num_gpus": 1}
115
+
116
+ def load_forecaster(self):
117
+ from ._internal import TotoForecaster
118
+ from .hf_pretrained_model import TotoConfig, TotoPretrainedModel
119
+
120
+ if not self._is_gpu_available():
121
+ raise RuntimeError(
122
+ f"{self.name} requires a GPU to run, but no GPU was detected. "
123
+ "Please make sure that you are using a computer with a CUDA-compatible GPU and "
124
+ "`import torch; torch.cuda.is_available()` returns `True`."
125
+ )
126
+
127
+ hyperparameters = self.get_hyperparameters()
128
+ pretrained_model = TotoPretrainedModel.from_pretrained(
129
+ self.model_path,
130
+ config=TotoConfig.from_pretrained(self.model_path),
131
+ device_map=hyperparameters["device"],
132
+ )
133
+
134
+ if hyperparameters["compile_model"]:
135
+ pretrained_model.model.compile()
136
+
137
+ self._forecaster = TotoForecaster(model=pretrained_model.model)
138
+
139
+ def persist(self) -> Self:
140
+ if self._forecaster is None:
141
+ self.load_forecaster()
142
+ return self
143
+
144
+ def _get_default_hyperparameters(self) -> dict:
145
+ return {
146
+ "batch_size": 24,
147
+ "num_samples": 256,
148
+ "device": "cuda",
149
+ "context_length": 4096,
150
+ "compile_model": True,
151
+ }
152
+
153
+ @property
154
+ def allowed_hyperparameters(self) -> list[str]:
155
+ return super().allowed_hyperparameters + [
156
+ "model_path",
157
+ "batch_size",
158
+ "num_samples",
159
+ "device",
160
+ "context_length",
161
+ "compile_model",
162
+ ]
163
+
164
+ def _more_tags(self) -> dict:
165
+ return {
166
+ "allow_nan": True,
167
+ "can_use_train_data": False,
168
+ "can_use_val_data": False,
169
+ }
170
+
171
+ def _fit(
172
+ self,
173
+ train_data: TimeSeriesDataFrame,
174
+ val_data: Optional[TimeSeriesDataFrame] = None,
175
+ time_limit: Optional[float] = None,
176
+ num_cpus: Optional[int] = None,
177
+ num_gpus: Optional[int] = None,
178
+ verbosity: int = 2,
179
+ **kwargs,
180
+ ) -> None:
181
+ self._check_fit_params()
182
+ self.load_forecaster()
183
+
184
+ def _predict(
185
+ self, data: TimeSeriesDataFrame, known_covariates: Optional[TimeSeriesDataFrame] = None, **kwargs
186
+ ) -> TimeSeriesDataFrame:
187
+ import torch
188
+
189
+ from .dataloader import TotoDataLoader, TotoInferenceDataset
190
+
191
+ hyperparameters = self.get_hyperparameters()
192
+
193
+ if self._forecaster is None:
194
+ self.load_forecaster()
195
+ assert self._forecaster, "Toto model failed to load"
196
+ device = self._forecaster.model.device
197
+
198
+ dataset = TotoInferenceDataset(
199
+ target_df=data.fill_missing_values("auto"),
200
+ max_context_length=hyperparameters["context_length"],
201
+ )
202
+ loader = TotoDataLoader(
203
+ dataset,
204
+ freq=self.freq,
205
+ batch_size=hyperparameters["batch_size"],
206
+ time_limit=kwargs.get("time_limit"),
207
+ device=device,
208
+ )
209
+
210
+ batch_means, batch_quantiles = [], []
211
+ with torch.inference_mode():
212
+ for masked_timeseries in loader:
213
+ forecast = self._forecaster.forecast(
214
+ masked_timeseries,
215
+ prediction_length=self.prediction_length,
216
+ num_samples=hyperparameters["num_samples"],
217
+ samples_per_batch=32,
218
+ )
219
+
220
+ batch_means.append(forecast.mean.cpu().numpy())
221
+ qs = np.array([forecast.quantile(q).cpu().numpy() for q in self.quantile_levels])
222
+ batch_quantiles.append(qs.squeeze(2).transpose(1, 2, 0))
223
+
224
+ df = pd.DataFrame(
225
+ np.concatenate(
226
+ [
227
+ np.concatenate(batch_means, axis=0).reshape(-1, 1),
228
+ np.concatenate(batch_quantiles, axis=0).reshape(-1, len(self.quantile_levels)),
229
+ ],
230
+ axis=1,
231
+ ),
232
+ columns=["mean"] + [str(q) for q in self.quantile_levels],
233
+ index=self.get_forecast_horizon_index(data),
234
+ )
235
+
236
+ return TimeSeriesDataFrame(df)