I Trained an LLM on 1.1M YouTube Videos — Transcript
Full transcript
- 0:00This is an LLM, and this is a YouTube
- 0:02video. And today we're going to train an
- 0:04LLM from scratch on 1.1 million YouTube
- 0:08video transcripts. You see, all of these
- 0:10LLMs are trained on the entire internet.
- 0:13Code, math, books, everything is in
- 0:15there. Your mom's lasagna recipes
- 0:17probably in there. And training them
- 0:18costs millions of dollars. But I've
- 0:20always wondered, what would happen if
- 0:22you trained an LLM on just YouTube
- 0:24videos and nothing else? Well, today
- 0:26we're going to find out. We're going to
- 0:27train three identical LLMs. One on 1.1
- 0:30million YouTube video transcripts,
- 0:32another one on all of Wikipedia, and
- 0:34then another one only trained on Stack
- 0:36Exchange. And after we train them, we're
- 0:38going to ask them questions, put them
- 0:40through science exams, test their
- 0:41capabilities with trust me bro
- 0:43benchmarks, and ultimately see if they
- 0:45make any sense at all. And my budget is
- 0:47$100. I have no idea if this is even
- 0:50possible, but there's only one way to
- 0:52find out. However, we have a few
- 0:55problems.
- 0:57Like how do I get this data? Like it's a
- 0:59lot of data. Like how am I getting 1.1
- 1:01million YouTube videos?
- 1:04AI companies have billions of dollars. I
- 1:07have $100. So I have to make my code
- 1:10mega fast. And currently it's it's not
- 1:13fast. Cool. Let's look at problem number
- 1:15one, getting the data. And as far as I
- 1:17see it, there's two options. Option A is
- 1:20downloading hundreds of thousands of
- 1:22YouTube videos, extracting their MP3
- 1:23files, and then using Whisper and a
- 1:25bunch of compute to transcribe
- 1:26everything they say into text. Option B
- 1:29is Well, someone already did that, so
- 1:31all I have to do really is to click
- 1:33download.
- 1:34I choose option B. And check it out. We
- 1:36have 1.1 million YouTube videos in a
- 1:38single txt file. It's kind of insane to
- 1:41be honest. We have kind of economy
- 1:42videos, daily blogs, chess videos,
- 1:45Arduino tutorials. We have a 1-hour
- 1:47lecture of discrete time dynamics. I
- 1:49don't know what that means, but we have
- 1:51everything you can imagine and even
- 1:52more. And before anyone comments, oh,
- 1:55Green Code is stealing people's work, he
- 1:57must be evil. First of all, chillax.
- 1:59Second of all, single YouTube video in
- 2:01this dataset was released under the
- 2:03Creative Commons license, which is
- 2:05really awesome. And this is all thanks
- 2:07to the Common Pile, which is an 8
- 2:10terabyte dataset of public domain and
- 2:12openly licensed text from where I got
- 2:14all these YouTube video transcripts. And
- 2:16actually, this is also where I got my
- 2:18Stack Overflow and Stack Exchange data,
- 2:21which is also open license. And if you
- 2:23don't know what Stack Overflow is, it's
- 2:24pretty much how everyone was able to
- 2:26code before AI. Anyway, I also decided
- 2:28to download the most recent Wikipedia
- 2:30dump, use Wiki Extractor to filter out
- 2:32all this junk, write a Python script to
- 2:34remove all these XML tags, and that's
- 2:36how I got all of Wikipedia in a single
- 2:38txt file. That took me a whole day to do
- 2:41for 5 seconds of this video. I love my
- 2:43life.
- 2:44Nice. Now we have all this data and my
- 2:46computer is barely alive, but that's it
- 2:48for problem number one. All we have to
- 2:49do now is make the code fast, make
- 2:52computer go brr. And currently, it's not
- 2:54fast. You see, this video is part of a
- 2:56series where I'm trying to build my own
- 2:58LLM from scratch. I'm calling it Anton,
- 3:01and my goal is to build Anton into a 1
- 3:03billion parameter model by the end of
- 3:05the series. So far, we have built and
- 3:07trained Anton only using NumPy, which is
- 3:09awesome to understand all the math
- 3:11behind training and building LLMs, but
- 3:13it also means that all the training
- 3:14happens on the CPU, which me no likey.
- 3:18So we got to make it faster. By the way,
- 3:20you might be wondering why I'm even
- 3:22doing this. Like what's the point of
- 3:23building my own LLM from scratch? Well,
- 3:25there's three reasons. One, because it's
- 3:27fun. Two, because ever since all of
- 3:28these AIs came out, I've always wondered
- 3:31how hard would it be to do this myself.
- 3:33And three, to raise money for charity.
- 3:35So far, you guys and some very cool
- 3:37sponsors have raised $20,000 for cancer
- 3:40research, which is just awesome. So if
- 3:42you like these videos, please consider
- 3:44donating. But first, we need computer to
- 3:46go brr. Let's do some quick maths. You
- 3:48see, 1.1 million YouTube video
- 3:50transcripts is about half a million
- 3:51hours of content, which is about 5
- 3:53billion tokens. With the NumPy code, we
- 3:56were training at about 500 tokens per
- 3:58second on the CPU. So 5 billion divided
- 4:01by 500 is about 10 million seconds,
- 4:04which is 4 months. And that's for Anton
- 4:06version one, which we trained in the
- 4:08last video. In this video, we're
- 4:09training Anton version two, which is
- 4:11about 80 times bigger. So with the
- 4:13current code, it would take like 20
- 4:15years. We need GPUs, which will make
- 4:18everything faster. And to use a GPU, we
- 4:21need to use PyTorch, which is one of the
- 4:23best deep learning libraries out there.
- 4:25So all I have to do now is convert my
- 4:27entire codebase from NumPy to PyTorch.
- 4:30Yay. This is easier than it sounds. The
- 4:32syntax is pretty similar. For example,
- 4:34this is a linear layer implemented in
- 4:36NumPy versus PyTorch. It's kind of the
- 4:38same. However, I have a few rules when
- 4:41using PyTorch. Rule number one, we're
- 4:43not using PyTorch pre-built layers.
- 4:45We're building our own. Rule number two,
- 4:47we're not using PyTorch pre-built
- 4:49optimizers. We're building our own. Rule
- 4:52number three, we're not using PyTorch
- 4:54flash attentions. We are building I I
- 4:56think you get the idea. We're building
- 4:57as much as possible from scratch cuz
- 4:59honestly doing optimizer equals
- 5:01torch.atom is mega boring. Like to
- 5:04replace the single line of code, I had
- 5:07to write 60 lines of my own code
- 5:09implementing Adam W from scratch. The
- 5:12one thing I'm letting PyTorch do is
- 5:14autograd because that means all the
- 5:16gradients are computed automatically. So
- 5:19instead of me having to rewrite all this
- 5:21math and manually calculate every single
- 5:23gradient, which is a pain in the ass,
- 5:25all I have to do is define the forward
- 5:27pass and PyTorch does the rest. So in
- 5:30just 300 lines of PyTorch and like a
- 5:33day, I was able to recreate pretty much
- 5:35everything we had done in NumPy. And
- 5:37just by using PyTorch and a really basic
- 5:40GPU, we should get about 10,000 tokens
- 5:43per second when training, which means
- 5:44we'll finish training the 5 billion
- 5:46YouTube tokens in about a week. So just
- 5:49by using PyTorch and a GPU, we've gone
- 5:52from 20 years to like a week. But that's
- 5:54not good enough. We can make this even
- 5:56faster and better because I want Anton
- 5:59to be the best YouTuber ever. I want him
- 6:01to be better than Mr. Beast. And for
- 6:03that, I got to mess around with his
- 6:05brain a little bit. I have to change its
- 6:07architecture. In Anton version one, we
- 6:09built something pretty similar to the
- 6:11original GPT architecture. But nowadays,
- 6:13this architecture is a bit unk. It's
- 6:15kind of like a bent-edge car. It's
- 6:17pretty and it works, but I want Anton to
- 6:19be giga brain. I want Anton to be a
- 6:22freaking Lamborghini. So let's replace
- 6:25some parts. For example, the classic
- 6:27cosine sine positional embeddings work,
- 6:29but the hottest new positional
- 6:31embeddings are rotary positional
- 6:33embeddings or rope. They work by taking
- 6:36into account relative distance between
- 6:37tokens rather than their absolute
- 6:39positions, and they generalize better to
- 6:41longer context sizes. And YouTube
- 6:43videos, I swear they keep getting
- 6:44longer, so handling longer context sizes
- 6:46is important. Cool, let's swap that.
- 6:48Let's also change the feed forward
- 6:50linear layer for something cooler. In
- 6:52the last few years, a ton of variants
- 6:53have been proposed. In Anton version
- 6:55one, I used FFN Relu, but now there's
- 6:57FFN Gelu, FFN Swish, FFN Glue by linear
- 7:01Gelu Swish Glue
- 7:03I don't even know how to pronounce these
- 7:05anymore. Anyway, the one that works the
- 7:06best for LLMs is Swi Glue, which is
- 7:08pretty much the same as FFN Relu, but
- 7:11uses gating and a more fancy activation
- 7:13function. You may ask, why does this
- 7:15work better? And to that, I respond by
- 7:17quoting the original paper's
- 7:19explanation. We offer no explanation as
- 7:21to why these architectures seem to work.
- 7:23We attribute their success as all else
- 7:25to the divine benevolence. Aka, they
- 7:28have zero freaking clue, but it works,
- 7:30so say no more. I also replaced layer
- 7:32norm with RMS norm, which is faster and
- 7:34uses less parameters cuz remember, every
- 7:36second we save is another couple of
- 7:38YouTube videos Anton could be watching.
- 7:40But by far, the hardest part of this
- 7:42whole project was to optimize multi-head
- 7:45attention. You see, multi-head attention
- 7:47is the communication phase of a GPT.
- 7:49It's what makes this whole thing work.
- 7:51It's like the motor of the car, but by
- 7:53default, it's also mega slow, and it has
- 7:55to compute all these super large
- 7:57matrices that completely crash our
- 7:59precious GPU memory. So we need flash
- 8:02attention, which optimizes the out
- 8:05of multi-head attention and makes GPU go
- 8:08Normally, this is one line of PyTorch,
- 8:10but I'm stupid and I decided that it
- 8:12would be a fantastic idea to spend two
- 8:14weeks learning how to design my own GPU
- 8:16kernels and writing 600 lines of code
- 8:18implementing Flash Attention from
- 8:20scratch. And I cannot tell you how hard
- 8:22this was. I had to learn Triton, profile
- 8:25GPU memory activations, learned about
- 8:27mixed precision training, and all in
- 8:29all, it's still slower than PyTorch, but
- 8:31it actually uses the same GPU memory as
- 8:34the PyTorch version, which is honestly
- 8:35the main thing. And after all of those
- 8:37optimizations and when using an A100
- 8:39GPU, we get 130 tokens a second, which
- 8:43means training will finish in about 8
- 8:45hours. And now look at Anton. He's fast.
- 8:47He's even more gigabrain and he's ready
- 8:49to be trained on 1.1 million YouTube
- 8:52videos. We got the data. We made
- 8:54computer go brr and now it's training
- 8:56time, baby. We're going to train three
- 8:58different Antons with the same
- 8:59architecture on YouTube videos,
- 9:01Wikipedia, and Stack Overflow. And then
- 9:03we're going to see which Anton is the
- 9:05best and if data even matters that much.
- 9:07While this trains, I want to show you
- 9:08how I was even able to train Anton on
- 9:11GPUs because normally it's very hard and
- 9:13very expensive. But luckily, for all my
- 9:15training runs, I use Modal who are
- 9:17sponsoring this episode and this whole
- 9:19series. They made my life so much easier
- 9:22and I could not have done it without
- 9:23them. So please go check them out
- 9:25because they deserve it. They already
- 9:26donated $15,000 to the charity
- 9:29fundraiser and they're the ones giving
- 9:31me $5,000 in compute credits so I can
- 9:34create the series in the first place.
- 9:36And Modal is so cool. They are a
- 9:38serverless AI platform. You can do
- 9:40training, inference, user sandboxes, and
- 9:42you only pay for what you use. So for
- 9:44example, when I was debugging Flash
- 9:46Attention, I would run my code on a GPU.
- 9:48It would crash 3 seconds later because
- 9:50I'm a bad programmer, but with Modal, I
- 9:52would only pay a few cents. On a
- 9:54traditional cloud provider, debugging
- 9:56this would have cost me a fortune
- 9:57because you pay for every second the
- 9:59server is up. And because I only paid
- 10:01for the seconds I used, I got to test my
- 10:03code on A100, which is a $20,000 GPU.
- 10:07And guess what? The models we're
- 10:09training right now will cost less than
- 10:11$30 each. And Motel gives you $30 of
- 10:14free credits every month just by signing
- 10:16up. So you can literally recreate one of
- 10:18these models for free just by signing up
- 10:20to Motel. The link is in the
- 10:22description. Plus Motel is an inference
- 10:24provider, so you can run the latest open
- 10:26weights model like DeepSeek and Kimi and
- 10:28plug them straight into tools like Codex
- 10:30or Open Code. They're super easy to use,
- 10:32really easy to scale, and they're the
- 10:34only compute provider that believed in
- 10:36this project. So seriously, thank you so
- 10:38much, Motel. And now, ladies and gents,
- 10:40let me introduce you to Anton version
- 10:42two. 230 million parameters, 1,024
- 10:45embedding dimension, 12 transformer
- 10:47blocks, 1,024 tokens of context.
- 10:49Training on 5 billion tokens of YouTube
- 10:51cost me around $27. Training on 5
- 10:54billion tokens of Stack Exchange and
- 10:55Stack Overflow cost me 29 and Wikipedia
- 10:5831 for a grand total of $90. Nice. Cool.
- 11:02Let's make Anton complete the sentence
- 11:04and let's see what it says.
- 11:05>> Hi. My name is Anton. I'm a PhD student
- 11:08at the University of Exeter in Scotland,
- 11:10where I specialize in computer science
- 11:12and technology.
- 11:14>> You know what? That's not too bad. Okay,
- 11:15Exeter is not in Scotland. It's actually
- 11:18on the complete other side of the UK,
- 11:20but that's okay. Let's check on
- 11:21Wikipedia, Anton.
- 11:22>> Hi. My name is Anton. It is an
- 11:24amalgamation of two old German names,
- 11:27Bünde and Her. The German Her refers to
- 11:31the former Her, a hill of oak forest
- 11:33near the town of Herhausen, which became
- 11:35famous as Her in English.
- 11:37>> Okay. This one is interesting. I don't
- 11:39know what to say to that, but it it's
- 11:41normal because it was trained on just
- 11:43Wikipedia. So all it knows is to write
- 11:45Wikipedia pages. All right, let's see
- 11:47Stack Overflow.
- 11:47>> Hi. My name is Anton. I just wanted to
- 11:50say thank you for the response. It was
- 11:52very well thought out and I am happy for
- 11:54all the help I can get.
- 11:56>> I mean, yeah, this one makes sense
- 11:57grammar-wise, but you can obviously tell
- 11:59that it's just been trained on Stack
- 12:00Overflow, which is a forum where people
- 12:02ask questions. Okay, wait, wait, wait.
- 12:04Let's ask YouTube Anton, should I like
- 12:06this video and subscribe to Green Code?
- 12:08>> If you have not yet subscribed to my
- 12:10channel, please do so.
- 12:11>> All I'm going to say to that
- 12:12>> is that the subscribe button is right
- 12:14there. However, this is obviously cute
- 12:16and really funny, but it left me
- 12:18wondering, what would happen if we
- 12:20trained a single Anton on all of these
- 12:22data combined? Well, that's exactly what
- 12:25I did, and I'm proud to announce Anton
- 12:272.1, the same architecture as before,
- 12:29but this time trained on 15 billion
- 12:31tokens. And I trained on YouTube,
- 12:33Wikipedia, Stack Overflow, but also on a
- 12:35bunch of open source books, science
- 12:37articles, and even the Creative Commons
- 12:39Common Crawl. And yeah, it did cost me
- 12:41$60, which is a bit over budget, but
- 12:43just count it as a bonus round, okay? I
- 12:45trained it on an H100 for 15 hours. And
- 12:48now that we have all these models, it's
- 12:50time for the Trust Me Bro Benchmarks.
- 12:53And the point of benchmarks is to
- 12:54evaluate our LLMs and run their
- 12:56performance. For example, we have the
- 12:58SciQ Benchmarks, which contains
- 13:00thousands of science exam questions, or
- 13:02the Social IQa, which tests for social
- 13:05common sense intelligence. But before we
- 13:07look at the results, if you were to
- 13:09start using these models yourself, you
- 13:11would realize pretty quickly that
- 13:12they're kind of dumb. For example, this
- 13:14is me asking GPT-2 and Anton 2.1, what
- 13:18is 2 + 2? Which yeah, it didn't go so
- 13:20well. But for a model below a billion
- 13:22parameters, this is kind of normal,
- 13:24especially if you spend less than $100
- 13:26training them. So how were they able to
- 13:28answer all of these questions? Well,
- 13:30instead of asking the model directly,
- 13:32what is the answer, I use the
- 13:33probability Anton predicts for each of
- 13:35the tokens of each option, and then I
- 13:37choose the option with the highest log
- 13:39likelihood. This is actually a really
- 13:41common practice when evaluating small
- 13:43models because again, they're they're
- 13:44kind of really dumb at this scale. But
- 13:46anyways, here are the results for the
- 13:48Trust Me Bro Benchmarks. And as you can
- 13:49see, Anton 2.1 beats all the previous
- 13:52models, which makes sense, right? It's
- 13:54trained on triple the data. For science
- 13:55questions, it beats YouTuber Anton by a
- 13:58lot. For example, question 22 of the
- 14:00SciQ Benchmarks.
- 14:02>> What happens when mammals raise their
- 14:03hair with tiny muscles in the skin? A,
- 14:05bleeding. B, balding. C, bruising. D,
- 14:09goosebumps.
- 14:10>> Well, all the Antons said goosebumps,
- 14:12which is the correct answer, but
- 14:13YouTuber Anton said A, bleeding. But on
- 14:16the other hand, with everyday speech
- 14:18benchmarks like swag, it actually
- 14:20outperforms Wikipedia and Stack
- 14:22Overflow. For example, in this question
- 14:24of common sense reasoning, only YouTuber
- 14:26Anton and Anton 2.1 got the correct
- 14:28answer. And here we clearly see how
- 14:31important the training data is because
- 14:33remember, all these models had the exact
- 14:35same architecture. The only difference
- 14:37was data. But what about comparing Anton
- 14:39to other GPT models? Well, as you can
- 14:41see here, for 60 bucks, Anton 2.1 is
- 14:44roughly at the GPT 2 small level, which
- 14:47was reportedly trained on 100 billion
- 14:49tokens. Granted, Anton is almost double
- 14:52the size, but for $60, only being
- 14:54trained on 15 billion tokens and trained
- 14:56on only open licensed data unlike GPT 2,
- 14:59I would say that's pretty good. Now, if
- 15:01you compare it to GPT 3 small, it's a
- 15:03different story. But Anton actually
- 15:04beats GPT 3 in some science benchmarks,
- 15:07which makes me really proud of my son.
- 15:08And guys, we did it. We trained Anton on
- 15:101.1 million YouTube videos on Wikipedia
- 15:13and Stack Overflow. Honestly, I think we
- 15:15got some pretty fun results at this
- 15:17scale. But what happens if instead of
- 15:19spending $100 on pre-training, I use the
- 15:21$5,000 in compute credits that model has
- 15:24given me? What if we teach Anton to
- 15:26actually answer our questions? What if
- 15:28we train Anton on multiple GPUs instead
- 15:30of one? And what if we make Anton a 1
- 15:33billion parameter model? Well, that's
- 15:35exactly what we're going to do in the
- 15:36next episode. And if you like these
- 15:38videos, please consider donating to the
- 15:40fundraiser. Oh yeah, and if we reach
- 15:42$30,000, I'll upload all the code and
- 15:44all the models to Hugging Face. And if
- 15:46you donate $50 or more, I'll put your
- 15:48name at the end of the video. And if you
- 15:50don't have the means to donate, please
- 15:51go check out model.com. Without them, I
- 15:54would not be making this video. Thank
- 15:55you so much to everyone who has already
- 15:58donated. Thank you DR for almost
- 16:00donating €1,000. You are awesome. Thank
- 16:03you Mareli as well for 200. Thank you to
- 16:05this anonymous goat. Thank you Michael.
- 16:08Thank you Dennis. Thank you Armando.
- 16:10Thank you Alex. Thank you Samuel. Thank
- 16:12you Soham. Thank you Ryan and thank you
- 16:14to everyone else who donated. Thank you
- 16:15for watching and I'll see you in the
- 16:17next one.
About this transcript
This page contains the full transcript of I Trained an LLM on 1.1M YouTube Videos by Green Code, generated from the public captions YouTube serves with the video. The transcript has 3,202 words across 466 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.