- in
- Raw text
- out
- [B, T, 128256]
- parameters
- 8,030,261,248 in all
Parameters
8,030,261,248 parameters in Llama 3 8B
| Component | Calculation | Parameters |
|---|---|---|
| Token embedding | 525,336,576 | |
| Transformer block | 6,979,584,000 | |
| Final RMSNorm | 4,096 | |
| Vocabulary projection | 525,336,576 | |
| Model total | 8,030,261,248 | |
Derived from the pinned catalogue dimensions and implementation. Checkpoint tensors have not been independently counted.
In numbers
Fact sheet
- Blocks
- 32, all densesku_list.py 19–207
- Width
- 4,096sku_list.py 19–207
- Attention
- 32 query heads, 8 key/value heads (4 query heads per key/value head); 128 features per headsku_list.py 19–207model.py 78–183
- Feed-forward
- SwiGLU, 14,336 hidden featuressku_list.py 19–207model.py 193–234
- Vocabulary
- 128,256sku_list.py 19–207generation.py 104
- Context
- 8,192 positionsThe training sequence length; the generation code accepts at most 8,192 positions.MODEL_CARD.md 13generation.py 67
- Parameters
- 8,030,261,248, all used per tokensku_list.py 19–207
- Llama 3.1
- Llama 3.1 8B: the same shapes, a 128K context and scaled RoPEsku_list.py 19–207Llama3-Herd-2407.21783v3.pdf
- KV cache
- 128 KiB per position, all layers8 key/value heads × 128 × 2 (K, V) × 32 layers × 2 bytes. Written in Prefill and Decode; the Full sequence view draws none.model.py 129–177generation.py 105–108
Weights · whole model
8,030,261,248 parameters × 2 bytes. The separate readout holds 128,256 × 4,096 = 525,336,576 of them (6.5%); tied to the embedding, the model would have 7,504,924,672.
sku_list.py 19–207model.py 267–269generation.py 105–108Sources
Based on Meta’s pinned catalogue and reference implementation. Direct checkpoint configuration and tokenizer assets remain unverified.
Direct evidence
The tokenizer loads fixed BPE ranks, combines them with a regex and special tokens, and returns token IDs with caller-controlled BOS/EOS insertion.
tokenizer · meta-llama/llama3 / llama/tokenizer.py
Pinned revision a0940f9cf706 ↗ · lines 45–160
Read code excerpt
num_reserved_special_tokens = 256
pat_str = r"(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}{1,3}| ?[^\s\p{L}\p{N}]+[\r\n]*|\s*[\r\n]+|\s+(?!\S)|\s+" # noqa: E501… lines 48–55 omitted …
assert os.path.isfile(model_path), model_path
mergeable_ranks = load_tiktoken_bpe(model_path)
num_base_tokens = len(mergeable_ranks)
special_tokens = [
"<|begin_of_text|>",
"<|end_of_text|>",
"<|reserved_special_token_0|>",
"<|reserved_special_token_1|>",
"<|reserved_special_token_2|>",
"<|reserved_special_token_3|>",
"<|start_header_id|>",
"<|end_header_id|>",
"<|reserved_special_token_4|>",
"<|eot_id|>", # end of turn
] + [
f"<|reserved_special_token_{i}|>"
for i in range(5, self.num_reserved_special_tokens - 5)
]
self.special_tokens = {
token: num_base_tokens + i for i, token in enumerate(special_tokens)
}
self.model = tiktoken.Encoding(
name=Path(model_path).name,
pat_str=self.pat_str,
mergeable_ranks=mergeable_ranks,
special_tokens=self.special_tokens,
)… lines 84–146 omitted …
t: List[int] = []
for substr in substrs:
t.extend(
self.model.encode(
substr,
allowed_special=allowed_special,
disallowed_special=disallowed_special,
)
)
if bos:
t.insert(0, self.bos_id)
if eos:
t.append(self.eos_id)
return tDirect evidence
The base text-completion caller inserts BOS and omits EOS when encoding each input prompt.
base-prompt · meta-llama/llama3 / llama/generation.py
Pinned revision a0940f9cf706 ↗ · lines 260–260
Read code excerpt
prompt_tokens = [self.tokenizer.encode(x, bos=True, eos=False) for x in prompts]Direct evidence
Meta’s original Llama 3 8B base catalogue entry supplies dimensions, head counts, vocabulary, MLP rounding settings, epsilon and unscaled RoPE settings.
config · meta-llama/llama-models / models/sku_list.py
Pinned revision 0e0b8c519242 ↗ · lines 19–207
Read code excerpt
LLAMA3_VOCAB_SIZE = 128256… lines 20–187 omitted …
def llama3_base_models() -> list[Model]:
return [
Model(
core_model_id=CoreModelId.llama3_8b,
description="Llama 3 8b model",
huggingface_repo="meta-llama/Llama-3-8B",
arch_args={
"dim": 4096,
"n_layers": 32,
"n_heads": 32,
"n_kv_heads": 8,
"vocab_size": LLAMA3_VOCAB_SIZE,
"ffn_dim_multiplier": 1.3,
"multiple_of": 1024,
"norm_eps": 1e-05,
"rope_theta": 500000.0,
"use_scaled_rope": False,
},
pth_file_count=1,
),Direct evidence
The model constructs a vocabulary-by-feature token embedding and looks up the supplied token IDs.
model-embedding · meta-llama/llama3 / llama/model.py
Pinned revision a0940f9cf706 ↗ · lines 253–280
Read code excerpt
super().__init__()
self.params = params
self.vocab_size = params.vocab_size
self.n_layers = params.n_layers
self.tok_embeddings = VocabParallelEmbedding(
params.vocab_size, params.dim, init_method=lambda x: x
)… lines 261–278 omitted …
_bsz, seqlen = tokens.shape
h = self.tok_embeddings(tokens)Direct evidence
The model constructs independent blocks and passes the same sequence-specific RoPE coefficients and mask through the block loop.
model-stack · meta-llama/llama3 / llama/model.py
Pinned revision a0940f9cf706 ↗ · lines 262–300
Read code excerpt
self.layers = torch.nn.ModuleList()
for layer_id in range(params.n_layers):
self.layers.append(TransformerBlock(layer_id, params))
self.norm = RMSNorm(params.dim, eps=params.norm_eps)… lines 267–297 omitted …
for layer in self.layers:
h = layer(h, start_pos, freqs_cis, mask)
h = self.norm(h)Direct evidence
Final RMSNorm precedes a separate bias-free vocabulary projection; the returned logits are converted to float32.
model-readout · meta-llama/llama3 / llama/model.py
Pinned revision a0940f9cf706 ↗ · lines 266–303
Read code excerpt
self.norm = RMSNorm(params.dim, eps=params.norm_eps)
self.output = ColumnParallelLinear(
params.dim, params.vocab_size, bias=False, init_method=lambda x: x
)… lines 270–297 omitted …
for layer in self.layers:
h = layer(h, start_pos, freqs_cis, mask)
h = self.norm(h)
output = self.output(h).float()
return output
Direct evidence
RoPE precomputation uses position indices; the forward call selects coefficients using the supplied offset and token sequence length.
model-positions · meta-llama/llama3 / llama/model.py
Pinned revision a0940f9cf706 ↗ · lines 49–282
Read code excerpt
def precompute_freqs_cis(dim: int, end: int, theta: float = 10000.0):
freqs = 1.0 / (theta ** (torch.arange(0, dim, 2)[: (dim // 2)].float() / dim))
t = torch.arange(end, device=freqs.device, dtype=torch.float32)
freqs = torch.outer(t, freqs)
freqs_cis = torch.polar(torch.ones_like(freqs), freqs) # complex64
return freqs_cis… lines 55–270 omitted …
self.freqs_cis = precompute_freqs_cis(
params.dim // params.n_heads,
params.max_seq_len * 2,
params.rope_theta,
)
@torch.inference_mode()
def forward(self, tokens: torch.Tensor, start_pos: int):
_bsz, seqlen = tokens.shape
h = self.tok_embeddings(tokens)
self.freqs_cis = self.freqs_cis.to(h.device)
freqs_cis = self.freqs_cis[start_pos : start_pos + seqlen]Direct evidence
The model builds the causal mask only when sequence length exceeds one and passes it into every block.
model-mask · meta-llama/llama3 / llama/model.py
Pinned revision a0940f9cf706 ↗ · lines 284–300
Read code excerpt
mask = None
if seqlen > 1:
mask = torch.full((seqlen, seqlen), float("-inf"), device=tokens.device)
mask = torch.triu(mask, diagonal=1)
# When performing key-value caching, we compute the attention scores
# only for the new sequence. Thus, the matrix of scores is of size
# (seqlen, cache_len + seqlen), and the only masked entries are (i, j) for
# j > cache_len + i, since row i corresponds to token cache_len + i.
mask = torch.hstack(
[torch.zeros((seqlen, start_pos), device=tokens.device), mask]
).type_as(h)
for layer in self.layers:
h = layer(h, start_pos, freqs_cis, mask)
h = self.norm(h)