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.3-cp312-cp312-win_amd64.whl (192.4 kB view details)

Uploaded CPython 3.12Windows x86-64

length_tokenizer_rs-0.1.3-cp312-cp312-macosx_11_0_arm64.whl (279.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

length_tokenizer_rs-0.1.3-cp311-cp311-macosx_11_0_arm64.whl (279.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

length_tokenizer_rs-0.1.3-cp310-cp310-macosx_11_0_arm64.whl (280.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

length_tokenizer_rs-0.1.3-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.3-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for length_tokenizer_rs-0.1.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 431b355a22d02a24d56fc5b31a7afa358cd0ef058809e5a79a50cc14b71ffb30
MD5 3db2c36375401fd2182823a69686db91
BLAKE2b-256 12e6849e80da988d8a29b8d9412297391b9778ef6612ecb5278d73ad2961591f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for length_tokenizer_rs-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8d14d5ecb5dd0769f997efb4cc04e75583e87ba6e0b4af002453f1b84ff80162
MD5 4a5c5fa144984b153f004c18f6d676a6
BLAKE2b-256 ab05dce31ad2c3ced4869027bc314052d826efbe359f0db1ba2523842e06c66a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for length_tokenizer_rs-0.1.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9fb466c4d6f1e1ba6cd743e5462f785b8cb022b057445a3da1fb84d7b83fa7e7
MD5 0dd021151b8ca0d3fc05bafda2db2caf
BLAKE2b-256 0abca76e09c327d665a80b5151437c2b27583e1d8635e0504cb2d2a019135b07

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for length_tokenizer_rs-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 15e6be2857fbeb73b9f021ca6ff45d36456fd4af23be8b9af081a44f8bd64b5f
MD5 7cc959922c6313fba41f8751a3c5ce40
BLAKE2b-256 5785a836279dacabcd8b8fef5b8af5d889480bbad13732e201be3419c3ba9cd4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for length_tokenizer_rs-0.1.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 23310e0bd05f355f2bf8ef7a6392114fa979ed4503d9b6ba5acfe8947f3f10a3
MD5 0c8b72a09dc52c1fcb1dfd4a12528498
BLAKE2b-256 2fb304ebcea15b2c87004303ec678be20224d448a9290c30f0d52f53fe25bbbe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for length_tokenizer_rs-0.1.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3731d12f52023bc68ceb62438f5a897554c9e6c57a9ad63d6ac4e44b5a0d718d
MD5 882d9bb1902e67935b494ea823c4a73f
BLAKE2b-256 48157530265e2adb51ab492f334802e5b1dd6817183583cc5fc05d075d1efeb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for length_tokenizer_rs-0.1.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ba0f76861b8e10cf2cbc52305fdd20be4c69de264e38e246737bc6443cd71e92
MD5 27a4546bd99307a67a50c6f66f4085db
BLAKE2b-256 1db465952f37821b07b7c9f1ea55d869fecdbc55f94ec13d7309a9d2674ec1ec

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