v0.2.2pre1
Pre-release
Pre-release
Release Notes v0.2.2 (pre1)
This release contains major updates, including the migration of the Python wrapper to pybind11, native NumPy support, enhanced offset mapping, performance optimizations, security hardening, and internal code modernization.
1. Python Wrapper (pybind11 Migration & Features)
- SWIG to pybind11 Migration: Fully migrated the Python wrapper from SWIG to pybind11, enabling better performance, safer memory management, and cleaner code integration (#1266, Commit
528dc9e). - Native NumPy Support:
- Supported zero-copy decoding for NumPy arrays using
IntSpanOrVector(Commitc5b0ce0). - Respected buffer strides in
CastToVectorIntto avoid Out-Of-Bounds (OOB) reads when processing NumPy arrays (#1275, Commita0daee2).
- Supported zero-copy decoding for NumPy arrays using
- Enhanced Offset Mapping:
- Type Stubs (PEP 561): Added inline type stubs (
.pyifiles) and packaged PEP 561 marker to provide auto-completion and static type safety in IDEs (#1258, Commit8b7f97b). - Parallel Encoding API: Introduced
parallel_encodeandThreadPoolAPIs, allowing Python users to tokenize single large documents across multiple CPU cores in parallel (#1254, Commit3c37c39). - Direct Proto Loading: Added support for loading processors and normalizers directly from in-memory Proto instances (Commit
12788ba). - Concurrency Enhancements: Added GIL release during C++ execution to improve multi-threaded Python performance (#1251, Commit
0a044ae). - BOS/EOS Behavior Hardening: Aligned BOS/EOS adding behavior with C++ constraints, raising explicit
ValueErrorinstead of silent failures or crashes (Commit780618a).
2. Performance Optimizations
- BPE Training Optimization: Ported O(log n) lazy priority queue update optimization to BPE trainer to speed up training (Commit
8db9878). - Encode/Decode Optimizations: Decoding/Encoding optimization for integer/string input case by skipping
SentencePieceTextconversion, resulting in ~2x speedup (Commit4b9231b). - Unigram Pruning: Improved unigram pruning using token-normalized frequency calculations (#1135, Commit
1cd0c59).
3. Security & Hardening
- Trie Validation at Load: Added verification of
darts-clonetrie offsets when loading models to prevent segfaults on corrupted or malicious model files (#1224, Commit6b2f05d). - Bounds Checking in Maps: Added bounds checks to piece accessors and validated value offsets in
DecompileCharsMap(#1265, Commit82b7c6d). - Crash Prevention: Replaced internal
CHECKmacros withDCHECKor returned errors to prevent host application crashes on invalid inputs (Commit66b2587). - Null Character Disallowment: Explicitly disallow vocabulary pieces containing null characters (Commit
eb3ba49). - NBest Timeout: Implemented a global timeout for NBest A* search to prevent hangs on pathological inputs (Commit
ba57749).
4. C++ API & Internals Modernization
- Abseil Migration: Extensively migrated from custom utilities to Abseil primitives (#1270, #1237, #1236):
- Migrated
sentencepiece::util::Statustoabsl::Status(Commit39279bf). - Switched to
absl::log(deprecating--minlogleveland introducing--quietflag, Commit7d25ca7). - Replaced custom random generators with
absl::random(Commit678a450).
- Migrated
- C++17 Requirement: Modernized the codebase to require C++17 (reverted from C++20 for compatibility, Commit
71de2ab). - Normalizer Maps: Supported loading normalizer from raw maps in C++ (#1273, Commit
e476e5e).
5. Build & Packaging
- Deprecate Win32 Wheels: Stopped support and distribution of 32-bit Windows wheels (win32) (Commit
24fd00c). - Modernized Python builds: Switched from calling
setup.pydirectly to the standardpypa/buildPEP 517 frontend (#1167, Commitf300c7d). - PEP 639 License: Added PEP 639 license metadata to
pyproject.toml(#1173). - Alpine & CI Updates: Upgraded build runners and updated alpine Docker images.
6. Documentation
- API Cheat Sheet: Added comparison tables, zero-copy, and sampling comparison guides.
- Refactored Options: Fully reorganized
options.mdandspecial_symbols.mdwith verified code examples.