Skip to content

Commit 4c2e48a

Browse files
authored
Update to PyO3 0.28 to automatically disable GIL (#1948)
* Update to PyO3 0.28 to automatically disable GIL * Use from_py_object for all PyClasses that derive Clone * Update PyO3 to 0.28.1 * Update to PyO3 0.28.2 * Update dev-dependencies as well
1 parent c58a474 commit 4c2e48a

File tree

11 files changed

+36
-17
lines changed

11 files changed

+36
-17
lines changed

bindings/python/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ serde = { version = "1.0", features = ["rc", "derive"] }
1414
serde_json = "1.0"
1515
libc = "0.2"
1616
env_logger = "0.11"
17-
pyo3 = { version = "0.27.2",default-features = false, features = ["abi3", "abi3-py39", "py-clone", "experimental-inspect"] }
18-
pyo3-async-runtimes = { version = "0.27.0", features = ["tokio-runtime"] }
17+
pyo3 = { version = "0.28.2",default-features = false, features = ["abi3", "abi3-py39", "py-clone", "experimental-inspect"] }
18+
pyo3-async-runtimes = { version = "0.28.0", features = ["tokio-runtime"] }
1919
tokio = { version = "1.47.1", features = ["rt", "rt-multi-thread", "macros", "signal"] }
2020
once_cell = "1.19.0"
21-
numpy = "0.27"
21+
numpy = "0.28"
2222
ndarray = "0.16"
2323
itertools = "0.14"
2424
ahash = { version = "0.8.11", features = ["serde"] }
25-
pyo3-ffi = "0.27.2"
25+
pyo3-ffi = "0.28.2"
2626

2727
[dependencies.tokenizers]
2828
path = "../../tokenizers"
2929

3030
[dev-dependencies]
3131
tempfile = "3.10"
32-
pyo3 = { version = "0.27.2", features = ["auto-initialize"] }
32+
pyo3 = { version = "0.28.2", features = ["auto-initialize"] }
3333

3434

3535
[features]

bindings/python/src/decoders.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ use super::error::ToPyResult;
2828
///
2929
/// This class is not supposed to be instantiated directly. Instead, any implementation of
3030
/// a Decoder will return an instance of this class when instantiated.
31-
#[pyclass(dict, module = "tokenizers.decoders", name = "Decoder", subclass)]
31+
#[pyclass(
32+
dict,
33+
module = "tokenizers.decoders",
34+
name = "Decoder",
35+
subclass,
36+
from_py_object
37+
)]
3238
#[derive(Clone, Deserialize, Serialize)]
3339
#[serde(transparent)]
3440
pub struct PyDecoder {
@@ -610,7 +616,7 @@ pub mod decoders {
610616

611617
/// Class needed for streaming decode
612618
///
613-
#[pyclass(module = "tokenizers.decoders", name = "DecodeStream")]
619+
#[pyclass(module = "tokenizers.decoders", name = "DecodeStream", from_py_object)]
614620
#[derive(Clone)]
615621
pub struct PyDecodeStream {
616622
/// Regular decode option that is kept throughout.

bindings/python/src/models.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use super::error::{deprecation_warning, ToPyResult};
2525
/// will contain and manage the learned vocabulary.
2626
///
2727
/// This class cannot be constructed directly. Please use one of the concrete models.
28-
#[pyclass(module = "tokenizers.models", name = "Model", subclass)]
28+
#[pyclass(module = "tokenizers.models", name = "Model", subclass, from_py_object)]
2929
#[derive(Clone, Serialize, Deserialize)]
3030
#[serde(transparent)]
3131
pub struct PyModel {

bindings/python/src/normalizers.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ impl PyNormalizedStringMut<'_> {
4141
///
4242
/// This class is not supposed to be instantiated directly. Instead, any implementation of a
4343
/// Normalizer will return an instance of this class when instantiated.
44-
#[pyclass(dict, module = "tokenizers.normalizers", name = "Normalizer", subclass)]
44+
#[pyclass(
45+
dict,
46+
module = "tokenizers.normalizers",
47+
name = "Normalizer",
48+
subclass,
49+
from_py_object
50+
)]
4551
#[derive(Clone, Debug, Serialize, Deserialize)]
4652
#[serde(transparent)]
4753
pub struct PyNormalizer {

bindings/python/src/pre_tokenizers.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ use super::utils::*;
3434
dict,
3535
module = "tokenizers.pre_tokenizers",
3636
name = "PreTokenizer",
37-
subclass
37+
subclass,
38+
from_py_object
3839
)]
3940
#[derive(Clone, Serialize, Deserialize)]
4041
#[serde(transparent)]

bindings/python/src/processors.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ use tokenizers as tk;
2929
dict,
3030
module = "tokenizers.processors",
3131
name = "PostProcessor",
32-
subclass
32+
subclass,
33+
from_py_object
3334
)]
3435
#[derive(Clone, Deserialize, Serialize)]
3536
#[serde(transparent)]

bindings/python/src/token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use pyo3::prelude::*;
22
use tk::Token;
33

4-
#[pyclass(module = "tokenizers", name = "Token", frozen)]
4+
#[pyclass(module = "tokenizers", name = "Token", frozen, from_py_object)]
55
#[derive(Clone)]
66
pub struct PyToken {
77
token: Token,

bindings/python/src/tokenizer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ type Tokenizer = TokenizerImpl<PyModel, PyNormalizer, PyPreTokenizer, PyPostProc
482482
/// model (:class:`~tokenizers.models.Model`):
483483
/// The core algorithm that this :obj:`Tokenizer` should be using.
484484
///
485-
#[pyclass(dict, module = "tokenizers", name = "Tokenizer")]
485+
#[pyclass(dict, module = "tokenizers", name = "Tokenizer", from_py_object)]
486486
#[derive(Clone, Serialize)]
487487
#[serde(transparent)]
488488
pub struct PyTokenizer {

bindings/python/src/trainers.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ use tokenizers as tk;
1414
///
1515
/// This class is not supposed to be instantiated directly. Instead, any implementation of a
1616
/// Trainer will return an instance of this class when instantiated.
17-
#[pyclass(module = "tokenizers.trainers", name = "Trainer", subclass)]
17+
#[pyclass(
18+
module = "tokenizers.trainers",
19+
name = "Trainer",
20+
subclass,
21+
from_py_object
22+
)]
1823
#[derive(Clone, Deserialize, Serialize)]
1924
#[serde(transparent)]
2025
pub struct PyTrainer {

bindings/python/src/utils/normalization.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ fn slice(
196196
/// Args:
197197
/// sequence: str:
198198
/// The string sequence used to initialize this NormalizedString
199-
#[pyclass(module = "tokenizers", name = "NormalizedString")]
199+
#[pyclass(module = "tokenizers", name = "NormalizedString", from_py_object)]
200200
#[derive(Clone)]
201201
pub struct PyNormalizedString {
202202
pub(crate) normalized: NormalizedString,
@@ -388,7 +388,7 @@ impl From<PyNormalizedString> for NormalizedString {
388388
}
389389
}
390390

391-
#[pyclass(module = "tokenizers", name = "NormalizedStringRefMut")]
391+
#[pyclass(module = "tokenizers", name = "NormalizedStringRefMut", from_py_object)]
392392
#[derive(Clone)]
393393
pub struct PyNormalizedStringRefMut {
394394
inner: RefMutContainer<NormalizedString>,

0 commit comments

Comments
 (0)