Skip to content

Commit 2ab6d37

Browse files
authored
Support the free-threaded build (#443)
See #406 (comment). It may be a little presumptuous to add wheel builds already but it looks like that's how CI is set up in this repo. It may also make sense to add some more tests that use either `rayon` or the python `threading` module. That said, IMO you'd be testing guarantees provided by PyO3 more than tiktoken itself.
1 parent 82dc3bb commit 2ab6d37

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

.github/workflows/build_wheels.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ jobs:
1717
# cibuildwheel builds linux wheels inside a manylinux container
1818
# it also takes care of procuring the correct python version for us
1919
os: [ubuntu-latest, windows-latest, macos-latest]
20-
python-version: [39, 310, 311, 312, 313]
20+
python-version: [39, 310, 311, 312, 313, 313t, 314, 314t]
2121

2222
steps:
2323
- uses: actions/checkout@v4
2424

25-
- uses: pypa/cibuildwheel@v2.22.0
25+
- uses: pypa/cibuildwheel@v3.1.4
2626
env:
2727
CIBW_BUILD: "cp${{ matrix.python-version}}-*"
28+
CIBW_ENABLE: cpython-freethreading
2829

2930
- uses: actions/upload-artifact@v4
3031
with:
@@ -39,19 +40,20 @@ jobs:
3940
fail-fast: false
4041
matrix:
4142
os: [ubuntu-24.04-arm]
42-
python-version: [39, 310, 311, 312, 313]
43+
python-version: [39, 310, 311, 312, 313, 313t, 314, 314t]
4344

4445
steps:
4546
- uses: actions/checkout@v4
4647

4748
- name: Build wheels
48-
uses: pypa/cibuildwheel@v2.22.0
49+
uses: pypa/cibuildwheel@v3.1.4
4950
env:
5051
CIBW_BUILD: "cp${{ matrix.python-version}}-*"
5152
CIBW_ARCHS: aarch64
5253
CIBW_BUILD_VERBOSITY: 3
5354
# https://github.com/rust-lang/cargo/issues/10583
5455
CIBW_ENVIRONMENT_LINUX: PATH="$PATH:$HOME/.cargo/bin" CARGO_NET_GIT_FETCH_WITH_CLI=true
56+
CIBW_ENABLE: cpython-freethreading
5557

5658
- uses: actions/upload-artifact@v4
5759
with:

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl std::error::Error for EncodeError {}
187187

188188
const MAX_NUM_THREADS: usize = 128;
189189

190-
#[cfg_attr(feature = "python", pyclass)]
190+
#[cfg_attr(feature = "python", pyclass(frozen))]
191191
#[derive(Clone)]
192192
pub struct CoreBPE {
193193
encoder: HashMap<Vec<u8>, Rank>,

src/py.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl CoreBPE {
183183
}
184184
}
185185

186-
#[pyclass]
186+
#[pyclass(frozen)]
187187
struct TiktokenBuffer {
188188
tokens: Vec<Rank>,
189189
}
@@ -248,7 +248,7 @@ impl TiktokenBuffer {
248248
}
249249
}
250250

251-
#[pymodule]
251+
#[pymodule(gil_used = false)]
252252
fn _tiktoken(_py: Python, m: &Bound<PyModule>) -> PyResult<()> {
253253
m.add_class::<CoreBPE>()?;
254254
Ok(())

0 commit comments

Comments
 (0)