Token embedding

×

Look up a learned feature vector for each token ID.

x0=E[I]{\htmlData{light=embedded embedding}{x_0}}=E[{\htmlData{light=token-ids tokenize}{I}}]
in
II [B batch, T positions]
out
x0x_0 [B batch, T positions, 4096 d]

Position enters only through RoPE on queries and keys.

Parameters525,336,576

525,336,576 parameters per instance.

ComponentCalculationParameters
Token embedding128,256 × 4,096525,336,576

The vocabulary projection owns a separate matrix.

Not checked against a checkpoint.

Sources

In codeself.tok_embeddings(tokens)

Open pinned code ↗

Direct evidence

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)

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,
        ),