D2Vformer
March 10, 2026 · View on GitHub
A official pytorch implementation for the paper: ' D2Vformer: A Flexible Time Series Prediction Model Based on Time Position Embedding '
🎯Introduction
This is the pytorch implementation of D2Vformer.
Unlike conventional prediction methods that rely on fixed-length predictors, D2Vformer can directly handle scenarios with arbitrary prediction lengths.
Additionally, it significantly reduces training resource consumption and proves highly effective in real-world dynamic environments.
The architecture of our model(D2Vformer) is shown as below:

Through extensive experiments on six datasets, we demonstrate that D2Vformer outperforms previous state-of-the-art methods respectively for multivariate forecasting tasks and skip prediction tasks
📚Model Statics
The following are the baseline models included in this project (continuously updated):
- Autoformer PDF Code (NlPS 2021)
- Dlinear PDF (AAAl 2022)
- Fedformer PDF Code (lCML 2022)
- PatchTST PDF Code (ICLR 2023)
- FITS PDF Code (ICLR 2024)
- TimeMixer PDF Code (ICLR 2024)
- ......
Setup
Table of Contents:
📝1. Install dependecies
Install the required packages
pip install -r requirements.txt
👉2. Download the data
We follow the same setting as previous work. The datasets for all the six benchmarks can be obtained from [Autoformer]. The datasets are placed in the 'datasets' folder of our project. The tree structure of the files are as follows:
datasets
├─electricity
│
├─ETT-small
│
├─exchange_rate
│
├─illness
│
└─traffic
🚀3. Experimental setup
The experiment consists of three parts, namely "D2VFormer" for regular time series prediction, "Flexible_Prediction" for jump prediction, and "DateVec" for validating the effectiveness of D2V. We have provided all the experimental scripts for the benchmark in the corresponding section of the ./scripts folder, which covers all the benchmarking experiments. To reproduce the results, you can run the following shell code.
D2Vformer for Regular time series forecasting
./D2Vformer/scripts/D2Vformer_s_train.sh
./D2Vformer/scripts/D2Vformer_train.sh
D2Vformer for Flexible Prediction
./Flexib_Prediction_1_Aug/scripts/D2Vformer.sh
Evalutaion of Date2vec
./Date2Vec/scripts/PatchTST_train.sh
./Date2Vec/scripts/T2V_PatchTST_train.sh
./Date2Vec/scripts/GLAFF_PatchTST_train.sh
./Date2Vec/scripts/D2V_PatchTST_train.sh
...
When you run the 'D2Vformer', the length of the historical input sequence is maintained at 96(or 36 for the illness dataset), whereas the length of the sequence to be predicted is selected from a range of values, i.e., {48, 96, 336} ({24, 36, 48} for the illness dataset).
When you run the 'Flexible_Prediction', the length of the historical input sequence is maintained at 96(or 36 for the illness dataset), whereas the length of the interva is selected from a range of values, i.e., {6, 8, 10} ({4, 6, 8} for the illness dataset) and the length of the sequence to be predicted is selected from a range of values, i.e., {4, 8, 10} ({2, 4, 8} for the illness dataset).
When you run the 'DateVec', to validate the effectiveness of D2V, we replace the position embedding method in typical transformer-based models PatchTST, Itransformer with T2V, GLAFF, and D2V, respectively.
Note that the input length is fixed to be 96 for all methods for a fair comparison. The evaluation is based on the mean squared error (MSE) and mean absolute error (MAE) metrics
Results
The results of regular time series forecasting

The results of flexible prediction.

The evaluation of the performance of different timestamp embedding methods

Acknowledge
We appreciate the following github repositories for their valuable code references: