Raw textto [B, T, 128256]
Specification
Parameters8,030,261,248
8,030,261,248 parameters in Llama 3 8B
| Component | Calculation | Parameters |
|---|---|---|
| Token embedding | 128,256 × 4,096 | 525,336,576 |
| Layer | 218,112,000 × 32 | 6,979,584,000 |
| Final RMSNorm | 4,096 | |
| Vocabulary projection | 4,096 × 128,256 | 525,336,576 |
| Model total | 8,030,261,248 | |
Counted from the pinned catalogue dimensions and code. Not checked against the checkpoint’s tensors.
Sources
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.py 45–160 ↗ · meta-llama/llama3 @ a0940f9cf706
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 tThe base text-completion caller inserts BOS and omits EOS when encoding each input prompt.
generation.py 260 ↗ · meta-llama/llama3 @ a0940f9cf706
Excerpt
prompt_tokens = [self.tokenizer.encode(x, bos=True, eos=False) for x in prompts]Meta’s original Llama 3 8B base catalogue entry supplies dimensions, head counts, vocabulary, MLP rounding settings, epsilon and unscaled RoPE settings.
sku_list.py 19–207 ↗ · meta-llama/llama-models @ 0e0b8c519242
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,
),The model constructs a vocabulary-by-feature token embedding and looks up the supplied token IDs.
model.py 253–280 ↗ · meta-llama/llama3 @ a0940f9cf706
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)The model constructs independent layers and passes the same sequence-specific RoPE coefficients and mask through the layer loop.
model.py 262–300 ↗ · meta-llama/llama3 @ a0940f9cf706
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)Final RMSNorm precedes a separate bias-free vocabulary projection; the returned logits are converted to float32.
model.py 266–303 ↗ · meta-llama/llama3 @ a0940f9cf706
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
RoPE precomputation uses position indices; the forward call selects coefficients using the supplied offset and token sequence length.
model.py 49–282 ↗ · meta-llama/llama3 @ a0940f9cf706
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]The model builds the causal mask only when sequence length exceeds one and passes it into every layer.
model.py 284–300 ↗ · meta-llama/llama3 @ a0940f9cf706
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)