autogluon.timeseries 1.4.1b20250823__tar.gz → 1.4.1b20250920__tar.gz
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.
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/PKG-INFO +1 -1
- autogluon.timeseries-1.4.1b20250920/src/autogluon/timeseries/configs/__init__.py +4 -0
- autogluon.timeseries-1.4.1b20250920/src/autogluon/timeseries/configs/hyperparameter_presets.py +62 -0
- autogluon.timeseries-1.4.1b20250920/src/autogluon/timeseries/configs/predictor_presets.py +84 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/metrics/abstract.py +2 -3
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/__init__.py +2 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/chronos/model.py +4 -1
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/chronos/pipeline/chronos_bolt.py +50 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/multi_window/multi_window_model.py +29 -18
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/predictor.py +2 -2
- autogluon.timeseries-1.4.1b20250920/src/autogluon/timeseries/trainer/__init__.py +3 -0
- autogluon.timeseries-1.4.1b20250920/src/autogluon/timeseries/trainer/model_set_builder.py +256 -0
- autogluon.timeseries-1.4.1b20250920/src/autogluon/timeseries/trainer/prediction_cache.py +149 -0
- {autogluon.timeseries-1.4.1b20250823/src/autogluon/timeseries → autogluon.timeseries-1.4.1b20250920/src/autogluon/timeseries/trainer}/trainer.py +26 -83
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/utils/features.py +1 -1
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/version.py +1 -1
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon.timeseries.egg-info/PKG-INFO +1 -1
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon.timeseries.egg-info/SOURCES.txt +6 -3
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon.timeseries.egg-info/requires.txt +4 -4
- autogluon.timeseries-1.4.1b20250823/src/autogluon/timeseries/configs/__init__.py +0 -3
- autogluon.timeseries-1.4.1b20250823/src/autogluon/timeseries/configs/presets_configs.py +0 -79
- autogluon.timeseries-1.4.1b20250823/src/autogluon/timeseries/models/presets.py +0 -280
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/setup.cfg +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/setup.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/__init__.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/dataset/__init__.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/dataset/ts_dataframe.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/evaluator.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/learner.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/metrics/__init__.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/metrics/point.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/metrics/quantile.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/metrics/utils.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/abstract/__init__.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/abstract/abstract_timeseries_model.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/abstract/model_trial.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/abstract/tunable.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/autogluon_tabular/__init__.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/autogluon_tabular/mlforecast.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/autogluon_tabular/per_step.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/autogluon_tabular/transforms.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/autogluon_tabular/utils.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/chronos/__init__.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/chronos/pipeline/__init__.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/chronos/pipeline/base.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/chronos/pipeline/chronos.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/chronos/pipeline/utils.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/ensemble/__init__.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/ensemble/abstract.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/ensemble/basic.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/ensemble/greedy.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/gluonts/__init__.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/gluonts/abstract.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/gluonts/dataset.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/gluonts/models.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/local/__init__.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/local/abstract_local_model.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/local/naive.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/local/npts.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/local/statsforecast.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/multi_window/__init__.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/models/registry.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/regressor.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/splitter.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/transforms/__init__.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/transforms/covariate_scaler.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/transforms/target_scaler.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/utils/__init__.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/utils/datetime/__init__.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/utils/datetime/base.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/utils/datetime/lags.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/utils/datetime/seasonality.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/utils/datetime/time_features.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/utils/forecast.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon/timeseries/utils/warning_filters.py +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon.timeseries.egg-info/dependency_links.txt +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon.timeseries.egg-info/namespace_packages.txt +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon.timeseries.egg-info/top_level.txt +0 -0
- {autogluon.timeseries-1.4.1b20250823 → autogluon.timeseries-1.4.1b20250920}/src/autogluon.timeseries.egg-info/zip-safe +0 -0
autogluon.timeseries-1.4.1b20250920/src/autogluon/timeseries/configs/hyperparameter_presets.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from typing import Any, Union
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def get_hyperparameter_presets() -> dict[str, dict[str, Union[dict[str, Any], list[dict[str, Any]]]]]:
|
|
5
|
+
return {
|
|
6
|
+
"very_light": {
|
|
7
|
+
"Naive": {},
|
|
8
|
+
"SeasonalNaive": {},
|
|
9
|
+
"ETS": {},
|
|
10
|
+
"Theta": {},
|
|
11
|
+
"RecursiveTabular": {"max_num_samples": 100_000},
|
|
12
|
+
"DirectTabular": {"max_num_samples": 100_000},
|
|
13
|
+
},
|
|
14
|
+
"light": {
|
|
15
|
+
"Naive": {},
|
|
16
|
+
"SeasonalNaive": {},
|
|
17
|
+
"ETS": {},
|
|
18
|
+
"Theta": {},
|
|
19
|
+
"RecursiveTabular": {},
|
|
20
|
+
"DirectTabular": {},
|
|
21
|
+
"TemporalFusionTransformer": {},
|
|
22
|
+
"Chronos": {"model_path": "bolt_small"},
|
|
23
|
+
},
|
|
24
|
+
"light_inference": {
|
|
25
|
+
"SeasonalNaive": {},
|
|
26
|
+
"DirectTabular": {},
|
|
27
|
+
"RecursiveTabular": {},
|
|
28
|
+
"TemporalFusionTransformer": {},
|
|
29
|
+
"PatchTST": {},
|
|
30
|
+
},
|
|
31
|
+
"default": {
|
|
32
|
+
"SeasonalNaive": {},
|
|
33
|
+
"AutoETS": {},
|
|
34
|
+
"NPTS": {},
|
|
35
|
+
"DynamicOptimizedTheta": {},
|
|
36
|
+
"RecursiveTabular": {},
|
|
37
|
+
"DirectTabular": {},
|
|
38
|
+
"TemporalFusionTransformer": {},
|
|
39
|
+
"PatchTST": {},
|
|
40
|
+
"DeepAR": {},
|
|
41
|
+
"Chronos": [
|
|
42
|
+
{
|
|
43
|
+
"ag_args": {"name_suffix": "ZeroShot"},
|
|
44
|
+
"model_path": "bolt_base",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"ag_args": {"name_suffix": "FineTuned"},
|
|
48
|
+
"model_path": "bolt_small",
|
|
49
|
+
"fine_tune": True,
|
|
50
|
+
"target_scaler": "standard",
|
|
51
|
+
"covariate_regressor": {"model_name": "CAT", "model_hyperparameters": {"iterations": 1_000}},
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
"TiDE": {
|
|
55
|
+
"encoder_hidden_dim": 256,
|
|
56
|
+
"decoder_hidden_dim": 256,
|
|
57
|
+
"temporal_hidden_dim": 64,
|
|
58
|
+
"num_batches_per_epoch": 100,
|
|
59
|
+
"lr": 1e-4,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""Preset configurations for autogluon.timeseries Predictors"""
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from . import get_hyperparameter_presets
|
|
6
|
+
|
|
7
|
+
TIMESERIES_PRESETS_ALIASES = dict(
|
|
8
|
+
chronos="chronos_small",
|
|
9
|
+
best="best_quality",
|
|
10
|
+
high="high_quality",
|
|
11
|
+
medium="medium_quality",
|
|
12
|
+
bq="best_quality",
|
|
13
|
+
hq="high_quality",
|
|
14
|
+
mq="medium_quality",
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def get_predictor_presets() -> dict[str, Any]:
|
|
19
|
+
hp_presets = get_hyperparameter_presets()
|
|
20
|
+
|
|
21
|
+
predictor_presets = dict(
|
|
22
|
+
best_quality={"hyperparameters": "default", "num_val_windows": 2},
|
|
23
|
+
high_quality={"hyperparameters": "default"},
|
|
24
|
+
medium_quality={"hyperparameters": "light"},
|
|
25
|
+
fast_training={"hyperparameters": "very_light"},
|
|
26
|
+
# Chronos-Bolt models
|
|
27
|
+
bolt_tiny={
|
|
28
|
+
"hyperparameters": {"Chronos": {"model_path": "bolt_tiny"}},
|
|
29
|
+
"skip_model_selection": True,
|
|
30
|
+
},
|
|
31
|
+
bolt_mini={
|
|
32
|
+
"hyperparameters": {"Chronos": {"model_path": "bolt_mini"}},
|
|
33
|
+
"skip_model_selection": True,
|
|
34
|
+
},
|
|
35
|
+
bolt_small={
|
|
36
|
+
"hyperparameters": {"Chronos": {"model_path": "bolt_small"}},
|
|
37
|
+
"skip_model_selection": True,
|
|
38
|
+
},
|
|
39
|
+
bolt_base={
|
|
40
|
+
"hyperparameters": {"Chronos": {"model_path": "bolt_base"}},
|
|
41
|
+
"skip_model_selection": True,
|
|
42
|
+
},
|
|
43
|
+
# Original Chronos models
|
|
44
|
+
chronos_tiny={
|
|
45
|
+
"hyperparameters": {"Chronos": {"model_path": "tiny"}},
|
|
46
|
+
"skip_model_selection": True,
|
|
47
|
+
},
|
|
48
|
+
chronos_mini={
|
|
49
|
+
"hyperparameters": {"Chronos": {"model_path": "mini"}},
|
|
50
|
+
"skip_model_selection": True,
|
|
51
|
+
},
|
|
52
|
+
chronos_small={
|
|
53
|
+
"hyperparameters": {"Chronos": {"model_path": "small"}},
|
|
54
|
+
"skip_model_selection": True,
|
|
55
|
+
},
|
|
56
|
+
chronos_base={
|
|
57
|
+
"hyperparameters": {"Chronos": {"model_path": "base"}},
|
|
58
|
+
"skip_model_selection": True,
|
|
59
|
+
},
|
|
60
|
+
chronos_large={
|
|
61
|
+
"hyperparameters": {"Chronos": {"model_path": "large", "batch_size": 8}},
|
|
62
|
+
"skip_model_selection": True,
|
|
63
|
+
},
|
|
64
|
+
chronos_ensemble={
|
|
65
|
+
"hyperparameters": {
|
|
66
|
+
"Chronos": {"model_path": "small"},
|
|
67
|
+
**hp_presets["light_inference"],
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
chronos_large_ensemble={
|
|
71
|
+
"hyperparameters": {
|
|
72
|
+
"Chronos": {"model_path": "large", "batch_size": 8},
|
|
73
|
+
**hp_presets["light_inference"],
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
# update with aliases
|
|
79
|
+
predictor_presets = {
|
|
80
|
+
**predictor_presets,
|
|
81
|
+
**{k: predictor_presets[v].copy() for k, v in TIMESERIES_PRESETS_ALIASES.items()},
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return predictor_presets
|
|
@@ -2,7 +2,6 @@ import warnings
|
|
|
2
2
|
from typing import Optional, Sequence, Union, overload
|
|
3
3
|
|
|
4
4
|
import numpy as np
|
|
5
|
-
import numpy.typing as npt
|
|
6
5
|
import pandas as pd
|
|
7
6
|
|
|
8
7
|
from autogluon.timeseries import TimeSeriesDataFrame
|
|
@@ -242,12 +241,12 @@ class TimeSeriesScorer:
|
|
|
242
241
|
@staticmethod
|
|
243
242
|
def check_get_horizon_weight(
|
|
244
243
|
horizon_weight: Union[Sequence[float], np.ndarray], prediction_length: int
|
|
245
|
-
) ->
|
|
244
|
+
) -> np.ndarray: ...
|
|
246
245
|
|
|
247
246
|
@staticmethod
|
|
248
247
|
def check_get_horizon_weight(
|
|
249
248
|
horizon_weight: Union[Sequence[float], np.ndarray, None], prediction_length: int
|
|
250
|
-
) -> Optional[
|
|
249
|
+
) -> Optional[np.ndarray]:
|
|
251
250
|
"""Convert horizon_weight to a non-negative numpy array that sums up to prediction_length.
|
|
252
251
|
Raises an exception if horizon_weight has an invalid shape or contains invalid values.
|
|
253
252
|
|
|
@@ -27,6 +27,7 @@ from .local import (
|
|
|
27
27
|
ThetaModel,
|
|
28
28
|
ZeroModel,
|
|
29
29
|
)
|
|
30
|
+
from .registry import ModelRegistry
|
|
30
31
|
|
|
31
32
|
__all__ = [
|
|
32
33
|
"ADIDAModel",
|
|
@@ -43,6 +44,7 @@ __all__ = [
|
|
|
43
44
|
"ETSModel",
|
|
44
45
|
"IMAPAModel",
|
|
45
46
|
"ChronosModel",
|
|
47
|
+
"ModelRegistry",
|
|
46
48
|
"NPTSModel",
|
|
47
49
|
"NaiveModel",
|
|
48
50
|
"PatchTSTModel",
|
|
@@ -482,9 +482,12 @@ class ChronosModel(AbstractTimeSeriesModel):
|
|
|
482
482
|
|
|
483
483
|
if self.prediction_length != fine_tune_prediction_length:
|
|
484
484
|
logger.debug(
|
|
485
|
-
f"\
|
|
485
|
+
f"\tChronos-Bolt models can only be fine-tuned with a maximum prediction_length of {model_prediction_length}. "
|
|
486
486
|
f"Fine-tuning prediction_length has been changed to {fine_tune_prediction_length}."
|
|
487
487
|
)
|
|
488
|
+
if self.quantile_levels != self.model_pipeline.quantiles:
|
|
489
|
+
self.model_pipeline.model.update_output_quantiles(self.quantile_levels)
|
|
490
|
+
logger.info(f"\tChronos-Bolt will be fine-tuned with quantile_levels={self.quantile_levels}")
|
|
488
491
|
else:
|
|
489
492
|
raise ValueError(f"Unsupported model pipeline: {type(self.model_pipeline)}")
|
|
490
493
|
|
|
@@ -371,6 +371,56 @@ class ChronosBoltModelForForecasting(T5PreTrainedModel):
|
|
|
371
371
|
|
|
372
372
|
return decoder_outputs.last_hidden_state # sequence_outputs, b x 1 x d_model
|
|
373
373
|
|
|
374
|
+
def update_output_quantiles(self, new_quantiles: list[float]) -> None:
|
|
375
|
+
"""In-place updates model's output layer to support only the specified new quantiles by copying weights from closest existing quantiles."""
|
|
376
|
+
old_quantiles = self.chronos_config.quantiles
|
|
377
|
+
new_quantiles = sorted(new_quantiles)
|
|
378
|
+
|
|
379
|
+
if new_quantiles == old_quantiles:
|
|
380
|
+
return
|
|
381
|
+
|
|
382
|
+
self.chronos_config.quantiles = new_quantiles
|
|
383
|
+
self.num_quantiles = len(new_quantiles)
|
|
384
|
+
self.register_buffer("quantiles", torch.tensor(new_quantiles, dtype=self.dtype), persistent=False)
|
|
385
|
+
|
|
386
|
+
old_output_layer = self.output_patch_embedding
|
|
387
|
+
new_output_layer = ResidualBlock(
|
|
388
|
+
in_dim=self.config.d_model,
|
|
389
|
+
h_dim=self.config.d_ff,
|
|
390
|
+
out_dim=len(new_quantiles) * self.chronos_config.prediction_length,
|
|
391
|
+
act_fn_name=self.config.dense_act_fn,
|
|
392
|
+
dropout_p=self.config.dropout_rate,
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
# hidden_layer is shared across all quantiles
|
|
396
|
+
new_output_layer.hidden_layer.weight.data.copy_(old_output_layer.hidden_layer.weight.data)
|
|
397
|
+
if old_output_layer.hidden_layer.bias is not None:
|
|
398
|
+
new_output_layer.hidden_layer.bias.data.copy_(old_output_layer.hidden_layer.bias.data)
|
|
399
|
+
|
|
400
|
+
def copy_quantile_weights(src_idx: int, dst_idx: int):
|
|
401
|
+
"""Copy weights for one quantile from src_idx to dst_idx"""
|
|
402
|
+
prediction_length = self.chronos_config.prediction_length
|
|
403
|
+
src_start, src_end = src_idx * prediction_length, (src_idx + 1) * prediction_length
|
|
404
|
+
dst_start, dst_end = dst_idx * prediction_length, (dst_idx + 1) * prediction_length
|
|
405
|
+
|
|
406
|
+
for layer_name in ["output_layer", "residual_layer"]:
|
|
407
|
+
old_layer_attr = getattr(old_output_layer, layer_name)
|
|
408
|
+
new_layer_attr = getattr(new_output_layer, layer_name)
|
|
409
|
+
|
|
410
|
+
new_layer_attr.weight[dst_start:dst_end] = old_layer_attr.weight[src_start:src_end]
|
|
411
|
+
if old_layer_attr.bias is not None:
|
|
412
|
+
new_layer_attr.bias[dst_start:dst_end] = old_layer_attr.bias[src_start:src_end]
|
|
413
|
+
|
|
414
|
+
with torch.no_grad():
|
|
415
|
+
for new_idx, new_q in enumerate(new_quantiles):
|
|
416
|
+
closest_q = min(old_quantiles, key=lambda x: abs(x - new_q))
|
|
417
|
+
closest_idx = old_quantiles.index(closest_q)
|
|
418
|
+
copy_quantile_weights(closest_idx, new_idx)
|
|
419
|
+
|
|
420
|
+
self.output_patch_embedding = new_output_layer
|
|
421
|
+
self.config.chronos_config["quantiles"] = new_quantiles
|
|
422
|
+
self.chronos_config.quantiles = new_quantiles
|
|
423
|
+
|
|
374
424
|
|
|
375
425
|
class ChronosBoltPipeline(BaseChronosPipeline):
|
|
376
426
|
forecast_type: ForecastType = ForecastType.QUANTILES
|
|
@@ -7,6 +7,7 @@ import time
|
|
|
7
7
|
from typing import Any, Optional, Type, Union
|
|
8
8
|
|
|
9
9
|
import numpy as np
|
|
10
|
+
from typing_extensions import Self
|
|
10
11
|
|
|
11
12
|
import autogluon.core as ag
|
|
12
13
|
from autogluon.timeseries.dataset.ts_dataframe import TimeSeriesDataFrame
|
|
@@ -73,10 +74,6 @@ class MultiWindowBacktestingModel(AbstractTimeSeriesModel):
|
|
|
73
74
|
def supports_past_covariates(self) -> bool:
|
|
74
75
|
return self.model_base.supports_past_covariates
|
|
75
76
|
|
|
76
|
-
@property
|
|
77
|
-
def supports_cat_covariates(self) -> bool:
|
|
78
|
-
return self.model_base.supports_cat_covariates
|
|
79
|
-
|
|
80
77
|
def _get_model_base(self):
|
|
81
78
|
return self.model_base
|
|
82
79
|
|
|
@@ -86,15 +83,18 @@ class MultiWindowBacktestingModel(AbstractTimeSeriesModel):
|
|
|
86
83
|
def _is_gpu_available(self) -> bool:
|
|
87
84
|
return self._get_model_base()._is_gpu_available()
|
|
88
85
|
|
|
89
|
-
def get_minimum_resources(self, is_gpu_available: bool = False) ->
|
|
86
|
+
def get_minimum_resources(self, is_gpu_available: bool = False) -> dict[str, Union[int, float]]:
|
|
90
87
|
return self._get_model_base().get_minimum_resources(is_gpu_available)
|
|
91
88
|
|
|
92
89
|
def _fit(
|
|
93
90
|
self,
|
|
94
91
|
train_data: TimeSeriesDataFrame,
|
|
95
92
|
val_data: Optional[TimeSeriesDataFrame] = None,
|
|
96
|
-
time_limit: Optional[
|
|
97
|
-
|
|
93
|
+
time_limit: Optional[float] = None,
|
|
94
|
+
num_cpus: Optional[int] = None,
|
|
95
|
+
num_gpus: Optional[int] = None,
|
|
96
|
+
verbosity: int = 2,
|
|
97
|
+
val_splitter: Optional[AbstractWindowSplitter] = None,
|
|
98
98
|
refit_every_n_windows: Optional[int] = 1,
|
|
99
99
|
**kwargs,
|
|
100
100
|
):
|
|
@@ -111,11 +111,15 @@ class MultiWindowBacktestingModel(AbstractTimeSeriesModel):
|
|
|
111
111
|
|
|
112
112
|
oof_predictions_per_window = []
|
|
113
113
|
global_fit_start_time = time.time()
|
|
114
|
+
model: Optional[AbstractTimeSeriesModel] = None
|
|
114
115
|
|
|
115
116
|
for window_index, (train_fold, val_fold) in enumerate(val_splitter.split(train_data)):
|
|
116
117
|
logger.debug(f"\tWindow {window_index}")
|
|
118
|
+
|
|
117
119
|
# refit_this_window is always True for the 0th window
|
|
118
120
|
refit_this_window = window_index % refit_every_n_windows == 0
|
|
121
|
+
assert window_index != 0 or refit_this_window
|
|
122
|
+
|
|
119
123
|
if time_limit is None:
|
|
120
124
|
time_left_for_window = None
|
|
121
125
|
else:
|
|
@@ -148,6 +152,7 @@ class MultiWindowBacktestingModel(AbstractTimeSeriesModel):
|
|
|
148
152
|
else:
|
|
149
153
|
time_left_for_prediction = time_limit - (time.time() - global_fit_start_time)
|
|
150
154
|
|
|
155
|
+
assert model is not None
|
|
151
156
|
model.score_and_cache_oof(
|
|
152
157
|
val_fold, store_val_score=True, store_predict_time=True, time_limit=time_left_for_prediction
|
|
153
158
|
)
|
|
@@ -172,11 +177,13 @@ class MultiWindowBacktestingModel(AbstractTimeSeriesModel):
|
|
|
172
177
|
|
|
173
178
|
# Only the model trained on most recent data is saved & used for prediction
|
|
174
179
|
self.most_recent_model = model
|
|
175
|
-
self.
|
|
180
|
+
assert self.most_recent_model is not None
|
|
181
|
+
|
|
182
|
+
self.most_recent_model_folder = most_recent_refit_window # type: ignore
|
|
176
183
|
self.predict_time = self.most_recent_model.predict_time
|
|
177
|
-
self.fit_time = time.time() - global_fit_start_time - self.predict_time
|
|
184
|
+
self.fit_time = time.time() - global_fit_start_time - self.predict_time # type: ignore
|
|
178
185
|
self._oof_predictions = oof_predictions_per_window
|
|
179
|
-
self.val_score = np.mean([info["val_score"] for info in self.info_per_val_window])
|
|
186
|
+
self.val_score = np.mean([info["val_score"] for info in self.info_per_val_window]) # type: ignore
|
|
180
187
|
|
|
181
188
|
def get_info(self) -> dict:
|
|
182
189
|
info = super().get_info()
|
|
@@ -227,7 +234,7 @@ class MultiWindowBacktestingModel(AbstractTimeSeriesModel):
|
|
|
227
234
|
train_fn_kwargs["init_params"]["model_base_kwargs"] = self.get_params()
|
|
228
235
|
return train_fn_kwargs
|
|
229
236
|
|
|
230
|
-
def save(self, path: str = None, verbose=True) -> str:
|
|
237
|
+
def save(self, path: Optional[str] = None, verbose: bool = True) -> str:
|
|
231
238
|
most_recent_model = self.most_recent_model
|
|
232
239
|
self.most_recent_model = None
|
|
233
240
|
save_path = super().save(path, verbose)
|
|
@@ -238,32 +245,36 @@ class MultiWindowBacktestingModel(AbstractTimeSeriesModel):
|
|
|
238
245
|
most_recent_model.save()
|
|
239
246
|
return save_path
|
|
240
247
|
|
|
241
|
-
def persist(self):
|
|
248
|
+
def persist(self) -> Self:
|
|
242
249
|
if self.most_recent_model is None:
|
|
243
250
|
raise ValueError(f"{self.name} must be fit before persisting")
|
|
244
251
|
self.most_recent_model.persist()
|
|
252
|
+
return self
|
|
245
253
|
|
|
246
254
|
@classmethod
|
|
247
255
|
def load(
|
|
248
256
|
cls, path: str, reset_paths: bool = True, load_oof: bool = False, verbose: bool = True
|
|
249
257
|
) -> AbstractTimeSeriesModel:
|
|
250
258
|
model = super().load(path=path, reset_paths=reset_paths, load_oof=load_oof, verbose=verbose)
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
259
|
+
if model.most_recent_model_folder is not None:
|
|
260
|
+
most_recent_model_path = os.path.join(model.path, model.most_recent_model_folder)
|
|
261
|
+
model.most_recent_model = model.model_base_type.load(
|
|
262
|
+
most_recent_model_path,
|
|
263
|
+
reset_paths=reset_paths,
|
|
264
|
+
verbose=verbose,
|
|
265
|
+
)
|
|
257
266
|
return model
|
|
258
267
|
|
|
259
268
|
def convert_to_refit_full_template(self) -> AbstractTimeSeriesModel:
|
|
260
269
|
# refit_model is an instance of base model type, not MultiWindowBacktestingModel
|
|
270
|
+
assert self.most_recent_model is not None, "Most recent model is None. Model must be fit first."
|
|
261
271
|
refit_model = self.most_recent_model.convert_to_refit_full_template()
|
|
262
272
|
refit_model.rename(self.name + ag.constants.REFIT_FULL_SUFFIX)
|
|
263
273
|
return refit_model
|
|
264
274
|
|
|
265
275
|
def convert_to_refit_full_via_copy(self) -> AbstractTimeSeriesModel:
|
|
266
276
|
# refit_model is an instance of base model type, not MultiWindowBacktestingModel
|
|
277
|
+
assert self.most_recent_model is not None, "Most recent model is None. Model must be fit first."
|
|
267
278
|
refit_model = self.most_recent_model.convert_to_refit_full_via_copy()
|
|
268
279
|
refit_model.rename(self.name + ag.constants.REFIT_FULL_SUFFIX)
|
|
269
280
|
return refit_model
|
|
@@ -21,7 +21,7 @@ from autogluon.core.utils.decorators import apply_presets
|
|
|
21
21
|
from autogluon.core.utils.loaders import load_pkl, load_str
|
|
22
22
|
from autogluon.core.utils.savers import save_pkl, save_str
|
|
23
23
|
from autogluon.timeseries import __version__ as current_ag_version
|
|
24
|
-
from autogluon.timeseries.configs import
|
|
24
|
+
from autogluon.timeseries.configs import get_predictor_presets
|
|
25
25
|
from autogluon.timeseries.dataset.ts_dataframe import ITEMID, TimeSeriesDataFrame
|
|
26
26
|
from autogluon.timeseries.learner import TimeSeriesLearner
|
|
27
27
|
from autogluon.timeseries.metrics import TimeSeriesScorer, check_get_evaluation_metric
|
|
@@ -432,7 +432,7 @@ class TimeSeriesPredictor:
|
|
|
432
432
|
)
|
|
433
433
|
return train_data
|
|
434
434
|
|
|
435
|
-
@apply_presets(
|
|
435
|
+
@apply_presets(get_predictor_presets())
|
|
436
436
|
def fit(
|
|
437
437
|
self,
|
|
438
438
|
train_data: Union[TimeSeriesDataFrame, pd.DataFrame, Path, str],
|