r/deeplearning • • Oct 29 '26

I trained LLaMa from scratch

I trained the LLaMA model from scratch. Implemented RoPE, grouped-query attention, RMSNorm, SwiGLU, and KV cache with batched inference.Used Umar Jamil's great video on LLaMA for learning. Used three datasets for training: 1. tiny-shakespeare (character-level), to check that everything was working fine; 2. TinyStories-v2, a 41M-parameter model; 3. FineWeb, a 125M-parameter model trained on 5.27B tokens on 2x A5000 GPUs for 11 hours.

From few time I am also learning and implementing RL algorithms. I think the next project will be an RLHF one. But I have to look at what model I can fit on my GPU.

41 Upvotes

9 comments sorted by

3

u/_pragmatic_machine Oct 29 '26

This is awesome! How long did it take from start to finish?

3

u/Clouded_Leopard17 Oct 30 '26

It took me around 4-5 days. I have already implemented a transformer model from scratch, so it was relatively quick.

6

u/Objective-Pop-7707 Oct 29 '26

If memory is the constraint for the RLHF step, I'd try DPO before PPO: PPO keeps four models around (policy, reference, reward, value), while DPO only needs the policy plus a frozen reference whose log-probs you can precompute once, and it also skips the reward-model training the other comment mentioned. On 2x A5000 that should leave room for full fine-tuning of a ~1B model with gradient checkpointing, or a 3B-class model with LoRA. I haven't run RLHF at that size myself, so take the exact limits as a rough estimate.

5

u/OkCampaign8400 Oct 29 '26

Umar Jamil is the Last Boss Video /Article before being self independent on training from scratch .
Congrats on such great endeavours to implement such hard concepts.

1

u/keixxxxxx Oct 30 '26

Can you have a conversation? What kind of responses do you expect?

1

u/Clouded_Leopard17 Oct 30 '26

It is a very small model by today's standards, trained on only 5B tokens. It can give you fluent, grammatical, properly paragraphed text. But it can be factually wrong, drift off topic, and sometimes output garbage.

2

u/[deleted] Oct 29 '26

[removed] — view removed comment

2

u/OkCampaign8400 Oct 29 '26

also tinyStories . Thats also great dataset with just 2 million rows