News for hackers. Stuff that matters.
Re:Microgpt by janis1234 on Saturday February 28, 2026 @10:23PM (#47203344)
I found reading Linux source more useful than learning about xv6 because I run Linux and reading through source felt immediately useful. I.e, tracing exactly how a real process I work with everyday gets created.

Can you explain this O(n2) vs O(n) significance better?

Re:Microgpt by Paddyz on Saturday February 28, 2026 @10:26PM (#47203369)
Sure - so without KV cache, every time the model generates a new token it has to recompute attention over the entire sequence from scratch. Token 1 looks at token 1. Token 2 looks at tokens 1,2. Token 3 looks at 1,2,3. That's 1+2+3+...+n = O(n^2) total work to generate n tokens.

With KV cache you store the key/value vectors from previous tokens, so when generating token n you only compute the new token's query against the cached keys. Each step is O(n) instead of recomputing everything, and total work across all steps drops to O(n^2) in theory but with way better constants because you're not redoing matrix multiplies you already did.

The thing that clicked for me reading the C code was seeing exactly where those cached vectors get stored in memory and how the pointer arithmetic works. In PyTorch it's just `past_key_values` getting passed around and you never think about it. In C you see the actual buffer layout and it becomes obvious why GPU memory is the bottleneck for long sequences.

Re:Microgpt by wasabi991011 on Saturday February 28, 2026 @11:13PM (#47203629)
I still don't quite get your insight. Maybe it would help me better if you could explain it while talking like a pirate?
Re:Microgpt by fc417fc802 on Saturday February 28, 2026 @11:29PM (#47203730)
It's weird because while the second comment felt like slop to me due to the reasoning pattern being expressed (not really sure how to describe it, it's like how an automaton that doesn't think might attempt to model a person thinking) skimming the account I don't immediately get the same vibe from the other comments.

Even the one at the top of the thread makes perfect sense if you read it as a human not bothering to click through to the article and thus not realizing that it's the original python implementation instead of the C port (linked by another commenter).

Perhaps I'm finally starting to fail as a turing test proctor.

Re:Microgpt by fc417fc802 on Saturday February 28, 2026 @11:13PM (#47203626)
> Each step is O(n) instead of recomputing everything, and total work across all steps drops to O(n^2)

In terms of computation isn't each step O(1) in the cached case, with the entire thing being O(n)? As opposed to the previous O(n) and O(n^2).

Re:Microgpt by ViktorRay on Saturday February 28, 2026 @11:14PM (#47203637)
But the code was written in Python not C?

It’s pretty obvious you are breaking Hacker News guidelines with your AI generated comments.