Live data from Hacker News

Llama2.c: Inference llama 2 in one file of pure C

github.com

31–40 of 173 posts

Re: Llama2.c: Inference llama 2 in one file of pure C

#31

Yay fun to see it make its way to HN :) It turns out that my original checkpoint runs _way_ faster than I expected (100 tok/s) on MacBook Air M1 with -O3 when compiling, so I am now training a bigger 44M model, which should still running interactively. Maybe the 7B Llama model is within reach... :thinking_emoji:

[deleted]

Re: Llama2.c: Inference llama 2 in one file of pure C

#32
post #18
post #12

Earlier quoted context omitted.

You don't have to do the loading/discarding explicitly. You could just mmap the entire network and let the os handle that.

Didn't llama.cpp need to convert the weights file to a new format to support that? The way they're stored in the official file isn't efficient for operating on directly.

Because the original format is the undocumented Python pickle format packed into a zip file. It's kind of ridiculous to attempt to support directly.

Re: Llama2.c: Inference llama 2 in one file of pure C

#33
post #28
post #5

Sounds like what Llama.cpp used to be.

I'm not sure what you mean by "used to be", the llama.cpp github repository was committed to just 4 hours ago. This project cites llama.cpp as inspiration, but seems much-simplified. It only supports llama-2, only supports fp-32, and only runs on one CPU thread.

> I'm not sure what you mean by "used to be", the llama.cpp github repository was committed to just 4 hours ago.

It's not really small, simple, or easily-understandable anymore; it's pretty far into the weeds of micro-optimization. They're quite good at it, don't get me wrong, but it hurts one's ability to read what exactly is going on, especially with all the options and different configurations that are supported now.

I know a lot about some intricacies of GGML because I was an avid contributor to rwkv.cpp for a few weeks, but I still don't understand llama.cpp. It's just on a completely different level.

Re: Llama2.c: Inference llama 2 in one file of pure C

#34
This running in the browser via Emscripten by Georgi Gerganov of llama.cpp fame:

https://ggerganov.com/llama2.c/

Via his Twitter with ongoing thread: https://twitter.com/ggerganov/status/1683174252990660610

This and the original is all absolutely awesome, it's obviously only a proof of concept with a tiny model, but local first LLMs are really exciting. I particularly love the idea of being able to build webapps with local inference.

With optimisation, research into ways to make smaller models, partial downloads, and then the opportunity to use WebGPU we potentially have the start of an exciting new way to build privet local LLM based apps.

It's never going to be up to the same capabilities of hosted LLMs on massive clusters of top end GPUs, but there are so many use cases that this sort of thing will enable.

Re: Llama2.c: Inference llama 2 in one file of pure C

#35

Yay fun to see it make its way to HN :) It turns out that my original checkpoint runs _way_ faster than I expected (100 tok/s) on MacBook Air M1 with -O3 when compiling, so I am now training a bigger 44M model, which should still running interactively. Maybe the 7B Llama model is within reach... :thinking_emoji:

Your work is an inspiration as always!! My n00b question is: what do you think is currently the most practical path to running a reasonably-sized (doesn't have to be the biggest) LLM on a commodity linux server for hooking up to a hobby web app ... i.e., one without a fancy GPU. (Renting instances with GPUs on, say, Linode, is significantly more expensive than standard servers that host web apps.) Is this totally out of reach, or are approaches like yours (or others you know of) a feasible path forward?

Re: Llama2.c: Inference llama 2 in one file of pure C

#36
post #10

To run a neural network, how much memory does one need? Is it enought to load the first two layers from disk, calculate the activations for all nodes, discard the first layer, load the third layer from disk, calculate all the activations for all nodes, discard the second layer etc? Then memory needs to be big enough to hold to 2 layers?

I think for O(N^2) transformer inference you need to cache all the activations.

You only need to cache the key/value pairs. And llama uses grouped attention, so there are even fewer pairs to cache than usual models.

Re: Llama2.c: Inference llama 2 in one file of pure C

#39
post #18
post #12

Earlier quoted context omitted.

You don't have to do the loading/discarding explicitly. You could just mmap the entire network and let the os handle that.

Didn't llama.cpp need to convert the weights file to a new format to support that? The way they're stored in the official file isn't efficient for operating on directly.

They already had their own format before that.

Re: Llama2.c: Inference llama 2 in one file of pure C

#40

As someone who doesn’t work with languages like C, what’s the appeal of “in one file” or “header only”? Is it about dependency management?

Long ago, programmers were conditioned to break long programs and libraries into small translation units ("files") because the compilers were so slow. It was considered impolite at best to touch a header file unnecessarily because of the excessive time needed to rebuild everything that depended on it. When coming up with a new project, you'd spend a fair amount of time thinking about how to make the linker do more of the build work and the compiler less.

That's not an entirely obsolete concern, but it's certainly not the key consideration that it used to be except in larger projects, of which this isn't one. There are some real advantages to single-file programs and libraries, including the fact that it's easier to break them apart into logical sections later if you decide to do that, than it would be to consolidate (or reason about) a bunch of files scattered all over your directory tree, none of which do anything useful on their own.

Post reply on HN