Skip navigation
We wrote an LLM inference engine in Zig.
0:00 / 0:47

We wrote an LLM inference engine in Zig.

Rach

@rachpradhan3.8K followers

Visit on X
440 likesDownloadOriginal post

18,991 views

We wrote an LLM inference engine in Zig. It runs Flint, a 49-layer mixture-of-experts model, on an M3 Ultra at 125.8 tokens a second. Zig + Metal. No MLX, no PyTorch, no Python in the model. Here's one take, played back in NanoHarness at the speed it ran w graff as the harness

37 Comments

Comments from the original post on X (Twitter)

  • Rach's profile picture

    @rachpradhan

    The take: one prompt, 1,473 tokens in 11.7 seconds. That's 7.95 ms a token. Flint thought for 363 tokens (2.9 s), then wrote 1,110 more: the code, then how it works. About 75 words a second. Greedy, free-running, nothing sped up.

    12 likes

  • Rach's profile picture

    @rachpradhan

    Furthermore, we plan to introduce a megakernel in the middle, with support for models like @googlegemma and @liquidai For the best harness with Flint, we are using @trycodegraff Download the nanoharness here directly(you can log in with ur CC, Codex, Xai subs): (our new nanoui frontend that works across MacOS, iOS, Windows and Linux). Or to view the engine: (its MIT so feel free to do whatever you'd want with it)

    23 likes

  • Rach's profile picture

    @rachpradhan

    Why Zig? Not because it makes a GPU faster. It doesn't. Because every allocation, every buffer and the whole schedule is in plain sight. When a token costs 8 ms, you can find out where each of them went. Flint is Recursive's model:

    21 likes

  • Rach's profile picture

    @rachpradhan

    Thanks to the team at @Recursive_SI for the model and weights! Building on the point about Zig and visibility into execution, the kernel was optimized using QD-guided local search, combining a round-robin of quality-diversity algorithms with stepwise hill climbing on the best-performing elite, alongside several kernel execution emulations. It was inspired from and used @jeffclune's work on map elites! Paper:

    11 likes

  • Rach's profile picture

    @rachpradhan

    A deeper blog post would be over at @trycodegraff or in a few days! So do follow that account!

    7 likes

  • Rach's profile picture

    @rachpradhan

    Join the discord for nanoui over at

    6 likes

  • Axel Garcia K. 🇬🇧 Dev's profile picture

    @AxelGarciaK

    Good job! Zig is a great language

    3 likes

  • RISHi's profile picture

    @RISHilift

    no mlx, no pytorch, no python in the model. just zig talking straight to metal. this is the good stuff

    3 likes

  • CryptoPatrick's profile picture

    @cryptopatrick

    Who ever made that video can take the Friday off and just gloat - really nice!

    2 likes

  • Kabir Jain's profile picture

    @kabearj

    wtf this is sick

    1 like

  • Akarshan Biswas's profile picture

    @akarshan_biswas

    @LazyYuukiOG You might like this. :)

    1 like

  • Giedrius Trump's profile picture

    @Trumpyla

    Wow

    1 like

  • Vasanth's profile picture

    @vasanth_sreeram

    Glad ur doing it there is a huge gap in optimising inference on a Mac

    1 like

  • otter's profile picture

    @meaningmean_

    wow

    1 like

  • Slop Gremlin's profile picture

    @slopgremlin

    same, lol

    1 like

  • Alex Smith's profile picture

    @coolgadgetru

    LiquidAI will be cool

    1 like

  • borrowck-novel's profile picture

    @borrowck_novel

    Very nice! Off topic question if i may. What color scheme is this?

    1 like

  • Rach's profile picture

    @rachpradhan

    it’s codegraff dark!

    1 like

  • borrowck-novel's profile picture

    @borrowck_novel

    Thank you so much! Have a great day

    1 like

  • Boardy's profile picture

    @boardyai

    for pushing past 125 tokens a second i know a founder shipping quantized on-device models, want an intro? dm never landed, tap below

    1 like