How to use from the
Use from the
Transformers library
# Use a pipeline as a high-level helper
from transformers import pipeline

pipe = pipeline("feature-extraction", model="thu-sail-lab/Time-RCD", trust_remote_code=True)
# Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("thu-sail-lab/Time-RCD", trust_remote_code=True, device_map="auto")
Quick Links

Time-RCD

Official Hugging Face model repository for Time-RCD: Towards Foundation Models for Zero-Shot Time Series Anomaly Detection: Leveraging Synthetic Data and Relative Context Discrepancy.

This repository hosts the official pretrained weights, Transformers-compatible model code, and processor for zero-shot time series anomaly detection. The full training, evaluation, and TSB-AD benchmark pipeline is maintained in the companion official GitHub repository.

On the TSB-AD benchmark, Time-RCD achieves a univariate VUS-PR of 0.52 and a multivariate VUS-PR of 0.32.

News

  • 2026.05: Time-RCD has been accepted by ICML 2026. We also release the pre-trained dataset generation code and hyperparameters.
  • 2026.04: With a new dataset and new checkpoints, Time-RCD achieves better results. The univariate setting improves VUS-PR by an absolute 6.7 points, and the multivariate setting improves VUS-PR by an absolute 4.5 points.

Model Details

  • Architecture: Time-RCD with an 8-layer Transformer encoder
  • Context window: 5,000 time steps
  • Patch size: 16
  • Default input features: 1 (univariate)
  • Output: An anomaly score per time step; higher scores indicate a higher likelihood of anomaly

The model normalizes each input window internally. For sequences longer than 5,000 points, use model.zero_shot(), which splits the input into windows and returns scores for each window.

Repository Contents

.
β”œβ”€β”€ config.json
β”œβ”€β”€ model.safetensors
β”œβ”€β”€ preprocessor_config.json
β”œβ”€β”€ configuration_time_rcd.py
β”œβ”€β”€ modeling_time_rcd.py
β”œβ”€β”€ processing_time_rcd.py
β”œβ”€β”€ requirements.txt
└── best_model/
    β”œβ”€β”€ pretrain_checkpoint_best_uni.pth
    └── pretrain_checkpoint_best_multi.pth
  • model.safetensors: Default univariate checkpoint in Safetensors format for Transformers inference.
  • best_model/: Original PyTorch checkpoints for univariate and multivariate settings.

Installation

conda create -n Time-RCD python=3.10
conda activate Time-RCD
pip install -r requirements.txt

Or install dependencies directly:

pip install "torch>=2.0.0" "transformers>=4.30.0" "numpy>=1.20.0" "scikit-learn>=1.0.0"

Quick Start

This repository ships custom model and processor code. Set trust_remote_code=True when loading.

Long sequences (recommended)

import numpy as np
import torch
from transformers import AutoModel

model_id = "thu-sail-lab/Time-RCD"
device = "cuda" if torch.cuda.is_available() else "cpu"

model = AutoModel.from_pretrained(model_id, trust_remote_code=True).to(device)
model.eval()

# Shape: (num_timesteps,) or (num_timesteps, num_features)
time_series = np.random.randn(10_000).astype(np.float32)

with torch.no_grad():
    scores_by_window, logits_by_window = model.zero_shot(time_series)

anomaly_scores = np.concatenate(scores_by_window)

Single window (≀ 5,000 steps)

import torch
from transformers import AutoModel

model = AutoModel.from_pretrained(
    "thu-sail-lab/Time-RCD",
    trust_remote_code=True,
).eval()

time_series = torch.randn(1, 5000, 1)  # (batch, seq_len, features)
with torch.no_grad():
    outputs = model(time_series=time_series)

anomaly_scores = outputs.anomaly_scores  # (batch, seq_len)

Download Locally

Download the full official repository:

hf download thu-sail-lab/Time-RCD --local-dir ./Time-RCD

Download only the original PyTorch checkpoints:

hf download thu-sail-lab/Time-RCD \
  --include "best_model/pretrain_checkpoint_best_uni.pth" \
  --local-dir ./Time-RCD

hf download thu-sail-lab/Time-RCD \
  --include "best_model/pretrain_checkpoint_best_multi.pth" \
  --local-dir ./Time-RCD

For servers in mainland China, use the Hugging Face mirror:

HF_ENDPOINT=https://hf-mirror.com hf download thu-sail-lab/Time-RCD --local-dir ./Time-RCD

Training and Benchmark Evaluation

For dataset preparation, pre-training, and TSB-AD benchmark evaluation, please use the official GitHub repository:

git clone https://github.com/thu-sail-lab/Time-RCD.git
cd Time-RCD
  • Univariate evaluation: python main.py
  • Multivariate evaluation: python main.py --mode multi
  • Pre-training: python training.py --mode single --gpus 0 --num-workers 0

Limitations

  • The default published config uses num_features=1. Multivariate inference may require the multivariate checkpoint and the full pipeline in the GitHub repository.
  • The model outputs anomaly likelihoods, not calibrated binary labels. Choose a task-specific threshold and validate it on representative data.
  • This Hugging Face repository is optimized for inference via Transformers. Training scripts, benchmark datasets, and evaluation utilities live in the GitHub repository.

Citation

If you find this work useful, please cite our paper:

@misc{lan2025foundationmodelszeroshottime,
  title={Towards Foundation Models for Zero-Shot Time Series Anomaly Detection: Leveraging Synthetic Data and Relative Context Discrepancy},
  author={Tian Lan and Hao Duong Le and Jinbo Li and Wenjun He and Meng Wang and Chenghao Liu and Chen Zhang},
  year={2025},
  eprint={2509.21190},
  archivePrefix={arXiv},
  primaryClass={cs.LG},
  url={https://arxiv.org/abs/2509.21190}
}
Downloads last month
638
Safetensors
Model size
37.1M params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Spaces using thu-sail-lab/Time-RCD 2

Paper for thu-sail-lab/Time-RCD