Skip to main content

library_name: pytorch pipeline_tag: time-series-forecasting tags:

  • time-series
  • forecasting
  • probabilistic-forecasting
  • pytorch

Tafsut Univariate Base

Tafsut is a probabilistic model for univariate time-series forecasting. The pretrained base model is hosted at Tafsut-FM/tafsut-univariate-base and can be loaded directly from Python without cloning the model repository.

Installation

Tafsut requires Python 3.10 or newer.

pip install tafsut

For forecast visualization:

pip install "tafsut[visualization]"

With uv:

uv venv --python 3.11 .venv
uv pip install --python .venv/bin/python "tafsut[visualization]"

GPU users: PyTorch must be compatible with the NVIDIA driver on the target machine. If the default PyTorch installation does not match your CUDA environment, install the appropriate PyTorch build for your system before installing Tafsut.

Load the pretrained model

import torch
from tafsut import TafsutModel

device = "cuda" if torch.cuda.is_available() else "cpu"

model = TafsutModel.from_pretrained(
    "Tafsut-FM/tafsut-univariate-base",
    device=device,
)

from_pretrained() downloads config.json and model.safetensors from the Hugging Face Hub and uses the standard Hugging Face cache. A local model directory can also be passed instead of a Hub repository ID.

Forecast

The high-level forecast() helper accepts a single series with shape (T,) or a batch with shape (B, T).

import numpy as np
from tafsut import TafsutModel, forecast

model = TafsutModel.from_pretrained(
    "Tafsut-FM/tafsut-univariate-base",
    device="cpu",
)

context = np.asarray(
    [1.0, 1.2, 1.1, 1.4, 1.5, 1.7],
    dtype=np.float32,
)

pred = forecast(
    model,
    context,
    horizon=128,
)

print(pred.shape)          # (1, 128, 9)
print(model.cfg.quantiles) # (0.1, ..., 0.9)

The returned tensor has shape:

(batch, horizon, quantile)

For tafsut-univariate-base, the released quantiles are:

0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9

If a requested horizon is longer than one native prediction block, forecast() continues autoregressively using the median forecast as feedback.

Missing observations

Missing historical values can be represented with NaN:

context = np.asarray(
    [1.0, 1.2, np.nan, 1.4, 1.5],
    dtype=np.float32,
)

pred = forecast(model, context, horizon=64)

An explicit boolean context_mask can also be supplied to forecast() when needed.

Visualization

Install the optional visualization dependency:

pip install "tafsut[visualization]"

Then plot history and probabilistic forecasts:

from tafsut import plot_forecast

fig, ax = plot_forecast(
    context,
    pred,
    model.cfg.quantiles,
    history_length=256,
)

fig.savefig(
    "forecast.png",
    dpi=160,
    bbox_inches="tight",
)

To overlay observed future values:

fig, ax = plot_forecast(
    context,
    pred,
    model.cfg.quantiles,
    target=observed_future,
)

The plot uses the median forecast as the central prediction and shades available central quantile intervals.

Command-line inference

Installing Tafsut provides the tafsut-forecast command. The model repository defaults to Tafsut-FM/tafsut-univariate-base.

From a NumPy file:

tafsut-forecast \
  --context-file series.npy \
  --horizon 128

Save a forecast visualization:

tafsut-forecast \
  --context-file series.npy \
  --horizon 128 \
  --plot-output forecast.png

Or specify the model explicitly:

tafsut-forecast \
  --model Tafsut-FM/tafsut-univariate-base \
  --context-file series.npy \
  --horizon 128

The context file may be .npy or .json.

Save locally

A loaded model can be saved as a local pretrained directory:

model.save_pretrained("./tafsut-local")

This writes:

tafsut-local/
├── config.json
└── model.safetensors

Reload it with the same API:

model = TafsutModel.from_pretrained("./tafsut-local")

Base model configuration

The published tafsut-univariate-base model uses:

Setting Value
Context length 32,768
Default prediction length 1,024
Patch size 32
Quantiles 9
Model dimension 768
Encoder layers 14
Attention heads 12

The forecast() helper can request horizons shorter or longer than the configured default prediction length.

Metadata

Release files for tafsut 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tafsut 0.1.0
File Size Uploaded
tafsut-0.1.0.tar.gz 16.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tafsut 0.1.0
File Interpreter ABI Platform
tafsut-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 34.3 kB

Release files / tafsut-0.1.0.tar.gz

Download URL tafsut-0.1.0.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
41c1f3a512995090decc2c8a46041559d9d64356806a3da81ae97494ea7cca4a
BLAKE2b-256 checksum
How to use checksums
fa709041794f03613571ddaf136b8139a9c9cad9db49f367caeb7be6696f7791
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / tafsut-0.1.0-py3-none-any.whl

Download URL tafsut-0.1.0-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c892f4f521ae60014073e43faabae2c8e3427db554f035729c29590b4d5de1a
BLAKE2b-256 checksum
How to use checksums
201808de8e3db29a5cfe06449ef692113e50966c7915c8709aaa4a0ac4a9e7bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page