You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.9 KiB

1 month ago
  1. # Kronos Fine-tuning on Custom CSV Datasets
  2. This module provides a comprehensive pipeline for fine-tuning Kronos models on your own CSV-formatted financial data. It supports both sequential training (tokenizer followed by predictor) and individual component training, with full distributed training capabilities.
  3. ## 1. Data Preparation
  4. ### Required Data Format
  5. Your CSV file must contain the following columns:
  6. - `timestamps`: DateTime stamps for each data point
  7. - `open`: Opening price
  8. - `high`: Highest price
  9. - `low`: Lowest price
  10. - `close`: Closing price
  11. - `volume`: Trading volume
  12. - `amount`: Trading amount
  13. (volume and amount can be 0 if not available)
  14. ### Sample Data Format
  15. | timestamps | open | close | high | low | volume | amount |
  16. |------------|------|-------|------|-----|--------|--------|
  17. | 2019/11/26 9:35 | 182.45215 | 184.45215 | 184.95215 | 182.45215 | 15136000 | 0 |
  18. | 2019/11/26 9:40 | 184.35215 | 183.85215 | 184.55215 | 183.45215 | 4433300 | 0 |
  19. | 2019/11/26 9:45 | 183.85215 | 183.35215 | 183.95215 | 182.95215 | 3070900 | 0 |
  20. > **Reference**: Check `data/HK_ali_09988_kline_5min_all.csv` for a complete example of the proper data format.
  21. ## 2. Config Preparation
  22. Please edit the correct data path & pretrained model path and set your training parameters.
  23. ```yaml
  24. # Data configuration
  25. data:
  26. data_path: "/path/to/your/data.csv"
  27. lookback_window: 512 # Historical data points to use
  28. predict_window: 48 # Future points to predict
  29. max_context: 512 # Maximum context length
  30. ...
  31. ```
  32. There are some other settings here, please see `configs/config_ali09988_candle-5min.yaml` for more comments.
  33. ## 3. Training
  34. ### Method 1: Sequential Training (Recommended)
  35. The `train_sequential.py` script handles the complete training pipeline automatically:
  36. ```bash
  37. # Complete training (tokenizer + predictor)
  38. python train_sequential.py --config configs/config_ali09988_candle-5min.yaml
  39. # Skip existing models
  40. python train_sequential.py --config configs/config_ali09988_candle-5min.yaml --skip-existing
  41. # Only train tokenizer
  42. python train_sequential.py --config configs/config_ali09988_candle-5min.yaml --skip-basemodel
  43. # Only train predictor
  44. python train_sequential.py --config configs/config_ali09988_candle-5min.yaml --skip-tokenizer
  45. ```
  46. ### Method 2: Individual Component Training
  47. Train each component separately for more control:
  48. ```bash
  49. # Step 1: Train tokenizer
  50. python finetune_tokenizer.py --config configs/config_ali09988_candle-5min.yaml
  51. # Step 2: Train predictor (requires fine-tuned tokenizer)
  52. python finetune_base_model.py --config configs/config_ali09988_candle-5min.yaml
  53. ```
  54. ### DDP Training
  55. For faster training on multiple GPUs:
  56. ```bash
  57. # Set communication backend (nccl for NVIDIA GPUs, gloo for CPU/mixed)
  58. DIST_BACKEND=nccl \
  59. torchrun --standalone --nproc_per_node=8 train_sequential.py --config configs/config_ali09988_candle-5min.yaml
  60. ```
  61. ## 4. Training Results
  62. The training process generates several outputs:
  63. ### Model Checkpoints
  64. - **Tokenizer**: Saved to `{base_save_path}/{exp_name}/tokenizer/best_model/`
  65. - **Predictor**: Saved to `{base_save_path}/{exp_name}/basemodel/best_model/`
  66. ### Training Logs
  67. - **Console output**: Real-time training progress and metrics
  68. - **Log files**: Detailed logs saved to `{base_save_path}/logs/`
  69. - **Validation tracking**: Best models are saved based on validation loss
  70. ## 5. Prediction Vis
  71. The following images show example training results on alibaba (HK stock) data:
  72. ![Training Result 1](examples/HK_ali_09988_kline_5min_all_historical_20250919_073929.png)
  73. ![Training Result 2](examples/HK_ali_09988_kline_5min_all_historical_20250919_073944.png)
  74. ![Training Result 3](examples/HK_ali_09988_kline_5min_all_historical_20250919_074012.png)
  75. ![Training Result 4](examples/HK_ali_09988_kline_5min_all_historical_20250919_074042.png)
  76. ![Training Result 5](examples/HK_ali_09988_kline_5min_all_historical_20250919_074251.png)