r/deeplearning • • 14h ago

I trained a 326M language model from scratch on one 3060 Ti

i wanted to train a model from random weights on the card i already had. Lyra ended up at 326M params. it took about a week to get through 6.4B tokens on my 8 GB 3060 Ti, then i did a separate instruction-tuning run on about 78k examples.

my dumbest mistake was resuming from the best checkpoint. it only saved when validation improved, so a restart sent me back 20k steps. now i save the latest checkpoint separately and resume from that. i wrote up that bug and the others in the architecture walkthrough.

Lyra itself is still kinda dumb. it can answer a simple question and then make up a date. i built it to learn the whole pipeline and might keep tinkering. the data prep and trainer are open source (Apache 2.0), so you can retrain it. both checkpoints are open weights under CC BY-NC 4.0 for noncommercial use.

base weights · instruct weights · training code on GitHub · architecture walkthrough

29 Upvotes

27 comments sorted by

8

u/user221272 14h ago

CC BY-NC 4.0 for noncommercial use

Argh... I really wanted to use it for commercial purposes!

5

u/luka0x12 14h ago

lol lyra would probably make up your refund policy.

the trainer is Apache 2.0 though. you can use it to train your own model with data you’re allowed to use commercially.

1

u/CraveCuffd 2h ago

yeah the nc clause always kills the fun when you have actual plans for it

1

u/MidnightTempts 57m ago

lol same, commercial or not i just wanna mess around with the weights too

-1

u/SnaggyPeach_ 11h ago

haha what kind of shady commercial stuff were you planning with it anyway

4

u/user221272 11h ago

It was sarcasm, because OP put a non-commercial license on an unusable model.

But given OP's answer, their soul is too pure to tell them.

5

u/shamen_uk 10h ago

It's likely that OP used data that was CC BY-NC 4.0 and is forced to follow that licensing.

Which kinda makes this comment seem a little dickish

2

u/luka0x12 8h ago

yeah, DailyDialog was in the instruct mix and has noncommercial terms. that’s why i went with CC BY-NC for both sets of weights. appreciate you pointing that out.

2

u/Full-World8839 10h ago

Awesome! I did a little nano! Best thing ever!

3

u/luka0x12 8h ago

hell yeah! what did you train yours on?

1

u/Full-World8839 6h ago

I downloaded fine-web edu. And a little fine tune!

1

u/Kermit-the-Frog_ 12h ago

I'm not super knowledgeable about how deep learning works more broadly or what is being done today regarding research of it, I only use it for scientific research, but I had a thought in case anyone would be able to answer it:

If you're able to train a model with this number of parameters, but wanted to easily scale up to a larger model, is there a way you could take this smaller trained model and scale it up to a larger model with functional equivalence, and then fine tune that model to find deeper minima? As in you could progressively add complexity with each step requiring less adjustment, hypothetically being easier on training time for a home device.

2

u/luka0x12 9h ago

yeah, Net2Net is pretty close to what you’re describing. for Lyra i’d try widening the feed-forward layers first. you can duplicate a SwiGLU channel and split its outgoing weights across the original and the copy. together they give the same output at first. once you’ve checked that, you can add a little noise so the copies learn different things and keep pretraining.

i’d measure total GPU hours to reach the same validation loss as a from-scratch run at the larger size, including time spent training the small one. the larger stage still has to fit in VRAM.

Net2Net paper

1

u/JazzlikeEggy 9h ago

Maybe coming back to Knowledge Distillation was completing the whole circle😭✌️

1

u/Kermit-the-Frog_ 9h ago

I'm referring to increasing the efficiency of creating a large model from the ground up, not condensing a large model into a small one. But maybe knowledge distillation could be done after that process to save the space used by fine tuning an expanded model rather than training the large model from the ground up.

1

u/balanceIn_all_things 12h ago

Cool project

1

u/luka0x12 8h ago

thanks! getting it to fit on that 3060 Ti taught me a ton.

1

u/balanceIn_all_things 8h ago

Are you a student/new grad or a researcher?

2

u/luka0x12 8h ago

i’m still in school. Lyra was a side project to teach myself how to train a model from scratch.

1

u/MEFISTUZ 5h ago

he is 14 year old..

1

u/Cautious-Act-4487 11h ago

Wait how did you even fit a 326M pretrain into 8 GB VRAM at a decent speed? AdamW states in fp32 alone eat like five gigs so there's barely anything left for batch and context - did you run a tiny microbatch with gradient accumulation and short context or did you hook up 8-bit Adam?

1

u/luka0x12 8h ago

yeah, small microbatches and accumulation. i used PyTorch’s fused AdamW with fp32 weights and bf16 autocast. the two Adam moment buffers are about 2.6 GB by themselves. add the fp32 weights and grads and you’re at about 5.2 GB before activations and temporary buffers.

i ran 4 sequences of 1,024 tokens at a time and accumulated 8 microbatches per update (32,768 tokens). activation checkpointing on every layer kept it inside 8 GB. the run averaged about 10k tokens/sec.

1

u/Born_Concentrate_771 9h ago

How long did it take you to train? Isnt training even just a gramatically correct LLM with a consumer GPU impossible?

1

u/luka0x12 8h ago

pretraining took about 178 hours on the 3060 Ti for 6.4B tokens, then another 2-3 hours for instruction tuning. it can write grammatical sentences at 326m. getting an answer that actually checks out is where this one struggles.

1

u/kakhaev 1h ago

data?