# KiT Fine-Tuning: Training on Official 284M Weights

> Fine-tuning the official KiT on a 16GB GPU: why full training blows up the memory, and training only the last 4 layers takes just 3.3GB;

Source: https://gaodong.ai/en/kit/3-train/04-finetune

---

# 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 {#第二次-只训最后-4-层}

`--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 {#第三次-用-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
```

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.

**我的情况是……**

- **显存 16GB 以下**：用 --train-last。--train-last 4 峰值 2.8~3.3GB。还不够就改成 2，或者减小 --batch。
- **想全量微调**：需要更大的显存。2.84 亿参数全量训练，我们 7GB 可用时 batch 8 就爆了。需要更大显存的卡，或者自己加梯度检查点（配置里的 use_activation_checkpointing）。
- **有 2026-01 以后的新数据**：值得微调。官方 step_market_284M 训练加验证用到 2025 年底。用之后的数据微调、留一段更晚的做验证。
- **只有 2025 年以前的数据**：别微调官方模型。这段时间它训练或选模型时都用过。我们实测验证损失 1.363 → 1.369，没有改善。
- **只做 A 股**：也可以换起点。官方另一个检查点 step_market_284M_train260410 只用 A 股、训练到 2026-03-09。用它做起点，要把 data/ 里的 instruments.json 和 stats.json 换成它包里的那两份，微调数据也要从 2026-03-10 以后取。

**小测验：** 用 2025 年的数据微调官方 step_market_284M，验证损失几乎不变，最可能的原因是？
- A. 学习率太小
- B. 这段时间已经参与过模型的训练和选模型，对它不新
- C. 只训了最后 4 层

答案：这段时间已经参与过模型的训练和选模型，对它不新。论文里 2023 年底以前是训练集、2024–2025 年是验证集。换成 2026 年的数据，同样的设置验证损失就降了。

## 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](/kit/4-paper/01-map), looking at the reasoning and evidence behind each design choice.
