Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 173 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
description: Publish the current version after verification (requires an existing release tag)
type: boolean
default: false
desktop_only:
description: Check only Windows and macOS builds without publishing
type: boolean
default: false

permissions:
contents: read
Expand All @@ -31,6 +35,7 @@ env:
jobs:
build:
name: Build and verify Linux x86_64 distributions
if: github.event_name != 'workflow_dispatch' || !inputs.desktop_only
runs-on: ubuntu-22.04
timeout-minutes: 30
defaults:
Expand Down Expand Up @@ -163,6 +168,7 @@ jobs:

build-arm64:
name: Build and verify Linux ARM64 VAD and experimental MiniLM wheel
if: github.event_name != 'workflow_dispatch' || !inputs.desktop_only
runs-on: ubuntu-24.04-arm
container:
image: quay.io/pypa/manylinux_2_28_aarch64
Expand Down Expand Up @@ -268,6 +274,167 @@ jobs:
compression-level: 0
retention-days: 14

build-desktop:
name: Build and verify ${{ matrix.name }} wheel
runs-on: ${{ matrix.runner }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
- name: Windows x64
runner: windows-2022
platform: win_amd64
artifact: windows-x86_64
- name: macOS Intel
runner: macos-15-intel
platform: macosx_11_0_x86_64
artifact: macos-x86_64
- name: macOS Apple Silicon
runner: macos-15
platform: macosx_11_0_arm64
artifact: macos-arm64
env:
PYTHONUTF8: "1"
TRANSFORMERS_OFFLINE: "1"
MACOSX_DEPLOYMENT_TARGET: "11.0"
AKIKI_EXPECTED_PLATFORM: ${{ matrix.platform }}
AKIKI_VAD_TEST_NATIVE: "1"
AKIKI_MINILM_TEST_NATIVE: "1"
defaults:
run:
shell: bash
steps:
# Preserve exact model and metadata bytes on Windows as well as macOS.
- name: Preserve LF source files
run: git config --global core.autocrlf false

- name: Check out Python package
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Check out pinned Akiki engine
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: Akiki-AI/akiki-inference
ref: ${{ env.AKIKI_INFERENCE_REV }}
path: .cache/akiki-inference
ssh-key: ${{ secrets.AKIKI_INFERENCE_SSH_KEY }}
persist-credentials: false

- name: Set up Python
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.12"

- name: Set up Rust
uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
with:
toolchain: "1.98.1"

- name: Install build tools and cache Cargo dependencies
run: |
python -m pip install build "setuptools>=77.0.3" wheel twine
cargo fetch --locked --manifest-path .cache/akiki-inference/Cargo.toml

- name: Build native engines offline
run: python tools/build_native.py --inference-dir .cache/akiki-inference

- name: Select both native libraries
run: |
python - <<'PY'
import os
import sys
from pathlib import Path

directory = Path(".cache/native-target/release").resolve()
names = (
["akiki_vad_engine.dll", "akiki_minilm_engine.dll"]
if sys.platform == "win32"
else ["libakiki_vad_engine.dylib", "libakiki_minilm_engine.dylib"]
)
libraries = [directory / name for name in names]
assert all(path.is_file() for path in libraries)
with Path(os.environ["GITHUB_ENV"]).open("a", encoding="utf-8") as stream:
stream.write("AKIKI_NATIVE_LIBRARY=" + os.pathsep.join(map(str, libraries)) + "\n")
PY

- name: Build and verify the native wheel
run: |
python -m build --no-isolation
python verify_dist.py --all-wheels --require-native
python -m twine check --strict dist/*

- name: Test the installed wheel and both native engines
run: |
python - <<'PY'
import os
import subprocess
import sys
import venv
from pathlib import Path

root = Path.cwd()
wheels = list((root / "dist").glob("*.whl"))
assert len(wheels) == 1
wheel = wheels[0]
assert wheel.name.endswith("-" + os.environ["AKIKI_EXPECTED_PLATFORM"] + ".whl"), wheel.name
directory = Path(os.environ["RUNNER_TEMP"]) / "akiki-installed"
venv.EnvBuilder(with_pip=True).create(directory)
executable = directory / ("Scripts/python.exe" if sys.platform == "win32" else "bin/python")
subprocess.run(
[str(executable), "-m", "pip", "install", str(wheel), "pytest", "setuptools>=77.0.3", "wheel"],
check=True,
)
code = """
import importlib.util
import sys
from pathlib import Path
import akiki
import numpy as np
from akiki.decision import _load_library

assert importlib.util.find_spec('onnxruntime') is None
assert importlib.util.find_spec('torch') is None
native = Path(akiki.__file__).parent / 'native'
with akiki.VAD() as vad:
assert vad.engine is akiki.Engine.AKIKI
assert vad.model_precision is akiki.ModelPrecision.INT8
assert vad.fft_precision is akiki.FFTPrecision.FP32
assert Path(vad._backend.lib._name).parent == native
assert len(vad.push(np.zeros(256 * 3 + 17, np.float32))) == 3
assert _load_library()[1].parent == native
print('Installed wheel loads bundled VAD and decision engines with base dependencies only')
"""
import textwrap

subprocess.run([str(executable), "-I", "-c", textwrap.dedent(code)], cwd=directory, check=True)
subprocess.run(
[str(executable), "-m", "pytest", "-q", "-rs", "-o", "pythonpath="],
cwd=root,
check=True,
)
if sys.platform == "win32":
for _ in range(5):
subprocess.run(
[str(executable), "-m", "pytest", "-q", "-o", "pythonpath=",
"tests/test_affine_cache.py::test_concurrent_saves_leave_one_complete_valid_layer",
"tests/test_quantization.py::test_concurrent_first_use_produces_one_valid_variant"],
cwd=root,
check=True,
)
PY

- name: Save the verified native wheel
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: python-distributions-${{ matrix.artifact }}
path: dist/*.whl
if-no-files-found: error
compression-level: 0
retention-days: 14

training:
name: Verify the private training companion
needs: build
Expand Down Expand Up @@ -350,8 +517,10 @@ jobs:

publish:
name: Publish to PyPI
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.publish)
needs: [build, build-arm64, training]
if: >-
github.event_name == 'release' ||
(github.event_name == 'workflow_dispatch' && inputs.publish && !inputs.desktop_only)
needs: [build, build-arm64, build-desktop, training]
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down Expand Up @@ -387,8 +556,8 @@ jobs:
raise SystemExit("Manual publication must use tagged package source; only CI/release docs may differ")
PY

- name: Verify both native architectures before publishing
run: python3 verify_dist.py --all-wheels --require-native --require-arm64
- name: Verify all native platforms before publishing
run: python3 verify_dist.py --all-wheels --require-native --require-arm64 --require-desktop

# No environment is set: the PyPI publisher was registered without one.
- name: Publish with PyPI Trusted Publishing
Expand Down
36 changes: 32 additions & 4 deletions docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,41 @@ and that `akiki.decision._load_library()` loads the installed MiniLM
library. When no precision is specified, ONNX and PyTorch compatibility engines use
FP32; an explicit non-FP32 request must require the Akiki engine.

## Build Windows and macOS wheels

The release workflow builds Windows x64, macOS Intel, and macOS Apple Silicon wheels.
It uses Windows and macOS GitHub-hosted runners.
No local Windows or Mac computer is required.
Each wheel contains the VAD and decision-model libraries.
The jobs use the pinned engine revision and baseline CPU settings.

Windows wheels use the `win_amd64` tag.
Mac wheels use separate `macosx_11_0_x86_64` and `macosx_11_0_arm64` tags.
The macOS deployment target is 11.0. CI tests run on macOS 15.
Windows ARM64 is not part of this build matrix.

Each job installs its wheel into a new virtual environment.
It checks that VAD and decision inference load the bundled native libraries.
It runs the Python tests against the installed package with both native engines required.
Tests generate small synthetic checkpoints. No model is downloaded.
The release verifier checks PE and Mach-O architecture headers against wheel tags.
It preserves exact bundled model checksums.

For a targeted check, run `publish.yml` manually with `desktop_only` enabled.
Leave `publish` disabled. Desktop-only runs cannot publish a package.
The verified wheels are saved as `python-distributions-windows-x86_64`,
`python-distributions-macos-x86_64`, and `python-distributions-macos-arm64` artifacts.
Private engine source is not included in these artifacts.

## Publish from GitHub Actions

The workflow is `.github/workflows/publish.yml`. It builds and verifies the
portable wheel, source archive, and Linux x86_64 and ARM64 native wheels.
portable wheel, source archive, Linux x86_64 and ARM64 native wheels,
Windows x64 wheel, and both macOS architecture wheels.
The current decision runtime supports MiniLM/BERT exports.
Its ARM64 support is experimental.
ARM64 builds in manylinux_2_28 on a native ARM64 runner.
x86_64 retains the glibc 2.34 floor. Both build jobs must pass before publishing. It tests the
x86_64 retains the glibc 2.34 floor. All native build jobs must pass before publishing. It tests the
native loader, Python API, and clean installations before saving the artifacts.
Models come exclusively from `src/akiki/models/`; no model is downloaded.

Expand Down Expand Up @@ -228,7 +255,7 @@ After merging, run the workflow manually on `main` with the `publish` input enab
The retry requires an existing GitHub release.
It checks that package source matches its version tag;
only the workflow and this release document may differ. This preserves the tag
while allowing CI-only repairs. Both native build jobs run again before upload.
while allowing CI-only repairs. All native build jobs run again before upload.

The existing PyPI `akiki` project must trust owner `Akiki-AI`, repository
`akiki-python`, workflow filename `publish.yml`, with the environment left
Expand Down Expand Up @@ -279,5 +306,6 @@ Do not store credentials in this repository.
```

The script verifies and uploads all wheels for the current version plus its
source archive. It refuses a release with no native wheel or stale description.
source archive. It requires the Linux, Windows, and macOS native wheels.
It rejects stale descriptions.
It does not upload artifacts from previous versions.
2 changes: 1 addition & 1 deletion publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export TMPDIR="${TMPDIR:-$project_root/.cache/tmp}"
export UV_CACHE_DIR="${UV_CACHE_DIR:-$project_root/.cache/uv}"
export PYTHONDONTWRITEBYTECODE=1
mkdir -p "$TMPDIR" "$UV_CACHE_DIR"
python3 "$project_root/verify_dist.py" --all-wheels --require-native --require-arm64
python3 "$project_root/verify_dist.py" --all-wheels --require-native --require-arm64 --require-desktop
version="$(python3 "$project_root/verify_dist.py" --version)"
shopt -s nullglob
wheels=("$project_root/dist/akiki-${version}-"*.whl)
Expand Down
25 changes: 25 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Optionally bundle prebuilt C-ABI libraries in a platform-specific wheel."""

import os
import re
import shutil
import struct
from pathlib import Path
Expand Down Expand Up @@ -56,6 +57,29 @@ def linux_platform(libraries):
return "linux_aarch64" if machine == 183 else "linux_x86_64"


def macos_platform(libraries, tag):
"""Use the bundled Mach-O architecture instead of the Python interpreter's tag."""
if not libraries or not all(path.suffix == ".dylib" for path in libraries):
return None
platform = re.fullmatch(r"(macosx_\d+_\d+)_(?:x86_64|arm64|universal2)", tag)
if platform is None:
raise ValueError("Native macOS libraries require a macOS wheel platform")
machines = set()
for path in libraries:
with path.open("rb") as source:
header = source.read(8)
if len(header) != 8 or header[:4] != b"\xcf\xfa\xed\xfe":
raise ValueError(f"Expected a thin little-endian Mach-O64 library: {path.name}")
machine = int.from_bytes(header[4:8], "little")
if machine not in {0x01000007, 0x0100000C}:
raise ValueError(f"Unsupported Mach-O architecture in {path.name}: {machine}")
machines.add(machine)
if len(machines) != 1:
raise ValueError("Native libraries must have the same architecture")
architecture = "arm64" if machines.pop() == 0x0100000C else "x86_64"
return f"{platform[1]}_{architecture}"


class BuildPy(build_py):
def run(self):
super().run()
Expand All @@ -80,6 +104,7 @@ def get_tag(self):
python, abi, platform = super().get_tag()
libraries = native_libraries()
platform = linux_platform(libraries) or platform
platform = macos_platform(libraries, platform) or platform
# ctypes uses the C ABI; this library has no CPython ABI dependency.
return ("py3", "none", platform) if libraries else (python, abi, platform)

Expand Down
3 changes: 2 additions & 1 deletion src/akiki/_affine_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import numpy as np

from ._atomic import replace_file
from ._base_models import BaseModel
from ._quantization import default_cache_dir

Expand Down Expand Up @@ -151,7 +152,7 @@ def __setitem__(self, base: BaseModel, layer: AffineLayer) -> None:
)
stream.flush()
os.fsync(stream.fileno())
os.replace(temporary, path)
replace_file(temporary, path)
except OSError as error:
raise RuntimeError(
f"Cannot save trained affine cache entry {path}. "
Expand Down
22 changes: 22 additions & 0 deletions src/akiki/_atomic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Replace cache files atomically across supported operating systems."""

import os
import sys
import time
from pathlib import Path


def replace_file(source: Path, destination: Path) -> None:
"""Retry temporary Windows file-sharing failures without removing the destination."""
for attempt in range(9):
try:
os.replace(source, destination)
return
except PermissionError as error:
if (
sys.platform != "win32"
or getattr(error, "winerror", None) not in {5, 32, 33}
or attempt == 8
):
raise
time.sleep(0.01 * 2**attempt)
3 changes: 2 additions & 1 deletion src/akiki/_quantization.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import numpy as np

from ._atomic import replace_file
from ._precision import ModelPrecision

# AKVAD003 format IDs are fixed independently of enum declaration order.
Expand Down Expand Up @@ -187,7 +188,7 @@ def _atomic_write(path, data):
stream.write(data)
stream.flush()
os.fsync(stream.fileno())
os.replace(temporary, path)
replace_file(temporary, path)
finally:
if temporary is not None:
temporary.unlink(missing_ok=True)
Expand Down
Loading
Loading