Foundational Models#
Source Files
twiga/models/foundational/base.py-BaseFoundationalModeltwiga/models/foundational/chronos2_model.py-Chronos2Model/Chronos2Configtwiga/models/foundational/tabicl_model.py-TabICLModel/TabICLConfigtwiga/models/foundational/moirai_model.py-MoiraiModel/MoiraiConfigtwiga/models/foundational/timesfm_model.py-TimesFMModel/TimesFMConfigtwiga/models/foundational/lag_llama_model.py-LagLlamaModel/LagLlamaConfig
Twiga’s foundational domain provides pre-trained, task-agnostic models that require no training on your target data. Unlike learned models that fit parameters to your specific time series, foundational models download pre-trained weights and generate probabilistic forecasts immediately through zero-shot inference. They leverage transfer learning from training on millions of diverse time series, making them robust to domain shift and data scarcity.
Foundational models share the same TwigaForecaster interface as ML and NN models and can be composed freely with learned models for ensemble forecasting. All foundational models are inherently probabilistic (quantile-based) and generate confidence intervals and prediction intervals without requiring explicit calibration.
For the full model catalogue see the Model Catalog Overview.
When to use foundational models
Use case |
Recommended model |
|---|---|
Rapid prototyping on new domain |
|
Small datasets (<1000 samples) |
|
Production with minimal latency |
|
Domain transfer / few-shot learning |
|
Probabilistic baseline or ensemble component |
|
Confidence estimation without calibration |
|
When NOT to use foundational models:
Extreme latency requirements (<100ms per prediction) — inference is ~seconds per batch
Custom quantile levels — Chronos2 outputs 21 fixed quantiles, not arbitrary τ values
Multivariate forecasting — current generation is univariate only
Specialized domains with abundant domain-specific data — fine-tuned domain models often outperform
Common Interface#
All foundational models extend BaseQuantileRegressor and implement the quantile regression interface. They are zero-shot: no local training occurs, only weight loading and inference.
Constructor Pattern#
Model(model_config: Config | None = None)
Each model defaults to its own config class when model_config is omitted.
Chronos2Model#
Chronos2Model implements zero-shot forecasting via a pre-trained 12-billion-parameter autoregressive transformer trained on 2M+ diverse time series spanning energy, traffic, weather, retail, and more. It generates 21 quantile predictions per forecast horizon without any fine-tuning on your data.
Zero-Shot Inference Paradigm#
Unlike learned models (QR, parametric) that fit to your dataset:
# Learned model: fit on training data, then predict
qr_model = QRXGBOOSTConfig()
forecaster = TwigaForecaster(data_config, [qr_model])
forecaster.fit(train_df) # ← Parameters optimized to train_df
forecaster.predict(test_df)
Foundational models skip the fitting step:
# Foundational model: download weights, then predict (no fit optimization)
chronos = Chronos2Config(device="cpu")
forecaster = TwigaForecaster(data_config, [chronos])
forecaster.fit(train_df) # ← Downloads pre-trained weights, validates dimensions only
forecaster.predict(test_df)
The training phase validates shapes and prepares the data pipeline, but does not optimize parameters. All predictive knowledge comes from the 2M+ time series in pre-training.
Quantile Levels#
Chronos2 outputs 21 fixed quantile levels. These are architectural and cannot be changed:
[0.025, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45,
0.5 (median),
0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.975]
These levels provide 95% nominal coverage (0.025 to 0.975) with fine granularity in the center and tails. If custom quantiles are required, use Quantile Regression models instead.
Device Selection#
Chronos2 supports three compute devices for inference:
Device |
Use case |
Performance |
|---|---|---|
|
Default, broad compatibility |
~seconds per batch |
|
NVIDIA GPUs (large batches) |
~100ms per large batch on V100/A100 |
|
Apple Silicon (M1/M2/M3 chips) |
~500ms per batch on M1 Pro |
Device defaults to 'cpu'. Switch at config time:
config = Chronos2Config(device="cuda")
forecaster = TwigaForecaster(data_config, [config])
GPU Inference
For production batch inference, 'cuda' with batch sizes 64–256 is 10–100× faster than CPU. For single-step or small batches (<32), CPU overhead is comparable.
Monotonicity Enforcement#
Chronos2 quantile predictions are enforced to be monotonically increasing (Q₀.₁ ≤ Q₀.₂ ≤ … ≤ Q₀.₉) to respect the definition of quantiles. Three strategies control enforcement:
Strategy |
Method |
Speed |
Use case |
|---|---|---|---|
|
Sort along quantile axis |
Fastest |
Default; respects quantile order absolutely |
|
Isotonic regression per (horizon, target) |
Slower; preserves more prediction structure |
When crossing quantiles indicate model miscalibration |
|
No enforcement |
Fastest |
Research / diagnostic; warnings enabled |
config = Chronos2Config(enforce_monotonic="sort") # default
All strategies are applied post-inference and do not affect weight loading or latency significantly.
Chronos2Config#
Field |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Model identifier. Excluded from parameter dumps. |
|
|
|
Domain identifier. Excluded from parameter dumps. |
|
|
|
Compute device for inference. |
|
|
|
Monotonicity enforcement strategy. |
|
|
empty |
No hyperparameter tuning; omitted from Optuna trials. |
No search space: Chronos2 has no tunable hyperparameters. The search_space field is always empty. All behavior is controlled via the config fields above.
Example: Zero-Shot Forecasting#
import pandas as pd
from twiga import TwigaForecaster
from twiga.core.config import DataPipelineConfig, ExperimentConfig
from twiga.models.foundational.chronos2_model import Chronos2Config
# Load data
data = pd.read_parquet("my_timeseries.parquet")
train_df = data[data["timestamp"] < "2024-01-01"]
test_df = data[data["timestamp"] >= "2024-01-01"]
# Configure pipeline and model
data_config = DataPipelineConfig(
target_feature="load",
period="30min",
forecast_horizon=48,
lookback_window_size=96,
latitude=40.0,
longitude=-75.0,
calendar_features=["hour", "day_of_week"],
)
chronos = Chronos2Config(device="cpu")
# Create forecaster
forecaster = TwigaForecaster(data_config, [chronos])
# Fit (loads weights, no training)
forecaster.fit(train_df)
# Predict
predictions, metrics = forecaster.evaluate_quantile_forecast(test_df)
# Access quantiles
print(predictions.columns) # ['timestamp', 'Actual', 'forecast', 'q_0.025', 'q_0.05', ..., 'q_0.975']
Example: Ensemble with Learned Models#
Combine Chronos2 (zero-shot) with learned models for robustness:
from twiga.models.ml import QRXGBOOSTConfig
configs = [
Chronos2Config(device="cpu"),
QRXGBOOSTConfig(),
]
forecaster = TwigaForecaster(
data_config,
configs,
ensemble_strategy="median_quantiles",
)
forecaster.fit(train_df)
predictions, metrics = forecaster.evaluate_quantile_forecast(test_df)
The ensemble median across Chronos2 and QR-XGBoost provides blended uncertainty.
Additional Zero-Shot Models#
Alongside Chronos2, Twiga wraps four more zero-shot foundation models. All share
the same TwigaForecaster interface and emit 9 quantile levels
([0.1, 0.2, …, 0.9]). Each requires an optional package that is not pulled
in by twiga[foundational] (which ships only Chronos2 + torch); the install
notes below are also surfaced in the model docstrings.
All four configs follow the Chronos2 device convention: device="auto" (the
default) selects CUDA → MPS → CPU automatically, or pin "cuda", "mps", or
"cpu".
TabICLModel#
A tabular foundation model that forecasts via in-context learning over
engineered temporal features rather than autoregressive token decoding. Its
pre-training mixes synthetic and real tabular datasets, so it generalises across
domains without per-task fitting. Inference is ensembled across n_estimators
members (4–8 is a good CPU speed/quality trade-off).
Installation
pip install "tabicl[forecast]>=2.1". Not included in twiga[foundational]:
tabicl transitively pins numpy < 2.2 via gluonts, which conflicts with the
rest of the stack. Install it into a dedicated environment.
MoiraiModel#
Salesforce’s universal time-series transformer, loaded through the uni2ts
package and run via the GluonTS predictor pipeline. The model_type field
selects the variant: "moirai2" (v2.0, native quantile output — the default),
"moirai" (v1.x, sample-based), or "moirai-moe" (mixture-of-experts,
sample-based). Sample-based variants draw num_samples paths and reduce them to
the 9-quantile grid; Moirai 2.0 emits quantiles directly.
Installation
pip install "uni2ts>=1.2".
TimesFMModel#
Google Research’s TimesFM 2.5, a 200M-parameter decoder-only transformer with a 16k-token context and a continuous quantile head. It forecasts autoregressively like Chronos2 but at a fraction of the parameter count, exposing its 9 native quantile levels.
Installation
Not on PyPI — install from source:
pip install "git+https://github.com/google-research/timesfm.git#egg=timesfm[torch]".
LagLlamaModel#
The first open-source time-series foundation model: a decoder-only transformer
that ingests lag features rather than raw sequences. It is sample-based —
the wrapper draws num_samples paths per series and reduces them to the
9-quantile grid. The wrapper resolves a relative ckpt_path against the CWD, the
model-file directory, and ancestor directories up to the project root.
Installation
Install the package, then download the checkpoint (a separate manual step):
pip install git+https://github.com/time-series-foundation-models/lag-llama.git
pip install "gluonts[torch]<=0.14.4" pytorch-lightning
huggingface-cli download time-series-foundation-models/Lag-Llama \
lag-llama.ckpt --local-dir lag-llama
BaseFoundationalModel#
Internal abstract base class for foundational models. Custom foundational models should inherit from this class and implement:
class MyFoundationalModel(BaseFoundationalModel):
quantile_levels = [0.1, 0.5, 0.9] # Define fixed quantiles
def __init__(self, model_config):
super().__init__(
data_pipeline=None,
model_instance=None,
quantiles=self.quantile_levels,
conf_level=0.05,
enforce_monotonic="sort",
)
self.model_config = model_config
def _initialize_models(self):
"""Load pre-trained weights from external source."""
self.model = load_pretrained_weights(...)
def _predict(self, x):
"""Generate quantile predictions."""
return self.model.predict(x) # shape (B, n_quantiles, horizon, n_targets)
See Custom Models for a complete walkthrough.
Advantages vs. Disadvantages#
Advantages#
✅ No training cost — Download weights, forecast immediately (seconds to setup) ✅ Robust to domain shift — Pre-trained on 2M+ diverse series ✅ Works on small datasets — No overfitting risk; better than underfitted QR on <500 samples ✅ Automatic uncertainty — 21 quantiles without explicit calibration ✅ Ensemble-ready — Mix with learned models for blended forecasts ✅ Simple API — One config, identical to learned models
Disadvantages#
❌ Slow inference — ~seconds per batch (vs. ~10ms for tree models) ❌ Fixed quantiles — Cannot request custom τ values; must accept 21 levels ❌ Univariate only — No multivariate or multi-output support (current gen) ❌ May underperform — On specialized domains with abundant domain-specific training data ❌ Black-box — Cannot inspect or fine-tune learned parameters (by design)
Comparison with Other Quantile Models#
Model |
Training |
Inference |
Quantiles |
Uncertainty Calibration |
Use case |
|---|---|---|---|---|---|
Chronos2 (foundational) |
None (zero-shot) |
~seconds |
21 fixed |
Automatic (pre-trained) |
Rapid prototyping, domain transfer, small data |
QR-XGBoost (ML) |
Minutes to hours |
~10ms |
Any τ |
Manual (calibration step) |
Production, custom quantiles, large data |
QR-MLPF (NN) |
Hours (GPU) |
~50ms |
Any τ |
Manual (calibration step) |
High-capacity, complex patterns, very large data |
FPQR-MLPGAM (NN) |
Hours (GPU) |
~50ms |
Any τ |
Learned (output layer) |
Adaptive quantile bounds, complex interactions |
References#
Ansari et al., 2024. Chronos: Pretrained (Language) Models for Time Series Forecasting
Foundational Model Architecture: Autoregressive Transformer with Tokenization
Pre-training corpus: 2M+ public and proprietary time series
API Reference#
BaseFoundationalModel#
- class twiga.models.foundational.base.BaseFoundationalModel(data_pipeline=None, model_instance=None, model_config=None, quantiles=None, conf_level=0.05, enforce_monotonic='sort', *, horizon=None, num_targets=1)#
Bases:
BaseQuantileRegressorBase for zero-shot foundation models (Chronos, GPT4TS, etc).
Foundation models are pre-trained on diverse data and produce fixed quantile outputs without fine-tuning on the target dataset. They inherit from
BaseQuantileRegressorto leverage quantile-specific logic like monotonicity enforcement and multi-output support.Zero-shot use — no fit() required:
Subclasses call
_ensure_loaded()at the start of_predict(), which lazily loads model weights on the firstpredict()call:model = Chronos2Model(Chronos2Config(device="cuda"), horizon=24) quantiles = model.predict(x) # weights loaded here automatically
Explicit
fit()is still supported for upfront validation and warm-starting (avoids cold-start latency on the first fold):model.fit(X_train, y_train) # optional, pre-loads weights quantiles = model.predict(x)
Subclasses must define:
quantile_levels— fixed quantile list from the model architecture._initialize_models()— download / load pre-trained weights and assign toself.model._predict()— call_ensure_loaded()then run inference.
- Parameters:
data_pipeline – Feature preprocessing pipeline (typically
None).model_instance – Model instance class (typically
None).model_config – Model config dict (handled by subclass).
quantiles (
list[float] |None) – Fixed quantile levels from the architecture.conf_level (
float) – Confidence level reference (default0.05).enforce_monotonic (
str) – Monotonicity strategy ("sort"/"isotonic"/"none").horizon (
int|None) – Optional forecast horizon hint. When provided, allowspredict()to be called without a priorfit().num_targets (
int) – Number of target variables (default1). Foundation models are typically univariate.
- set_fit_request(*, eval_set='$UNCHANGED$', trial='$UNCHANGED$', verbose='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- eval_setstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
eval_setparameter infit.- trialstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
trialparameter infit.- verbosestr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
verboseparameter infit.
Returns#
- selfobject
The updated object.
- set_predict_request(*, sigma='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
predictmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- sigmastr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sigmaparameter inpredict.
Returns#
- selfobject
The updated object.
- set_score_request(*, sample_weight='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
Returns#
- selfobject
The updated object.
Chronos2Model#
- class twiga.models.foundational.chronos2_model.Chronos2Model(model_config=None)#
Bases:
BaseFoundationalModelZero-shot forecasting with Chronos-2.
Chronos-2 is a 12B-parameter autoregressive transformer that performs zero-shot time series forecasting without fine-tuning on the target dataset. It produces 21 quantile predictions spanning
[0.025, 0.05, …, 0.95, 0.975].fit() is optional — model weights are loaded lazily on the first
predict()call:# Zero-shot: no fit() required when horizon is known model = Chronos2Model(Chronos2Config(horizon=24)) quantiles = model.predict(x) # loads weights from HuggingFace here # Explicit pre-loading (avoids cold-start on first fold) model.fit(X_train, y_train) quantiles = model.predict(x)
The model loads pre-trained weights from HuggingFace on first use. No fine-tuning or gradient updates happen on the provided data.
- Parameters:
model_config (
Chronos2Config|None) –Chronos2Configwith device and horizon settings.
Example:
config = Chronos2Config(device="cuda", horizon=24) model = Chronos2Model(config) quantiles = model.predict(X_test) # shape: (batch, horizon, 21)
- __init__(model_config=None)#
Initialize Chronos-2 model.
- Parameters:
model_config (
Chronos2Config|None) – Configuration with device and horizon settings. Defaults toChronos2Config(device'auto').
- fit(X, y, eval_set=None, verbose=False)#
Pre-load Chronos-2 weights (optional — called automatically on first predict).
No training occurs.
fit()validates array dimensions and loads the pre-trained pipeline from HuggingFace so that the first fold of a backtesting loop does not pay the cold-start cost.- Parameters:
- Return type:
- Returns:
Self for method chaining.
- Raises:
ValueError – If
X/yare not 3-D orn_targets > 1.ImportError – If the
chronos-forecastinglibrary is not installed.RuntimeError – If HuggingFace model loading fails.
- quantile_levels: list[float] = [0.025, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.975]#
- set_fit_request(*, eval_set='$UNCHANGED$', verbose='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- eval_setstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
eval_setparameter infit.- verbosestr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
verboseparameter infit.
Returns#
- selfobject
The updated object.
- set_predict_request(*, sigma='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
predictmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- sigmastr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sigmaparameter inpredict.
Returns#
- selfobject
The updated object.
- set_score_request(*, sample_weight='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
Returns#
- selfobject
The updated object.
Chronos2Config#
- class twiga.models.foundational.chronos2_model.Chronos2Config(**data)#
Bases:
BaseModelConfigConfiguration for Chronos-2 zero-shot forecasting.
Chronos-2 is a 12B-parameter autoregressive transformer trained on 2M+ diverse time series. It performs zero-shot forecasting without fine-tuning on the target dataset and produces 21 quantile predictions.
- Fixed quantiles: 0.025, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45,
0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.975
- Variables:
name – Model identifier, fixed to
'chronos2'.domain – Domain identifier, fixed to
'foundational'.device – Compute device.
"auto"(default) selects CUDA when available, then MPS (Apple Silicon), then CPU. Pass"cuda","mps", or"cpu"to override.horizon – Optional forecast horizon hint. When set,
predict()can be called without a priorfit().enforce_monotonic – Monotonicity enforcement strategy.
TabICLModel#
- class twiga.models.foundational.tabicl_model.TabICLModel(model_config=None)#
Bases:
BaseFoundationalModelZero-shot forecasting with TabICLv2.
TabICLv2 is a tabular foundation model that supports time series forecasting via in-context learning over engineered temporal features. It produces 9 quantile predictions: [0.1, 0.2, …, 0.9].
The model loads pre-trained weights from HuggingFace via the
tabiclpackage. No training happens on the input data; fit() only validates dimensions and instantiates the forecaster.- Parameters:
model_config (
TabICLConfig|None) – TabICLConfig with device, n_estimators, and other options.
Example
>>> config = TabICLConfig(device="cuda", n_estimators=8) >>> model = TabICLModel(model_config=config) >>> model.fit(X_train, y_train) >>> quantiles = model.predict(X_test)
- __init__(model_config=None)#
Initialize TabICLv2 model.
- Parameters:
model_config (
TabICLConfig|None) – Configuration. Defaults to TabICLConfig().
- fit(X, y, eval_set=None, verbose=False)#
Load pre-trained TabICLv2 forecaster.
The input data is not used for training; fit() instantiates the zero-shot forecaster (which lazily downloads weights from HuggingFace on first predict) and validates array dimensions.
- Parameters:
X (
ndarray) – Lookback window features, shape (batch, seq_len, n_features). Used only for dimension validation.y (
ndarray) – Target forecast horizons, shape (batch, horizon, n_targets). Used only for dimension validation.eval_set (
tuple[ndarray,ndarray] |None) – Ignored (included for interface compatibility).verbose (
bool) – Ignored (included for interface compatibility).
- Return type:
- Returns:
Self for method chaining.
- Raises:
ImportError – If the tabicl library is not installed.
ValueError – If inputs are not 3-D or num_targets != 1.
- set_fit_request(*, eval_set='$UNCHANGED$', verbose='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- eval_setstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
eval_setparameter infit.- verbosestr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
verboseparameter infit.
Returns#
- selfobject
The updated object.
- set_predict_request(*, sigma='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
predictmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- sigmastr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sigmaparameter inpredict.
Returns#
- selfobject
The updated object.
- set_score_request(*, sample_weight='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
Returns#
- selfobject
The updated object.
TabICLConfig#
- class twiga.models.foundational.tabicl_model.TabICLConfig(**data)#
Bases:
BaseModelConfigConfiguration for TabICLv2 zero-shot forecasting.
TabICLv2 is a tabular foundation model that performs time series forecasting by converting temporal sequences into tabular features and using in-context learning. It produces quantile predictions without fine-tuning on the target dataset.
Fixed default quantiles: 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9.
- Variables:
name – Model identifier, fixed to ‘tabicl’.
domain – Domain identifier, fixed to ‘foundational’.
device – Compute device. ‘auto’ (default) picks CUDA → MPS → CPU.
n_estimators – Number of ensemble members (higher = better, slower).
max_context_length – Maximum number of historical timesteps fed to the model.
point_estimate – Aggregation strategy for the point forecast (‘mean’ or ‘median’).
enforce_monotonic – Strategy for non-crossing quantiles.
MoiraiModel#
- class twiga.models.foundational.moirai_model.MoiraiModel(model_config=None)#
Bases:
BaseFoundationalModelZero-shot forecasting with Moirai (v1.x, MoE, or v2.0).
Loads pre-trained weights from HuggingFace via the
uni2tspackage and runs the GluonTS predictor pipeline. Output samples (or native quantiles formoirai2) are reduced to 9 quantile levels.- Parameters:
model_config (
MoiraiConfig|None) – MoiraiConfig controlling variant, size, and device.
Example
>>> config = MoiraiConfig(model_type="moirai2", size="small", device="cpu") >>> model = MoiraiModel(model_config=config) >>> model.fit(X_train, y_train) >>> quantiles = model.predict(X_test)
- __init__(model_config=None)#
Initialize Moirai model.
- Parameters:
model_config (
MoiraiConfig|None) – Configuration. Defaults to MoiraiConfig().
- fit(X, y, eval_set=None, verbose=False)#
Load pre-trained Moirai module.
- Parameters:
X (
ndarray) – Lookback window features, shape (batch, seq_len, n_features). Used only for dimension validation.y (
ndarray) – Target forecast horizons, shape (batch, horizon, n_targets). Used only for dimension validation.eval_set (
tuple[ndarray,ndarray] |None) – Ignored (included for interface compatibility).verbose (
bool) – Ignored (included for interface compatibility).
- Return type:
- Returns:
Self for method chaining.
- set_fit_request(*, eval_set='$UNCHANGED$', verbose='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- eval_setstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
eval_setparameter infit.- verbosestr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
verboseparameter infit.
Returns#
- selfobject
The updated object.
- set_predict_request(*, sigma='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
predictmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- sigmastr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sigmaparameter inpredict.
Returns#
- selfobject
The updated object.
- set_score_request(*, sample_weight='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
Returns#
- selfobject
The updated object.
MoiraiConfig#
- class twiga.models.foundational.moirai_model.MoiraiConfig(**data)#
Bases:
BaseModelConfigConfiguration for Moirai zero-shot forecasting.
Moirai is a transformer foundation model with three publicly released variants:
moirai: original v1.1 — sample-based output.moirai-moe: mixture-of-experts variant — sample-based output.moirai2: v2.0 — direct quantile output.
- Variables:
name – Model identifier, fixed to ‘moirai’.
domain – Domain identifier, fixed to ‘foundational’.
model_type – Which Moirai variant to load.
size – Model size; one of ‘small’, ‘base’, ‘large’.
device – Compute device. ‘auto’ (default) picks CUDA → MPS → CPU.
patch_size – Patch size for sample-based variants (‘auto’ or 8/16/32/64/128). Ignored for
moirai2.num_samples – Number of probabilistic samples to draw from sample-based variants before computing empirical quantiles. Ignored for
moirai2.frequency – Pandas frequency alias for the input series. If None, uses
data_pipeline.periodwhen available, else'1h'.enforce_monotonic – Strategy for non-crossing quantiles.
TimesFMModel#
- class twiga.models.foundational.timesfm_model.TimesFMModel(model_config=None)#
Bases:
BaseFoundationalModelZero-shot forecasting with TimesFM 2.5.
Loads pre-trained weights from HuggingFace via the
timesfmpackage and runs univariate zero-shot inference. The continuous quantile head emits 9 quantile levels: [0.1, 0.2, …, 0.9].- Parameters:
model_config (
TimesFMConfig|None) – TimesFMConfig controlling device, context, and horizon.
Example
>>> config = TimesFMConfig(device="cpu") >>> model = TimesFMModel(model_config=config) >>> model.fit(X_train, y_train) >>> quantiles = model.predict(X_test)
- __init__(model_config=None)#
Initialize TimesFM 2.5 model.
- Parameters:
model_config (
TimesFMConfig|None) – Configuration. Defaults to TimesFMConfig().
- fit(X, y, eval_set=None, verbose=False)#
Load and compile the pre-trained TimesFM 2.5 model.
- Parameters:
X (
ndarray) – Lookback window features, shape (batch, seq_len, n_features). Used for dimension validation and to size the context window.y (
ndarray) – Target forecast horizons, shape (batch, horizon, n_targets). Used for dimension validation and to size the horizon.eval_set (
tuple[ndarray,ndarray] |None) – Ignored (included for interface compatibility).verbose (
bool) – Ignored (included for interface compatibility).
- Return type:
- Returns:
Self for method chaining.
- set_fit_request(*, eval_set='$UNCHANGED$', verbose='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- eval_setstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
eval_setparameter infit.- verbosestr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
verboseparameter infit.
Returns#
- selfobject
The updated object.
- set_predict_request(*, sigma='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
predictmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- sigmastr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sigmaparameter inpredict.
Returns#
- selfobject
The updated object.
- set_score_request(*, sample_weight='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
Returns#
- selfobject
The updated object.
TimesFMConfig#
- class twiga.models.foundational.timesfm_model.TimesFMConfig(**data)#
Bases:
BaseModelConfigConfiguration for TimesFM 2.5 zero-shot forecasting.
- Variables:
name – Model identifier, fixed to ‘timesfm’.
domain – Domain identifier, fixed to ‘foundational’.
device – Compute device. ‘auto’ (default) picks CUDA → MPS → CPU.
max_context – Maximum context length compiled into the model (capped at TimesFM’s 16k token limit). Auto-raised to the lookback window at fit time if the configured value is smaller.
max_horizon – Maximum forecast horizon compiled into the model. Auto-raised to the requested horizon at fit time if smaller.
hf_repo – HuggingFace checkpoint id.
enforce_monotonic – Strategy for non-crossing quantiles.
LagLlamaModel#
- class twiga.models.foundational.lag_llama_model.LagLlamaModel(model_config=None)#
Bases:
BaseFoundationalModelZero-shot forecasting with Lag-Llama.
- Parameters:
model_config (
LagLlamaConfig|None) – LagLlamaConfig pointing at the local checkpoint.
Example
>>> config = LagLlamaConfig(ckpt_path="lag-llama/lag-llama.ckpt", device="cpu") >>> model = LagLlamaModel(model_config=config) >>> model.fit(X_train, y_train) >>> quantiles = model.predict(X_test)
- __init__(model_config=None)#
Initialize Lag-Llama model.
- Parameters:
model_config (
LagLlamaConfig|None) – Configuration. Defaults to LagLlamaConfig().
- fit(X, y, eval_set=None, verbose=False)#
Load the Lag-Llama checkpoint (zero-shot — no training).
- Parameters:
X (
ndarray) – Lookback window features, shape (batch, seq_len, n_features). Used for dimension validation and to size the context budget.y (
ndarray) – Target forecast horizons, shape (batch, horizon, n_targets). Used for dimension validation and to size the prediction length.eval_set (
tuple[ndarray,ndarray] |None) – Ignored (included for interface compatibility).verbose (
bool) – Ignored (included for interface compatibility).
- Return type:
- Returns:
Self for method chaining.
- set_fit_request(*, eval_set='$UNCHANGED$', verbose='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- eval_setstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
eval_setparameter infit.- verbosestr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
verboseparameter infit.
Returns#
- selfobject
The updated object.
- set_predict_request(*, sigma='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
predictmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- sigmastr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sigmaparameter inpredict.
Returns#
- selfobject
The updated object.
- set_score_request(*, sample_weight='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
Returns#
- selfobject
The updated object.
LagLlamaConfig#
- class twiga.models.foundational.lag_llama_model.LagLlamaConfig(**data)#
Bases:
BaseModelConfigConfiguration for Lag-Llama zero-shot forecasting.
- Variables:
name – Model identifier, fixed to ‘lag_llama’.
domain – Domain identifier, fixed to ‘foundational’.
ckpt_path – Path to the
lag-llama.ckptcheckpoint. The repo source is expected at the same directory (added tosys.pathat fit time).context_length – Total memory budget passed to the estimator (the transformer context + lag features). Auto-raised at fit time if the data’s lookback is larger.
device – Compute device. ‘auto’ (default) picks CUDA → MPS → CPU.
num_samples – Number of probabilistic samples drawn per series before computing empirical quantiles.
enforce_monotonic – Strategy for non-crossing quantiles.