Avinab Neogy (@avinab_neogy) header
Avinab Neogy (@avinab_neogy) profile picture

how far can a 6gb rtx 3060 go? pytorch + triton inference. prev @bitspilaniindia

india
Joined March 2023
Photo by Avinab Neogy (@avinab_neogy)Photo by Avinab Neogy (@avinab_neogy)Photo by Avinab Neogy (@avinab_neogy)Photo by Avinab Neogy (@avinab_neogy)Photo by Avinab Neogy (@avinab_neogy)Photo by Avinab Neogy (@avinab_neogy)Photo by Avinab Neogy (@avinab_neogy)Photo by Avinab Neogy (@avinab_neogy)Photo by Avinab Neogy (@avinab_neogy)Photo by Avinab Neogy (@avinab_neogy)
Why do we fall? So we can learn to pick ourselves up. Batman Begin
3,053
156,261
8,828
648,706
38,369,978
Avinab Neogy retweeted
I don’t think we appreciate how hard it is to die a billionaire and have basically ZERO controversies or enemies. Not sure we’ll see it again, tbh.
500
1,444
126
27,713
1,581,174
Avinab Neogy retweeted
Human intelligence is probably the most underrated and underutilized resource in the world
148
102
25
1,210
55,542
zero nn.module layers. just raw state_dict tensors and gpu math. wired up all 12 blocks of gpt2 from scratch on my 6gb rtx 3060. it streams real english at 75.5 tok/s and matches huggingface token for token.
1
2
104
back after a short sick break. days 1 to 9 finally came together into a working inference loop. this is the naive baseline without a kv cache. day 10 of gpt2 from scratch. phase 2 done. next up is kv caching and custom triton kernels.
22
Avinab Neogy retweeted
impossible to compete with someone having fun and recursively self improving
38
127
8
1,138
28,708
Avinab Neogy retweeted
How to become a polymath in an age of infinite supply
Don’t wait for permission. Don’t wait for readiness. The gatekeepers are busy fighting over who has the key to an empty building. Keep an eye on what’s decaying. Honor what’s eternal. Build something new. Do it daily. Do it diligently. Do it for yourself.
1
40
1
472
21,468
attention gets all the hype in transformers, but inside every gpt2 block it is only 33% of the weights. the other 67% sits in a simple two layer mlp that blows 768 dims up to 3072 and projects right back down.
1
3
63
during single token decode you haul every weight from vram once per token. that means two thirds of your memory bandwidth per block goes straight into the mlp. day 9 of gpt2 from scratch. last piece audited, full forward pass video tomorrow.
1
19
Avinab Neogy retweeted
If you are not recursively self improving, you are ngmi.
14
23
3
267
9,830
classic bug when writing attention from scratch: masking future tokens with 0 instead of negative infinity. softmax turns 0 into e^0 = 1, so your model still peeks at future words. fill the upper triangle with -inf first so softmax zeros them out cleanly.
1
3
86
this is why prefill needs a causal mask, while single token decode with a kv cache does not. during decode there are no future keys in the cache to hide. day 8 of gpt2 from scratch. causal masking done, wiring the full forward pass next.
1
17
pass the number 12 into a naive fp16 softmax and your attention layer breaks into nan. fp16 caps out at 65,504, and e^12 is over 162,000. so e^12 becomes inf, and inf divided by inf gives you nan.
1
2
33
you fix it by subtracting the row max from every score before taking the exp. the math stays identical, every number becomes 0 or negative, and nothing can overflow. day 7 of gpt2 from scratch. safe softmax working by hand, next up is causal masking.
22
Avinab Neogy retweeted
Goals make you fragile. If you tie your identity to a finish line, every detour feels like failure. Loops make you resilient. When your identity is the iteration itself, a bad week is just data for the next lap.
41
173
23
1,201
223,615
Avinab Neogy retweeted
I just realized that the 20th century was perhaps an anomaly in how much it rewarded being book smart over street smart. For 80 years, the recipe for success was to study hard, get a degree, specialize and follow the rules. AI is about to commoditize much of what made that recipe work. I think we’re entering an era that will disproportionately reward the curious, the resourceful, the self-taught and those who thrive in uncertainty. When intelligence becomes abundant, agency becomes scarce. That’s probably the most important thing we can cultivate in our kids now.
104
408
41
3,762
113,970
transformer diagrams always draw q, k, and v as three separate layers. gpt2 doesn't actually do that. it packs all three into one weight matrix of shape [768, 2304]. one matrix multiply instead of three, then you just slice the output into three chunks.
1
2
86
doing one bigger matmul instead of three small ones means the gpu only reads the input activations from memory once, and you cut kernel launch overhead by 3x. day 6 of gpt2 from scratch. building out the attention block without nn.linear.
20
Avinab Neogy retweeted
i realized this in 2024 and it changed my life
part of your job as a swe now is to scroll twitter
25
120
9
3,543
78,169