Hacker News

Hacker News

Show HN: A language model that lives in a boot sector (github.com)
103 points by kerlenton •                         
All the ideas came from the boot sector demo scene where people had been writing chess and BASIC games in 512 bytes, even a C compiler. I wondered what one can do using a neural network instead of a program and generating boot logs for non-existent hardware was something fun to try.

Entire inference engine is 510 bytes of MBR, weights, vocab, and strings reside in the sectors following MBR. Small char-level neural network was trained on dmesg generated by machine, so machine produces Linux boot messages infinitely.

train.py performs precisely the same integer arithmetic operations as the asm code does and thus produces an output identical character-by-character to the one produced by QEMU. The difference analysis revealed my favorite bug. The characters at the beginning matched those generated by the simulator, but then the output diverged. I retrieved the hidden layer via QEMU’s debug port and compared the neurons' values with those of the simulator, one neuron at a time. Only the value of the first neuron was correct. The activation involves idiv, and idiv stores its remainder in edx. The pointer to the biases table was stored in edx, which resulted in the first neuron being biased correctly and the following ones using garbage. Now the bias' address is determined from the loop counter, and no pointers have to survive the division. Another bug I found simply by looking at the code before I did my first run-through: the BIOS print routine zeros out bx, but bx contains the predicted character number. This explains the push and pop of bx surrounding the print.

sectorllm is the most similar to my project, as it runs an actual 5-layer llama2 with attention mechanism in just 1.2K of assembly code. It is the trade-off in the opposite direction, as my engine needs to fit into one sector and therefore my network has just one hidden layer of int8 operations for dreaming the dmesg.

aDyslecticCrow •                         
This is the kind of silly engineering that makes me appreciate humans.

I need reminders sometimes that the world is filled with humans doing wierd things to share with one another.

Not everything is about economic value or practicality. Making silly shit can be the goal.

andai •                         
This principle applied to YouTube:

https://news.ycombinator.com/item?id=50319510

It very much reminded me of what the web was like 15 years ago. Just people sharing cool stuff with each other. I'm glad we still have that here.

kerlenton •                         
Thanks very much, it really cheered me up. Yes, I believe that there are things that are done for fun and nothing else. I am sure that most people who delve into software engineering have that urge occasionally.
andai •                         
Delightful. Would love to read more about how you made it, or how you learned to do this kind of thing.
kerlenton •                         
Thanks! Seriously, it is quite difficult for me to recommend the way that would lead you to this. I believe that you should be interested in it and have the motivation to dig deep into it. It is a long process that requires patience and persistence.

The surrounding also plays its role here, even greater than one might think at first. If the people around you create such things, sooner or later, you will want to do it as well, and you only need to channel this need in the right way. For instance, my team lead at work takes time to reverse engineer electric cars. It is still wizardry to me, but one thing that is for sure is that it motivates me to do this type of stuff.

contingencies •                         
Sounds like a fun place to work!