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 VisionTS context len issue #124

Merged
merged 2 commits into from
Sep 18, 2024
Merged
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
18 changes: 8 additions & 10 deletions project/benchmarks/run_visionts.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def norm_freq_str(freq_str: str) -> str:

def get_seasonality_list(freq: str) -> int:
offset = pd.tseries.frequencies.to_offset(freq)
base_seasonality_list = POSSIBLE_SEASONALITIES.get(norm_freq_str(offset.name), 1)
base_seasonality_list = POSSIBLE_SEASONALITIES.get(norm_freq_str(offset.name), [])
seasonality_list = []
for base_seasonality in base_seasonality_list:
seasonality, remainder = divmod(base_seasonality, offset.n)
Expand Down Expand Up @@ -156,12 +156,11 @@ def evaluate(
best_valid_mae = float("inf")
best_valid_p = 1
for periodicity in seasonality_list:
# Round context length to the integer multiples of the period
context_len = convert_context_len(
cur_context_len = convert_context_len(
context_len, no_periodicity_context_len, periodicity
)
model.update_config(
context_len,
cur_context_len,
prediction_length,
periodicity,
norm_const,
Expand All @@ -177,7 +176,7 @@ def evaluate(
[x["target"][-prediction_length:] for x in batch]
)
cur_forecast_samples = forcast_batch(
input_batch, device, context_len, align_const, model
input_batch, device, cur_context_len, align_const, model
)
assert cur_forecast_samples.shape == label_batch.shape
cur_mae_list.append(np.abs(label_batch - cur_forecast_samples))
Expand All @@ -198,23 +197,22 @@ def evaluate(
else:
periodicity = int(periodicity)

print(f"Use periodicity = {periodicity}, context len = {context_len}")

# Generate forecast samples
forecast_samples = []
context_len = convert_context_len(
cur_context_len = convert_context_len(
context_len, no_periodicity_context_len, periodicity
)
print(f"Use periodicity = {periodicity}, context len = {cur_context_len}")
model.update_config(
context_len, prediction_length, periodicity, norm_const, align_const
cur_context_len, prediction_length, periodicity, norm_const, align_const
)
for batch in tqdm(
list(batcher(test_data.input, batch_size=batch_size)),
desc="Forecasting",
):
batch = [x["target"] for x in batch]
cur_forecast_samples = forcast_batch(
batch, device, context_len, align_const, model
batch, device, cur_context_len, align_const, model
)
forecast_samples.append(cur_forecast_samples)
forecast_samples = np.concatenate(forecast_samples, axis=0)
Expand Down
Loading