Skip to content
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

fix: Chronos inference in foundation ts arena #382

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions experiments/foundation-time-series-arena/eval-chronos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import fire
import transformers
from xiuhmolpilli.arena import FoundationalTimeSeriesArena
from xiuhmolpilli.models.foundational import Chronos


if __name__ == "__main__":
transformers.set_seed(42) # for reproducibility

frequencies = ["Hourly", "Daily", "Weekly", "Monthly"]
files = [
f"./nixtla-foundational-time-series/data/{freq}.parquet" for freq in frequencies
]
arena = FoundationalTimeSeriesArena(
models=[
Chronos(
repo_id="amazon/chronos-t5-large", batch_size=16, alias="Chronos-Large"
),
Chronos(
repo_id="amazon/chronos-t5-base", batch_size=40, alias="Chronos-Base"
),
Chronos(
repo_id="amazon/chronos-t5-small", batch_size=64, alias="Chronos-Small"
),
Chronos(
repo_id="amazon/chronos-t5-mini", batch_size=128, alias="Chronos-Mini"
),
Chronos(
repo_id="amazon/chronos-t5-tiny", batch_size=256, alias="Chronos-Tiny"
),
],
parquet_data_paths=files,
)
fire.Fire(arena.compete)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Iterable, List
from typing import Iterable

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -29,23 +29,13 @@ def __init__(

@classmethod
def from_df(cls, df: pd.DataFrame, batch_size: int):
num_unique_ids = df["unique_id"].nunique()
max_series_length = df["unique_id"].value_counts().max()
padded_tensor = torch.full(
size=(num_unique_ids, max_series_length),
fill_value=torch.nan,
dtype=torch.bfloat16,
) # type: ignore
tensors = []
df_sorted = df.sort_values(by=["unique_id", "ds"])
for idx, (_, group) in enumerate(df_sorted.groupby("unique_id")):
series_length = len(group)
padded_tensor[idx, -series_length:] = torch.tensor(
group["y"].values,
dtype=torch.bfloat16,
)
for _, group in df_sorted.groupby("unique_id"):
tensors.append(torch.tensor(group["y"].values))
uids = df_sorted["unique_id"].unique()
last_times = df_sorted.groupby("unique_id")["ds"].tail(1)
return cls(padded_tensor, uids, last_times, batch_size)
return cls(tensors, uids, last_times, batch_size)

def __len__(self):
return self.n_batches
Expand Down