excerpts and reflections, deviant ideas and intrusive thoughts.

llm 的 journey

Posted on 2025-09-20 in series llm

从开始接触 llm 的 day1 起我就在记录,也伴随着 llm 技术自身的发展。

入门是受 Andrej Karpathy 启发,train toy llm to reverse string 来上手。

datelog
2023
0515basic transformer understanding; nanoGPT on shakespear text generation; gpt4all train gptj6B w/ lora; streamlit chatbot
0523run inference on llama 7B; finetune alpaca lora
0605implement rotary position embedding
0701implement llm attention
0702implement llm full model
0704implement trainer /tokenizer / spm
0705start train on anderson fairy tale dataset
0710download zhwiki data and extract
0714extract zhwiki with enwiki, retrain
0717change epoch to 2
0718inference on anderson, not good
0719放弃 train on anderson dataset,不收敛; train toy llm to reverse string
0720done

然后受 scaling law 影响,开始研究 base model 训练。用了 wiki 的海量数据。发现靠自己的训练资源其实 scale 远远不够。

datelog
0730clean scifi dataset
0731change head dimension, train 2.7B on zhwiki
0803调整各种参数
0804loss 下不去,调参
0806扩大模型参数量到 104M,有点用
0807推理效果一般
0808扩展参数量到 447M,vocab 设为 32000/16000; 调整 lr 和 micro、bs,loss 下降很光滑
0809add gradient checkpoint
0811设置 2M token per step, training 2x slower
0818hypertune on 117M
0821train done, compare loss and lr
0828117M lr=3e-4, 1.5B lr=1e-4
0829train 2.4B on zhwiki
0904tune lr, context_size,bsz,micro
0926loss=2.7 下不去了
0927fix max_seq_len=2024, 国庆节 retrain
1007loss=3.5

所以 base model 只能靠开源的。然后 baichuan2 出现了,我觉得可以微调下,于是折腾 lora。 又想到了公司的营销文案业务。但最终生成结果效果一般,数据量太少。 等大厂出了各种领域机器人,包括营销文案生成机器人,就被吊打,果断放弃。

datelog
1007run baichuan2-lora with transformer
1010rewrite baichuan2 model; load model shards done; load tokenizer done
1013inference on baichuan2 base model done
1019rewrite jupyter code to python code; inference ok
1020alibi mask 问题,提 github issue
1024inference add repetition penalty and early stop
1025rewrite alibi mask; 合并 alibi mask 和 attension mask
1027implement lora inject adapter to replace module in base model; change chat dataset to (input_ids,labels,mask)
1107start finetune
1108add hyperparam search,delete ray tune
1113param search
1211belle dataset 不太行; finetune with multiturn dataset
1215改造 dataset format
1219loss=2,下不去
2024
0104retrain, fix 数据集问题,loss=1.82,推理效果不错
0115streamlit chat app done
0130设计营销文案生成 bot
0220finetune baichuan3 13B + lora on multiturn
0221retrain v2
0222retrain v3
0308retrain v4 done

中间半年我也不记得我忙啥去了。24 年下半年开始有几个业务上的 idea,开始研究单机多卡推理。做了无数开源模型的推理 demo,最后也成功上线到了公司的业务。

datelog
1112fsdp train on mnist
1113fsdp add wandb log
1114read fsdp paper; get molmo 7B
1115molmo 7B inference done
1120molmo optimize pipeline
1122streamlit demo done
1123学习 DP,DDP,NMP,PP,TP,2D,3D
1125deepseed not working
1202torchrun 多进程单机多卡推理 done
1203qwen2-VL-7B-instruct demo done
1204llama-3.2-11B-vision demo done
1206llava demo done

2025 年自然是被 deepseek 带动,研究强化学习 grpo 微调。搞定了小模型的多卡微调,最终停滞在多卡上跑 big model。

datelog
2025
0211read deepseek r1 paper; qwen2.5-0.5B with GRPO, but oom
0212read deepseek v2 paper
0217read deepseek v3、math、janus paper
0227janus inference done 效果一般
0311janus pro 7B inference done; multimodal understanding done; text to image generation done
0424llama.cpp build and deploy
0606qwen2.5 0.5B + grpo on gsm8k done; full param finetuning
0613grpo inference to witness aha moment
0619start peft+vllm+grpo
0806grpo+peft+qwen2.5 3B+gsm8k done
0813start grpo with custom reward
0903grpo with custom reward done
0904start qwen2.5 7B+peft+trl
0910先不搞了