Instructions to use thu-sail-lab/Time-RCD with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use thu-sail-lab/Time-RCD with Transformers:
# 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") - Notebooks
- Google Colab
- Kaggle
# Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("thu-sail-lab/Time-RCD", trust_remote_code=True, device_map="auto")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.
| Resource | Link |
|---|---|
| Paper | arXiv:2509.21190 |
| Code | github.com/thu-sail-lab/Time-RCD |
| Demo | Hugging Face Space |
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
# 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)