Kronos provides a complete pipeline for finetuning the model on custom datasets, demonstrated using the Microsoft Qlib framework for A-share market data. The process follows four stages: Configuration, Data Preparation, Model Finetuning (Tokenizer then Predictor), and Backtesting.
Prerequisites
- Install dependencies from
requirements.txt. - Install
pyqlib:pip install pyqlib
- Prepare local Qlib data following the official Qlib guide.
Step 1: Configure the Experiment
Modify finetune/config.py to set the following essential paths and parameters:
qlib_data_path: Path to your local Qlib data.dataset_path: Where processed pickle files will be saved.save_path: Base directory for model checkpoints.backtest_result_path: Directory for backtesting results.pretrained_tokenizer_path & pretrained_predictor_path: Paths to pre-trained models (local or Hugging Face names).use_comet: Set to False if not using Comet.ml.
Step 2: Prepare the Dataset
Run the preprocessing script to load raw Qlib data and split it into train_data.pkl, val_data.pkl, and test_data.pkl:
python finetune/qlib_data_preprocess.py
Step 3: Run Finetuning
Finetuning is done in two stages using torchrun for multi-GPU support.
3.1 Finetune the Tokenizer (adjusts tokenizer to your domain distribution):
# Replace NUM_GPUS with your GPU count
torchrun --standalone --nproc_per_node=NUM_GPUS finetune/train_tokenizer.py
3.2 Finetune the Predictor (finetunes the main forecasting model):
# Replace NUM_GPUS with your GPU count
torchrun --standalone --nproc_per_node=NUM_GPUS finetune/train_predictor.py
Step 4: Evaluate with Backtesting
Run the backtesting script to perform inference on the test set and evaluate a top-K strategy:
python finetune/qlib_test.py --device cuda:0
# Example workflow sequence
pip install pyqlib
python finetune/qlib_data_preprocess.py
torchrun --standalone --nproc_per_node=2 finetune/train_tokenizer.py
torchrun --standalone --nproc_per_node=2 finetune/train_predictor.py
python finetune/qlib_test.py --device cuda:0