Close
0%
0%

KernelGPT

Training an AI in kernel space

Similar projects worth following
KernelGPT is a from-scratch implementation of a GPT (Generative Pre-trained Transformer) written in pure C, running directly on bare metal x86 hardware.

It boots a heavily modified version of my custom Operating System MooseOS solely to train a neural network. No Linux, no Python, no PyTorch, no Standard Library (libc) — just raw pointers, math, and attention mechanisms.

It is heavily inspired off Andrej Karpathy's MicroGPT.

While I haven’t tested KernelGPT on real hardware yet (my 2009 HP PC is currently out of commission due to dried-out thermal paste), MooseOS runs fine on a real PC, and KernelGPT runs perfectly in QEMU. This makes it highly likely that it will work on actual hardware, and I’m planning to test it once my machine is back in action.

KernelGPT takes MooseOS's source code, and removes unneeded functions like filesystems, ATA support, GUI, etc, leaving only a mostly bare-bones kernel. KernelGPT sits directly inside the kernel.

Caption: A (slightly oversimplified) description of MooseOS vs KernelGPT architecture.

Inspiration for the LLM design choice was taken from Andrej Karpathy's MicroGPT. This meant implementation for a GPT-2 style LLM, while keeping Karpathy's choice of switching Layernorm for RMSNorm and GELU for ReLU. To merge the AI into MooseOS, KernelGPT uses an arena allocator for easy memory allocation, and initialises the FPU for floating-point arithmetic.

MicroGPT’s `names.txt` was converted into a C header before runtime so KernelGPT can access the vocabulary directly in memory, avoiding any filesystem dependencies.”

Extra Links/Credits
I built MooseOS. You can view

the repo

the Hackaday article about it

Andrej Karpathy built MicroGPT. You can find his Github Gist here

MooseOS.iso

The modified KernelGPT variant of MooseOS

octet-stream - 8.08 MB - 02/16/2026 at 08:38

Download

  • Building the Project

    Ethan Zhang02/16/2026 at 09:10 0 comments

    Why did I build this project?

    I've always been into low-level development. Recently, I've been experimenting with AI, specifically creating models that can run on edge devices. I saw Andrej Karpathy's MicroGPT, and I was inspired by its "lack of libraries" - it seemed to conclude the entire AI industry in only 243 lines of code. I wanted to see what would happen if I took this further: demonstrating an entire AI stack, with every single line of code written by me: strictly no dependencies.

    The Building Progress

    KernelGPT started by taking the MooseOS source and removing unneeded functionality — filesystem drivers, ATA support, GUI, etc. The goal was a minimal, mostly barebones kernel to host the LLM. 

    Before I started, I converted MicroGPT’s names.txt file into a C header so KernelGPT could access the character-level vocabulary entirely in memory. While it felt a bit "hardcoded" and unreadable, it ended up working so well that I ended up accepting it as a design choice.


    Inspired by Andrej Karpathy’s MicroGPT, I implemented a GPT-2 style LLM directly in kernel space. Key GPT-2 modifications from MicroGPT were retained: RMSNorm instead of LayerNorm, and ReLU instead of GELU. All tensors are allocated from a pre-reserved arena for simple memory management. The only non-AI addition was the FPU, which was initialized in kernel mode to allow floating-point arithmetic .


    The overall coding experience was very smooth. The only minor mishap I experienced was when I spent a full hour chasing a General Protection Fault — only to realize it was because I forgot to disable interrupts, and the PIT timer was still firing even though I had removed the system clock! Funnily enough, all my debugging code pointed to an issue with the matrix multiplication; it was only when I decided to check which files I had removed when I noticed the real cause of the issue.

    Overall, this is one of the projects that really made me feel proud of myself. Personally, I think you shouldn't code for the money and fame. Instead, you should code for the sake of coding. The feeling of thinking "wait.. I'm 15 and I built the ENTIRE THING by myself?? Wow" is really unmatched; I haven't felt the feeling in any other subject.

    I hope you enjoyed the read, and have a nice day!

View project log

  • 1
    Download the project
    git clone https://github.com/appleroll/kernelgpt.git

    While I have provided the ISO file for the KernelGPT here at Hackaday, I recommend using git as the repo is updated often, and you also have access to the README and other files.

  • 2
    Install QEMU

    This could be through the official website or your favourite package manager. The specific QEMU CLI tool used is called qemu-system-i386

  • 3
    Run through Make
    cd kernelgpt/
    make run

View all 3 instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates