Skip to content

Commit

Permalink
feat: adjust configuration to validate data from preload model providers
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelmmiguel committed Sep 27, 2023
1 parent bd8abd8 commit 6b78225
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
27 changes: 16 additions & 11 deletions crates/worker/src/features/wasi_nn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,19 @@ impl Display for WasiNnBackend {
}

/// Available providers to load Wasi NN models.
#[derive(Deserialize, Clone, Default)]
#[serde(rename_all = "lowercase")]
#[derive(Deserialize, Clone, Debug)]
#[serde(rename_all = "lowercase", tag = "type")]
pub enum WasiNnModelProvider {
/// Load it from the local filesystem
#[default]
Local,
Local { dir: PathBuf },
}

impl Default for WasiNnModelProvider {
fn default() -> Self {
Self::Local {
dir: PathBuf::from("./"),
}
}
}

#[derive(Deserialize, Clone, Default)]
Expand All @@ -53,21 +60,19 @@ pub struct WasiNnModel {
provider: WasiNnModelProvider,
/// Backend to run this specific model
backend: WasiNnBackend,
/// For a local provider, it will retrieve the data from a local path.
dir: PathBuf,
}

impl WasiNnModel {
/// Provide the graph configuration from the current model. Depending on the
/// provider, it may need to perform other tasks before running it.
pub fn build_graph_data(&self, worker_path: &Path) -> (String, String) {
match self.provider {
WasiNnModelProvider::Local => {
let data = if self.dir.is_relative() {
match &self.provider {
WasiNnModelProvider::Local { dir } => {
let data = if dir.is_relative() {
worker_path.parent().map(|parent| {
(
self.backend.clone().to_string(),
parent.join(&self.dir).to_string_lossy().to_string(),
parent.join(dir).to_string_lossy().to_string(),
)
})
} else {
Expand All @@ -78,7 +83,7 @@ impl WasiNnModel {
// Absolute path or best effort if it cannot retrieve the parent path
(
self.backend.clone().to_string(),
self.dir.to_string_lossy().to_string(),
dir.to_string_lossy().to_string(),
)
})
}
Expand Down
3 changes: 1 addition & 2 deletions examples/rust-wasi-nn-preload/inference.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ MODEL = "model"

[[features.wasi_nn.preload_models]]
backend = "openvino"
provider = "local"
dir = "./_models/mobilenet/"
provider = { type = "local", dir = "./_models/mobilenet/" }

[[folders]]
from = "./_data"
Expand Down

0 comments on commit 6b78225

Please sign in to comment.