fastokens 0.1.1__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.
- fastokens-0.1.1/.cargo/config.toml +2 -0
- fastokens-0.1.1/.github/workflows/build-maturin.yml +222 -0
- fastokens-0.1.1/.github/workflows/build-release-fastokens.yml +42 -0
- fastokens-0.1.1/.github/workflows/ci.yml +91 -0
- fastokens-0.1.1/.gitignore +7 -0
- fastokens-0.1.1/Cargo.lock +2487 -0
- fastokens-0.1.1/Cargo.toml +40 -0
- fastokens-0.1.1/LICENSE +177 -0
- fastokens-0.1.1/NOTICES.txt +82 -0
- fastokens-0.1.1/PKG-INFO +7 -0
- fastokens-0.1.1/README.md +82 -0
- fastokens-0.1.1/assets/speedup_average.png +0 -0
- fastokens-0.1.1/assets/speedup_oss.png +0 -0
- fastokens-0.1.1/assets/ttft_p50.png +0 -0
- fastokens-0.1.1/examples/ablation.sh +177 -0
- fastokens-0.1.1/examples/dynamo_ablation.py +339 -0
- fastokens-0.1.1/examples/dynamo_speed.py +1128 -0
- fastokens-0.1.1/examples/get_step_kinds.rs +107 -0
- fastokens-0.1.1/examples/print_pipeline.rs +26 -0
- fastokens-0.1.1/examples/profile_sample.rs +135 -0
- fastokens-0.1.1/examples/profile_stages.rs +274 -0
- fastokens-0.1.1/examples/sglang_quality.py +428 -0
- fastokens-0.1.1/examples/sglang_speed.py +631 -0
- fastokens-0.1.1/examples/simple_bench.rs +435 -0
- fastokens-0.1.1/examples/validate_model.sh +43 -0
- fastokens-0.1.1/pyproject.toml +13 -0
- fastokens-0.1.1/python/Cargo.toml +19 -0
- fastokens-0.1.1/python/fastokens/__init__.py +134 -0
- fastokens-0.1.1/python/fastokens/_compat.py +426 -0
- fastokens-0.1.1/python/fastokens/_native.pyi +140 -0
- fastokens-0.1.1/python/src/lib.rs +922 -0
- fastokens-0.1.1/python/tests/test_patch_transformers.py +57 -0
- fastokens-0.1.1/src/added_tokens.rs +519 -0
- fastokens-0.1.1/src/decoders/byte_level.rs +91 -0
- fastokens-0.1.1/src/decoders.rs +68 -0
- fastokens-0.1.1/src/json_structs.rs +281 -0
- fastokens-0.1.1/src/lib.rs +1858 -0
- fastokens-0.1.1/src/models/bpe.rs +1374 -0
- fastokens-0.1.1/src/models.rs +89 -0
- fastokens-0.1.1/src/normalizers/nfc.rs +77 -0
- fastokens-0.1.1/src/normalizers.rs +61 -0
- fastokens-0.1.1/src/post_processors.rs +522 -0
- fastokens-0.1.1/src/pre_tokenized.rs +350 -0
- fastokens-0.1.1/src/pre_tokenizers/byte_level.rs +540 -0
- fastokens-0.1.1/src/pre_tokenizers/split.rs +1510 -0
- fastokens-0.1.1/src/pre_tokenizers.rs +79 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# This file is autogenerated by maturin v1.8.1
|
|
2
|
+
# To update, run
|
|
3
|
+
#
|
|
4
|
+
# maturin generate-ci github
|
|
5
|
+
#
|
|
6
|
+
name: build-maturin
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
workflow_call:
|
|
10
|
+
inputs:
|
|
11
|
+
publish_pypi:
|
|
12
|
+
description: "Whether to publish the package to PyPI."
|
|
13
|
+
required: false
|
|
14
|
+
type: boolean
|
|
15
|
+
default: false
|
|
16
|
+
secrets:
|
|
17
|
+
PYPI_TOKEN:
|
|
18
|
+
description: "The PyPI token for publishing."
|
|
19
|
+
required: true
|
|
20
|
+
|
|
21
|
+
permissions:
|
|
22
|
+
contents: read
|
|
23
|
+
id-token: write
|
|
24
|
+
attestations: write
|
|
25
|
+
|
|
26
|
+
jobs:
|
|
27
|
+
linux:
|
|
28
|
+
runs-on: ${{ matrix.platform.runner }}
|
|
29
|
+
strategy:
|
|
30
|
+
matrix:
|
|
31
|
+
platform:
|
|
32
|
+
- runner: ubuntu-22.04
|
|
33
|
+
target: x86_64
|
|
34
|
+
manylinux: auto
|
|
35
|
+
ft: true
|
|
36
|
+
- runner: ubuntu-22.04
|
|
37
|
+
target: x86
|
|
38
|
+
manylinux: auto
|
|
39
|
+
ft: true
|
|
40
|
+
- runner: ubuntu-22.04
|
|
41
|
+
target: aarch64
|
|
42
|
+
manylinux: manylinux_2_28
|
|
43
|
+
ft: false
|
|
44
|
+
- runner: ubuntu-22.04
|
|
45
|
+
target: armv7
|
|
46
|
+
manylinux: manylinux_2_28
|
|
47
|
+
ft: false
|
|
48
|
+
- runner: ubuntu-22.04
|
|
49
|
+
target: ppc64le
|
|
50
|
+
manylinux: manylinux_2_28
|
|
51
|
+
ft: true
|
|
52
|
+
steps:
|
|
53
|
+
- uses: actions/checkout@v6
|
|
54
|
+
- uses: actions/setup-python@v6
|
|
55
|
+
with:
|
|
56
|
+
python-version: 3.x
|
|
57
|
+
- name: Build wheels
|
|
58
|
+
uses: PyO3/maturin-action@v1
|
|
59
|
+
with:
|
|
60
|
+
target: ${{ matrix.platform.target }}
|
|
61
|
+
args: --release --out dist --find-interpreter
|
|
62
|
+
sccache: "false"
|
|
63
|
+
manylinux: ${{ matrix.platform.manylinux }}
|
|
64
|
+
before-script-linux: |
|
|
65
|
+
if command -v apt-get &> /dev/null; then
|
|
66
|
+
apt-get update && apt-get install libssl-dev libatomic-ops-dev -y
|
|
67
|
+
elif command -v yum &> /dev/null; then
|
|
68
|
+
yum install openssl-devel perl-IPC-Cmd -y
|
|
69
|
+
else
|
|
70
|
+
echo "Neither apt-get nor yum is installed. Please install a package manager."
|
|
71
|
+
exit 1
|
|
72
|
+
fi
|
|
73
|
+
- name: Build free-threaded wheels
|
|
74
|
+
uses: PyO3/maturin-action@v1
|
|
75
|
+
if: ${{ matrix.platform.ft }}
|
|
76
|
+
with:
|
|
77
|
+
target: ${{ matrix.platform.target }}
|
|
78
|
+
args: --release --out dist -i python3.13t
|
|
79
|
+
sccache: "false"
|
|
80
|
+
manylinux: auto
|
|
81
|
+
before-script-linux: |
|
|
82
|
+
if command -v apt-get &> /dev/null; then
|
|
83
|
+
apt-get update && apt-get install libssl-dev libatomic-ops-dev -y
|
|
84
|
+
elif command -v yum &> /dev/null; then
|
|
85
|
+
yum install openssl-devel perl-IPC-Cmd -y
|
|
86
|
+
else
|
|
87
|
+
echo "Neither apt-get nor yum is installed. Please install a package manager."
|
|
88
|
+
exit 1
|
|
89
|
+
fi
|
|
90
|
+
- name: Upload wheels
|
|
91
|
+
uses: actions/upload-artifact@v4
|
|
92
|
+
with:
|
|
93
|
+
name: wheels-linux-${{ matrix.platform.target }}
|
|
94
|
+
path: dist
|
|
95
|
+
|
|
96
|
+
musllinux:
|
|
97
|
+
runs-on: ${{ matrix.platform.runner }}
|
|
98
|
+
strategy:
|
|
99
|
+
matrix:
|
|
100
|
+
platform:
|
|
101
|
+
- runner: ubuntu-22.04
|
|
102
|
+
target: x86_64
|
|
103
|
+
- runner: ubuntu-22.04
|
|
104
|
+
target: x86
|
|
105
|
+
- runner: ubuntu-22.04
|
|
106
|
+
target: aarch64
|
|
107
|
+
- runner: ubuntu-22.04
|
|
108
|
+
target: armv7
|
|
109
|
+
steps:
|
|
110
|
+
- uses: actions/checkout@v6
|
|
111
|
+
- uses: actions/setup-python@v6
|
|
112
|
+
with:
|
|
113
|
+
python-version: 3.x
|
|
114
|
+
- name: Build wheels
|
|
115
|
+
uses: PyO3/maturin-action@v1
|
|
116
|
+
with:
|
|
117
|
+
target: ${{ matrix.platform.target }}
|
|
118
|
+
args: --release --out dist --find-interpreter
|
|
119
|
+
sccache: "false"
|
|
120
|
+
manylinux: musllinux_1_2
|
|
121
|
+
- name: Build free-threaded wheels
|
|
122
|
+
uses: PyO3/maturin-action@v1
|
|
123
|
+
with:
|
|
124
|
+
target: ${{ matrix.platform.target }}
|
|
125
|
+
args: --release --out dist -i python3.13t
|
|
126
|
+
sccache: "false"
|
|
127
|
+
manylinux: musllinux_1_2
|
|
128
|
+
- name: Upload wheels
|
|
129
|
+
uses: actions/upload-artifact@v4
|
|
130
|
+
with:
|
|
131
|
+
name: wheels-musllinux-${{ matrix.platform.target }}
|
|
132
|
+
path: dist
|
|
133
|
+
|
|
134
|
+
windows:
|
|
135
|
+
runs-on: windows-latest
|
|
136
|
+
steps:
|
|
137
|
+
- uses: actions/checkout@v6
|
|
138
|
+
- uses: actions/setup-python@v6
|
|
139
|
+
with:
|
|
140
|
+
python-version: 3.x
|
|
141
|
+
architecture: x64
|
|
142
|
+
- name: Build wheels
|
|
143
|
+
uses: PyO3/maturin-action@v1
|
|
144
|
+
with:
|
|
145
|
+
target: x64
|
|
146
|
+
args: --release --out dist --find-interpreter
|
|
147
|
+
sccache: "false"
|
|
148
|
+
- name: Upload wheels
|
|
149
|
+
uses: actions/upload-artifact@v4
|
|
150
|
+
with:
|
|
151
|
+
name: wheels-windows-x64
|
|
152
|
+
path: dist
|
|
153
|
+
|
|
154
|
+
macos:
|
|
155
|
+
runs-on: ${{ matrix.platform.runner }}
|
|
156
|
+
strategy:
|
|
157
|
+
matrix:
|
|
158
|
+
platform:
|
|
159
|
+
- runner: macos-15
|
|
160
|
+
target: x86_64
|
|
161
|
+
- runner: macos-15
|
|
162
|
+
target: aarch64
|
|
163
|
+
steps:
|
|
164
|
+
- uses: actions/checkout@v6
|
|
165
|
+
- uses: actions/setup-python@v6
|
|
166
|
+
with:
|
|
167
|
+
python-version: 3.x
|
|
168
|
+
- name: Build wheels
|
|
169
|
+
uses: PyO3/maturin-action@v1
|
|
170
|
+
with:
|
|
171
|
+
target: ${{ matrix.platform.target }}
|
|
172
|
+
args: --release --out dist --find-interpreter
|
|
173
|
+
sccache: "false"
|
|
174
|
+
- name: Build free-threaded wheels
|
|
175
|
+
uses: PyO3/maturin-action@v1
|
|
176
|
+
with:
|
|
177
|
+
target: ${{ matrix.platform.target }}
|
|
178
|
+
args: --release --out dist -i python3.13t
|
|
179
|
+
sccache: "false"
|
|
180
|
+
- name: Upload wheels
|
|
181
|
+
uses: actions/upload-artifact@v4
|
|
182
|
+
with:
|
|
183
|
+
name: wheels-macos-${{ matrix.platform.target }}
|
|
184
|
+
path: dist
|
|
185
|
+
|
|
186
|
+
sdist:
|
|
187
|
+
runs-on: ubuntu-latest
|
|
188
|
+
steps:
|
|
189
|
+
- uses: actions/checkout@v6
|
|
190
|
+
- name: Build sdist
|
|
191
|
+
uses: PyO3/maturin-action@v1
|
|
192
|
+
with:
|
|
193
|
+
command: sdist
|
|
194
|
+
args: --out dist
|
|
195
|
+
- name: Upload sdist
|
|
196
|
+
uses: actions/upload-artifact@v4
|
|
197
|
+
with:
|
|
198
|
+
name: wheels-sdist
|
|
199
|
+
path: dist
|
|
200
|
+
|
|
201
|
+
release:
|
|
202
|
+
name: Release
|
|
203
|
+
runs-on: ubuntu-latest
|
|
204
|
+
if: ${{ github.event_name == 'workflow_dispatch' }}
|
|
205
|
+
needs: [linux, musllinux, windows, macos, sdist]
|
|
206
|
+
permissions:
|
|
207
|
+
id-token: write
|
|
208
|
+
attestations: write
|
|
209
|
+
steps:
|
|
210
|
+
- uses: actions/download-artifact@v4
|
|
211
|
+
- name: Generate artifact attestation
|
|
212
|
+
uses: actions/attest-build-provenance@v1
|
|
213
|
+
with:
|
|
214
|
+
subject-path: "wheels-*/*"
|
|
215
|
+
- name: Publish to PyPI
|
|
216
|
+
if: ${{ inputs.publish_pypi }}
|
|
217
|
+
uses: PyO3/maturin-action@v1
|
|
218
|
+
env:
|
|
219
|
+
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
|
|
220
|
+
with:
|
|
221
|
+
command: upload
|
|
222
|
+
args: --non-interactive --skip-existing wheels-*/*
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
name: Build and Release fastokens
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
- master
|
|
8
|
+
paths:
|
|
9
|
+
- "python/**"
|
|
10
|
+
- "src/**"
|
|
11
|
+
- "Cargo.toml"
|
|
12
|
+
- "Cargo.lock"
|
|
13
|
+
- ".github/workflows/**"
|
|
14
|
+
tags:
|
|
15
|
+
- "*"
|
|
16
|
+
pull_request:
|
|
17
|
+
paths:
|
|
18
|
+
- "python/**"
|
|
19
|
+
- "src/**"
|
|
20
|
+
- "Cargo.toml"
|
|
21
|
+
- "Cargo.lock"
|
|
22
|
+
- ".github/workflows/**"
|
|
23
|
+
workflow_dispatch:
|
|
24
|
+
inputs:
|
|
25
|
+
publish_pypi:
|
|
26
|
+
description: "Publish to PyPI?"
|
|
27
|
+
required: false
|
|
28
|
+
type: boolean
|
|
29
|
+
default: false
|
|
30
|
+
|
|
31
|
+
permissions:
|
|
32
|
+
contents: read
|
|
33
|
+
id-token: write
|
|
34
|
+
attestations: write
|
|
35
|
+
|
|
36
|
+
jobs:
|
|
37
|
+
build-package:
|
|
38
|
+
uses: ./.github/workflows/build-maturin.yml
|
|
39
|
+
with:
|
|
40
|
+
publish_pypi: ${{ github.event_name == 'workflow_dispatch' && fromJSON(github.event.inputs.publish_pypi) }}
|
|
41
|
+
secrets:
|
|
42
|
+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
env:
|
|
10
|
+
CARGO_TERM_COLOR: always
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v6
|
|
17
|
+
|
|
18
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
19
|
+
with:
|
|
20
|
+
components: rustfmt, clippy
|
|
21
|
+
|
|
22
|
+
- uses: Swatinem/rust-cache@v2
|
|
23
|
+
|
|
24
|
+
- name: Check formatting
|
|
25
|
+
run: cargo fmt --check
|
|
26
|
+
|
|
27
|
+
- name: Run clippy
|
|
28
|
+
run: cargo clippy -- -D warnings
|
|
29
|
+
|
|
30
|
+
- name: Run tests
|
|
31
|
+
run: cargo test
|
|
32
|
+
|
|
33
|
+
install:
|
|
34
|
+
runs-on: ubuntu-latest
|
|
35
|
+
steps:
|
|
36
|
+
- uses: actions/checkout@v6
|
|
37
|
+
|
|
38
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
39
|
+
|
|
40
|
+
- uses: Swatinem/rust-cache@v2
|
|
41
|
+
|
|
42
|
+
- uses: actions/setup-python@v5
|
|
43
|
+
with:
|
|
44
|
+
python-version: "3.12"
|
|
45
|
+
|
|
46
|
+
- name: Install maturin
|
|
47
|
+
run: pip install maturin
|
|
48
|
+
|
|
49
|
+
- name: Build and install wheel
|
|
50
|
+
run: maturin build --release --out dist && pip install dist/*.whl
|
|
51
|
+
|
|
52
|
+
- name: Smoke test
|
|
53
|
+
run: |
|
|
54
|
+
python - <<'EOF'
|
|
55
|
+
import fastokens
|
|
56
|
+
tok = fastokens.Tokenizer.from_model("Qwen/Qwen3-0.6B")
|
|
57
|
+
ids = tok.encode("hello world", add_special_tokens=False)
|
|
58
|
+
assert len(ids.ids) > 0, "encode returned empty ids"
|
|
59
|
+
decoded = tok.decode(list(ids.ids))
|
|
60
|
+
assert decoded == "hello world", f"unexpected decode: {decoded!r}"
|
|
61
|
+
print("smoke test passed")
|
|
62
|
+
EOF
|
|
63
|
+
|
|
64
|
+
patch-transformers:
|
|
65
|
+
runs-on: ubuntu-latest
|
|
66
|
+
strategy:
|
|
67
|
+
fail-fast: false
|
|
68
|
+
matrix:
|
|
69
|
+
transformers: ["4.57.1", "5.3.0"]
|
|
70
|
+
steps:
|
|
71
|
+
- uses: actions/checkout@v6
|
|
72
|
+
|
|
73
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
74
|
+
|
|
75
|
+
- uses: Swatinem/rust-cache@v2
|
|
76
|
+
|
|
77
|
+
- uses: actions/setup-python@v5
|
|
78
|
+
with:
|
|
79
|
+
python-version: "3.12"
|
|
80
|
+
|
|
81
|
+
- name: Install maturin
|
|
82
|
+
run: pip install maturin
|
|
83
|
+
|
|
84
|
+
- name: Build and install wheel
|
|
85
|
+
run: maturin build --release --out dist && pip install dist/*.whl
|
|
86
|
+
|
|
87
|
+
- name: Install transformers ${{ matrix.transformers }} and pytest
|
|
88
|
+
run: pip install transformers==${{ matrix.transformers }} pytest
|
|
89
|
+
|
|
90
|
+
- name: Test patch_transformers
|
|
91
|
+
run: pytest python/tests/test_patch_transformers.py -v
|