Live data from Hacker News

Llama 3 implemented in pure NumPy

docs.likejazz.com

41–50 of 54 posts

Re: Llama 3 implemented in pure NumPy

#41
post #25

It's also worth mentioning that the original implementation by Meta is only 300 lines of very readable code [1]. [1]: https://github.com/meta-llama/llama3/blob/main/llama/model.p...

On line 59, there is a less-than-or-equals comparison between 0 and 1. Curious https://github.com/meta-llama/llama3/blob/main/llama/model.p...

I am a reasonably competent python coder, yet when I see stuff like this I regard it with the same suspicion as a switch in the "more magic" position.

https://www.catb.org/jargon/html/magic-story.html

Re: Llama 3 implemented in pure NumPy

#42

Earlier quoted context omitted.

On line 59, there is a less-than-or-equals comparison between 0 and 1. Curious https://github.com/meta-llama/llama3/blob/main/llama/model.p...

What's the operator precedence in python? Is it `assert(0 <= (1 < ndim))` or `assert((0 <= 1) < ndim)`, or something even stranger like `assert(0 <= 1) < ndim`?

Python actually does something pretty neat: it chains comparisons so that `x In linked code we can be confident that `0 <= 1`, so only `1 < ndim` should matter. In fact I'd expect peephole optimization to remove most of the code for `0 <= 1`

Re: Llama 3 implemented in pure NumPy

#43
post #25

It's also worth mentioning that the original implementation by Meta is only 300 lines of very readable code [1]. [1]: https://github.com/meta-llama/llama3/blob/main/llama/model.p...

Why is max_seq_len set to 2048 [1] when the model card says the context size is 8k [2]?

[1] https://github.com/meta-llama/llama3/blob/14aab0428d3ec3a959...

[2] https://github.com/meta-llama/llama3/blob/14aab0428d3ec3a959...

Re: Llama 3 implemented in pure NumPy

#45
post #43
post #25

It's also worth mentioning that the original implementation by Meta is only 300 lines of very readable code [1]. [1]: https://github.com/meta-llama/llama3/blob/main/llama/model.p...

Why is max_seq_len set to 2048 [1] when the model card says the context size is 8k [2]? [1] https://github.com/meta-llama/llama3/blob/14aab0428d3ec3a959... [2] https://github.com/meta-llama/llama3/blob/14aab0428d3ec3a959...

That's just the default. You can set max_seq_len to 8k. From the readme [0]:

> All models support sequence length up to 8192 tokens, but we pre-allocate the cache according to max_seq_len and max_batch_size values. So set those according to your hardware.

[0] https://github.com/meta-llama/llama3/tree/14aab0428d3ec3a959...

Re: Llama 3 implemented in pure NumPy

#46
post #44

Trainable Llama-like transformer (with backpropagation) in numpy only (~600 lines) https://github.com/joennlae/tensorli

The description says GPT-like, but is is just a GPT, right?

GPT refers to the specific family of models developed at OpenAI.

Re: Llama 3 implemented in pure NumPy

#48
post #29
post #28

Earlier quoted context omitted.

So is this the case that the information is in the data set? Or the code is very well defined to be so small? As an outsider it's surprising that such a capable model can be so "simple".

The training code is presumably quite a bit more complex than what they've open sourced, but part of the beauty of the GPT-based LLMs is their structural simplicity. Now, that simplicity can be deceiving - there are a lot of conceptual interconnectedness within these models. They've been put together "just so" if you will. If you look at the source code to nanoGPT and compare it to Llama3, the most remarkable thing (…

Forgot one: the positional encoding also changed, llama3 uses RoPE, gpt2 uses a learned embedding.

Re: Llama 3 implemented in pure NumPy

#49
post #47
post #46

Earlier quoted context omitted.

GPT refers to the specific family of models developed at OpenAI.

It also stands for generative pretrained transformer, which this seems to be.

It’s like saying SSD is a YOLO. Both are single shot object detectors, but only YOLO is “a YOLO”.

Re: Llama 3 implemented in pure NumPy

#50
post #25

It's also worth mentioning that the original implementation by Meta is only 300 lines of very readable code [1]. [1]: https://github.com/meta-llama/llama3/blob/main/llama/model.p...

The numpy code can seem more accessible and easy to understand. Torch can look scary even though it's similar to numpy.
Post reply on HN