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
61 changes: 47 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,9 @@ name: ci

on:
pull_request:
paths:
- Cargo.toml
- Cargo.lock
- src/**
- tests/**
- coreml/**
- .github/workflows/ci.yml
push:
branches:
- dev
paths:
- Cargo.toml
- Cargo.lock
- src/**
- tests/**
- coreml/**
- .github/workflows/ci.yml
workflow_dispatch:

permissions:
Expand All @@ -29,8 +15,44 @@ concurrency:
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
# The workflow runs on every PR so its required check always reports; the Rust job is
# skipped (which satisfies the requirement) when the change touches nothing it reads.
changes:
name: changes
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
rust: ${{ steps.diff.outputs.rust }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Diff against the base
id: diff
env:
EVENT: ${{ github.event_name }}
PR_BASE: ${{ github.event.pull_request.base.sha }}
PUSH_BEFORE: ${{ github.event.before }}
run: |
case "$EVENT" in
pull_request) base="$PR_BASE" ;;
push) base="$PUSH_BEFORE" ;;
*) echo "rust=true" >> "$GITHUB_OUTPUT"; exit 0 ;;
esac
if ! git cat-file -e "$base^{commit}" 2>/dev/null; then
echo "rust=true" >> "$GITHUB_OUTPUT"; exit 0
fi
if git diff --name-only "$base" HEAD -- Cargo.toml Cargo.lock 'src/**' 'tests/**' 'coreml/**' .github/workflows/ci.yml | grep -q .; then
echo "rust=true" >> "$GITHUB_OUTPUT"
else
echo "rust=false" >> "$GITHUB_OUTPUT"
fi

rust:
name: fmt, clippy, test (macOS)
needs: changes
if: needs.changes.outputs.rust == 'true'
runs-on: macos-15
timeout-minutes: 20
steps:
Expand All @@ -53,3 +75,14 @@ jobs:
run: cargo hack clippy --locked --each-feature --all-targets --workspace -- -D warnings
- name: test
run: cargo test --locked --workspace
- name: Install uv
uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
with:
version: 0.9.16
- name: Generate Core ML contract models
run: uv run --directory coreml/fixtures --locked python generate.py
- name: Core ML contracts
env:
ONDEVICE_COREML_FIXTURES: ${{ github.workspace }}/coreml/fixtures/models
ONDEVICE_COREML_MODEL_DIR: ${{ github.workspace }}/coreml/fixtures/models/buckets
run: cargo test --locked -p ondevice-coreml --all-features --test runtime --test model -- --include-ignored
2 changes: 2 additions & 0 deletions .github/workflows/release-plz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches:
- dev
- main
# Re-runs release-plz on a branch whose push event GitHub never delivered.
workflow_dispatch:

permissions:
contents: read
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/target/
/coreml/fixtures/.venv/
/coreml/fixtures/models/
__pycache__/
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.2](https://github.com/May-Agent/ondevice/compare/v0.0.1...v0.0.2) - 2026-11-17

### Added

- *(coreml)* [**breaking**] separate model functions, native tensors and stateful sessions

### Fixed

- *(store)* document Windows read-only attribute cleanup
- *(store)* retain writable archive handles through synchronization

### Other

- let release-plz run on demand
- report the required check on every pull request
- release v0.0.1

## [0.0.1](https://github.com/May-Agent/ondevice/releases/tag/v0.0.1) - 2026-11-06

### Added
Expand Down
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tracing = { version = "0.1.44", default-features = false, features = ["std"] }

[package]
name = "ondevice"
version = "0.0.1"
version = "0.0.2"
description = "Pinned, verified first-use downloads of on-device model files"
edition.workspace = true
rust-version.workspace = true
Expand Down
14 changes: 14 additions & 0 deletions coreml/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.2](https://github.com/May-Agent/ondevice/compare/coreml/v0.0.1...coreml/v0.0.2) - 2026-11-17

### Added

- *(coreml)* [**breaking**] separate model functions, native tensors and stateful sessions

### Fixed

- *(coreml)* drain native temporaries at operation boundaries

### Other

- release v0.0.1

## [0.0.1](https://github.com/May-Agent/ondevice/releases/tag/coreml/v0.0.1) - 2026-11-06

### Added
Expand Down
12 changes: 8 additions & 4 deletions coreml/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[package]
name = "ondevice-coreml"
version = "0.0.1"
description = "Bucketed Core ML inference over one compiled multifunction model"
version = "0.0.2"
description = "Typed Core ML functions, tensors, sessions and sequence bucketing"
edition.workspace = true
rust-version.workspace = true
license.workspace = true
repository.workspace = true

[features]
default = ["headroom"]
plan = ["dep:async-channel", "objc2-core-ml/MLComputePlan", "objc2-core-ml/MLComputePlanCost", "objc2-core-ml/MLComputePlanDeviceUsage", "objc2-core-ml/MLComputeDeviceProtocol", "objc2-core-ml/MLModelStructure", "objc2-core-ml/MLModelStructureProgram", "objc2-core-ml/MLModelStructureProgramFunction", "objc2-core-ml/MLModelStructureProgramBlock", "objc2-core-ml/MLModelStructureProgramOperation", "objc2-core-ml/MLModelStructureProgramNamedValueType", "objc2-core-ml/MLModelStructureNeuralNetwork", "objc2-core-ml/MLModelStructureNeuralNetworkLayer", "objc2-core-ml/MLModelStructurePipeline"]
# Whether the host has headroom for GPU inference — mains power and a SoC
# below serious thermal pressure — and a monitor reporting its changes.
headroom = [
Expand All @@ -20,18 +21,21 @@ headroom = [
]

[target.'cfg(target_vendor = "apple")'.dependencies]
async-channel = { version = "2.5.0", default-features = false, optional = true }
block2 = { version = "0.6.2", default-features = false }
half = { version = "2.7.1", default-features = false }
objc2 = { version = "0.6.5", default-features = false }
objc2-core-foundation = { version = "0.3.2", default-features = false, features = ["block2", "CFRunLoop", "CFString"], optional = true }
objc2-core-ml = { version = "0.3.2", default-features = false, features = ["MLArrayBatchProvider", "MLBatchProvider", "MLDictionaryFeatureProvider", "MLFeatureProvider", "MLFeatureValue", "MLModel", "MLModelConfiguration", "MLMultiArray", "block2"] }
objc2-core-ml = { version = "0.3.2", default-features = false, features = ["MLArrayBatchProvider", "MLBatchProvider", "MLDictionaryFeatureProvider", "MLFeatureProvider", "MLFeatureValue", "MLModel", "MLModelConfiguration", "MLModelDescription", "MLFeatureDescription", "MLMultiArrayConstraint", "MLState", "MLStateConstraint", "MLModel_MLState", "MLMultiArray", "block2"] }
objc2-foundation = { version = "0.3.2", default-features = false, features = ["NSArray", "NSDictionary", "NSError", "NSString", "NSURL", "NSValue", "block2"] }
objc2-io-kit = { version = "0.3.2", default-features = false, features = ["ps"], optional = true }
serde = { version = "1.0.229", default-features = false, features = ["derive", "std"] }
serde_json = { version = "1.0.154", default-features = false, features = ["std"] }
thiserror.workspace = true
tracing.workspace = true

[[test]]
name = "headroom"
required-features = ["headroom"]

[dev-dependencies]
futures-lite = { version = "2.6.1", default-features = false, features = ["std"] }
60 changes: 60 additions & 0 deletions coreml/fixtures/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""Generate small executable Core ML contracts for the Rust integration tests."""
from pathlib import Path
import json
import coremltools as ct
from coremltools.converters.mil import Builder as mb
from coremltools.converters.mil.mil import types

ROOT = Path(__file__).parent / "models"
ROOT.mkdir(exist_ok=True)


def save(program, name):
model = ct.convert(program, minimum_deployment_target=ct.target.macOS15,
compute_precision=ct.precision.FLOAT32,
compute_units=ct.ComputeUnit.CPU_ONLY)
path = ROOT / f"{name}.mlpackage"
model.save(str(path))
return path


def compile_model(path, destination):
ct.models.utils.compile_model(str(path), destination_path=str(destination))


@mb.program(input_specs=[mb.TensorSpec((2, 3)), mb.TensorSpec((3,))],
opset_version=ct.target.macOS15)
def affine(matrix, bias):
return mb.add(x=matrix, y=bias, name="output")


@mb.program(input_specs=[mb.TensorSpec((2, 3), dtype=types.fp16),
mb.StateTensorSpec((2, 3), dtype=types.fp16)],
opset_version=ct.target.macOS15)
def accumulate(delta, memory):
value = mb.add(x=mb.read_state(input=memory), y=delta)
return mb.coreml_update_state(state=memory, value=value, name="output")


compile_model(save(affine, "affine"), ROOT / "affine.mlmodelc")
compile_model(save(accumulate, "accumulate"), ROOT / "accumulate.mlmodelc")
descriptor = ct.utils.MultiFunctionDescriptor()
for length in (32, 64):
@mb.program(input_specs=[mb.TensorSpec((1, length), dtype=types.int32)],
opset_version=ct.target.macOS15)
def bucket(tokens):
return mb.reduce_sum(x=mb.cast(x=tokens, dtype="fp32"), axes=[1],
keep_dims=True, name="output")
name = f"len_{length}"
descriptor.add_function(str(save(bucket, name)), "main", name)
descriptor.default_function_name = "len_32"
package = ROOT / "buckets.mlpackage"
ct.utils.save_multifunction(descriptor, str(package))
directory = ROOT / "buckets"
directory.mkdir(exist_ok=True)
compile_model(package, directory / "model.mlmodelc")
(directory / "manifest.json").write_text(json.dumps({
"functions": {"len_32": 32, "len_64": 64},
"inputs": {"tokens": {"dtype": "int32", "shape": [1, "length"]}},
"outputs": {"output": {"dtype": "float32", "shape": [1, 1]}}
}))
5 changes: 5 additions & 0 deletions coreml/fixtures/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[project]
name = "ondevice-coreml-fixtures"
version = "0.0.0"
requires-python = ">=3.11,<3.13"
dependencies = ["coremltools==9.0", "numpy==2.2.6"]
Loading
Loading