API reference¶
This reference is generated from the docstrings in
src/tirex2/. It covers the public
API surface exported from the top-level tirex2 package.
- Forecasting —
load_model,TimeseriesType,ForecastModel. - Demo —
Demoandplot_demo_forecast, used in the Quickstart. - Plotting —
plot_multivariate,plot_forecast,plot_covariate.
tirex2.load_model ¶
load_model(
ckpt_path: str | Path = "NX-AI/TiRex-2",
device: str = "cuda",
*,
hf_kwargs: dict[str, Any] | None = None,
use_flex_attention: bool | None = None,
compile: bool = False,
) -> ForecastModel
Load an inference-ready :class:TiRex2 from a checkpoint directory or HF repo.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ckpt_path
|
str or Path
|
Hugging Face repo id ( |
'NX-AI/TiRex-2'
|
device
|
(cpu, cuda, mps)
|
Runtime device and recurrent-kernel family to use. This overrides any
device/backend stored in the checkpoint config. |
"cpu"
|
hf_kwargs
|
dict
|
Extra keyword arguments forwarded to |
None
|
use_flex_attention
|
bool
|
Override every variate mixer's checkpoint setting. |
None
|
compile
|
bool
|
If True, |
False
|
Returns:
| Type | Description |
|---|---|
ForecastModel
|
The instantiated backbone (with the checkpoint weights loaded, set to
evaluation mode) wrapped in a :class: |
Examples:
>>> import torch
>>> from tirex2 import TimeseriesType, load_model
>>> model = load_model("NX-AI/TiRex-2", device="cpu")
>>> ts = TimeseriesType(target=torch.randn(1, 128), past_covariates=None, future_covariates=None)
>>> forecast = model.forecast([ts], prediction_length=32, output_type="numpy")[0]
>>> forecast.shape
(1, 9, 32)
Source code in src/tirex2/base.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
tirex2.TimeseriesType
dataclass
¶
A single (possibly multivariate) series with optional covariates, as passed to
:meth:~tirex2.api_adapter.forecast.ForecastModel.forecast.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Tensor
|
Target history, shape |
required |
past_covariates
|
Tensor or None
|
Covariates known only up to the current time, shape |
required |
future_covariates
|
Tensor or None
|
Covariates known ahead of time for the whole forecast horizon, shape
|
required |
Examples:
>>> import torch
>>> from tirex2 import TimeseriesType
>>> ts = TimeseriesType(
... target=torch.randn(1, 128),
... past_covariates=None,
... future_covariates=None,
... )
>>> ts.past_length
128
Source code in src/tirex2/model/types.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |