Skip to content

Fine-tuning on the official weights ​

After finishing this section, you will be able to fine-tune a copy of the official KiT with new data from 2026, and know when fine-tuning helps and when it's a waste of effort.

What is fine-tuning ​

Training from scratch means having a model that knows nothing learn from the beginning. Fine-tuning means taking a model that has already learned and practicing a bit more with the data you care about.

It's like hiring an experienced veteran trader to your team: he doesn't need to learn what a candlestick chart is from scratch, he just needs to get familiar with recent market conditions.

First attempt: not enough GPU memory ​

The most straightforward approach is to continue training all 284 million parameters:

bash
python train_mini.py --scale 1d --ckpt ckpt/step_market_284M.pt --steps 300 --batch 8 --lr 2e-5 --out runs/ft-1d

Other programs were also running on our 16GB GPU, leaving only about 7GB, and the result:

text
model 285.8M params | scale 1d Lc=250 Lh=20 | windows train 4000 val 400 (8s)
step 0 | val 1.3630
torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 12.00 MiB. GPU 0 has a total capacity of 15.56 GiB of which 29.31 MiB is free.

During full training, each parameter, in addition to itself, also needs to store gradients and two copies of optimizer state. For 284 million parameters, these alone take 4~5GB, and with intermediate results on top, 7GB is not enough.

Second attempt: training only the last 4 layers ​

--train-last 4 freezes the earlier layers and trains only the last 4 Transformer blocks and the output layer. Frozen parameters don't need gradients or optimizer state, so the memory is suddenly sufficient:

bash
python train_mini.py --scale 1d --ckpt ckpt/step_market_284M.pt --train-last 4 --steps 300 --batch 8 --eval-every 50 --lr 2e-5 --warmup 20 --out runs/ft-1d
text
model 285.8M params (51.4M trainable) | scale 1d Lc=250 Lh=20 | windows train 4000 val 400 (8s)
step 0 | val 1.3630
step 50 | train 1.3012 | val 1.3650 | 4s | peak GPU 2.8 GB
...
step 300 | train 1.3271 | val 1.3690 | 25s | peak GPU 2.8 GB

Trainable parameters: 51.4 million, peak memory 2.8GB. But validation loss went from 1.363 to 1.369, not dropping at all.

Why it didn't work: this data isn't new to it ​

This time the training data was from 2016 to June 2025, and validation was the second half of 2025. According to Section 4.1 of the paper, the official checkpoint's training set is all data up to the end of 2023, and 2024–2025 are its validation set: during training, the loss on these two years was used all along to decide when to stop and which checkpoint to keep. In other words, it directly learned most of this training data, and the rest, along with the validation window, also took part in its model selection. Teaching it these again teaches it nothing new.

There's another signal: the official model's loss on these 400 validation segments is 1.363, far lower than your best result of 1.787 from training from scratch in the previous section. Part of this is because it's larger and learned much more data, and part is because this period took part in its model selection, so this comparison isn't fair.

Fine-tuning should use data the model never touched during training or validation. For the official checkpoint, that means data after 2026.

Third attempt: using new data from 2026 ​

The demo data goes up to 2026-04-10. Take 1-hour bars: fine-tune on January through the end of February, validate on March through April 10.

bash
python train_mini.py --scale 1h --ckpt ckpt/step_market_284M.pt --train-last 4 \
  --train-start 2026-01-01 --train-end 2026-02-27 --val-start 2026-03-02 --val-end 2026-04-10 \
  --per-stock 40 --steps 400 --batch 8 --eval-every 50 --lr 2e-5 --warmup 20 --out runs/ft-1h-2026

You should see the validation loss first drop and then rise:

text
model 285.8M params (51.4M trainable) | scale 1h Lc=400 Lh=20 | windows train 4000 val 400 (9s)
step 0 | val 1.8550
step 50 | train 1.6560 | val 1.8174 | 7s | peak GPU 3.3 GB
step 100 | train 1.6602 | val 1.8095 | 14s | peak GPU 3.3 GB
...
step 400 | train 1.4729 | val 1.8529 | 53s | peak GPU 3.3 GB
Drag itFine-tuning: loss curve (actual record)RTX 4080 SUPER tested
0 步200 步400 步1.91.4
Training lossValidation lossValidation minimum

第 100 step, lowest validation loss (1.809). train_mini.py saves best.pt at this point.

Validation loss 1.855 → 1.810 (lowest at step 100), a drop of about 2.5%. After that it starts rising again: two months of data, 100 steps of training is enough. Use runs/ft-1h-2026/best.pt:

bash
python eval/infer_for_pred.py --ckpt runs/ft-1h-2026/best.pt --case 300733.SZ,1h,"2026-03-20 15:00"

The validation loss dropped, which means the model is more familiar with the distribution of this new market period. Whether it makes rankings more accurate (RankIC) needs to be verified with infer_for_eval.py and cal_metrics.py over a longer test period and more stocks. January through April adds up to only a bit over three months, so this experiment can only show that the pipeline runs and the direction is right.

Look it upMy situation is…

Click one to see.

Quiz timeFine-tuning the official step_market_284M with 2025 data barely changes the validation loss. What's the most likely reason?

Check yourself ​

  • I know why full fine-tuning blows up GPU memory, and why --train-last saves it
  • I know fine-tuning should use data after the model's training cutoff date
  • I fine-tuned a best.pt with 2026 data and produced a prediction chart with it

Next chapter: Understanding the KiT paper, looking at the reasoning and evidence behind each design choice.

gaodong.aiAboutPrivacyTermsContact

Created and maintained by Haorui Li, co-author of the KiT candlestick foundation model.

Independent tutorials, not affiliated with any product mentioned. Product names and trademarks belong to their owners. Check official pages for prices and policies.