需从 Hugging Face 单独下载模型权重,仓库不含权重;requirements 曾更新过依赖版本,旧环境需重建;零样本预测需自行调 context length,超过训练长度要开 RoPE scaling

lag-llama
time-series-foundation-modelsApache-2.0长期未更新基于 Llama 架构的概率式时间序列基础模型,用滞后特征做零样本预测,免去为每条序列单独训练模型。
Lag-Llama: Towards Foundation Models for Probabilistic Time Series Forecasting
git clone https://github.com/time-series-foundation-models/lag-llama.git
pip install -r requirements.txtREADME 未说明显存、CPU 或 GPU 型号要求
首个开源时间序列基础模型,用概率分布做零样本预测,不用训练就能直接预测
基于 Llama 架构的概率式时间序列基础模型,用滞后特征做零样本预测,免去为每条序列单独训练模型。
核心能力
- 对任意频率、任意预测长度做零样本预测
- 输出每个时间步的概率分布而非单点值
- 支持在自有数据上微调以提升效果
- 提供复现论文预训练与微调实验的脚本
- 用滞后特征构建输入,适配多种时间序列格式
容易踩的坑
暂无 release 数据(可能没有发版,或尚未同步)。
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Lag-Llama: Towards Foundation Models for Probabilistic Time Series Forecasting

Lag-Llama is the first open-source foundation model for time series forecasting!
[Model Weights] [Colab Demo 1: Zero-Shot Forecasting] [Colab Demo 2: (Preliminary Finetuning)]
[Paper]
[Video]
Updates:
- 27-June-2024: Fixed critical issues in the kv_cache implementation, improving forecast accuracy. The fixes include: resetting the self.y_cache flag globally, using causal attention correctly during kv_cache initialization, and adjusting rotary embeddings post-concatenation. Contribution by @KelianM.
- 16-Apr-2024: Released pretraining and finetuning scripts to replicate the experiments in the paper. See Reproducing Experiments in the Paper for details.
- 9-Apr-2024: We have released a 15-minute video 🎥 on Lag-Llama on YouTube.
- 5-Apr-2024: Added a section in Colab Demo 1 on the importance of tuning the context length for zero-shot forecasting. Added a best practices section in the README; added recommendations for finetuning. These recommendations will be demonstrated with an example in Colab Demo 2 soon.
- 4-Apr-2024: We have updated our requirements file with new versions of certain packages. Please update/recreate your environments if you have previously used the code locally.
- 7-Mar-2024: We have released a preliminary Colab Demo 2 for finetuning. Please note this is a preliminary tutorial. We recommend taking a look at the best practices if you are finetuning the model or using it for benchmarking.
- 17-Feb-2024: We have released a new updated Colab Demo 1 for zero-shot forecasting that shows how one can load time series of different formats.
- 7-Feb-2024: We released Lag-Llama, with open-source model checkpoints and a Colab Demo for zero-shot forecasting.
Current Features:
💫 Zero-shot forecasting on a dataset of any frequency for any prediction length, using Colab Demo 1.
💫 Finetuning on a dataset using Colab Demo 2.
💫 Reproducing experiments in the paper using the released scripts. See Reproducing Experiments in the Paper for details.
Note: Please see the best practices section when using the model for zero-shot prediction and finetuning.
Reproducing Experiments in the Paper
To replicate the pretraining setup used in the paper, please see the pretraining script. Once a model is pretrained, instructions to finetune it with the setup in the paper can be found in the finetuning script.
Best Practices
Here are some general tips in using Lag-Llama.
General Information
- Lag-Llama is a probabilistic forecasting model trained to output a probability distribution for each timestep to be predicted. For your own specific use-case, we would recommend benchmarking the zero-shot performance of the model on your data first, and then finetuning if necessary. As we show in our paper, Lag-Llama has strong zero-shot capabilities, but performs best when finetuned. The more data you finetune on, the better. For specific tips on applying on model zero-shot or on finetuning, please refer to the sections below.
Zero-Shot Forecasting
- Importantly, we recommend trying different context lengths (starting from $32$ which it was trained on) and identifying what works best for your data. As we show in this section of the zero-shot forecasting demo, the model's zero-shot performance improves as the context length is increased, until a certain context length which may be specific to your data. Further, we recommend enabling RoPE scaling for the model to work well with context lengths larger than what it was trained on.
Fine-Tuning
If you are trying to benchmark the performance of the model under finetuning, or trying to obtain maximum performance from the model:
- We recommend tuning two important hyperparameters for each dataset that you finetune on: the context length (suggested values: $32$, $64$, $128$, $256$, $512$, $1024$) and the learning rate (suggested values: $10^{-2}$, $5 * 10^{-3}$, $10^{-3}$, $5 * 10^{-3}$, $1 * 10^{-4}$, $5 * 10^{-4}$).
- We also highly recommend using a validation split of your dataset to early stop your model, with an early stopping patience of 50 epochs.
Contact
We are dedicated to ensuring the reproducility of our results, and would be happy to help clarify questions about benchmarking our model or about the experiments in the paper. If you have questions, it would be best to create an issue in the GitHub repository.
Citing this work
Please use the following Bibtex entry to cite Lag-Llama.
@misc{rasul2024lagllama,
title={Lag-Llama: Towards Foundation Models for Probabilistic Time Series Forecasting},
author={Kashif Rasul and Arjun Ashok and Andrew Robert Williams and Hena Ghonia and Rishika Bhagwatkar and Arian Khorasani and Mohammad Javad Darvishi Bayazi and George Adamopoulos and Roland Riachi and Nadhir Hassen and Marin Biloš and Sahil Garg and Anderson Schneider and Nicolas Chapados and Alexandre Drouin and Valentina Zantedeschi and Yuriy Nevmyvaka and Irina Rish},
year={2024},
eprint={2310.08278},
archivePrefix={arXiv},
primaryClass={cs.LG}
}