Skip to main content

LengthTokenizer Rust (DP 最少 token / 最低 TPC) Python extension

Project description

length_tokenizer(Rust + HuggingFace + Python wheel)

这是一个 Rust 实现的 tokenizer(支持训练与推理),并提供两种分发形态:

  • HuggingFace remote-code tokenizer:在 hf_tokenizer_out/ 目录,可直接上传到 HuggingFace Hub(加载需 trust_remote_code=True
  • Python wheel(高性能):使用 PyO3+maturin 构建扩展模块 length_tokenizer_rs,供 remote-code tokenizer 优先调用(速度接近原生 Rust)

1) 构建 Python wheel(PyO3 / maturin)

要求:你的机器上有 Python 与 Rust 工具链。

pip install maturin
cd tokenizers_rust
maturin build --release

开发安装(直接 import length_tokenizer_rs):

pip install maturin
cd tokenizers_rust
maturin develop --release
python3 -c \"from length_tokenizer_rs import DpTokenizer; print(DpTokenizer)\"

2) HuggingFace 侧使用高性能扩展(可选)

在 HF 的 tokenization_length_tokenizer.py 中会优先尝试:

from length_tokenizer_rs import DpTokenizer

如果你安装了 wheel,则 _tokenize() 会调用 Rust 扩展来做 Trie+DP 最少 token 分词; 如果未安装,会自动回退到纯 Python 实现(更慢,但可用)。

你可以设置环境变量禁用 Rust 扩展(用于对齐/排障):

export LENGTH_TOKENIZER_DISABLE_RUST=1

3) 发布到 PyPI(让用户 pip install length-tokenizer-rs

推荐方式:GitHub Actions 自动构建并发布

仓库已包含工作流:tokenizers_rust/.github/workflows/publish_pypi.yml

你需要做:

  • 在 PyPI 注册账号,并创建一个 API Token(Account settings → API tokens)
  • 在 GitHub 仓库里设置 secretPYPI_API_TOKEN
  • 更新版本号(建议 Cargo.tomlpyproject.toml 同步),提交并打 tag:
git tag v0.1.1
git push --tags

工作流会在 Linux/macOS/Windows 上构建 wheels 并上传到 PyPI。

备选方式:本机直接发布(不推荐作为正式发布)

本机直接 maturin publish 会受你本地 glibc / 平台影响,可能生成兼容性较窄的 wheel。 正式发布建议用 CI(manylinux2014)来构建。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

length_tokenizer_rs-0.1.2-cp312-cp312-win_amd64.whl (192.4 kB view details)

Uploaded CPython 3.12Windows x86-64

length_tokenizer_rs-0.1.2-cp312-cp312-macosx_11_0_arm64.whl (279.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

length_tokenizer_rs-0.1.2-cp311-cp311-win_amd64.whl (191.9 kB view details)

Uploaded CPython 3.11Windows x86-64

length_tokenizer_rs-0.1.2-cp311-cp311-macosx_11_0_arm64.whl (279.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

length_tokenizer_rs-0.1.2-cp310-cp310-win_amd64.whl (192.2 kB view details)

Uploaded CPython 3.10Windows x86-64

length_tokenizer_rs-0.1.2-cp310-cp310-macosx_11_0_arm64.whl (280.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

length_tokenizer_rs-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (319.2 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file length_tokenizer_rs-0.1.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for length_tokenizer_rs-0.1.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4b6fb2c1732d66bfe563fa60f0ca3829dc62d5394616e7290699439429882ae0
MD5 8eea4735b442070a2e2554fb79b8e272
BLAKE2b-256 34607158f1fe6d506eeac5c151942d505b947837fb3e8325d8937b6d6ea0770f

See more details on using hashes here.

File details

Details for the file length_tokenizer_rs-0.1.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for length_tokenizer_rs-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3be7049b83fac678a02ef0eed931e4583ff76b78bbc3be723b5d8195d4a0197a
MD5 875a1a4bf72c80716a9fcaad1a0a2009
BLAKE2b-256 cda4de61ab8ef9254e3b2ca2b6f65e6de306a77918129df17148ead096b15576

See more details on using hashes here.

File details

Details for the file length_tokenizer_rs-0.1.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for length_tokenizer_rs-0.1.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 18e24003f2105e794155f8d566c215b75af53e39c10928e2130a490328ec526b
MD5 a86b0af4c625046133aeb63928fc48bf
BLAKE2b-256 a13df7e11d5d5c9b46e4a6ab1553e5ec79963f738fde19280cb965f5f3efbc23

See more details on using hashes here.

File details

Details for the file length_tokenizer_rs-0.1.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for length_tokenizer_rs-0.1.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9c9e6558c3003aa28eb63358e596b5b829962cbd9bfa0c840a563f1bf9d19a38
MD5 dac4108be6944c652049e1397bf21d90
BLAKE2b-256 1c5bcb7d1e1a03ee9f41f3babf087fea0f1e9feae177ea9d59aa1686a1d3f0e1

See more details on using hashes here.

File details

Details for the file length_tokenizer_rs-0.1.2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for length_tokenizer_rs-0.1.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 eb1fbc643653151132b90654662b984c581cc4e098080cef3a6a303d8bfb3d3b
MD5 239c430d1643a32d27910f9080eb926a
BLAKE2b-256 224aa7f688f715b29c849bea536e2f3f26cb3ea146a635adf2f2daab9f6c1bd6

See more details on using hashes here.

File details

Details for the file length_tokenizer_rs-0.1.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for length_tokenizer_rs-0.1.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2ddc91faa7b0aed09154d9c4f3f821315cc3de12070dc181abc9459cebac7c29
MD5 dd6ee2b7e04ea5d4735618d13bd6c618
BLAKE2b-256 9033eb8545e26226ff6fd234af751d95a41e5a54fd2bf6676faa40bd906ad998

See more details on using hashes here.

File details

Details for the file length_tokenizer_rs-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for length_tokenizer_rs-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dba4c5a81730b62879587b7ee8f90dca22411e15ee17830a3a1b68efbb529b54
MD5 5660e11b4c0f75cb77ab2608cf1030c3
BLAKE2b-256 1a7be7584065d87ed3d9bcff95ce255c3285ea728ed7f13fdfbc6fd6f53cd5f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page