Skip to content

Speed up compute_metrics()#144

Merged
shchur merged 9 commits into
autogluon:mainfrom
shchur:faster-metrics
May 18, 2026
Merged

Speed up compute_metrics()#144
shchur merged 9 commits into
autogluon:mainfrom
shchur:faster-metrics

Conversation

@shchur
Copy link
Copy Markdown
Contributor

@shchur shchur commented May 15, 2026

Issue #, if available:

Description of changes:

  • Refactor Metric.compute() to accept pre-built numpy arrays (y_true [N,H,D], y_pred [N,H,D], q_pred [N,H,D,Q], y_past [total_T, D] + y_past_lengths [N]) instead of HF
    Dataset objects. Arrays are built once per window in compute_metrics and shared across all metrics.
  • Use pyarrow (pc.list_flatten, pc.list_value_length, pc.is_finite) for array construction and prediction validation, replacing HF Dataset column access and the expensive
    .cast() + numpy finite check.
  • Fix combine_univariate_predictions_to_multivariate to use table.take() instead of Dataset.select(), avoiding lazy _indices views that break direct Arrow table access.
  • Fast path for seasonal error computation if all series have the same length

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@shchur shchur changed the title Speed up evaluation_summary() Speed up compute_metrics() May 15, 2026
@shchur shchur requested a review from abdulfatir May 15, 2026 20:24
shchur added 7 commits May 16, 2026 19:38
…jects

Build y_true [N,D,H], y_pred [N,D,H], q_pred [N,D,H,Q], and y_past
[total_T, D] + indptr [N+1] once per window in compute_metrics, then
pass to all metric.compute() calls. Avoids repeated column access and
array construction per metric per dimension.
- Replace HF Dataset column access with pc.list_flatten + to_numpy for
  building y_true, y_pred, q_pred, y_past arrays (~100x faster)
- Replace .cast(schema) + numpy finite check with pyarrow-native
  validation: check column names, list lengths, and pc.is_finite
- Total evaluation_summary speedup: 18.6s -> 0.48s (39x) on 35-dim
  multivariate task with 10 windows
- Replace .cast() + numpy finite check with pyarrow-native validation:
  check column names, list lengths via pc.list_value_length, and
  pc.is_finite on flattened arrays
- Fix combine_univariate_predictions_to_multivariate to use table.take()
  instead of Dataset.select() to avoid lazy _indices views
- evaluation_summary: 18.6s -> 0.5s on 35-dim task with 10 windows
_safemean(arr, axis=(0, 1)) replaces the manual
[self._safemean(arr[:, :, d]) for d in range(D)] pattern.
…per_item

Passing lengths [N] is simpler than CSR-style indptr [N+1] — offsets
are only needed inside _seasonal_error_per_item and are cheap to
reconstruct. Rename back to _per_item to clarify return shape [N, D].
Comment thread src/fev/metrics.py
@shchur shchur merged commit e6568bd into autogluon:main May 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants