Skip to content

Added new SentencePiece Lite runtime. - #1330

Merged
taku910 merged 5 commits into
masterfrom
lite
Sep 16, 2026
Merged

taku910 merged 5 commits into
masterfrom
lite

Conversation

@taku910

@taku910 taku910 commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

Introduce SentencePiece Lite (lite/), a compact (~45 KB stripped binary, < 2k LOC), zero-dependency C++20 runtime engine designed to execute SentencePiece tokenization directly on memory-mapped FlatBuffers model binaries (.spm.fb).

taku910 and others added 5 commits September 15, 2026 09:28
Introduce SentencePiece Lite (`lite/`), a compact (~45 KB stripped binary, < 2k LOC), zero-dependency C++20 runtime engine designed to execute SentencePiece tokenization directly on memory-mapped FlatBuffers model binaries (`.spm.fb`).

Key features:
- Zero Runtime Dependencies: Requires only standard C++20 without runtime dependency on Protobuf or Abseil.
- SQLite-Style Standalone Amalgamation: Provides `lite/amalgamate.py` to generate a self-contained 2-file distribution (`dist/sentencepiece_lite.h` and `dist/sentencepiece_lite.cc`) with FlatBuffers and rapidhash inlined.
- Zero-Copy Memory-Mapped Startup: Operates directly on `.spm.fb` FlatBuffers blobs via `mmap` with only 1.2 KB heap memory overhead.
- High-Throughput Token Caching (`CachedSentencePieceLite`): Optional 64-byte L1 cache-line aligned 2-way set-associative PLRU cache powered by `rapidhash` with 16-bit chunk tag validation.
- Safe-Boundary Pre-Tokenization: Built-in character bigram co-occurrence Double-Array Trie analysis (`PretokenizeAtSafeBoundaries`) for lock-free parallel multi-threaded document tokenization.
- CLI & Model Converter Tools: Includes `spm_to_fb` offline model converter and `spm_lite` command-line tokenizer, plus on-the-fly `ToFlatbuffer` C++ API.
- Full Canonical Parity & Security Hardening: Byte-for-byte normalization and token ID equivalence with canonical SentencePiece (Unigram and BPE), hardened against malformed models with buffer alignment and bounds verification.
- Build & CI Integration: Full CMake (`SPM_ENABLE_LITE`) and Bazel (`//lite:...`) build support, GitHub Actions CI workflow (`lite.yml`), and documentation site integration (`docs.yml`).
@taku910
taku910 merged commit b2db471 into master Sep 16, 2026
45 checks passed
@taku910
taku910 deleted the lite branch October 29, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant