Jay Mody's blog explaining machine learning internals, including GPT in 60 lines of NumPy, attention, and speculative sampling.
Commenters recommend the GPT-from-scratch post as a clear, code-based explanation, and one used it to build a Rust version.
Here are some high level answers:
"7B" refers to the number of parameters or weights for a model. For a specific model, the versions with more parameters take more compute power to train and perform better.
A foundational model is the part of a ML model that is "pretrained" on a massive data set (and usually is the bulk of the compute cost). This is usually considered the "raw" model after which it is fine-tuned for specific tasks (turned into a chatbot).
"8K length" refers to the Context Window length (in tokens). This is basically an LLM's short term memory - you can think of it as its attention span and what it can generate reasonable output for.
"1.5T tokens" refers to the size of the corpus of the training set.
In general Wikipedia (or I suppose ChatGPT 4/Bing Chat with Web Browsing) is a decent enough place to start reading/asking basic questions. I'd recommend starting here: https://en.wikipedia.org/wiki/Large_language_model and finding the related concepts.
For those going deeper, there are lot of general resources lists like https://github.com/Hannibal046/Awesome-LLM or https://github.com/Mooler0410/LLMsPracticalGuide or one I like, https://sebastianraschka.com/blog/2023/llm-reading-list.html (there are a bajillion of these and you'll find more once you get a grasp on the terms you want to surf for). Almost everything is published on arXiv, and most is fairly readable even as a layman.
For non-ML programmers looking to get up to speed, I feel like Karpathy's…
[1] is a good start, although if you want to train from scratch on CPU, you'll have to downscale as transformers need quite a bit of data before they learn to use position embeddings. For example try a single-layer RNN on Shakespeare texts [2] or a list of movie titles from IMDB [3]. You'll have to fill in the blanks because things have evolved quite a bit since those were used for language models, but you can find some tutorials [4] and examples [5].
[1] https://jaykmody.com/blog/gpt-from-scratch/
[2] https://github.com/demmojo/text-rnn/blob/master/datasets/shakespeare.txt
[3] https://datasets.imdbws.com/
[4] https://pytorch.org/tutorials/beginner/chatbot_tutorial.html
[5] https://github.com/pytorch/examples/tree/main/word_language_model
Some other good resources:
[0]: The original paper: https://arxiv.org/abs/1706.03762
[1]: Full walkthrough for building a GPT from Scratch: https://www.youtube.com/watch?v=kCc8FmEb1nY
[2]: A simple inference only implementation in just NumPy, that's only 60 lines: https://jaykmody.com/blog/gpt-from-scratch/
[3]: Some great visualizations and high-level explanations: http://jalammar.github.io/illustrated-transformer/
[4]: An implementation that is presented side-by-side with the original paper: https://nlp.seas.harvard.edu/2018/04/03/attention.html
oh this has code! great stuff. diffusion papers are famous for a lot of equations (https://twitter.com/cto_junior/status/1766518604395155830) but code is much more legible (and precise?) for the rest of us. all theory papers should come with reference impl code.
i'd love an extension of this for the diffusion transformer, which drives Sora and other videogen models. maybe combine this post with https://jaykmody.com/blog/gpt-from-scratch/ and make the "diffusion transformer from scratch" intro
> Uh oh! We’re getting NaNs! It seems our values are too high, and when being passed to the next encoder, they end up being too high and exploding! This is called gradient explosion.
As far as I understand this is wrong. You're not computing gradients at any point, so this is no gradient explosion. I believe the problem is with the implementation of softmax, here [0] you have an explanation of how to implement a numerically stable softmax.
[0]: https://jaykmody.com/blog/stable-softmax/
The more of these the better! I find when I'm learning something new I end up wanting to see a bunch of different versions of the same exposition until one sticks.
I also recommend this one for following along in code: https://jaykmody.com/blog/gpt-from-scratch/