i ran an experiment on a neural network i built from scratch, and learned why real ai code looks nothing like what i wrote.
my version treats every single number as its own python object. add two numbers, that's a new object. multiply two numbers, another one. it's great for learning because you can see everything.
then i counted. a tiny network (337 knobs) looking at just 100 data points created 64,200 objects for one pass. that took about a tenth of a second, for a network so small it would fit in a tweet.
so i rewrote the same network using tables of numbers (matrices) instead of single numbers. the maths is identical. i checked: both versions give the same answers, down to the 16th decimal place.
the difference is speed. one training step went from 374 milliseconds to 0.05. about 7,000x faster, with no new idea, just handing the computer a whole table at once instead of one number at a time.
that's the gap between code you can understand and code you can actually train. the language models i want to work on have billions of numbers, so this is the whole game.
next: teaching it to recognise handwritten digits, then running it on my mac's gpu to see when the gpu actually helps (i expect it to lose on small jobs, we'll see).
来源:rishabh · x.com