Skip to content

Commit

Permalink
v2.0.0-rc.1に追従する (#3)
Browse files Browse the repository at this point in the history
## 内容


~~2fdba8f0..[2.0.0-rc.0](pykeio@90b8d3045fe7b483ebea0b7bf0d31a4368bc2e49)~~
2fdba8f..[v2.0.0-rc.1](https://github.com/pykeio/ort/commit/69c191d0f5e1a93410001ff4561c9ac13cb31fd2)を取り込みます。

## 関連 Issue

## スクリーンショット・動画など

## その他

mainで

```console
$ # github.com/pykeioのremote名をpykeioとする
$ git pull --ff-only pykeio v2.0.0-rc.1
```

してVOICEVOXのmainにpushでもよくないかという気もします。
  • Loading branch information
Hiroshiba authored Apr 14, 2024
2 parents 2fdba8f + 69c191d commit cae5161
Show file tree
Hide file tree
Showing 77 changed files with 5,314 additions and 2,390 deletions.
63 changes: 33 additions & 30 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ jobs:
platform:
- os: ubuntu-latest
- os: windows-latest
- os: macos-latest
- os: macos-12
- os: macos-14
steps:
- uses: actions/checkout@v4
- name: Install stable Rust toolchain
Expand All @@ -46,32 +47,34 @@ jobs:
- name: Run tests
run: |
cargo test -p ort --verbose --features fetch-models -- --test-threads 1
cross-compile:
name: Cross-platform compile
runs-on: ${{ matrix.platform.os }}
needs: [test]
strategy:
fail-fast: false
matrix:
platform:
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
command: test
steps:
- uses: actions/checkout@v4
- name: Fix ring dependency for Windows ARM64
if: matrix.platform.target == 'aarch64-pc-windows-msvc'
shell: pwsh
run: |
@('', '[patch.crates-io]',
'ring = { git = "https://github.com/awakecoding/ring", branch = "0.16.20_alpha" }') | % {
Add-Content -Path "Cargo.toml" -Value $_
}
$VSINSTALLDIR = $(vswhere.exe -latest -requires Microsoft.VisualStudio.Component.VC.Llvm.Clang -property installationPath)
$VCINSTALLDIR = Join-Path $VSINSTALLDIR "VC"
$LLVM_ROOT = Join-Path $VCINSTALLDIR "Tools\Llvm\x64"
echo "PATH=$Env:PATH;${LLVM_ROOT}\bin" >> $Env:GITHUB_ENV
- name: Build/test
run: |
cargo install cross --git https://github.com/cross-rs/cross
cross test -p ort --features fetch-models --target aarch64-unknown-linux-gnu -v
# Disable cross-compile until cross updates aarch64-unknown-linux-gnu to Ubuntu 22.04
# ref https://github.com/cross-rs/cross/pull/973
#cross-compile:
# name: Cross-platform compile
# runs-on: ${{ matrix.platform.os }}
# needs: [test]
# strategy:
# fail-fast: false
# matrix:
# platform:
# - target: aarch64-unknown-linux-gnu
# os: ubuntu-latest
# command: test
# steps:
# - uses: actions/checkout@v4
# - name: Fix ring dependency for Windows ARM64
# if: matrix.platform.target == 'aarch64-pc-windows-msvc'
# shell: pwsh
# run: |
# @('', '[patch.crates-io]',
# 'ring = { git = "https://github.com/awakecoding/ring", branch = "0.16.20_alpha" }') | % {
# Add-Content -Path "Cargo.toml" -Value $_
# }
# $VSINSTALLDIR = $(vswhere.exe -latest -requires Microsoft.VisualStudio.Component.VC.Llvm.Clang -property installationPath)
# $VCINSTALLDIR = Join-Path $VSINSTALLDIR "VC"
# $LLVM_ROOT = Join-Path $VCINSTALLDIR "Tools\Llvm\x64"
# echo "PATH=$Env:PATH;${LLVM_ROOT}\bin" >> $Env:GITHUB_ENV
# - name: Build/test
# run: |
# cargo install cross --git https://github.com/cross-rs/cross
# cross test -p ort --features fetch-models --target aarch64-unknown-linux-gnu -v
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,6 @@ WixTools/

# IDEA
.idea

# Glassbench results
/glassbench*.db
27 changes: 18 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
[workspace]
members = [
'ort-sys',
'examples/async-gpt2-api',
'examples/custom-ops',
'examples/gpt2',
'examples/model-info',
'examples/yolov8',
'examples/modnet'
]
default-members = [
'.',
'examples/async-gpt2-api',
'examples/custom-ops',
'examples/gpt2',
'examples/model-info',
'examples/yolov8',
Expand All @@ -16,8 +20,8 @@ default-members = [

[package]
name = "ort"
description = "A safe Rust wrapper for ONNX Runtime 1.16 - Optimize and Accelerate Machine Learning Inferencing"
version = "2.0.0-alpha.4"
description = "A safe Rust wrapper for ONNX Runtime 1.17 - Optimize and Accelerate Machine Learning Inferencing"
version = "2.0.0-rc.1"
edition = "2021"
rust-version = "1.70"
license = "MIT OR Apache-2.0"
Expand All @@ -30,7 +34,7 @@ authors = [
"pyke.io <[email protected]>",
"Nicolas Bigaouette <[email protected]>"
]
include = [ "src/", "examples/", "tests/", "LICENSE-APACHE", "LICENSE-MIT", "README.md" ]
include = [ "src/", "benches/", "LICENSE-APACHE", "LICENSE-MIT", "README.md" ]

[profile.release]
opt-level = 3
Expand All @@ -39,14 +43,13 @@ strip = true
codegen-units = 1

[package.metadata.docs.rs]
features = [ "ndarray", "half", "profiling", "custom-ops", "fetch-models", "copy-dylibs" ]
features = [ "ndarray", "half", "operator-libraries", "fetch-models", "load-dynamic", "copy-dylibs" ]
rustdoc-args = [ "--cfg", "docsrs" ]

[features]
default = [ "ndarray", "half", "download-binaries", "copy-dylibs" ]

profiling = [ "widestring" ]
custom-ops = [ "libc", "winapi" ]
operator-libraries = [ "libc", "winapi" ]

fetch-models = [ "ureq" ]
download-binaries = [ "ort-sys/download-binaries" ]
Expand Down Expand Up @@ -74,7 +77,7 @@ qnn = [ "ort-sys/qnn" ]
[dependencies]
ndarray = { version = "0.15", optional = true }
thiserror = "1.0"
ort-sys = { version = "2.0.0-alpha.4", path = "ort-sys" }
ort-sys = { version = "2.0.0-rc.1", path = "ort-sys" }
libloading = { version = "0.8", optional = true }

ureq = { version = "2.1", optional = true, default-features = false, features = [ "tls" ] }
Expand All @@ -86,11 +89,17 @@ libc = { version = "0.2", optional = true }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", optional = true, features = [ "std", "libloaderapi" ] }
widestring = { version = "1.0", optional = true }

[dev-dependencies]
anyhow = "1.0"
ureq = "2.1"
image = "0.24"
image = "0.25"
test-log = { version = "0.2", default-features = false, features = [ "trace" ] }
tracing-subscriber = { version = "0.3", default-features = false, features = [ "env-filter", "fmt" ] }
glassbench = "0.4"
tokio = { version = "1.36", features = [ "test-util" ] }
tokio-test = "0.4.3"

[[bench]]
name = "squeezenet"
harness = false
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<hr />
<a href="https://app.codecov.io/gh/pykeio/ort" target="_blank"><img alt="Coverage Results" src="https://img.shields.io/codecov/c/gh/pykeio/ort?style=for-the-badge"></a> <a href="https://crates.io/crates/ort" target="_blank"><img alt="Crates.io" src="https://img.shields.io/crates/d/ort?style=for-the-badge"></a> <a href="https://opencollective.com/pyke-osai" target="_blank"><img alt="Open Collective backers and sponsors" src="https://img.shields.io/opencollective/all/pyke-osai?style=for-the-badge&label=sponsors"></a>
<br />
<a href="https://crates.io/crates/ort" target="_blank"><img alt="Crates.io" src="https://img.shields.io/crates/v/ort?style=for-the-badge&label=ort&logo=rust"></a> <img alt="ONNX Runtime" src="https://img.shields.io/badge/onnxruntime-v1.16.3-blue?style=for-the-badge&logo=cplusplus">
<a href="https://crates.io/crates/ort" target="_blank"><img alt="Crates.io" src="https://img.shields.io/crates/v/ort?style=for-the-badge&label=ort&logo=rust"></a> <img alt="ONNX Runtime" src="https://img.shields.io/badge/onnxruntime-v1.17.0-blue?style=for-the-badge&logo=cplusplus">
</div>

`ort` is an (unofficial) [ONNX Runtime](https://onnxruntime.ai/) 1.16 wrapper for Rust based on the now inactive [`onnxruntime-rs`](https://github.com/nbigaouette/onnxruntime-rs). ONNX Runtime accelerates ML inference on both CPU & GPU.
`ort` is an (unofficial) [ONNX Runtime](https://onnxruntime.ai/) 1.17 wrapper for Rust based on the now inactive [`onnxruntime-rs`](https://github.com/nbigaouette/onnxruntime-rs). ONNX Runtime accelerates ML inference on both CPU & GPU.

## 📖 Documentation
- [Guide](https://ort.pyke.io/)
Expand Down
60 changes: 60 additions & 0 deletions benches/squeezenet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use std::{path::Path, sync::Arc};

use glassbench::{pretend_used, Bench};
use image::{imageops::FilterType, ImageBuffer, Pixel, Rgb};
use ndarray::{s, Array4};
use ort::{GraphOptimizationLevel, Session};

fn load_squeezenet_data() -> ort::Result<(Session, Array4<f32>)> {
const IMAGE_TO_LOAD: &str = "mushroom.png";

ort::init().with_name("integration_test").commit()?;

let session = Session::builder()?
.with_optimization_level(GraphOptimizationLevel::Level1)?
.with_intra_threads(1)?
.commit_from_url("https://parcel.pyke.io/v2/cdn/assetdelivery/ortrsv2/ex_models/squeezenet.onnx")
.expect("Could not download model from file");

let input0_shape: &Vec<i64> = session.inputs[0].input_type.tensor_dimensions().expect("input0 to be a tensor type");

let image_buffer: ImageBuffer<Rgb<u8>, Vec<u8>> = image::open(Path::new(env!("CARGO_MANIFEST_DIR")).join("tests").join("data").join(IMAGE_TO_LOAD))
.unwrap()
.resize(input0_shape[2] as u32, input0_shape[3] as u32, FilterType::Nearest)
.to_rgb8();

let mut array = ndarray::Array::from_shape_fn((1, 3, 224, 224), |(_, c, j, i)| {
let pixel = image_buffer.get_pixel(i as u32, j as u32);
let channels = pixel.channels();
(channels[c] as f32) / 255.0
});

let mean = [0.485, 0.456, 0.406];
let std = [0.229, 0.224, 0.225];
for c in 0..3 {
let mut channel_array = array.slice_mut(s![0, c, .., ..]);
channel_array -= mean[c];
channel_array /= std[c];
}

Ok((session, array))
}

fn bench_squeezenet(bench: &mut Bench) {
let (session, data) = load_squeezenet_data().unwrap();
bench.task("ArrayView", |task| {
task.iter(|| {
pretend_used(session.run(ort::inputs![data.view()].unwrap()).unwrap());
})
});

let raw = Arc::new(data.as_standard_layout().as_slice().unwrap().to_owned().into_boxed_slice());
let shape: Vec<i64> = data.shape().iter().map(|c| *c as _).collect();
bench.task("Raw data", |task| {
task.iter(|| {
pretend_used(session.run(ort::inputs![(shape.clone(), Arc::clone(&raw))].unwrap()).unwrap());
})
});
}

glassbench::glassbench!("SqueezeNet", bench_squeezenet,);
13 changes: 5 additions & 8 deletions docs/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: Introduction
`ort` makes it easy to deploy your machine learning models to production via [ONNX Runtime](https://onnxruntime.ai/), a hardware-accelerated inference engine. With `ort` + ONNX Runtime, you can run almost any ML model (including ResNet, YOLOv8, BERT, LLaMA) on almost any hardware, often far faster than PyTorch, and with the added bonus of Rust's efficiency.

<Warning>
These docs are for the latest alpha version of `ort`, `2.0.0-alpha.4`. This alpha version is production-ready (just not API stable) and we recommend new & existing projects use it.
These docs are for the latest alpha version of `ort`, `2.0.0-rc.1`. This version is production-ready (just not API stable) and we recommend new & existing projects use it.
</Warning>

# Why `ort`?
Expand All @@ -19,7 +19,7 @@ For one, `ort` simply supports more features:

| Feature comparison | **📕 ort** | **📗 [ors](https://github.com/HaoboGu/ors)** | **🪟 [onnxruntime-rs](https://github.com/microsoft/onnxruntime/tree/main/rust)** |
|---------------------------|-----------|-----------|----------------------|
| Upstream version | **v1.16.3** | v1.12.0 | v1.8 |
| Upstream version | **v1.17.1** | v1.12.0 | v1.8 |
| `dlopen()`? ||||
| Execution providers? ||||
| I/O Binding? ||||
Expand All @@ -38,15 +38,14 @@ Users of `ort` appreciate its ease of use and ergonomic API. `ort` is also battl
- [**Numerical Elixir**](https://github.com/elixir-nx) uses `ort` to create ONNX Runtime bindings for the Elixir language.
- [**`rust-bert`**](https://github.com/guillaume-be/rust-bert) implements many ready-to-use NLP pipelines in Rust à la Hugging Face Transformers with both [`tch`](https://crates.io/crates/tch) & `ort` backends.
- [**`edge-transformers`**](https://github.com/npc-engine/edge-transformers) also implements Hugging Face Transformers pipelines in Rust using `ort`.
- We use `ort` in nearly all of our ML projects, including [VITRI](https://vitri.pyke.io/) 😊

# Getting started
<Steps>
<Step title="Add ort to your Cargo.toml">
If you have a [supported platform](/setup/platforms) (and you probably do), installing `ort` couldn't be any simpler! Just add it to your Cargo dependencies:
```toml
[dependencies]
ort = "2.0.0-alpha.4"
ort = "2.0.0-rc.1"
```
</Step>
<Step title="Convert your model">
Expand All @@ -66,7 +65,7 @@ Users of `ort` appreciate its ease of use and ergonomic API. `ort` is also battl
let model = Session::builder()?
.with_optimization_level(GraphOptimizationLevel::Level3)?
.with_intra_threads(4)?
.with_model_from_file("yolov8m.onnx")?;
.commit_from_file("yolov8m.onnx")?;
```
</Step>
<Step title="Perform inference">
Expand All @@ -77,9 +76,7 @@ Users of `ort` appreciate its ease of use and ergonomic API. `ort` is also battl

// Postprocessing
let output = outputs["output0"]
.extract_tensor::<f32>()
.unwrap()
.view()
.extract_tensor::<f32>()?
.t()
.slice(s![.., .., 0])
.into_owned();
Expand Down
14 changes: 11 additions & 3 deletions docs/migrating/v2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ort::init()
.commit()?;
```

`commit()` must be called before any sessions are created to take effect. Otherwise, the environment will be set to default and cannot be modified afterwards.
`commit()` must be called before any sessions are created to take effect. Otherwise, a default environment will be created. The global environment can be updated afterward by calling `commit()` on another `EnvironmentBuilder`, however you'll need to recreate sessions after comitting the new environment in order for them to use it.

## Session creation
`SessionBuilder::new(&environment)` has been soft-replaced with `Session::builder()`:
Expand All @@ -23,9 +23,17 @@ ort::init()
-// v1.x
-let session = SessionBuilder::new(&environment)?.with_model_from_file("model.onnx")?;
+// v2
+let session = Session::builder()?.with_model_from_file("model.onnx")?;
+let session = Session::builder()?.commit_from_file("model.onnx")?;
```

### `SessionBuilder::with_model_*` -> `SessionBuilder::commit_*`
The final `SessionBuilder` methods have been renamed for clarity.

- `SessionBuilder::with_model_from_file` -> `SessionBuilder::commit_from_file`
- `SessionBuilder::with_model_from_memory` -> `SessionBuilder::commit_from_memory`
- `SessionBuilder::with_model_from_memory_directly` -> `SessionBuilder::commit_from_memory_directly`
- `SessionBuilder::with_model_downloaded` -> `SessionBuilder::commit_from_url`

## Session inputs

### `CowArray`/`IxDyn`/`ndarray` no longer required
Expand Down Expand Up @@ -147,7 +155,7 @@ The dependency on `ndarray` is now declared optional. If you use `ort` with `def
## Model Zoo structs have been removed
ONNX pushed a new Model Zoo structure that adds hundreds of different models. This is impractical to maintain, so the built-in structs have been removed.

You can still use `Session::with_model_downloaded`, it just now takes a URL string instead of a struct.
You can still use `Session::commit_from_url`, it just now takes a URL string instead of a struct.

## Changes to logging
Environment-level logging configuration (i.e. `EnvironmentBuilder::with_log_level`) has been removed because it could cause unnecessary confusion with our `tracing` integration.
Expand Down
6 changes: 2 additions & 4 deletions docs/migrating/version-mapping.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: Information about `ort`'s versioning and relation to ONNX Runtime v
## A note on SemVer
`ort` versions pre-2.0 were not SemVer compatible. From v2.0 onwards, breaking API changes are accompanied by a **major version update**.

Updates to the version of ONNX Runtime used by `ort` may occur on **minor** version updates, i.e. 2.0 ships with ONNX Runtime 1.16.2, but 2.1 may ship with 1.17.0. ONNX Runtime is generally forward compatible, but in case you require a specific version of ONNX Runtime, you should pin the minor version in your `Cargo.toml` using a [tilde requirement](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#tilde-requirements):
Updates to the version of ONNX Runtime used by `ort` may occur on **minor** version updates, i.e. 2.0 ships with ONNX Runtime 1.17.0, but 2.1 may ship with 1.18.0. ONNX Runtime is generally forward compatible, but in case you require a specific version of ONNX Runtime, you should pin the minor version in your `Cargo.toml` using a [tilde requirement](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#tilde-requirements):
```toml
[dependencies]
ort = { version = "~2.0", ... }
Expand All @@ -16,12 +16,10 @@ ort = { version = "~2.0", ... }

| **ort** | **ONNX Runtime** |
| -------- | ----------------:|
| v2.0.0+ | v1.16.2 |
| v2.0.0+ | v1.17.0 |
| v1.16.0-v1.16.2 | v1.16.0 |
| v1.15.0-v1.15.5 | v1.15.1 |
| v1.14.2-v1.14.8 | v1.14.1 |
| v1.14.0-v1.14.1 | v1.14.0 |
| v1.13.1-v1.13.3 | v1.13.1 |
| v1.13.0 | v1.12.1 |

If you need support for an old (&lt;1.15) version of `ort`, or need an even older version of ONNX Runtime, [contact us](mailto:[email protected]).
Loading

0 comments on commit cae5161

Please sign in to comment.