Get the latest tech news

Implementing LLaMA3 in 100 Lines of Pure Jax


his post, we'll implement llama3 from scratch using pure jax in just 100 lines of code. Why jax? Because I think it has good aesthetics.

Instead of relying on a single global seed as in NumPy or PyTorch, in jax we need to manage randomness with explicit pseudo-random number generator (PRNG) keys. The forward pass takes your data through the entire model from converting input tokens into embeddings, through a series of transformer blocks, and finally to the output layer. vmap is like a vectorized loop; it takes a function that processes a single index (using lax.dynamic_slice to get a sequence of tokens) and applies it to every element in our array of indices.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of lines

lines

Photo of Llama3

Llama3

Photo of pure jax

pure jax

Related news:

News photo

Parsing JSON in 500 lines of Rust

News photo

Nanoleaf Lowers Prices for Shapes, Lines, Skylight and More With New 'SmarterLife' Initiative

News photo

Canada is on the front lines of an airship boom — but hurdles still abound