Jay Mody

jaykmody.com · Personal blog · on HN since 2023

Jay Mody's blog explaining machine learning internals, including GPT in 60 lines of NumPy, attention, and speculative sampling.

What HN saysCommenters recommend the GPT-from-scratch post as a clear, code-based explanation, and one used it to build a Rust version.
17HN people shared it
13linked it in comments
4stories submitted
7story points
10 months agolast shared
2023people per year2026

Most-shared posts

  1. 1
    GPT in 60 Lines of NumPy
    11 people · 3 points · first shared 2023 · discussion on HN
  2. 2
    Speculative Sampling
    2 people · 2 points · first shared 2023 · discussion on HN
  3. 3
  4. 4
    Stable softmax
    1 people · first shared 2024
  5. 5
    Homepage
    1 people · first shared 2026

What HN people wrote when they linked it

enricozb · 2025-09-15
I did this [0] (gpt in rust) with picogpt, following the great blog by jaykmody [1]. [0]: https://github.com/enricozb/picogpt-rust [1]: https://jaykmody.com/blog/gpt-from-scratch/
eclectic29 · 2024-08-31
This is excellent. Thanks for sharing. It's always good to go back to the fundamentals. There's another resource that is also quite good: https://jaykmody.com/blog/gpt-from-scratch/
andy99 · 2024-05-19
And if you want to understand I'd recommend this post (gpt2 in 60 lines of numpy) and the post on attention it links to. The concepts are mostly identical to llama, just with a few minor architectural tweaks. https://jaykmody.com/blog/gpt-from-scratch/
swyx · 2024-03-11
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
version_five · 2023-07-28
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/
lhl · 2023-06-29
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…
larme · 2024-01-27
https://jaykmody.com/blog/gpt-from-scratch/ for a gpt2 inference engine in numpy then https://www.dipkumar.dev/becoming-the-unbeatable/posts/gpt-kvcache/ for adding a kv cache implementation
alexmolas · 2024-01-04
> 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/
Scene_Cast2 · 2023-08-25
techbruv · 2023-06-23
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
jaymody · 2023-04-30
I wrote an article that attempts to explain attention in a more intuitive manner, without any PyTorch or other deep learning specific context: https://jaykmody.com/blog/attention-intuition/
benob · 2023-05-26
[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.t… [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

Keyboard shortcuts

/Search
j kNext / previous blog
EnterOpen selected blog
vVisit the blog site
fFollow / unfollow
lSwitch grid / list view
dSwitch dark mode
g hHome
g pTop posts
g tTopics
g fFollowing
g lLiked
g yHistory
g qFAQ
EscBack / close