Skip to content

Implement LLaMA 3 BPE Tokenizer #174

Closed

Description

@thejhh

Implement a pure-Go LLaMA 3 byte-pair-encoding (BPE) tokenizer compatible with BitNet-b1.58.

Load tokenizer.json (or vocab.json + merges.txt) (from the downloaded tokenizer files) and implement encoding of input strings into token ID sequences and decoding of token IDs back to text
ar5iv.org. Ensure round-trip encode -> decode is loss-less and byte-exact.

Ensure the tokenizer supports the full vocabulary size (~128k tokens) and produces token sequences up to 4096 tokens long. Test the tokenizer on sample text (e.g. known prompts) to confirm it matches the BitNet tokenization scheme. Handle all special tokens (BOS, EOS, , etc.) and reject or truncate inputs that exceed 4 096 tokens.

Add unit tests that compare token IDs against the reference Python LLaMA 3 tokenizer for at least: (a) ASCII, (b) multibyte Unicode, (c) emoji, (d) leading-space words.

The encoder/decoder must be thread-safe and capable of streaming tokenization (process chunks without re-reading merges).

Metadata

Metadata

Assignees

Labels

bitnetBitNet implementationtask

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions