Metadata-Version: 2.4
Name: tafsut
Version: 0.2.0
Summary: Nine-quantile time-series forecasting with Tafsut backbones and covariate adaptation
Author: Tafsut-FM
License-Expression: MIT
Project-URL: Homepage, https://github.com/Tafsut-FM/tafsut
Project-URL: Repository, https://github.com/Tafsut-FM/tafsut
Project-URL: Models, https://huggingface.co/collections/Tafsut-FM/tafsut-6b0bcaf9b0d7f6b68fed2984
Keywords: time-series,forecasting,probabilistic-forecasting,pytorch
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: torch>=2.1
Requires-Dist: numpy>=1.24
Requires-Dist: safetensors>=0.4
Requires-Dist: huggingface_hub>=0.24
Provides-Extra: visualization
Requires-Dist: matplotlib>=3.7; extra == "visualization"
Dynamic: license-file

<img src="https://huggingface.co/Tafsut-FM/tafsut-legacy/resolve/7e7a50c39d27752beb684d63fbc0d32443dcc593/assets/tafsut-icon.png" width="76" height="76" alt="Tafsut logo">

# Tafsut

Tafsut forecasts nine quantiles for each future time step, from the 10th to the 90th percentile. Version 0.2.0 adds three forecasting backbones and a covariate adapter that also works with forecasts from other models. Existing code using the public legacy checkpoint can keep using the same model loader and `forecast` function.

## Install

Requires Python 3.10 or newer.

```bash
python -m pip install --upgrade tafsut
```

For plots, install `python -m pip install "tafsut[visualization]"`. For CUDA inference, use a PyTorch build compatible with your GPU.

## Make a forecast

This example runs on CPU with [Tafsut-GIFT](https://huggingface.co/Tafsut-FM/tafsut-gift). Use `Tafsut-FM/tafsut-legacy` to reproduce a forecast with the original model.

```python
import torch
from tafsut import TafsutModel, forecast

model = TafsutModel.from_pretrained("Tafsut-FM/tafsut-gift", device="cpu")
history = torch.tensor([19., 21., 20., float("nan"), 24., 23.])
prediction = forecast(model, history, horizon=24)

print(prediction.shape)       # (1, 24, 9)
median = prediction[0, :, 4]
```

Pass one series or a batch shaped `(batch, time)`. Mark missing observations with `NaN` or supply a boolean `context_mask`. The result is a CPU tensor shaped `(batch, horizon, 9)` in the original units.

## Checkpoints in 0.2.0

The [Tafsut collection](https://huggingface.co/collections/Tafsut-FM/tafsut-6b0bcaf9b0d7f6b68fed2984) contains the four new checkpoints. All four can be loaded by Hub ID without signing in. Both loaders also accept a local checkpoint directory.

| Hugging Face model ID | Use |
| --- | --- |
| `Tafsut-FM/tafsut-gift` | Target-only forecasting with the backbone adapted for GIFT-Eval. |
| `Tafsut-FM/tafsut-fev` | Target-only forecasting with the backbone adapted for FEV-Bench. |
| `Tafsut-FM/tafsut-synth` | Target-only forecasting with a backbone and quantile head trained on synthetic series. |
| `Tafsut-FM/tafsut-adapter` | Refine a base forecast using past or known-future covariates. |

The three backbones accept up to 32,768 history steps and forecast up to 1,024 steps per pass. The adapter uses the latest 8,192 history steps and accepts up to 16 covariates.

## Add a covariate

Load the FEV backbone and adapter on the same device. Calendar features such as day of week are available for both the history and the forecast horizon.

```python
from tafsut import TafsutAdapter

backbone = TafsutModel.from_pretrained("Tafsut-FM/tafsut-fev", device="cpu")
adapter = TafsutAdapter.from_pretrained("Tafsut-FM/tafsut-adapter", device="cpu")
day = torch.arange(history.numel() + 24).remainder(7).float()
covariates = {
    "past_covariates": day[:history.numel()],
    "future_covariates": day[history.numel():],
}
refined = forecast(backbone, history, horizon=24, adapter=adapter, **covariates)
```

To use another backbone, pass its target-only quantiles in original units. For example, the GIFT forecast above can be refined with the same calendar feature.

```python
refined_gift = adapter.refine(
    history, prediction,
    quantile_levels=[i / 10 for i in range(1, 10)],
    **covariates,
)
```

Supply all nine deciles for learned quantile spacing, or q0.1, q0.5 and q0.9 for interpolation between refined anchors.

## Command line

```bash
tafsut-forecast --model Tafsut-FM/tafsut-gift --context 19,21,20,24,23 --horizon 24 --device cpu
```

The command prints a JSON forecast. Omit `--model` inside a checkpoint directory to load its weights. In other directories the default is Tafsut-GIFT. Use `tafsut-forecast --help` for file inputs, covariates, and plotting options.
