Skip to content

Commit

Permalink
remove model files, download them instead. Switch from resnet18 to sq…
Browse files Browse the repository at this point in the history
…ueezenet1.1
  • Loading branch information
rahulchaphalkar committed Oct 14, 2024
1 parent e1afdbe commit 39f9271
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion crates/wasi-nn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ pytorch = ["dep:tch"]

[[test]]
name = "test-programs"
harness = false
harness = false
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ your system.
- `export LIBTORCH=/path/to/libtorch`
2. Build Wasmtime with `wasmtime-wasi-nn/pytorch` feature.
3. Navigate to this example directory `crates/wasi-nn/examples/classification-example-pytorch`.
4. Download `squeezenet1_1.pt` model
```
curl https://github.com/rahulchaphalkar/libtorch-models/releases/download/v0.1/squeezenet1_1.pt --output fixture/model.pt -L
```
4. Build this example `cargo build --target=wasm32-wasip1`.
5. Run the generated wasm file with wasmtime after mapping the directory containing Resnet18 `model.pt` and sample image `kitten.png`
5. Run the generated wasm file with wasmtime after mapping the directory containing squeezenet1.1 `model.pt` and sample image `kitten.png`
```
${Wasmtime_root_dir}/target/debug/wasmtime -S nn --dir ${Wasmtime_root_dir}/crates/wasi-nn/examples/classification-example-pytorch::. ${Wasmtime_root_dir}/crates/wasi-nn/examples/classification-example-pytorch/target/wasm32-wasip1/debug/wasi-nn-example-pytorch.wasm
```
Expand Down
Binary file not shown.
27 changes: 15 additions & 12 deletions crates/wasi-nn/tests/check/pytorch.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
use super::{artifacts_dir, DOWNLOAD_LOCK};
use anyhow::Result;
use super::{artifacts_dir, download, DOWNLOAD_LOCK};
use anyhow::{bail, Context, Result};
use std::{env, fs};

/// Return `Ok` if we find the cached MobileNet test artifacts; this will
/// download the artifacts if necessary.
pub fn are_artifacts_available() -> Result<()> {
let _exclusively_retrieve_artifacts = DOWNLOAD_LOCK.lock().unwrap();
const PYTORCH_BASE_URL: &str =
"https://github.com/rahulchaphalkar/libtorch-models/releases/download/v0.1/squeezenet1_1.pt";
let artifacts_dir = artifacts_dir();
if !artifacts_dir.is_dir() {
fs::create_dir(&artifacts_dir)?;
}

// Copy preprocessed image tensor from source tree to artifact directory.
let local_path = artifacts_dir.join("model.pt");
let remote_url = PYTORCH_BASE_URL;
if !local_path.is_file() {
download(&remote_url, &local_path).with_context(|| "unable to retrieve test artifact")?;
} else {
println!("> using cached artifact: {}", local_path.display())
}

// Copy image from source tree to artifact directory.
let image_path = env::current_dir()?
.join("tests")
.join("fixtures")
.join("kitten.tensor");
let dest_path = artifacts_dir.join("kitten.tensor");
fs::copy(&image_path, &dest_path)?;

// Copy Resnet18 model from source tree to artifact directory.
let image_path = env::current_dir()?
.join("tests")
.join("fixtures")
.join("resnet.pt");
let dest_path = artifacts_dir.join("model.pt");
fs::copy(&image_path, &dest_path)?;

Ok(())
}
Binary file removed crates/wasi-nn/tests/fixtures/resnet.pt
Binary file not shown.

0 comments on commit 39f9271

Please sign in to comment.