-
Notifications
You must be signed in to change notification settings - Fork 194
Chronos 2 #660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abaranov25
wants to merge
15
commits into
sintel-dev:master
Choose a base branch
from
abaranov25:chronos-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Chronos 2 #660
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ea80ca7
Added Cisco and Chronos2 Time Series Foundation Models to Orion
d8a70ee
Added dataset-specific JSON files for Cisco and Chronos2
aa239f4
Add chronos2 tutorial notebook with hyperparameters
2771272
Remove cisco files from chronos-2 branch
014b12c
Addressing minor issues in PR
81de3ca
Cleaned tutorial notebook with multivariate dataset
afd81e2
Updated primitive to have cleaner hyperparameters
b18e62b
Merge remote-tracking branch 'origin/master' into chronos-2
4413c8a
Fixed lints
99dd617
Fix failed tests
223c89e
Made notebook smaller to run faster
1a95944
Addressed latest comments
aa2f7c3
Reordering imports
cb64765
Fix lint error
ee8f8b9
Added chronos2 time_interval parameter to jsons
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| { | ||
| "primitives": [ | ||
| "mlstars.custom.timeseries_preprocessing.time_segments_aggregate", | ||
| "sklearn.impute.SimpleImputer", | ||
| "mlstars.custom.timeseries_preprocessing.rolling_window_sequences", | ||
| "orion.primitives.chronos2.Chronos2", | ||
| "orion.primitives.timeseries_errors.regression_errors", | ||
| "orion.primitives.timeseries_anomalies.find_anomalies" | ||
| ], | ||
| "init_params": { | ||
| "mlstars.custom.timeseries_preprocessing.time_segments_aggregate#1": { | ||
| "time_column": "timestamp", | ||
| "interval": 21600, | ||
| "method": "mean" | ||
| }, | ||
| "mlstars.custom.timeseries_preprocessing.rolling_window_sequences#1": { | ||
| "target_column": 0, | ||
| "window_size": 250 | ||
| }, | ||
| "orion.primitives.chronos2.Chronos2#1": { | ||
| "time_interval": 21600 | ||
| }, | ||
| "orion.primitives.timeseries_anomalies.find_anomalies#1": { | ||
| "window_size_portion": 0.33, | ||
| "window_step_size_portion": 0.1, | ||
| "fixed_threshold": true | ||
| } | ||
| }, | ||
| "input_names": { | ||
| "orion.primitives.chronos2.Chronos2#1": { | ||
| "start_indices": "index" | ||
| }, | ||
| "orion.primitives.timeseries_anomalies.find_anomalies#1": { | ||
| "index": "target_index" | ||
| } | ||
| }, | ||
| "output_names": { | ||
| "orion.primitives.timeseries_anomalies.find_anomalies#1": { | ||
| "y": "anomalies" | ||
| } | ||
| } | ||
| } | ||
9 changes: 9 additions & 0 deletions
9
orion/pipelines/pretrained/chronos2/chronos2_artificialwithanomaly.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "mlstars.custom.timeseries_preprocessing.time_segments_aggregate#1": { | ||
| "time_column": "timestamp", | ||
| "interval": 600 | ||
| }, | ||
| "orion.primitives.chronos2.Chronos2#1": { | ||
| "time_interval": 600 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,9 @@ | ||||||||||||
| { | ||||||||||||
| "mlstars.custom.timeseries_preprocessing.time_segments_aggregate#1": { | ||||||||||||
| "time_column": "timestamp", | ||||||||||||
| "interval": 21600 | ||||||||||||
| }, | ||||||||||||
| "orion.primitives.chronos2.Chronos2#1": { | ||||||||||||
| "time_interval": 21600 | ||||||||||||
| } | ||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be adjusted for all datasets
Suggested change
|
||||||||||||
| } | ||||||||||||
9 changes: 9 additions & 0 deletions
9
orion/pipelines/pretrained/chronos2/chronos2_realadexchange.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "mlstars.custom.timeseries_preprocessing.time_segments_aggregate#1": { | ||
| "time_column": "timestamp", | ||
| "interval": 3600 | ||
| }, | ||
| "orion.primitives.chronos2.Chronos2#1": { | ||
| "time_interval": 3600 | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
orion/pipelines/pretrained/chronos2/chronos2_realawscloudwatch.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "mlstars.custom.timeseries_preprocessing.time_segments_aggregate#1": { | ||
| "time_column": "timestamp", | ||
| "interval": 600 | ||
| }, | ||
| "orion.primitives.chronos2.Chronos2#1": { | ||
| "time_interval": 600 | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
orion/pipelines/pretrained/chronos2/chronos2_realtraffic.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "mlstars.custom.timeseries_preprocessing.time_segments_aggregate#1": { | ||
| "time_column": "timestamp", | ||
| "interval": 600 | ||
| }, | ||
| "orion.primitives.chronos2.Chronos2#1": { | ||
| "time_interval": 600 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "mlstars.custom.timeseries_preprocessing.time_segments_aggregate#1": { | ||
| "time_column": "timestamp", | ||
| "interval": 600 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "mlstars.custom.timeseries_preprocessing.time_segments_aggregate#1": { | ||
| "time_column": "timestamp", | ||
| "interval": 21600 | ||
| }, | ||
| "orion.primitives.chronos2.Chronos2#1": { | ||
| "time_interval": 21600 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "mlstars.custom.timeseries_preprocessing.time_segments_aggregate#1": { | ||
| "time_column": "timestamp", | ||
| "interval": 300 | ||
| }, | ||
| "orion.primitives.chronos2.Chronos2#1": { | ||
| "time_interval": 300 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "mlstars.custom.timeseries_preprocessing.time_segments_aggregate#1": { | ||
| "time_column": "timestamp", | ||
| "interval": 1 | ||
| }, | ||
| "orion.primitives.chronos2.Chronos2#1": { | ||
| "time_interval": 1 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "mlstars.custom.timeseries_preprocessing.time_segments_aggregate#1": { | ||
| "time_column": "timestamp", | ||
| "interval": 1 | ||
| }, | ||
| "orion.primitives.chronos2.Chronos2#1": { | ||
| "time_interval": 1 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "mlstars.custom.timeseries_preprocessing.time_segments_aggregate#1": { | ||
| "time_column": "timestamp", | ||
| "interval": 1 | ||
| }, | ||
| "orion.primitives.chronos2.Chronos2#1": { | ||
| "time_interval": 1 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "mlstars.custom.timeseries_preprocessing.time_segments_aggregate#1": { | ||
| "time_column": "timestamp", | ||
| "interval": 1 | ||
| }, | ||
| "orion.primitives.chronos2.Chronos2#1": { | ||
| "time_interval": 1 | ||
| } | ||
| } |
sarahmish marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| """ | ||
| This primitive an implementation of Amazon's Chronos2 model for timeseries forecasting. | ||
|
|
||
| The model implementation can be found at | ||
| https://huggingface.co/amazon/chronos-2 | ||
| """ | ||
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
| import torch | ||
|
|
||
| from chronos import Chronos2Pipeline | ||
|
|
||
|
|
||
| class Chronos2: | ||
| """Chronos2 model for timeseries forecasting. | ||
|
|
||
| Args: | ||
| pred_len (int): | ||
| Prediction horizon length. Default to 1. | ||
| repo_id (str): | ||
| Directory of the model checkpoint. Default to "amazon/chronos-2" | ||
| batch_size(int): | ||
| Size of one batch. Default to 32. | ||
| target (int): | ||
| Index of target column in multivariate case. Default to 0. | ||
| start_time (datetime): | ||
| Start time of the timeseries. Default to Jan 1, 2020 00:00:00. | ||
| time_interval (int): | ||
| Time interval between two samples in seconds. Default to 600. | ||
|
|
||
| Returns: | ||
| np.ndarray: | ||
| Forecasted timeseries. | ||
| """ | ||
|
|
||
| def __init__(self, | ||
| pred_len=1, | ||
| repo_id="amazon/chronos-2", | ||
| batch_size=32, | ||
| target=0, | ||
| time_interval=21600): | ||
|
|
||
| self.pred_len = pred_len | ||
| self.batch_size = batch_size | ||
| self.target = f"{target}" | ||
| self.time_interval = time_interval | ||
| self.cur_item_id = 0 | ||
|
|
||
| device = "cuda" if torch.cuda.is_available() else "cpu" | ||
| self.model = Chronos2Pipeline.from_pretrained(repo_id, device_map=device) | ||
|
|
||
| def predict(self, X, start_indices, force=False): | ||
| """Forecasting timeseries | ||
|
|
||
| Args: | ||
| X (ndarray): | ||
| input timeseries with shape (n_windows, window_size, n_features). | ||
| Return: | ||
| ndarray: | ||
| forecasted timeseries. | ||
| """ | ||
| n_windows = X.shape[0] | ||
| outs = [] | ||
|
|
||
| for i in range(0, n_windows, self.batch_size): | ||
| x_batch = self.convert_to_df(X[i:i + self.batch_size], | ||
| start_timestamps=start_indices[i:i + self.batch_size]) | ||
| y_batch = self.model.predict_df( | ||
| df=x_batch, | ||
| prediction_length=self.pred_len, | ||
| id_column="item_id", | ||
| timestamp_column="timestamp", | ||
| target=self.target, | ||
| ) | ||
|
|
||
| y_batch = y_batch.sort_values(["item_id", "timestamp"]) | ||
| preds = np.stack( | ||
| y_batch.groupby("item_id", sort=False)["predictions"] | ||
| .apply(lambda s: s.to_numpy()) | ||
| .to_list() | ||
| ) | ||
| outs.append(preds) | ||
|
|
||
| return np.concatenate(outs, axis=0) | ||
|
|
||
| def convert_to_df(self, x_batch, start_timestamps): | ||
| n_windows_in_batch, window_size, n_features = x_batch.shape | ||
|
|
||
| rows = [] | ||
| for window in range(n_windows_in_batch): | ||
| for data_entry in range(window_size): | ||
| rows.append({ | ||
| "timestamp": start_timestamps[window] + self.time_interval * data_entry, | ||
| "item_id": f"window_{window + self.cur_item_id}", | ||
| **{f"{i}": x_batch[window, data_entry, i] for i in range(n_features)} | ||
| }) | ||
|
|
||
| self.cur_item_id += n_windows_in_batch | ||
| rows = pd.DataFrame(rows) | ||
| return rows |
62 changes: 62 additions & 0 deletions
62
orion/primitives/jsons/orion.primitives.chronos2.Chronos2.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| { | ||
| "name": "orion.primitives.chronos2.Chronos2", | ||
| "contributors": [ | ||
| "Allen Baranov <baranov@mit.edu>" | ||
| ], | ||
| "documentation": "https://huggingface.co/amazon/chronos-2", | ||
| "description": "Amazon Chronos2 model for timeseries forecasting", | ||
| "classifiers": { | ||
| "type": "estimator", | ||
| "subtype": "regressor" | ||
| }, | ||
| "modalities": [], | ||
| "primitive": "orion.primitives.chronos2.Chronos2", | ||
| "produce": { | ||
| "method": "predict", | ||
| "args": [ | ||
| { | ||
| "name": "X", | ||
| "type": "ndarray" | ||
| }, | ||
| { | ||
| "name": "start_indices", | ||
| "type": "ndarray" | ||
| }, | ||
| { | ||
| "name": "force", | ||
| "type": "bool", | ||
| "default": false | ||
| } | ||
| ], | ||
| "output": [ | ||
| { | ||
| "name": "y_hat", | ||
| "type": "ndarray" | ||
| } | ||
| ] | ||
| }, | ||
| "hyperparameters": { | ||
| "fixed": { | ||
| "pred_len": { | ||
| "type": "int", | ||
| "default": 1 | ||
| }, | ||
| "repo_id": { | ||
| "type": "str", | ||
| "default": "amazon/chronos-2" | ||
| }, | ||
| "batch_size": { | ||
| "type": "int", | ||
| "default": 32 | ||
| }, | ||
| "target": { | ||
| "type": "int", | ||
| "default": 0 | ||
| }, | ||
| "time_interval": { | ||
| "type": "int", | ||
| "default": 600 | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.