# naklecha/llama3-from-scratch architecture

> Architecture diagram of the GitHub repository naklecha/llama3-from-scratch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/naklecha/llama3-from-scratch
- Repository: https://github.com/naklecha/llama3-from-scratch

## Overview

This repository is an educational Llama 3 inference implementation presented as a notebook. Its documented workflow loads Meta’s tokenizer and model assets, tokenizes a prompt, maps tokens to embeddings, normalizes them, and begins implementing transformer attention from tensor operations. The README excerpt ends during first-layer attention, so later inference stages and their relationships are not represented. The notebook is the only runtime source file shown; component paths therefore point to that notebook, while downloaded assets are external inputs.

Main entry points: [`llama3-from-scratch.ipynb`](https://github.com/naklecha/llama3-from-scratch/blob/main/llama3-from-scratch.ipynb) (Weight and config loading)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Inputs and setup"]
  node_notebook["Llama 3 notebook"]
  node_assets[("Model assets")]
end

subgraph group_encoding["Text encoding"]
  node_tokenizer["Tokenizer setup"]
  node_prompt["Prompt encoding"]
end

subgraph group_inference["Model computation"]
  node_weights["Weight and config loading"]
  node_embeddings["Token embeddings"]
  node_normalization["RMS normalization"]
  node_attention["Transformer attention"]
end

node_user(("Notebook user"))

node_user -->|"runs"| node_notebook
node_assets -->|"provides tokenizer model"| node_tokenizer
node_assets -->|"provides weights and config"| node_weights
node_notebook -->|"sets up"| node_tokenizer
node_tokenizer -->|"encodes prompt"| node_prompt
node_prompt -->|"provides token IDs"| node_embeddings
node_weights -->|"provides embedding weights"| node_embeddings
node_embeddings -->|"normalizes"| node_normalization
node_weights -->|"provides norm weights"| node_normalization
node_normalization -->|"feeds attention"| node_attention
node_weights -->|"provides attention weights"| node_attention

click node_notebook "https://github.com/naklecha/llama3-from-scratch/blob/main/llama3-from-scratch.ipynb"
click node_tokenizer "https://github.com/naklecha/llama3-from-scratch/blob/main/llama3-from-scratch.ipynb"
click node_prompt "https://github.com/naklecha/llama3-from-scratch/blob/main/llama3-from-scratch.ipynb"
click node_weights "https://github.com/naklecha/llama3-from-scratch/blob/main/llama3-from-scratch.ipynb"
click node_embeddings "https://github.com/naklecha/llama3-from-scratch/blob/main/llama3-from-scratch.ipynb"
click node_normalization "https://github.com/naklecha/llama3-from-scratch/blob/main/llama3-from-scratch.ipynb"
click node_attention "https://github.com/naklecha/llama3-from-scratch/blob/main/llama3-from-scratch.ipynb"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_notebook,node_assets,node_user toneBlue
class node_tokenizer,node_prompt toneAmber
class node_weights,node_embeddings,node_normalization,node_attention toneMint
```

## Components

### Inputs and setup

- [Llama 3 notebook](https://github.com/naklecha/llama3-from-scratch/blob/main/llama3-from-scratch.ipynb): `llama3-from-scratch.ipynb`
- **Model assets**

### Text encoding

- [Tokenizer setup](https://github.com/naklecha/llama3-from-scratch/blob/main/llama3-from-scratch.ipynb): `llama3-from-scratch.ipynb`
- [Prompt encoding](https://github.com/naklecha/llama3-from-scratch/blob/main/llama3-from-scratch.ipynb): `llama3-from-scratch.ipynb`

### Model computation

- [Weight and config loading](https://github.com/naklecha/llama3-from-scratch/blob/main/llama3-from-scratch.ipynb): `llama3-from-scratch.ipynb`
- [Token embeddings](https://github.com/naklecha/llama3-from-scratch/blob/main/llama3-from-scratch.ipynb): `llama3-from-scratch.ipynb`
- [RMS normalization](https://github.com/naklecha/llama3-from-scratch/blob/main/llama3-from-scratch.ipynb): `llama3-from-scratch.ipynb`
- [Transformer attention](https://github.com/naklecha/llama3-from-scratch/blob/main/llama3-from-scratch.ipynb): `llama3-from-scratch.ipynb`

### Other components

- **Notebook user**

## Connections

- Notebook user → Llama 3 notebook: runs (evidence: `README.md`)
- Model assets → Tokenizer setup: provides tokenizer model (evidence: `README.md`)
- Model assets → Weight and config loading: provides weights and config (evidence: `README.md`)
- Llama 3 notebook → Tokenizer setup: sets up (evidence: `README.md`)
- Tokenizer setup → Prompt encoding: encodes prompt (evidence: `README.md`)
- Prompt encoding → Token embeddings: provides token IDs (evidence: `README.md`)
- Weight and config loading → Token embeddings: provides embedding weights (evidence: `README.md`)
- Token embeddings → RMS normalization: normalizes (evidence: `README.md`)
- Weight and config loading → RMS normalization: provides norm weights (evidence: `README.md`)
- RMS normalization → Transformer attention: feeds attention (evidence: `README.md`)
- Weight and config loading → Transformer attention: provides attention weights (evidence: `README.md`)
