Skip to content

REF cleaner BaseTSFMSolver with richer default adaptation strategies#42

Open
rtavenar wants to merge 1 commit into
benchopt:mainfrom
rtavenar:feat-cleaner-basesolvertsfm
Open

REF cleaner BaseTSFMSolver with richer default adaptation strategies#42
rtavenar wants to merge 1 commit into
benchopt:mainfrom
rtavenar:feat-cleaner-basesolvertsfm

Conversation

@rtavenar
Copy link
Copy Markdown
Contributor

@rtavenar rtavenar commented Jun 4, 2026

Summary (cf #39 )

  • Abstract model_id property + base-class model caching: the loaded model is now reused across set_objective calls and only reloaded when model_id changes (previously each call reloaded).
  • build_adapter is no longer abstract: a non-abstract default covers all four tasks using the first available capability (see table below). Solvers only need to override it for genuinely custom adapter logic.
  • embed() / time_embed() public methods: wrap embed_batch / time_embed_batch with numpy conversion, making them directly usable in adapters and subclasses.
  • event_detection added to the _Task type alias.
  • forecast() type fix: numpy inputs are now converted to tensors before forecast_batch, and tensor outputs converted back to numpy before assembly (was a silent type mismatch).
  • Docstring fixes: swapped docstrings on embed_batch / time_embed_batch corrected; build_adapter docstring now lists numbered fallback options instead of ambiguous .

Default adaptation strategies in build_adapter (discussed in #31 )

Task Option 1 Option 2 (fallback)
forecasting forecast_batch (zero-shot) embed_batch → windowed ridge regression
classification embed_batch → LinearProbe time_embed_batch → mean-pooled + LinearProbe
anomaly_detection embed_batch → distance-from-mean forecast_batch → forecast-error residuals
event_detection time_embed_batch → per-position LogReg embed_batch → causal-windowed LogReg

Test plan

  • Existing solvers (Chronos, Moment, …) still extend BaseSolver directly and are unaffected by this PR
  • A new solver implementing only forecast_batch + supported_tasks + model_id + load_model should work end-to-end for forecasting and anomaly detection without any further code
  • Model is not reloaded across tasks when model_id is unchanged

🤖 Generated with Claude Code

- Add abstract model_id property; base class now caches the loaded model
  across set_objective calls (no reload unless model_id changes).
- Replace abstract build_adapter with a non-abstract default that picks
  the first available capability per task:
    forecasting      forecast_batch → windowed-embed ridge regression
    classification   embed_batch    → pooled time_embed + LinearProbe
    anomaly_detection embed_batch   → forecast residuals
    event_detection  time_embed     → causal-windowed embed + LogReg
- Add event_detection to the _Task type alias.
- Add embed() and time_embed() public methods (call embed_batch /
  time_embed_batch and convert to numpy).
- Fix forecast() to convert numpy inputs to tensors before forecast_batch
  and tensor outputs back to numpy before assembly.
- Fix swapped docstrings on embed_batch / time_embed_batch.
- Drop unused Callable import.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant