README.md

July 22, 2025 ยท View on GitHub

๐Ÿš€ A Library for High-Dimensional Time Series Forecasting [Paper Page]

Python 3.8+ PyTorch License Framework

A comprehensive, production-ready framework for high-dimensional time series forecasting with support for 20+ state-of-the-art models, distributed training, automated hyperparameter optimization.

๐ŸŒŸ Key Features

  • ๐Ÿ“Š High-Dimensional: Optimized for datasets with thousands of dimensions
  • ๐Ÿค– 20+ SOTA Models: Latest time series forecasting models (2017-2024) with unified interface
  • ๐Ÿš€ Distributed Training: Built-in multi-GPU support with HuggingFace Accelerate
  • ๐Ÿ” AutoML: Automated hyperparameter search with multi-horizon evaluation

๐Ÿ“‹ Supported Models (20+)

๐ŸŽฏ High-Dimensional Specialized

ModelYearPaperDescription
UCast2025Learning Latent Hierarchical Channel StructureHigh-dimensional forecasting

๐Ÿ›๏ธ Transformer-Based Models

ModelYearPaperDescription
Transformer2017Attention Is All You NeedOriginal transformer architecture
Informer2021Beyond Efficient TransformerProbSparse attention mechanism
Autoformer2021Decomposition TransformersAuto-correlation mechanism
Pyraformer2021Pyramidal AttentionLow-complexity attention
FEDformer2022Frequency Enhanced DecomposedFrequency domain modeling
Nonstationary Transformer2022Non-stationary TransformersHandles non-stationarity
ETSformer2022Exponential Smoothing TransformersETS-based transformers
Crossformer2023Cross-Dimension DependencyCross-dimensional attention
PatchTST2023A Time Series is Worth 64 WordsPatch-based transformers
iTransformer2024Inverted TransformersChannel-attention design

๐Ÿง  CNN & MLP-Based Models

ModelYearPaperDescription
MICN2023Multi-scale Local and Global ContextIsometric convolution
TimesNet2023Temporal 2D-Variation Modeling2D temporal modeling
ModernTCN2024Modern Temporal Convolutional NetworksEnhanced TCN architecture
DLinear2023Are Transformers Effective?Simple linear baseline
TSMixer2023All-MLP ArchitectureMLP-based mixing
FreTS2023Simple yet Effective ApproachFrequency representation
TiDE2023Time-series Dense EncoderDense encoder design
SegRNN2023Segment Recurrent Neural NetworkSegment-based RNN
LightTS2023Lightweight Time SeriesEfficient forecasting

๐Ÿ“Š Supported Datasets

๐ŸŽฏ Time-HD: High-Dimensional Benchmark

Our framework supports the Time-HD benchmark dataset through HuggingFace Datasets:

๐Ÿ“ˆ Traditional Benchmarks

  • ETT (ETTh1, ETTh2, ETTm1, ETTm2) - Electricity transformer temperature
  • Weather - Multi-variate weather forecasting
  • Traffic - Road traffic flow
  • ECL - Electricity consuming load

๐Ÿš€ Quick Start

Installation

# Clone the repository
git clone https://github.com/LingFengGold/Time-HD-Lib
cd Time-HD-Lib

# Method 1: Using pip
pip install -r requirements.txt

# Method 2: Using conda (recommended)
conda env create -f environment.yaml
conda activate tsf

# Install optional dependencies for full functionality
pip install pandas torchinfo einops reformer-pytorch

Data Preparation

To access the Time-HD benchmark dataset, follow these steps:

a. Create a Hugging Face account, if you do not already have one.

b. Visit the dataset page:
https://huggingface.co/datasets/Time-HD-Anonymous/High_Dimensional_Time_Series

c. Click "Agree and access repository". You must be logged in to complete this step.

d. Create new Access Token. Token type should be "write".

e. Authenticate on your local machine by running:

huggingface-cli login

and enter your generated token above.

f. Then, you can manually download all the dataset by running:

python download_dataset.py

The summary of the supported high-dimensional time series datasets is shown in Table 2 above. Besides these, we also support datasets such as ECL, ETTh1, ETTh2, ETTm1, ETTm2, Weather, and Traffic.

Basic Usage

# ๐Ÿ–ฅ๏ธ Single GPU training
accelerate launch --num_processes=1 run.py --model UCast --data "Measles" --gpu 0

# ๐Ÿš€ Multi-GPU training (auto-detect all GPUs)
accelerate launch run.py --model UCast --data "Measles"

# ๐ŸŽฏ Specific GPU selection (e.g. 4 GPUs, id: 0,2,3,7)
accelerate launch --num_processes=4 run.py --model UCast --data "Measles" --gpu 0,2,3,7

# ๐Ÿ“‹ List available models
accelerate launch run.py --list-models

# โ„น๏ธ Show framework information
python run.py --info
# ๐Ÿ” Automated hyperparameter search
accelerate launch run.py --model UCast --data "Measles" --hyper_parameter_searching
accelerate launch --num_processes=1 run.py --model UCast --data "Measles" --gpu 0 --hyper_parameter_searching
accelerate launch --num_processes=4 run.py --model UCast --data "Measles" --gpu 0,2,3,7 --hyper_parameter_searching

๐Ÿ”ง Configuration System

Model Configuration

Create dataset-specific configurations in configs/:

# configs/UCast.yaml
Measles:
  enc_in: 1161
  train_epochs: 10
  alpha: 0.01
  seq_len_factor: 4
  learning_rate: 0.001

Air_Quality:
  enc_in: 2994
  train_epochs: 15
  alpha: 0.1
  seq_len_factor: 5
  learning_rate: 0.0001

Hyperparameter Search Configuration

Define search spaces in config_hp/:

# config_hp/UCast.yaml
learning_rate: [0.001, 0.0001]
seq_len_factor: [4, 5]
d_model: [256, 512]
alpha: [0.01, 0.1]

๐Ÿ—๏ธ Architecture Overview

๐Ÿ“ Time-HD-Lib Framework
โ”œโ”€โ”€ ๐Ÿš€ run.py                     # Main entry point with GPU management
โ”œโ”€โ”€ ๐Ÿ—๏ธ  core/                     # Core framework components
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ config/                # Configuration management system
โ”‚   โ”‚   โ”œโ”€โ”€ base.py               # Base configuration classes
โ”‚   โ”‚   โ”œโ”€โ”€ manager.py            # Configuration manager
โ”‚   โ”‚   โ””โ”€โ”€ model_configs.py      # Model-specific configs
โ”‚   โ”œโ”€โ”€ ๐Ÿ“Š registry/              # Model/dataset registration
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py           # Registry decorators
โ”‚   โ”‚   โ””โ”€โ”€ model_registry.py     # Model registration system
โ”‚   โ”œโ”€โ”€ ๐Ÿค– models/                # Model management and loading
โ”‚   โ”‚   โ”œโ”€โ”€ model_manager.py      # Dynamic model loading
โ”‚   โ”‚   โ””โ”€โ”€ __init__.py           # Model manager interface
โ”‚   โ”œโ”€โ”€ ๐Ÿ“Š data/                  # Self-contained data pipeline
โ”‚   โ”‚   โ”œโ”€โ”€ data_provider.py      # Main data provider
โ”‚   โ”‚   โ”œโ”€โ”€ data_factory.py       # Dataset factory
โ”‚   โ”‚   โ””โ”€โ”€ data_loader.py        # Custom dataset classes
โ”‚   โ”œโ”€โ”€ ๐Ÿงช experiments/           # Experiment orchestration
โ”‚   โ”‚   โ”œโ”€โ”€ base_experiment.py    # Base experiment class
โ”‚   โ”‚   โ””โ”€โ”€ long_term_forecasting.py  # Forecasting experiments
โ”‚   โ”œโ”€โ”€ โš™๏ธ  execution/             # Execution engine
โ”‚   โ”‚   โ””โ”€โ”€ runner.py             # Experiment runners
โ”‚   โ”œโ”€โ”€ ๐Ÿ› ๏ธ  utils/                # Self-contained utilities
โ”‚   โ”‚   โ”œโ”€โ”€ tools.py              # Training utilities
โ”‚   โ”‚   โ”œโ”€โ”€ metrics.py            # Evaluation metrics
โ”‚   โ”‚   โ”œโ”€โ”€ timefeatures.py       # Time feature extraction
โ”‚   โ”‚   โ”œโ”€โ”€ augmentation.py       # Data augmentation
โ”‚   โ”‚   โ”œโ”€โ”€ masked_attention.py   # Attention mechanisms
โ”‚   โ”‚   โ””โ”€โ”€ masking.py            # Masking utilities
โ”‚   โ”œโ”€โ”€ ๐Ÿ”Œ plugins/               # Plugin system for extensibility
โ”‚   โ””โ”€โ”€ ๐Ÿ’ป cli/                   # Command-line interface
โ”‚       โ””โ”€โ”€ argument_parser.py    # Comprehensive CLI parser
โ”œโ”€โ”€ ๐Ÿค– models/                    # Model implementations with @register_model
โ”‚   โ”œโ”€โ”€ UCast.py                  # High-dimensional specialist
โ”‚   โ”œโ”€โ”€ TimesNet.py               # 2D temporal modeling
โ”‚   โ”œโ”€โ”€ iTransformer.py           # Inverted transformer
โ”‚   โ”œโ”€โ”€ ModernTCN.py              # Modern TCN
โ”‚   โ””โ”€โ”€ ...                       # 16+ other models
โ”œโ”€โ”€ ๐Ÿ—‚๏ธ configs/                   # Model-dataset configurations
โ”œโ”€โ”€ ๐Ÿ” config_hp/                 # Hyperparameter search configs
โ”œโ”€โ”€ ๐Ÿงฑ layers/                    # Neural network building blocks
โ””โ”€โ”€ ๐Ÿ“Š results/                   # Experiment outputs and logs

๐Ÿ“ˆ Performance Benchmarks

๐ŸŽฏ Best Practices

1. Model Hyperparameter Configuration

Create Model Configuration Files

Create YAML configuration files for each model in the configs/ directory:

# configs/YourModel.yaml
Measles:
  enc_in: 1161
  train_epochs: 10
  learning_rate: 0.001
  d_model: 512
  batch_size: 16
  seq_len_factor: 4

Prediction Length Configuration

Edit configs/pred_len_config.yaml to set default prediction lengths for datasets:

# configs/pred_len_config.yaml
Measles: [7]           # Use the first value as default
Temp: [168]

2. Multi-GPU Setup and Distributed Training

Automatic GPU Detection

# Use all available GPUs
accelerate launch run.py --model UCast --data "Measles"

Specify Specific GPUs

# Use GPUs 0,2,3,7
accelerate launch --num_processes=4 run.py --model UCast --data "Measles" --gpu 0,2,3,7

# Single GPU training
accelerate launch --num_processes=1 run.py --model UCast --data "Measles" --gpu 0

Configure Distributed Training

# Multi-node training
accelerate launch --multi_gpu --main_process_port 29500 run.py --model UCast --data "Measles"

3. Automatic Batch Size Finding during Hyperparameter Searching

The framework automatically finds the maximum available batch size during hyperparameter searching:

# Start from batch size 64, automatically reduce to 32, 16, 8, 4, 2, 1 when encountering OOM
accelerate launch run.py --model UCast --data "Measles" --batch_size 64 --hyper_parameter_searching

Manual batch size control:

# configs/UCast.yaml 
Measles:
  batch_size: 16  # Set smaller batch size for high-dimensional data
  
Wiki-20k:
  batch_size: 8   # Use even smaller batch size for ultra-high-dimensional data

4. Mixed Precision Training

Enable Mixed Precision

accelerate launch --mixed_precision fp16 run.py --model UCast --data "Measles"

5. Batch Training

Use Batch Mode

# Run predefined batch experiments
python run.py --batch

Custom Batch Experiments

from core.config import ConfigManager
from core.execution.runner import BatchRunner

# Create batch experiments
config_manager = ConfigManager()
batch_runner = BatchRunner(config_manager)

# Add experiments
models = ['UCast', 'TimesNet', 'iTransformer']
datasets = ['Measles', 'SIRS', 'ETTh1']

for model in models:
    for dataset in datasets:
        batch_runner.add_experiment(
            model=model,
            data=dataset,
            is_training=True
        )

# Run batch experiments
results = batch_runner.run_batch()

6. Hyperparameter Search Configuration and Execution

Create Hyperparameter Search Configuration

# config_hp/UCast.yaml
learning_rate: [0.001, 0.0001, 0.00001]
seq_len_factor: [3, 4, 5]
d_model: [256, 512, 1024]
alpha: [0.01, 0.1, 1.0]
batch_size: [8, 16, 32]

Set Prediction Length Ranges for Datasets

# configs/pred_len_config.yaml  
Measles: [7, 14, 21]      # These 3 values will be tested during hyperparameter search
ETTh1: [96, 192, 336]     # Multiple prediction lengths for traditional datasets
"Air Quality": [28, 56]   # Suitable prediction lengths for high-dimensional data
# Single GPU hyperparameter search
accelerate launch --num_processes=1 run.py --model UCast --data "Measles" --hyper_parameter_searching

# Multi-GPU hyperparameter search
accelerate launch --num_processes=4 run.py --model UCast --data "Measles" --gpu 0,2,3,7 --hyper_parameter_searching

# Specify log directory
accelerate launch run.py --model UCast --data "Measles" --hyper_parameter_searching --hp_log_dir ./my_hp_logs/

View Search Results

# Results are saved in hp_logs/ directory
hp_logs/
โ””โ”€โ”€ UCast_Measles_20241201_143022/
    โ”œโ”€โ”€ best_result.json     # Best configuration and results
    โ”œโ”€โ”€ hp_summary.json      # Summary of all configurations
    โ”œโ”€โ”€ results.csv          # CSV format results
    โ””โ”€โ”€ result_*.json        # Detailed results for each configuration

๐Ÿ”ง Development & Extension

1. Adding New Models

Step 1: Implement Model Class

Create a new model file in the models/ directory:

# models/YourNewModel.py
import torch
import torch.nn as nn
from core.registry import register_model

@register_model("YourNewModel", paper="Your Paper Title", year=2024)
class Model(nn.Module):  # Class name must be 'Model'
    def __init__(self, configs):
        super().__init__()
        self.configs = configs
        
        # Get parameters from configs
        self.seq_len = configs.seq_len
        self.pred_len = configs.pred_len
        self.enc_in = configs.enc_in
        self.d_model = configs.d_model
        
        # Implement your model architecture
        self.encoder = nn.Linear(self.enc_in, self.d_model)
        self.decoder = nn.Linear(self.d_model, self.enc_in)
        
    def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
        # x_enc: [batch_size, seq_len, enc_in]
        # Return: [batch_size, pred_len, enc_in]
        
        # Implement forward propagation
        encoded = self.encoder(x_enc)
        # ... Your model logic ...
        output = self.decoder(encoded)
        
        return output

Step 2: Create Model Configuration

# configs/YourNewModel.yaml
Measles:
  enc_in: 1161
  train_epochs: 10
  learning_rate: 0.001
  d_model: 512
  batch_size: 16
  seq_len_factor: 4
  # Add model-specific parameters
  your_param: 0.1

ETTh1:
  enc_in: 7
  train_epochs: 15
  learning_rate: 0.0001
  d_model: 256

Step 3: Create Hyperparameter Search Configuration

# config_hp/YourNewModel.yaml
learning_rate: [0.001, 0.0001]
d_model: [256, 512]
your_param: [0.1, 0.5, 1.0]
seq_len_factor: [3, 4, 5]

Step 4: Test New Model

# Test if model is correctly registered
python run.py --list-models

# Quick validation training
accelerate launch --num_processes=1 run.py --model YourNewModel --data "Measles" --train_epochs 1

# Full training
accelerate launch run.py --model YourNewModel --data "Measles"

# Hyperparameter search
accelerate launch run.py --model YourNewModel --data "Measles" --hyper_parameter_searching

2. Adding New Datasets (Upload to HuggingFace)

Step 1: Prepare Dataset

๐Ÿ“Š Standard Dataset Format

Time-HD-Lib expects datasets to follow a standardized format:

  • ๐Ÿ“… Date Column: First column named 'date' containing timestamps
  • ๐Ÿ“ˆ Feature Columns: Remaining columns represent different features/dimensions
  • โฐ Row Structure: Each row represents one time step/timestamp
  • ๐Ÿ“‹ Column Order: ['date', 'feature_0', 'feature_1', ..., 'feature_n']

Example Dataset Structure:

        date          feature_0    feature_1    feature_2    ...    feature_499
0    2020-01-01 00:00:00   0.234       -1.456       0.789    ...       2.341
1    2020-01-01 01:00:00  -0.567        0.891      -0.234    ...      -1.234  
2    2020-01-01 02:00:00   1.234       -0.567       1.456    ...       0.567
...               ...        ...          ...         ...    ...         ...
9999 2021-02-23 07:00:00   0.123        1.789      -0.987    ...       1.567

๐Ÿ”ง Format Requirements:

  • Time Column: Must be named 'date' and contain valid timestamps
  • Feature Naming: Can use any naming convention (e.g., feature_0, sensor_1, temperature)
  • Data Types: Numeric values for features, datetime for date column
  • Missing Values: Handle NaN values before uploading (interpolate or remove)
  • Frequency: Consistent time intervals (hourly, daily, etc.)

Step 2: Upload to HuggingFace (https://huggingface.co/datasets/Time-HD-Anonymous/High_Dimensional_Time_Series)

Step 3: Add Dataset Support in Framework or use Dataset_Custom

# core/data/data_loader.py - Add new dataset class
class Dataset_YourDataset(Dataset):
    def __init__(self, args, root_path, flag='train', size=None, 
                 features='S', data_path='your_dataset.csv',
                 target='feature_0', scale=True, timeenc=0, freq='h'):
        
        # Implement data loading logic
        # Can load from HuggingFace or local CSV
        if args.use_hf_datasets:
            from datasets import load_dataset
            hf_dataset = load_dataset("your-username/your-dataset-name")
            self.data_x = hf_dataset[flag].to_pandas()
        else:
            # Load from local
            df_raw = pd.read_csv(os.path.join(root_path, data_path))
            self.data_x = df_raw
            
        # Implement the rest of data processing logic...

Step 4: Update Data Factory

# core/data/data_factory.py
data_dict = {
    'ETTh1': Dataset_ETT_hour,
    'ETTh2': Dataset_ETT_hour,
    'ETTm1': Dataset_ETT_minute,
    'ETTm2': Dataset_ETT_minute,
    'custom': Dataset_Custom,
    'your_dataset': Dataset_YourDataset,  # Add new dataset
}

Step 5: Add Configuration Support

# configs/pred_len_config.yaml
your_dataset: [24, 48, 96]  # Set default prediction length

# configs/UCast.yaml (or other model configurations)
your_dataset:
  enc_in: 500  # Number of features in your dataset
  train_epochs: 10
  learning_rate: 0.001
  seq_len_factor: 4

Step 6: Test New Dataset

# Test data loading
accelerate launch --num_processes=1 run.py --model UCast --data your_dataset --train_epochs 1

# Full training
accelerate launch run.py --model UCast --data your_dataset

# Hyperparameter search
accelerate launch run.py --model UCast --data your_dataset --hyper_parameter_searching

๐Ÿ“Š Experiment Results Management

๐Ÿ“ Output Structure

Time-HD-Lib/
โ”œโ”€โ”€ ๐Ÿ“Š results/                          # Main experiment results
โ”‚   โ””โ”€โ”€ long_term_forecast_{model}_{dataset}_slxxx_plxxx/
โ”‚       โ”œโ”€โ”€ metrics.npy                  # Final test metrics [mae, mse, rmse, mape, mspe]
โ”‚       โ”œโ”€โ”€ pred.npy                     # Model predictions [batch, pred_len, features]
โ”‚       โ””โ”€โ”€ true.npy                     # Ground truth values [batch, pred_len, features]
โ”‚
โ”œโ”€โ”€ ๐ŸŽฏ test_results/                     # Visualization and detailed analysis
โ”‚   โ””โ”€โ”€ long_term_forecast_{model}_{dataset}_slxxx_plxxx/
โ”‚       โ”œโ”€โ”€ 0.pdf                        # Prediction plots for feature 0
โ”‚       โ”œโ”€โ”€ 20.pdf                       # Prediction plots for feature 20
โ”‚       โ””โ”€โ”€ ...                          # Additional feature visualizations
โ”‚
โ””โ”€โ”€ ๐Ÿ” hp_logs/                          # Hyperparameter search results
    โ””โ”€โ”€ {model}_{dataset}_{timestamp}/
        โ”œโ”€โ”€ best_result.json             # Best configuration and performance metrics
        โ”œโ”€โ”€ hp_summary.json              # Summary of all tested configurations
        โ””โ”€โ”€ results.csv                  # All results in tabular format

๐Ÿ“ Citation

If you use Time-HD-Lib or Time-HD benchmark in your research, please cite:

@article{ucast_2024,
    title = {Are We Overlooking the Dimensions? Learning Latent Hierarchical Channel Structure for High-Dimensional Time Series Forecasting},
    author = {Juntong Ni, Shiyu Wang, Zewen Liu, Xiaoming Shi, Xinyue Zhong, Zhou Ye, Wei Jin},
    journal = {In Submission},
    year = {2025}
}

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿค Acknowledgments

  • Time-Series-Library - Foundation and inspiration (GitHub)
  • HuggingFace Accelerate - Distributed training infrastructure
  • PyTorch Ecosystem - Deep learning framework
  • Time Series Research Community - For advancing the field

๐ŸŒŸ Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. ๐Ÿด Fork the repository
  2. ๐ŸŒฟ Create a feature branch (git checkout -b feature/amazing-feature)
  3. ๐Ÿ’ป Make your changes and add tests
  4. โœ… Ensure all tests pass (python -m pytest tests/)
  5. ๐Ÿ“ Update documentation if needed
  6. ๐Ÿš€ Submit a pull request

๐Ÿ“ž Support & Community


๐Ÿš€ Ready to forecast the future with high-dimensional time series? Get started today!