Skip to content

Commit

Permalink
Full build in CI (#19)
Browse files Browse the repository at this point in the history
* Remove Cargo.lock from examples .gitignore

* Remove security audit to sub crates in workspace

* Remove use of deprecated functions of ndarray 0.16.0

* Fix tensor tests

* Fix docs tests

* Full build in CI

* Install torch in setup_dev.py
  • Loading branch information
barakugav authored Aug 10, 2024
1 parent 5872e42 commit 9f829a9
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 41 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/develop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}

############ Install executorch deps ############
# - name: Setup dev env, install executorch and its deps
# run: python scripts/setup_dev.py
- name: Setup dev env, install executorch and its deps
run: python scripts/setup_dev.py

############ Build executorch-rs ############
# - name: Build
# run: cargo build
- name: Build
run: cargo build

############ Linters ############
- name: Rust Clippy linter
Expand All @@ -49,10 +49,13 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}

############ Tests ############
# - name: Run Rust tests
# run: cargo test
- name: Run Rust tests
run: cargo test --workspace --all-features

############ Examples ############
# - name: Run 'hello world add' example
# run: cargo run
# working-directory: examples/hello_world_add
# - name: Run 'hello world add no_std' example
# run: cargo run
# working-directory: examples/hello_world_add_no_std
12 changes: 2 additions & 10 deletions .github/workflows/security_scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,7 @@ jobs:
run: cargo install cargo-audit

############ Checks ############
- name: Check executorch
- name: Audit
run: cargo audit -D warnings
# its enough to only check the top level Cargo.lock because we are in a workspace
working-directory: ./
- name: Check executorch-sys
run: cargo audit -D warnings
working-directory: executorch-sys
- name: Check examples/hello_world_add
run: cargo audit -D warnings
working-directory: examples/hello_world_add
- name: Check examples/hello_world_add_no_std
run: cargo audit -D warnings
working-directory: examples/hello_world_add_no_std
1 change: 0 additions & 1 deletion examples/hello_world_add/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/Cargo.lock
/model.pte
1 change: 0 additions & 1 deletion examples/hello_world_add_no_std/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/Cargo.lock
/model.pte
48 changes: 31 additions & 17 deletions scripts/setup_dev.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import multiprocessing
import shutil
import subprocess
Expand All @@ -12,6 +13,20 @@


def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"--clean",
action="store_true",
help="Remove the existing executorch directory before cloning",
)
args = parser.parse_args()

if args.clean:
if DEV_EXECUTORCH_DIR.exists():
shutil.rmtree(DEV_EXECUTORCH_DIR)

# TODO setup a venv here

clone_executorch()

# subprocess.check_call(["./install_requirements.sh"], cwd=DEV_EXECUTORCH_DIR)
Expand All @@ -25,30 +40,29 @@ def main():
"tomli",
"wheel",
"zstd",
"torch==2.4.0",
]
)

build_executorch()


def clone_executorch():
if DEV_EXECUTORCH_DIR.exists():
shutil.rmtree(DEV_EXECUTORCH_DIR)

DEV_EXECUTORCH_DIR.parent.mkdir(parents=True, exist_ok=True)
# git clone --depth 1 --branch v0.3.0 https://github.com/pytorch/executorch.git
subprocess.check_call(
[
"git",
"clone",
"--depth",
"1",
"--branch",
"v0.3.0", # TODO: parse from somewhere
"https://github.com/pytorch/executorch.git",
],
cwd=DEV_EXECUTORCH_DIR.parent,
)
if not DEV_EXECUTORCH_DIR.exists():
DEV_EXECUTORCH_DIR.parent.mkdir(parents=True, exist_ok=True)
# git clone --depth 1 --branch v0.3.0 https://github.com/pytorch/executorch.git
subprocess.check_call(
[
"git",
"clone",
"--depth",
"1",
"--branch",
"v0.3.0", # TODO: parse from somewhere
"https://github.com/pytorch/executorch.git",
],
cwd=DEV_EXECUTORCH_DIR.parent,
)

subprocess.check_call(
["git", "submodule", "sync", "--recursive"], cwd=DEV_EXECUTORCH_DIR
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! The following example create a simple model in Python, exports it, and then executes it in Rust:
//!
//! Create a model in `Python` and export it:
//! ```
//! ```ignore
//! import torch
//! from executorch.exir import to_edge
//! from torch.export import export
Expand All @@ -32,7 +32,7 @@
//! ```
//!
//! Execute the model in Rust:
//! ```rust
//! ```no_run
//! use executorch::evalue::{EValue, Tag};
//! use executorch::module::Module;
//! use executorch::tensor::{Array, Tensor};
Expand Down
8 changes: 4 additions & 4 deletions src/tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,8 @@ mod tests {
let arr1 = Array::new(arr1.as_ref().view().into_dyn());
let tensor_impl = arr1.to_tensor_impl();
let tensor = Tensor::new(&tensor_impl);
let arr2 = tensor.as_array::<f32, ndarray::IxDyn>();
assert_eq!(arr1.as_ref().view().into_shape(vec![18, 4]).unwrap(), arr2);
let arr2 = tensor.as_array::<f32, ndarray::IxDyn>().into_shape_with_order(vec![18, 4]).unwrap();
assert_eq!(arr1.as_ref().view().into_shape_with_order(vec![18, 4]).unwrap(), arr2);
assert_eq!(arr2.strides(), [4, 1]);
} }
}
Expand All @@ -903,11 +903,11 @@ mod tests {
cfg_if::cfg_if! { if #[cfg(feature = "alloc")] {
let mut arr1 = arr1.as_ref().clone().into_dyn();
let arr1_clone = arr1.clone();
let mut arr1 = Array::new(arr1.view_mut().into_shape((18, 4)).unwrap());
let mut arr1 = Array::new(arr1.view_mut().into_shape_with_order((18, 4)).unwrap());
let mut tensor_impl = arr1.to_tensor_impl_mut();
let mut tensor = TensorMut::new(&mut tensor_impl);
let arr2 = tensor.as_array_mut::<f32, ndarray::IxDyn>();
assert_eq!(arr1_clone.view().into_shape(vec![18, 4]).unwrap(), arr2);
assert_eq!(arr1_clone.view().into_shape_with_order(vec![18, 4]).unwrap(), arr2);
assert_eq!(arr2.strides(), [4, 1]);
} }
}
Expand Down

0 comments on commit 9f829a9

Please sign in to comment.