Skip to content

Commit

Permalink
[Example] ggml: add model not found test
Browse files Browse the repository at this point in the history
Signed-off-by: dm4 <[email protected]>
  • Loading branch information
dm4 committed Apr 16, 2024
1 parent 6e81ae3 commit ca92d07
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/llama.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ jobs:
default \
'JSON object with 5 country names as keys and their capitals as values: '
- name: Model Not Found
run: |
test -f ~/.wasmedge/env && source ~/.wasmedge/env
cd wasmedge-ggml/test/model-not-found
cargo build --target wasm32-wasi --release
time wasmedge --dir .:. \
--nn-preload default:GGML:AUTO:model-not-found.gguf \
target/wasm32-wasi/release/wasmedge-ggml-model-not-found.wasm \
default
- name: Build llama-stream
run: |
cd wasmedge-ggml/llama-stream
Expand Down
8 changes: 8 additions & 0 deletions wasmedge-ggml/test/model-not-found/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "wasmedge-ggml-model-not-found"
version = "0.1.0"
edition = "2021"

[dependencies]
serde_json = "1.0"
wasmedge-wasi-nn = "0.7.0"
11 changes: 11 additions & 0 deletions wasmedge-ggml/test/model-not-found/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# `model-not-found`

Ensure that we get the `ModelNotFound` error when the model does not exist.

## Execute

```console
$ wasmedge --dir .:. \
--nn-preload default:GGML:AUTO:model-not-found.gguf \
wasmedge-ggml-model-not-found.wasm default
```
24 changes: 24 additions & 0 deletions wasmedge-ggml/test/model-not-found/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::env;
use wasmedge_wasi_nn::{self, BackendError, Error, ExecutionTarget, GraphBuilder, GraphEncoding};

fn main() {
let args: Vec<String> = env::args().collect();
let model_name: &str = &args[1];

// Create graph and initialize context.
let graph =
GraphBuilder::new(GraphEncoding::Ggml, ExecutionTarget::AUTO).build_from_cache(model_name);

// Check graph
match graph {
Err(Error::BackendError(BackendError::ModelNotFound)) => {
println!("Model not found");
}
Err(_) => {
panic!("Should be model not found");
}
Ok(_) => {
panic!("Should be model not found");
}
}
}
Binary file not shown.

0 comments on commit ca92d07

Please sign in to comment.