Skip to content

Commit

Permalink
Testing ABI3 wheels to reduce number of wheels (#1674)
Browse files Browse the repository at this point in the history
* Testing ABI3 wheels to reduce number of wheels

* No need for py-clone  anymore.

* Upgrade python versions.

* Remove those flakes.

* Promoting new CI + Fixing secret.
  • Loading branch information
Narsil authored Nov 15, 2024
1 parent 5aa9f6c commit f4c9fd7
Show file tree
Hide file tree
Showing 14 changed files with 246 additions and 66 deletions.
181 changes: 181 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
# This file is autogenerated by maturin v1.7.4
# To update, run
#
# maturin generate-ci github -m bindings/python/Cargo.toml
#
name: CI

on:
push:
branches:
- main
- master
tags:
- '*'
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
linux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
- runner: ubuntu-latest
target: s390x
- runner: ubuntu-latest
target: ppc64le
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --manifest-path bindings/python/Cargo.toml
sccache: 'true'
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.platform.target }}
path: dist

musllinux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --manifest-path bindings/python/Cargo.toml
sccache: 'true'
manylinux: musllinux_1_2
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-musllinux-${{ matrix.platform.target }}
path: dist

windows:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: windows-latest
target: x64
- runner: windows-latest
target: x86
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
architecture: ${{ matrix.platform.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --manifest-path bindings/python/Cargo.toml
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.platform.target }}
path: dist

macos:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: macos-12
target: x86_64
- runner: macos-14
target: aarch64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --manifest-path bindings/python/Cargo.toml
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.platform.target }}
path: dist

sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist --manifest-path bindings/python/Cargo.toml
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: dist

release:
name: Release
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
needs: [linux, musllinux, windows, macos, sdist]
permissions:
# Use to sign the release artifacts
id-token: write
# Used to upload release artifacts
contents: write
# Used to generate artifact attestation
attestations: write
steps:
- uses: actions/download-artifact@v4
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-path: 'wheels-*/*'
- name: Publish to PyPI
if: "startsWith(github.ref, 'refs/tags/')"
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_TOKEN_DIST}}
with:
command: upload
args: --non-interactive --skip-existing wheels-*/*
11 changes: 6 additions & 5 deletions .github/workflows/python-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ jobs:
with:
path: ./bindings/python/dist
merge-multiple: true
- name: Upload to PyPi
working-directory: ./bindings/python
run: |
pip install twine
twine upload dist/* -u __token__ -p "$PYPI_TOKEN"
# Temporary deactivation while testing abi3 CI
# - name: Upload to PyPi
# working-directory: ./bindings/python
# run: |
# pip install twine
# twine upload dist/* -u __token__ -p "$PYPI_TOKEN"
4 changes: 2 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
python: ["3.7", "3.8", "3.9", "3.10"]
python: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: 3.11
python-version: 3.13
architecture: "x64"


Expand Down
4 changes: 2 additions & 2 deletions bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ serde = { version = "1.0", features = ["rc", "derive"] }
serde_json = "1.0"
libc = "0.2"
env_logger = "0.11"
pyo3 = { version = "0.22", features = ["py-clone"] }
pyo3 = { version = "0.22", features = ["abi3", "abi3-py39"] }
numpy = "0.22"
ndarray = "0.15"
itertools = "0.12"
Expand All @@ -24,7 +24,7 @@ path = "../../tokenizers"

[dev-dependencies]
tempfile = "3.10"
pyo3 = { version = "0.22", features = ["auto-initialize", "py-clone"] }
pyo3 = { version = "0.22", features = ["auto-initialize"] }

[features]
defaut = ["pyo3/extension-module"]
1 change: 0 additions & 1 deletion bindings/python/src/decoders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ impl PySequenceDecoder {
}
}

#[derive(Clone)]
pub(crate) struct CustomDecoder {
inner: PyObject,
}
Expand Down
8 changes: 4 additions & 4 deletions bindings/python/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,11 @@ impl PyEncoding {

if let Some(kwargs) = kwargs {
for (key, value) in kwargs {
let key: &str = key.extract()?;
match key {
let key: String = key.extract()?;
match key.as_ref() {
"direction" => {
let value: &str = value.extract()?;
direction = match value {
let value: String = value.extract()?;
direction = match value.as_ref() {
"left" => Ok(PaddingDirection::Left),
"right" => Ok(PaddingDirection::Right),
other => Err(PyError(format!(
Expand Down
8 changes: 4 additions & 4 deletions bindings/python/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ impl PyBPE {
) -> PyResult<(Self, PyModel)> {
if let Some(kwargs) = kwargs {
for (key, value) in kwargs {
let key: &str = key.extract()?;
match key {
let key: String = key.extract()?;
match key.as_ref() {
"cache_capacity" => builder = builder.cache_capacity(value.extract()?),
"dropout" => {
if let Some(dropout) = value.extract()? {
Expand Down Expand Up @@ -581,8 +581,8 @@ impl PyWordPiece {
) -> PyResult<(Self, PyModel)> {
if let Some(kwargs) = kwargs {
for (key, val) in kwargs {
let key: &str = key.extract()?;
match key {
let key: String = key.extract()?;
match key.as_ref() {
"unk_token" => {
builder = builder.unk_token(val.extract()?);
}
Expand Down
9 changes: 4 additions & 5 deletions bindings/python/src/normalizers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,8 @@ macro_rules! getter {
let super_ = $self.as_ref();
if let PyNormalizerTypeWrapper::Single(ref norm) = super_.normalizer {
let wrapper = norm.read().unwrap();
if let PyNormalizerWrapper::Wrapped(NormalizerWrapper::$variant(o)) = (*wrapper).clone()
{
o.$name
if let PyNormalizerWrapper::Wrapped(NormalizerWrapper::$variant(o)) = (&*wrapper) {
o.$name.clone()
} else {
unreachable!()
}
Expand Down Expand Up @@ -538,7 +537,7 @@ impl PyReplace {
}
}

#[derive(Debug, Clone)]
#[derive(Debug)]
pub(crate) struct CustomNormalizer {
inner: PyObject,
}
Expand Down Expand Up @@ -581,7 +580,7 @@ impl<'de> Deserialize<'de> for CustomNormalizer {
}
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Deserialize)]
#[serde(untagged)]
pub(crate) enum PyNormalizerWrapper {
Custom(CustomNormalizer),
Expand Down
3 changes: 1 addition & 2 deletions bindings/python/src/pre_tokenizers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,6 @@ impl PyUnicodeScripts {
}
}

#[derive(Clone)]
pub(crate) struct CustomPreTokenizer {
inner: PyObject,
}
Expand Down Expand Up @@ -662,7 +661,7 @@ impl<'de> Deserialize<'de> for CustomPreTokenizer {
}
}

#[derive(Clone, Deserialize)]
#[derive(Deserialize)]
#[serde(untagged)]
pub(crate) enum PyPreTokenizerWrapper {
Custom(CustomPreTokenizer),
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/src/processors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl From<PyTemplate> for Template {

impl FromPyObject<'_> for PyTemplate {
fn extract_bound(ob: &Bound<'_, PyAny>) -> PyResult<Self> {
if let Ok(s) = ob.extract::<&str>() {
if let Ok(s) = ob.extract::<String>() {
Ok(Self(
s.try_into().map_err(exceptions::PyValueError::new_err)?,
))
Expand Down
Loading

0 comments on commit f4c9fd7

Please sign in to comment.