chronos-forecasting 2.3.0__tar.gz → 2.3.2__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.
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/PKG-INFO +2 -2
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/notebooks/chronos-2-quickstart.ipynb +28 -2
- chronos_forecasting-2.3.2/src/chronos/__about__.py +1 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/src/chronos/chronos2/dataset.py +29 -2
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/src/chronos/chronos2/model.py +2 -2
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/src/chronos/chronos2/pipeline.py +8 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/src/chronos/chronos_bolt.py +7 -3
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/test_chronos2.py +111 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/test_chronos_bolt.py +23 -0
- chronos_forecasting-2.3.0/src/chronos/__about__.py +0 -1
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/.gitattributes +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/.github/ISSUE_TEMPLATE/config.yml +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/.github/workflows/ci.yml +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/.github/workflows/eval-model.yml +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/.github/workflows/publish-to-pypi.yml +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/.gitignore +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/CITATION.cff +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/CODE_OF_CONDUCT.md +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/CONTRIBUTING.md +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/LICENSE +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/NOTICE +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/README.md +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/ci/evaluate/backtest_config.yaml +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/notebooks/deploy-chronos-to-amazon-sagemaker.ipynb +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/pyproject.toml +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/README.md +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/agg-relative-score.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/configs/in-domain.yaml +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/configs/zero-shot.yaml +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/evaluate.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-bolt-base-agg-rel-scores.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-bolt-base-in-domain.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-bolt-base-zero-shot.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-bolt-mini-agg-rel-scores.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-bolt-mini-in-domain.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-bolt-mini-zero-shot.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-bolt-small-agg-rel-scores.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-bolt-small-in-domain.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-bolt-small-zero-shot.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-bolt-tiny-agg-rel-scores.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-bolt-tiny-in-domain.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-bolt-tiny-zero-shot.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-t5-base-agg-rel-scores.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-t5-base-in-domain.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-t5-base-zero-shot.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-t5-large-agg-rel-scores.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-t5-large-in-domain.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-t5-large-zero-shot.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-t5-mini-agg-rel-scores.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-t5-mini-in-domain.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-t5-mini-zero-shot.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-t5-small-agg-rel-scores.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-t5-small-in-domain.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-t5-small-zero-shot.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-t5-tiny-agg-rel-scores.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-t5-tiny-in-domain.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/chronos-t5-tiny-zero-shot.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/seasonal-naive-in-domain.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/results/seasonal-naive-zero-shot.csv +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/kernel-synth.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/training/configs/chronos-gpt2.yaml +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/training/configs/chronos-t5-base.yaml +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/training/configs/chronos-t5-large.yaml +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/training/configs/chronos-t5-mini.yaml +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/training/configs/chronos-t5-small.yaml +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/training/configs/chronos-t5-tiny.yaml +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/training/train.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/src/chronos/__init__.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/src/chronos/base.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/src/chronos/boto_utils.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/src/chronos/chronos.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/src/chronos/chronos2/__init__.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/src/chronos/chronos2/config.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/src/chronos/chronos2/layers.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/src/chronos/chronos2/preprocess.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/src/chronos/chronos2/trainer.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/src/chronos/df_utils.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/src/chronos/utils.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/__init__.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/dummy-chronos-bolt-model/config.json +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/dummy-chronos-bolt-model/model.safetensors +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/dummy-chronos-model/config.json +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/dummy-chronos-model/generation_config.json +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/dummy-chronos-model/model.safetensors +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/dummy-chronos2-lora/adapter_config.json +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/dummy-chronos2-lora/adapter_model.safetensors +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/dummy-chronos2-model/config.json +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/dummy-chronos2-model/model.safetensors +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/test_chronos.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/test_df_utils.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/test_preprocess.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/test_utils.py +0 -0
- {chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/util.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: chronos-forecasting
|
|
3
|
-
Version: 2.3.
|
|
3
|
+
Version: 2.3.2
|
|
4
4
|
Summary: Chronos: Pretrained models for time series forecasting
|
|
5
5
|
Project-URL: Homepage, https://github.com/amazon-science/chronos-forecasting
|
|
6
6
|
Project-URL: Issues, https://github.com/amazon-science/chronos-forecasting/issues
|
{chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/notebooks/chronos-2-quickstart.ipynb
RENAMED
|
@@ -1485,6 +1485,32 @@
|
|
|
1485
1485
|
")"
|
|
1486
1486
|
]
|
|
1487
1487
|
},
|
|
1488
|
+
{
|
|
1489
|
+
"cell_type": "markdown",
|
|
1490
|
+
"id": "d1decf85",
|
|
1491
|
+
"metadata": {},
|
|
1492
|
+
"source": [
|
|
1493
|
+
"Optionally, you can fine-tune with a larger than memory dataset without loading it all to RAM. Here is an example how to do this with a Hugging Face `datasets` library. \n",
|
|
1494
|
+
"\n",
|
|
1495
|
+
"You will need to save your data to disk in batches to avoid loading it all to memory."
|
|
1496
|
+
]
|
|
1497
|
+
},
|
|
1498
|
+
{
|
|
1499
|
+
"cell_type": "code",
|
|
1500
|
+
"execution_count": null,
|
|
1501
|
+
"id": "b2db17cf",
|
|
1502
|
+
"metadata": {},
|
|
1503
|
+
"outputs": [],
|
|
1504
|
+
"source": [
|
|
1505
|
+
"# %pip install datasets\n",
|
|
1506
|
+
"# import datasets\n",
|
|
1507
|
+
"\n",
|
|
1508
|
+
"# path = \"my_lazy_dataset\"\n",
|
|
1509
|
+
"# datasets.Dataset.from_list(train_inputs).save_to_disk(path)\n",
|
|
1510
|
+
"# ds = datasets.load_dataset(path).with_format(\"torch\")\n",
|
|
1511
|
+
"# # Pass `ds` instead of `train_inputs` when calling `fit()`"
|
|
1512
|
+
]
|
|
1513
|
+
},
|
|
1488
1514
|
{
|
|
1489
1515
|
"cell_type": "code",
|
|
1490
1516
|
"execution_count": 19,
|
|
@@ -1766,7 +1792,7 @@
|
|
|
1766
1792
|
"notebook_metadata_filter": "-all"
|
|
1767
1793
|
},
|
|
1768
1794
|
"kernelspec": {
|
|
1769
|
-
"display_name": ".venv
|
|
1795
|
+
"display_name": ".venv",
|
|
1770
1796
|
"language": "python",
|
|
1771
1797
|
"name": "python3"
|
|
1772
1798
|
},
|
|
@@ -1780,7 +1806,7 @@
|
|
|
1780
1806
|
"name": "python",
|
|
1781
1807
|
"nbconvert_exporter": "python",
|
|
1782
1808
|
"pygments_lexer": "ipython3",
|
|
1783
|
-
"version": "3.11.
|
|
1809
|
+
"version": "3.11.15"
|
|
1784
1810
|
}
|
|
1785
1811
|
},
|
|
1786
1812
|
"nbformat": 4,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.3.2"
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# Authors: Abdul Fatir Ansari <ansarnd@amazon.com>
|
|
5
5
|
|
|
6
|
+
import logging
|
|
6
7
|
import math
|
|
7
8
|
from enum import Enum
|
|
8
9
|
from typing import Any, Iterator, Mapping, Sequence, TypeAlias, cast
|
|
@@ -20,8 +21,13 @@ __all__ = [
|
|
|
20
21
|
"PreparedInput",
|
|
21
22
|
]
|
|
22
23
|
|
|
24
|
+
logger = logging.getLogger(__name__)
|
|
25
|
+
|
|
23
26
|
TensorOrArray: TypeAlias = torch.Tensor | np.ndarray
|
|
24
27
|
|
|
28
|
+
# Consecutive too-short draws tolerated during training before giving up on a lazy source.
|
|
29
|
+
MAX_REJECTED_SAMPLES = 10_000
|
|
30
|
+
|
|
25
31
|
|
|
26
32
|
def left_pad_and_cat_2D(tensors: list[torch.Tensor]) -> torch.Tensor:
|
|
27
33
|
"""
|
|
@@ -136,6 +142,7 @@ class Chronos2Dataset(IterableDataset):
|
|
|
136
142
|
raise ValueError("`inputs` is empty. Please provide at least one time series.")
|
|
137
143
|
|
|
138
144
|
self.inputs: Sequence[PreparedInput]
|
|
145
|
+
inputs_are_lazy = False
|
|
139
146
|
if isinstance(inputs, (torch.Tensor, np.ndarray)):
|
|
140
147
|
self.inputs = preprocess.from_tensor(inputs, prediction_length=prediction_length)
|
|
141
148
|
elif isinstance(inputs[0], (torch.Tensor, np.ndarray)):
|
|
@@ -145,11 +152,19 @@ class Chronos2Dataset(IterableDataset):
|
|
|
145
152
|
elif "context" in inputs[0]:
|
|
146
153
|
validate_prepared_schema(inputs[0])
|
|
147
154
|
self.inputs = cast(Sequence[PreparedInput], inputs)
|
|
155
|
+
# A pre-processed sequence may be lazy (e.g. memory-mapped); only TRAIN filters it lazily.
|
|
156
|
+
inputs_are_lazy = mode == DatasetMode.TRAIN and not isinstance(self.inputs, list)
|
|
157
|
+
if inputs_are_lazy:
|
|
158
|
+
logger.info(
|
|
159
|
+
"Treating pre-processed inputs as a lazy source; filtering too-short series on the fly during training."
|
|
160
|
+
)
|
|
148
161
|
else:
|
|
149
162
|
self.inputs = preprocess.from_list_of_dicts(cast(list[dict], inputs), prediction_length=prediction_length)
|
|
150
163
|
|
|
151
|
-
|
|
152
|
-
|
|
164
|
+
self.min_length = min_past + prediction_length
|
|
165
|
+
if mode != DatasetMode.TEST and not inputs_are_lazy:
|
|
166
|
+
# Lazy inputs are filtered on the fly during iteration to keep peak memory O(batch).
|
|
167
|
+
self.inputs = [x for x in self.inputs if x["context"].shape[-1] >= self.min_length]
|
|
153
168
|
if len(self.inputs) == 0:
|
|
154
169
|
raise ValueError(
|
|
155
170
|
"The dataset is empty after filtering based on the length of the time series "
|
|
@@ -263,8 +278,20 @@ class Chronos2Dataset(IterableDataset):
|
|
|
263
278
|
current_batch_size = 0
|
|
264
279
|
input_indices = []
|
|
265
280
|
|
|
281
|
+
n_rejected = 0
|
|
266
282
|
while current_batch_size < self.batch_size:
|
|
267
283
|
input_idx = np.random.randint(len(self.inputs))
|
|
284
|
+
# Reject too-short series lazily rather than pre-filtering the (possibly lazy) source.
|
|
285
|
+
if self.inputs[input_idx]["context"].shape[-1] < self.min_length:
|
|
286
|
+
n_rejected += 1
|
|
287
|
+
if n_rejected >= MAX_REJECTED_SAMPLES:
|
|
288
|
+
raise ValueError(
|
|
289
|
+
f"Could not sample a time series with at least min_past + prediction_length "
|
|
290
|
+
f"({self.min_length}) observations after {MAX_REJECTED_SAMPLES} attempts. Please "
|
|
291
|
+
"provide longer time series or reduce `min_past` or `prediction_length`."
|
|
292
|
+
)
|
|
293
|
+
continue
|
|
294
|
+
n_rejected = 0
|
|
268
295
|
input_indices.append(input_idx)
|
|
269
296
|
current_batch_size += self.inputs[input_idx]["context"].shape[0]
|
|
270
297
|
|
|
@@ -48,7 +48,7 @@ class Chronos2EncoderBlockOutput(ModelOutput):
|
|
|
48
48
|
class Chronos2EncoderBlock(nn.Module):
|
|
49
49
|
def __init__(self, config: Chronos2CoreConfig):
|
|
50
50
|
super().__init__()
|
|
51
|
-
assert not config
|
|
51
|
+
assert not getattr(config, "is_decoder", False)
|
|
52
52
|
|
|
53
53
|
self.layer = nn.ModuleList()
|
|
54
54
|
self.layer.append(TimeSelfAttention(config))
|
|
@@ -99,7 +99,7 @@ class Chronos2EncoderOutput(ModelOutput):
|
|
|
99
99
|
class Chronos2Encoder(nn.Module):
|
|
100
100
|
def __init__(self, config: Chronos2CoreConfig):
|
|
101
101
|
super().__init__()
|
|
102
|
-
assert not config
|
|
102
|
+
assert not getattr(config, "is_decoder", False)
|
|
103
103
|
|
|
104
104
|
self.block = nn.ModuleList([Chronos2EncoderBlock(config) for i in range(config.num_layers)])
|
|
105
105
|
self.final_layer_norm = Chronos2LayerNorm(config.d_model, eps=config.layer_norm_epsilon)
|
|
@@ -1164,6 +1164,14 @@ class Chronos2Pipeline(BaseChronosPipeline):
|
|
|
1164
1164
|
)
|
|
1165
1165
|
from peft import AutoPeftModel
|
|
1166
1166
|
|
|
1167
|
+
# Allow importing the adapter's parent library from our own package.
|
|
1168
|
+
# See https://github.com/huggingface/peft/pull/3090.
|
|
1169
|
+
# The version guard can be dropped once min `peft` is 0.20.
|
|
1170
|
+
from peft import __version__ as peft_version
|
|
1171
|
+
|
|
1172
|
+
if version.parse(peft_version) >= version.parse("0.20.0"):
|
|
1173
|
+
kwargs.setdefault("import_allowlist", ["chronos"])
|
|
1174
|
+
|
|
1167
1175
|
model = AutoPeftModel.from_pretrained(pretrained_model_name_or_path, *args, **kwargs)
|
|
1168
1176
|
model = model.merge_and_unload()
|
|
1169
1177
|
return cls(model=model)
|
|
@@ -121,8 +121,12 @@ class InstanceNorm(nn.Module):
|
|
|
121
121
|
|
|
122
122
|
return scaled_x.to(orig_dtype), (loc, scale)
|
|
123
123
|
|
|
124
|
-
def inverse(
|
|
125
|
-
|
|
124
|
+
def inverse(
|
|
125
|
+
self,
|
|
126
|
+
x: torch.Tensor,
|
|
127
|
+
loc_scale: tuple[torch.Tensor, torch.Tensor],
|
|
128
|
+
output_dtype: torch.dtype | None = None,
|
|
129
|
+
) -> torch.Tensor:
|
|
126
130
|
x = x.to(torch.float32)
|
|
127
131
|
loc, scale = loc_scale
|
|
128
132
|
|
|
@@ -131,7 +135,7 @@ class InstanceNorm(nn.Module):
|
|
|
131
135
|
|
|
132
136
|
x = x * scale + loc
|
|
133
137
|
|
|
134
|
-
return x.to(
|
|
138
|
+
return x if output_dtype is None else x.to(output_dtype)
|
|
135
139
|
|
|
136
140
|
|
|
137
141
|
class ResidualBlock(nn.Module):
|
|
@@ -14,7 +14,9 @@ import torch
|
|
|
14
14
|
|
|
15
15
|
from chronos import BaseChronosPipeline, Chronos2Pipeline
|
|
16
16
|
from chronos.chronos2.config import Chronos2CoreConfig
|
|
17
|
+
from chronos.chronos2.dataset import MAX_REJECTED_SAMPLES, Chronos2Dataset, DatasetMode
|
|
17
18
|
from chronos.chronos2.layers import MHA
|
|
19
|
+
from chronos.chronos2.model import Chronos2Encoder
|
|
18
20
|
from chronos.chronos2.preprocess import from_data_frame
|
|
19
21
|
from chronos.df_utils import make_future_df, normalize_df
|
|
20
22
|
from test.util import create_df, create_future_df, get_forecast_start_times, validate_tensor, timeout_callback
|
|
@@ -31,6 +33,25 @@ def pipeline() -> Chronos2Pipeline:
|
|
|
31
33
|
return BaseChronosPipeline.from_pretrained(DUMMY_MODEL_PATH, device_map="cpu")
|
|
32
34
|
|
|
33
35
|
|
|
36
|
+
def test_chronos2_encoder_accepts_config_without_is_decoder():
|
|
37
|
+
config = Chronos2CoreConfig(d_model=32, d_kv=8, d_ff=32, num_layers=2, num_heads=4)
|
|
38
|
+
|
|
39
|
+
if hasattr(config, "is_decoder"):
|
|
40
|
+
del config.is_decoder
|
|
41
|
+
|
|
42
|
+
encoder = Chronos2Encoder(config)
|
|
43
|
+
|
|
44
|
+
assert len(encoder.block) == config.num_layers
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_when_chronos2_model_uses_bfloat16_then_unscaled_predictions_use_float32(pipeline):
|
|
48
|
+
pipeline.model.to(torch.bfloat16)
|
|
49
|
+
|
|
50
|
+
output = pipeline.model(context=torch.rand(1, 16), num_output_patches=1)
|
|
51
|
+
|
|
52
|
+
assert output.quantile_preds.dtype == torch.float32
|
|
53
|
+
|
|
54
|
+
|
|
34
55
|
def test_base_chronos2_pipeline_loads_from_s3():
|
|
35
56
|
BaseChronosPipeline.from_pretrained("s3://autogluon/chronos-2", device_map="cpu")
|
|
36
57
|
|
|
@@ -1220,3 +1241,93 @@ def test_pipeline_can_be_finetuned_with_preprocessed_hf_dataset(pipeline):
|
|
|
1220
1241
|
for ft_out in ft_outputs:
|
|
1221
1242
|
assert ft_out.shape == (1, DEFAULT_MODEL_NUM_QUANTILES, prediction_length)
|
|
1222
1243
|
assert not torch.isnan(ft_out).any()
|
|
1244
|
+
|
|
1245
|
+
|
|
1246
|
+
class _CountingSequence:
|
|
1247
|
+
def __init__(self, n_items: int, context_length: int) -> None:
|
|
1248
|
+
self._n_items = n_items
|
|
1249
|
+
self._context_length = context_length
|
|
1250
|
+
self.access_count = 0
|
|
1251
|
+
|
|
1252
|
+
def __len__(self) -> int:
|
|
1253
|
+
return self._n_items
|
|
1254
|
+
|
|
1255
|
+
def __getitem__(self, idx: int) -> dict:
|
|
1256
|
+
if not 0 <= idx < self._n_items:
|
|
1257
|
+
raise IndexError(idx)
|
|
1258
|
+
self.access_count += 1
|
|
1259
|
+
return {
|
|
1260
|
+
"context": torch.rand(1, self._context_length),
|
|
1261
|
+
"future_covariates": torch.zeros(1, 0),
|
|
1262
|
+
"n_targets": 1,
|
|
1263
|
+
"n_covariates": 0,
|
|
1264
|
+
"n_future_covariates": 0,
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
|
|
1268
|
+
def test_train_dataset_does_not_materialize_lazy_inputs():
|
|
1269
|
+
n_items, batch_size, num_steps = 10_000, 4, 5
|
|
1270
|
+
src = _CountingSequence(n_items, context_length=64)
|
|
1271
|
+
|
|
1272
|
+
dataset = Chronos2Dataset(
|
|
1273
|
+
inputs=src,
|
|
1274
|
+
context_length=512,
|
|
1275
|
+
prediction_length=8,
|
|
1276
|
+
batch_size=batch_size,
|
|
1277
|
+
output_patch_size=16,
|
|
1278
|
+
mode=DatasetMode.TRAIN,
|
|
1279
|
+
)
|
|
1280
|
+
|
|
1281
|
+
it = iter(dataset)
|
|
1282
|
+
for _ in range(num_steps):
|
|
1283
|
+
next(it)
|
|
1284
|
+
|
|
1285
|
+
assert src.access_count <= 5 * num_steps * batch_size
|
|
1286
|
+
|
|
1287
|
+
|
|
1288
|
+
def test_train_dataset_raises_when_all_lazy_inputs_too_short():
|
|
1289
|
+
prediction_length, min_past = 8, 4
|
|
1290
|
+
src = _CountingSequence(16, context_length=min_past + prediction_length - 1)
|
|
1291
|
+
|
|
1292
|
+
dataset = Chronos2Dataset(
|
|
1293
|
+
inputs=src,
|
|
1294
|
+
context_length=512,
|
|
1295
|
+
prediction_length=prediction_length,
|
|
1296
|
+
batch_size=4,
|
|
1297
|
+
output_patch_size=16,
|
|
1298
|
+
min_past=min_past,
|
|
1299
|
+
mode=DatasetMode.TRAIN,
|
|
1300
|
+
)
|
|
1301
|
+
|
|
1302
|
+
src.access_count = 0
|
|
1303
|
+
with pytest.raises(ValueError, match="at least"):
|
|
1304
|
+
next(iter(dataset))
|
|
1305
|
+
|
|
1306
|
+
assert src.access_count == MAX_REJECTED_SAMPLES
|
|
1307
|
+
|
|
1308
|
+
|
|
1309
|
+
def test_validation_dataset_filters_too_short_preprocessed_inputs():
|
|
1310
|
+
prediction_length, min_past = 8, 4
|
|
1311
|
+
inputs = [
|
|
1312
|
+
{"context": torch.rand(1, 64), "future_covariates": torch.zeros(1, 0),
|
|
1313
|
+
"n_targets": 1, "n_covariates": 0, "n_future_covariates": 0},
|
|
1314
|
+
{"context": torch.rand(1, min_past + prediction_length - 1), "future_covariates": torch.zeros(1, 0),
|
|
1315
|
+
"n_targets": 1, "n_covariates": 0, "n_future_covariates": 0},
|
|
1316
|
+
{"context": torch.rand(1, 64), "future_covariates": torch.zeros(1, 0),
|
|
1317
|
+
"n_targets": 1, "n_covariates": 0, "n_future_covariates": 0},
|
|
1318
|
+
]
|
|
1319
|
+
|
|
1320
|
+
dataset = Chronos2Dataset(
|
|
1321
|
+
inputs=inputs,
|
|
1322
|
+
context_length=512,
|
|
1323
|
+
prediction_length=prediction_length,
|
|
1324
|
+
batch_size=1,
|
|
1325
|
+
output_patch_size=16,
|
|
1326
|
+
min_past=min_past,
|
|
1327
|
+
mode=DatasetMode.VALIDATION,
|
|
1328
|
+
)
|
|
1329
|
+
|
|
1330
|
+
batches = list(dataset)
|
|
1331
|
+
assert len(batches) == 2
|
|
1332
|
+
for batch in batches:
|
|
1333
|
+
assert batch["future_target"].shape[-1] == prediction_length
|
|
@@ -22,6 +22,14 @@ def pipeline() -> ChronosBoltPipeline:
|
|
|
22
22
|
return BaseChronosPipeline.from_pretrained(DUMMY_MODEL_PATH, device_map="cpu")
|
|
23
23
|
|
|
24
24
|
|
|
25
|
+
def test_when_chronos_bolt_model_uses_bfloat16_then_unscaled_predictions_use_float32():
|
|
26
|
+
pipeline = ChronosBoltPipeline.from_pretrained(DUMMY_MODEL_PATH, device_map="cpu", torch_dtype=torch.bfloat16)
|
|
27
|
+
|
|
28
|
+
output = pipeline.model(context=torch.rand(1, 16))
|
|
29
|
+
|
|
30
|
+
assert output.quantile_preds.dtype == torch.float32
|
|
31
|
+
|
|
32
|
+
|
|
25
33
|
def test_base_chronos_pipeline_loads_from_huggingface():
|
|
26
34
|
BaseChronosPipeline.from_pretrained("amazon/chronos-bolt-tiny", device_map="cpu")
|
|
27
35
|
|
|
@@ -355,6 +363,21 @@ def test_when_instancenorm_applied_and_reversed_then_output_correct():
|
|
|
355
363
|
assert torch.allclose(output, input_)
|
|
356
364
|
|
|
357
365
|
|
|
366
|
+
def test_when_instancenorm_reversed_to_float32_then_precision_is_preserved():
|
|
367
|
+
inorm = InstanceNorm()
|
|
368
|
+
normalized = torch.tensor([[0.125]], dtype=torch.bfloat16)
|
|
369
|
+
loc = torch.tensor([[1_000_000.0]], dtype=torch.float32)
|
|
370
|
+
scale = torch.tensor([[100.0]], dtype=torch.float32)
|
|
371
|
+
|
|
372
|
+
output = inorm.inverse(normalized, (loc, scale))
|
|
373
|
+
|
|
374
|
+
assert output.dtype == torch.float32
|
|
375
|
+
torch.testing.assert_close(
|
|
376
|
+
output,
|
|
377
|
+
torch.tensor([[1_000_012.5]], dtype=torch.float32),
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
|
|
358
381
|
@pytest.mark.parametrize("task_kwargs", [{}, {"eval_metric": "WQL", "quantile_levels": [0.1, 0.2]}])
|
|
359
382
|
def test_pipeline_can_evaluate_on_dummy_fev_task(task_kwargs):
|
|
360
383
|
pipeline = BaseChronosPipeline.from_pretrained(
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "2.3.0"
|
|
File without changes
|
{chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/.github/ISSUE_TEMPLATE/bug_report.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/.github/workflows/publish-to-pypi.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/agg-relative-score.py
RENAMED
|
File without changes
|
{chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/configs/in-domain.yaml
RENAMED
|
File without changes
|
{chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/evaluation/configs/zero-shot.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/scripts/training/configs/chronos-gpt2.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/dummy-chronos-bolt-model/config.json
RENAMED
|
File without changes
|
|
File without changes
|
{chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/dummy-chronos-model/config.json
RENAMED
|
File without changes
|
|
File without changes
|
{chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/dummy-chronos-model/model.safetensors
RENAMED
|
File without changes
|
{chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/dummy-chronos2-lora/adapter_config.json
RENAMED
|
File without changes
|
|
File without changes
|
{chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/dummy-chronos2-model/config.json
RENAMED
|
File without changes
|
{chronos_forecasting-2.3.0 → chronos_forecasting-2.3.2}/test/dummy-chronos2-model/model.safetensors
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|