bbpe-tokenizer 0.5.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. bbpe_tokenizer-0.5.4/.gitattributes +12 -0
  2. bbpe_tokenizer-0.5.4/.gitignore +49 -0
  3. bbpe_tokenizer-0.5.4/CHANGELOG.md +103 -0
  4. bbpe_tokenizer-0.5.4/CONTRIBUTING.md +75 -0
  5. bbpe_tokenizer-0.5.4/Cargo.lock +992 -0
  6. bbpe_tokenizer-0.5.4/Cargo.toml +208 -0
  7. bbpe_tokenizer-0.5.4/LICENSE-APACHE +202 -0
  8. bbpe_tokenizer-0.5.4/LICENSE-MIT +21 -0
  9. bbpe_tokenizer-0.5.4/PKG-INFO +248 -0
  10. bbpe_tokenizer-0.5.4/README.md +217 -0
  11. bbpe_tokenizer-0.5.4/README.zh-CN.md +201 -0
  12. bbpe_tokenizer-0.5.4/SECURITY.md +40 -0
  13. bbpe_tokenizer-0.5.4/build.rs +68 -0
  14. bbpe_tokenizer-0.5.4/clean_pycache.sh +15 -0
  15. bbpe_tokenizer-0.5.4/examples/cancel_drop_probe.rs +76 -0
  16. bbpe_tokenizer-0.5.4/examples/decode_phase_split.rs +116 -0
  17. bbpe_tokenizer-0.5.4/examples/phase_split.rs +104 -0
  18. bbpe_tokenizer-0.5.4/pyproject.toml +62 -0
  19. bbpe_tokenizer-0.5.4/python/bbpe_tokenizer/__init__.py +182 -0
  20. bbpe_tokenizer-0.5.4/python/bbpe_tokenizer/bbpe_rs.pyi +268 -0
  21. bbpe_tokenizer-0.5.4/python/bbpe_tokenizer/config.py +75 -0
  22. bbpe_tokenizer-0.5.4/python/bbpe_tokenizer/core.py +333 -0
  23. bbpe_tokenizer-0.5.4/python/bbpe_tokenizer/logits_processor.py +94 -0
  24. bbpe_tokenizer-0.5.4/python/bbpe_tokenizer/py.typed +0 -0
  25. bbpe_tokenizer-0.5.4/scripts/check.sh +383 -0
  26. bbpe_tokenizer-0.5.4/scripts/check_version.py +180 -0
  27. bbpe_tokenizer-0.5.4/scripts/compare_e2e_speed.py +87 -0
  28. bbpe_tokenizer-0.5.4/scripts/publish-pypi.sh +91 -0
  29. bbpe_tokenizer-0.5.4/scripts/release.sh +273 -0
  30. bbpe_tokenizer-0.5.4/src/bin/bbpe.rs +8 -0
  31. bbpe_tokenizer-0.5.4/src/bin/bbpe_jsonl_bench.rs +497 -0
  32. bbpe_tokenizer-0.5.4/src/bin/bench.rs +105 -0
  33. bbpe_tokenizer-0.5.4/src/bin/bench_attribution.rs +128 -0
  34. bbpe_tokenizer-0.5.4/src/bin/compare.rs +8 -0
  35. bbpe_tokenizer-0.5.4/src/bin/compare_merges.rs +9 -0
  36. bbpe_tokenizer-0.5.4/src/bin/cut.rs +8 -0
  37. bbpe_tokenizer-0.5.4/src/bin/cut_vocab.rs +10 -0
  38. bbpe_tokenizer-0.5.4/src/bin/decode.rs +8 -0
  39. bbpe_tokenizer-0.5.4/src/bin/encode.rs +8 -0
  40. bbpe_tokenizer-0.5.4/src/bin/freeze_probe.rs +755 -0
  41. bbpe_tokenizer-0.5.4/src/bin/inspect.rs +8 -0
  42. bbpe_tokenizer-0.5.4/src/bin/inspect_model.rs +9 -0
  43. bbpe_tokenizer-0.5.4/src/bin/run_real_data.rs +57 -0
  44. bbpe_tokenizer-0.5.4/src/bin/sample.rs +8 -0
  45. bbpe_tokenizer-0.5.4/src/bin/sample_corpus.rs +10 -0
  46. bbpe_tokenizer-0.5.4/src/bin/sweep.rs +8 -0
  47. bbpe_tokenizer-0.5.4/src/bin/sweep_vocab.rs +13 -0
  48. bbpe_tokenizer-0.5.4/src/bin/train.rs +8 -0
  49. bbpe_tokenizer-0.5.4/src/bin/train_vocab.rs +13 -0
  50. bbpe_tokenizer-0.5.4/src/bindings/inference_executor.rs +302 -0
  51. bbpe_tokenizer-0.5.4/src/bindings/mod.rs +4 -0
  52. bbpe_tokenizer-0.5.4/src/bindings/python.rs +2744 -0
  53. bbpe_tokenizer-0.5.4/src/cancel.rs +246 -0
  54. bbpe_tokenizer-0.5.4/src/cli/compare.rs +109 -0
  55. bbpe_tokenizer-0.5.4/src/cli/cut.rs +162 -0
  56. bbpe_tokenizer-0.5.4/src/cli/decode.rs +79 -0
  57. bbpe_tokenizer-0.5.4/src/cli/dispatch.rs +62 -0
  58. bbpe_tokenizer-0.5.4/src/cli/encode.rs +132 -0
  59. bbpe_tokenizer-0.5.4/src/cli/inspect.rs +318 -0
  60. bbpe_tokenizer-0.5.4/src/cli/mod.rs +30 -0
  61. bbpe_tokenizer-0.5.4/src/cli/sample.rs +192 -0
  62. bbpe_tokenizer-0.5.4/src/cli/sweep.rs +357 -0
  63. bbpe_tokenizer-0.5.4/src/cli/train.rs +570 -0
  64. bbpe_tokenizer-0.5.4/src/cli/util.rs +549 -0
  65. bbpe_tokenizer-0.5.4/src/compare.rs +303 -0
  66. bbpe_tokenizer-0.5.4/src/error.rs +103 -0
  67. bbpe_tokenizer-0.5.4/src/external.rs +696 -0
  68. bbpe_tokenizer-0.5.4/src/inference_runtime.rs +119 -0
  69. bbpe_tokenizer-0.5.4/src/lib.rs +43 -0
  70. bbpe_tokenizer-0.5.4/src/pool_cache.rs +177 -0
  71. bbpe_tokenizer-0.5.4/src/pre_tokenizer.rs +478 -0
  72. bbpe_tokenizer-0.5.4/src/reader.rs +653 -0
  73. bbpe_tokenizer-0.5.4/src/sampling.rs +448 -0
  74. bbpe_tokenizer-0.5.4/src/tokenizer.rs +3011 -0
  75. bbpe_tokenizer-0.5.4/src/trainer.rs +2085 -0
  76. bbpe_tokenizer-0.5.4/tests/cli_sigint_test.rs +574 -0
  77. bbpe_tokenizer-0.5.4/tests/cli_test.rs +525 -0
  78. bbpe_tokenizer-0.5.4/tests/dlpack_consumer.c +76 -0
  79. bbpe_tokenizer-0.5.4/tests/equiv_test.rs +241 -0
  80. bbpe_tokenizer-0.5.4/tests/golden_merges.txt +161 -0
  81. bbpe_tokenizer-0.5.4/tests/inference_executor.rs +177 -0
  82. bbpe_tokenizer-0.5.4/tests/installed_artifact_smoke.py +223 -0
  83. bbpe_tokenizer-0.5.4/tests/integration_test.rs +171 -0
  84. bbpe_tokenizer-0.5.4/tests/model_contract_test.rs +811 -0
  85. bbpe_tokenizer-0.5.4/tests/test_bbpe_advanced.py +169 -0
  86. bbpe_tokenizer-0.5.4/tests/test_bbpe_real_world.py +191 -0
  87. bbpe_tokenizer-0.5.4/tests/test_bbpe_safety.py +187 -0
  88. bbpe_tokenizer-0.5.4/tests/test_bench_scripts.py +201 -0
  89. bbpe_tokenizer-0.5.4/tests/test_boundary_fixes.py +335 -0
  90. bbpe_tokenizer-0.5.4/tests/test_cancel_p1.py +176 -0
  91. bbpe_tokenizer-0.5.4/tests/test_cancel_p2.py +232 -0
  92. bbpe_tokenizer-0.5.4/tests/test_cancel_sigint.py +200 -0
  93. bbpe_tokenizer-0.5.4/tests/test_dlpack.py +240 -0
  94. bbpe_tokenizer-0.5.4/tests/test_dlpack_release_gates.py +109 -0
  95. bbpe_tokenizer-0.5.4/tests/test_inference_cancel_matrix.py +172 -0
  96. bbpe_tokenizer-0.5.4/tests/test_inference_runtime.py +188 -0
  97. bbpe_tokenizer-0.5.4/tests/test_inference_sigint.py +102 -0
  98. bbpe_tokenizer-0.5.4/tests/test_logits_integration.py +198 -0
  99. bbpe_tokenizer-0.5.4/tests/test_python_binding.py +551 -0
  100. bbpe_tokenizer-0.5.4/tests/test_release_acceptance.py +193 -0
  101. bbpe_tokenizer-0.5.4/tests/test_release_policy.py +419 -0
  102. bbpe_tokenizer-0.5.4/tests/test_sample_precheck.py +188 -0
  103. bbpe_tokenizer-0.5.4/tests/test_token_buffer.py +257 -0
  104. bbpe_tokenizer-0.5.4/tests/test_token_buffer_cancel.py +189 -0
  105. bbpe_tokenizer-0.5.4/tests/track_a_test.rs +394 -0
  106. bbpe_tokenizer-0.5.4/tests_corpus.txt +500 -0
@@ -0,0 +1,12 @@
1
+ * text=auto eol=lf
2
+
3
+ *.rs text eol=lf
4
+ *.py text eol=lf
5
+ *.pyi text eol=lf
6
+ *.toml text eol=lf
7
+ *.json text eol=lf
8
+ *.md text eol=lf
9
+ *.sh text eol=lf
10
+ *.yml text eol=lf
11
+ *.yaml text eol=lf
12
+ *.txt text eol=lf
@@ -0,0 +1,49 @@
1
+ # Rust build output
2
+ /target/
3
+
4
+ # Release artifacts
5
+ /dist/
6
+ *.whl
7
+
8
+ # Local corpora, models and scratch output
9
+ /data/
10
+ /output/
11
+ /tmp/
12
+ *.jsonl
13
+
14
+ # Python
15
+ __pycache__/
16
+ *.py[cod]
17
+ *.so
18
+ .pytest_cache/
19
+ .mypy_cache/
20
+ .venv*/
21
+ venv/
22
+ *.egg-info/
23
+ uv.lock
24
+
25
+ # Local release credentials
26
+ .env
27
+
28
+ # Editors and OS files
29
+ .idea/
30
+ .vscode/
31
+ .DS_Store
32
+
33
+ # Profiling output
34
+ perf.data*
35
+ profile*.gz
36
+ *.folded
37
+ dhat-heap.json
38
+
39
+ # Local models, review checkouts and benchmark run artifacts
40
+ /model_learn_tokenizer/
41
+ /model_learn_tokenizer_hf/
42
+ /tests_tokenizer.json
43
+ /tests_corpus.txt
44
+ /review-check-*/
45
+ /bench/200G规模语料/data/
46
+ /bench/200G规模语料/output/
47
+ /bench/200G规模语料/runs/
48
+ /bench/binding_attribution/results/
49
+ AGENTS.md
@@ -0,0 +1,103 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.5.4] - 2026-11-28
11
+
12
+ ### Fixed
13
+
14
+ - Stabilize timing-sensitive cancellation and GIL-release regression tests so
15
+ strict release gates validate behavior without depending on runner speed.
16
+
17
+ ## [0.5.3] - 2026-11-28
18
+
19
+ ### Fixed
20
+
21
+ - Limit prebuilt Windows wheels to x64; the `sonic-simd` dependency used by
22
+ `sonic-rs` does not build for 32-bit x86 Windows.
23
+
24
+ ## [0.5.2] - 2026-11-28
25
+
26
+ ### Fixed
27
+
28
+ - Build the Python extension before strict PyPI release checks so the
29
+ `python-base` and `inference-cpu` gates run against the current source.
30
+
31
+ ## [0.5.1] - 2026-11-28
32
+
33
+ ### Added
34
+
35
+ - PyPI publishing for `bbpe_tokenizer`, including platform wheels for
36
+ supported CPython versions, an sdist and Trusted Publishing.
37
+ - Local `.env`-backed PyPI publishing script with a non-uploading dry-run mode.
38
+
39
+ ## [0.5.0] - 2026-11-28
40
+
41
+ ### Added
42
+
43
+ - Read-only `TokenBuffer` encoding APIs with `memoryview` and NumPy support.
44
+ - One-shot CPU int32 DLPack handoff through `DLPackTokens`.
45
+ - Cooperative inference executor with cancellation, fork initialization and
46
+ bounded thread-pool reuse.
47
+ - Shared quality gates, version checks, wheel/sdist install smoke tests and
48
+ unified build verification.
49
+ - Expanded regression coverage for cancellation, model export, decode safety,
50
+ benchmark tooling and release policy.
51
+
52
+ ### Fixed
53
+
54
+ - Atomic model export cancellation and final sweep export responsiveness.
55
+ - Negative decode IDs and oversized heuristic decode table allocation.
56
+ - Corpus input/output alias rejection and staged sample/held-out commits.
57
+ - Checkpoint rollback error reporting and inference cancellation boundaries.
58
+
59
+ ## [0.1.0] - 2026-11-10
60
+
61
+ First public release.
62
+
63
+ ### Added
64
+
65
+ - Rust library and `bbpe` CLI with subcommands `train`, `sweep`, `cut`,
66
+ `sample`, `compare`, `inspect`, `encode`, `decode`.
67
+ - Byte-level BPE training over JSONL and plain-text corpora with a streaming,
68
+ bounded-memory line reader.
69
+ - Sampling-based training for out-of-core corpora, with held-out split output
70
+ and a pre-flight memory budget check.
71
+ - `cut`: derive any smaller vocabulary from a `K_max` model without retraining.
72
+ - Deterministic merges and token ids, independent of thread count.
73
+ - Model contract v1 (`format = "bbpe-rs-model"`, `format_version = 1`) with
74
+ provenance metadata (git commit, corpus counters, sampling parameters,
75
+ pre-tokenizer pattern) and on-load self-consistency validation.
76
+ - v0 → v1 model migration via `bbpe inspect --migrate`.
77
+ - Python package `bbpe_tokenizer` with `BBPETokenizer`, `BBPETrainer`,
78
+ `TokenizerGlobalConfig`, `BBTokenizer`, corpus readers and
79
+ `UTF8StrictLogitsProcessor` (optional, requires `torch` + `transformers`).
80
+ - GIL-released training and encoding, with `Ctrl+C`, `CancellationToken` and
81
+ `timeout` support.
82
+ - Legacy command aliases (`train_vocab`, `sweep_vocab`, `cut_vocab`,
83
+ `sample_corpus`, `inspect_model`, `compare_merges`); deprecated and slated
84
+ for removal in a future major release.
85
+
86
+ ### Known limitations
87
+
88
+ - Throughput figures are measured on Chinese web text; English- or
89
+ code-heavy corpora should be re-benchmarked.
90
+ - Peak memory is modelled as `9.2 × corpus bytes`; for corpora far above the
91
+ validated 8.28 GB, run a sampled pilot before a full job.
92
+ - `encode` accepts `&str` only (matching `tiktoken`); byte-level input is not
93
+ exposed directly.
94
+ - CLI exit status is `0` when every corpus line is skipped; check the reported
95
+ counters when a run produces a degenerate model.
96
+
97
+ [Unreleased]: https://github.com/hoare211/bbpe_rs/compare/v0.5.4...HEAD
98
+ [0.5.4]: https://github.com/hoare211/bbpe_rs/releases/tag/v0.5.4
99
+ [0.5.3]: https://github.com/hoare211/bbpe_rs/releases/tag/v0.5.3
100
+ [0.5.2]: https://github.com/hoare211/bbpe_rs/releases/tag/v0.5.2
101
+ [0.5.1]: https://github.com/hoare211/bbpe_rs/releases/tag/v0.5.1
102
+ [0.5.0]: https://github.com/hoare211/bbpe_rs/releases/tag/v0.5.0
103
+ [0.1.0]: https://github.com/hoare211/bbpe_rs/releases/tag/v0.1.0
@@ -0,0 +1,75 @@
1
+ # Contributing
2
+
3
+ Thanks for considering a contribution. This document covers the local setup and
4
+ the checks a pull request must pass.
5
+
6
+ ## Prerequisites
7
+
8
+ - Rust 1.85 or newer (`rustup toolchain install stable`)
9
+ - Python 3.8+ and `maturin` for the Python bindings
10
+ - `pytest` for the Python test suite
11
+
12
+ ## Build and test
13
+
14
+ ```bash
15
+ # CLI only (no pyo3, fastest loop)
16
+ cargo build --release --no-default-features
17
+
18
+ # Rust tests, CLI feature set
19
+ cargo test --locked --no-default-features
20
+
21
+ # Formatting and lints (both are enforced in CI)
22
+ cargo fmt --all --check
23
+ cargo clippy --locked --no-default-features --all-targets -- -D warnings
24
+ ```
25
+
26
+ Python bindings:
27
+
28
+ ```bash
29
+ python -m venv .venv
30
+ source .venv/bin/activate
31
+ pip install maturin pytest jinja2
32
+ maturin develop --release
33
+ python -m pytest tests/ -q
34
+ ```
35
+
36
+ `cargo test` without `--no-default-features` compiles the pyo3 binding layer and
37
+ therefore needs the Python development headers (`libpython3.x-dev` on Debian or
38
+ Ubuntu). CI covers the binding layer through the wheel build instead.
39
+
40
+ ## Making changes
41
+
42
+ - Keep changes focused; unrelated refactors make review harder.
43
+ - Add or update tests for behaviour changes. Rust integration tests live in
44
+ `tests/`, Python tests in `tests/test_*.py`.
45
+ - Do not introduce `unsafe` code in `src/`.
46
+ - User-facing behaviour changes need a `CHANGELOG.md` entry under
47
+ `[Unreleased]`.
48
+ - Document model-format or CLI contract changes in `docs/使用说明.md`.
49
+
50
+ ## Commit messages
51
+
52
+ Use conventional-commit prefixes, matching the existing history:
53
+
54
+ ```text
55
+ feat(train): add --sample-seed
56
+ fix(encode): reject empty special tokens
57
+ docs: clarify held-out acceptance
58
+ test(release): cover version consistency
59
+ ```
60
+
61
+ Keep the subject under ~72 characters, in the imperative mood.
62
+
63
+ ## Pull request checklist
64
+
65
+ - [ ] `cargo fmt --all --check` passes
66
+ - [ ] `cargo clippy --locked --no-default-features --all-targets -- -D warnings` passes
67
+ - [ ] `cargo test --locked --no-default-features` passes
68
+ - [ ] Python tests pass if the binding layer changed
69
+ - [ ] `CHANGELOG.md` updated for user-visible changes
70
+ - [ ] No new `unsafe`, no secrets, no local absolute paths in committed files
71
+
72
+ ## License
73
+
74
+ By submitting a pull request you agree that your contribution is dual licensed
75
+ under MIT and Apache-2.0, as described in the README.