# meta-llama/llama architecture

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

- Interactive diagram: https://gitdiagram.com/meta-llama/llama
- Repository: https://github.com/meta-llama/llama

## Overview

This deprecated Llama 2 repository is a minimal local inference example, with separate chat and pretrained text-completion entry points. Each example builds the inference runtime from checkpoint files and invokes its corresponding completion method; the runtime encodes prompts, runs autoregressive generation through the Transformer, and decodes results. The model implementation includes attention and feed-forward Transformer blocks. The graph focuses on this runtime workflow; edges reflect the shown calls and documented usage, while unsampled implementation details are omitted.

Main entry points: [`llama/generation.py`](https://github.com/meta-llama/llama/blob/main/llama/generation.py) (Llama runtime), [`example_chat_completion.py`](https://github.com/meta-llama/llama/blob/main/example_chat_completion.py) (Chat example), [`example_text_completion.py`](https://github.com/meta-llama/llama/blob/main/example_text_completion.py) (Text example), [`llama/tokenizer.py`](https://github.com/meta-llama/llama/blob/main/llama/tokenizer.py) (SentencePiece tokenizer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_examples["Inference examples"]
  node_chat_example["Chat example"]
  node_text_example["Text example"]
end

subgraph group_runtime["Generation runtime"]
  node_llama_runtime["Llama runtime<br/>[generation.py]"]
  node_tokenizer["SentencePiece tokenizer<br/>[tokenizer.py]"]
end

subgraph group_engine["Model engine"]
  node_transformer["Transformer model<br/>[model.py]"]
end

node_user(("Developer"))
node_checkpoints["Checkpoint files"]

node_user -->|"runs"| node_chat_example
node_user -->|"runs"| node_text_example
node_chat_example -->|"builds runtime"| node_llama_runtime
node_chat_example -->|"requests chat"| node_llama_runtime
node_text_example -->|"builds runtime"| node_llama_runtime
node_text_example -->|"requests completion"| node_llama_runtime
node_llama_runtime -->|"loads weights"| node_checkpoints
node_llama_runtime -->|"runs forward"| node_transformer
node_llama_runtime -->|"encodes and decodes"| node_tokenizer

click node_chat_example "https://github.com/meta-llama/llama/blob/main/example_chat_completion.py"
click node_text_example "https://github.com/meta-llama/llama/blob/main/example_text_completion.py"
click node_llama_runtime "https://github.com/meta-llama/llama/blob/main/llama/generation.py"
click node_tokenizer "https://github.com/meta-llama/llama/blob/main/llama/tokenizer.py"
click node_transformer "https://github.com/meta-llama/llama/blob/main/llama/model.py"

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_chat_example,node_text_example toneBlue
class node_llama_runtime,node_tokenizer toneAmber
class node_transformer toneMint
class node_user,node_checkpoints toneIndigo
```

## Components

### Inference examples

- [Chat example](https://github.com/meta-llama/llama/blob/main/example_chat_completion.py): `example_chat_completion.py`
- [Text example](https://github.com/meta-llama/llama/blob/main/example_text_completion.py): `example_text_completion.py`

### Generation runtime

- [Llama runtime](https://github.com/meta-llama/llama/blob/main/llama/generation.py): `llama/generation.py`
- [SentencePiece tokenizer](https://github.com/meta-llama/llama/blob/main/llama/tokenizer.py): `llama/tokenizer.py`

### Model engine

- [Transformer model](https://github.com/meta-llama/llama/blob/main/llama/model.py): `llama/model.py`

### Other components

- **Developer**
- **Checkpoint files**

## Connections

- Developer → Chat example: runs (evidence: `README.md`)
- Developer → Text example: runs (evidence: `README.md`)
- Chat example → Llama runtime: builds runtime (evidence: `example_chat_completion.py`)
- Chat example → Llama runtime: requests chat (evidence: `example_chat_completion.py`)
- Text example → Llama runtime: builds runtime (evidence: `example_text_completion.py`)
- Text example → Llama runtime: requests completion (evidence: `example_text_completion.py`)
- Llama runtime → Checkpoint files: loads weights (evidence: `llama/generation.py`)
- Llama runtime → Transformer model: runs forward (evidence: `llama/generation.py`)
- Llama runtime → SentencePiece tokenizer: encodes and decodes (evidence: `llama/generation.py`)
