Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasi-nn: update openvino backend to v0.7.2, use API 2.0 #8790

Merged
merged 7 commits into from
Jul 16, 2024

Conversation

rahulchaphalkar
Copy link
Contributor

  • Updates openvino to v0.7.1 in wasi-nn crate
  • Enables API 2.0 in openvino.rs.

@rahulchaphalkar rahulchaphalkar requested review from a team as code owners June 12, 2024 23:03
@rahulchaphalkar rahulchaphalkar requested review from fitzgen and removed request for a team June 12, 2024 23:03
@rahulchaphalkar
Copy link
Contributor Author

Converting this to draft temporarily, plan to bump openvino crate to a newer version than 0.7.1

@rahulchaphalkar rahulchaphalkar marked this pull request as draft June 12, 2024 23:57
@alexcrichton alexcrichton requested review from abrown and removed request for a team and fitzgen June 13, 2024 00:24
Copy link
Contributor

@abrown abrown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes complete sense. We still need to rebase so that CI runs (remember that one of these PRs should have prtest:full in it if that is not already the case?).

crates/wasi-nn/src/backend/openvino.rs Outdated Show resolved Hide resolved
crates/wasi-nn/src/backend/openvino.rs Outdated Show resolved Hide resolved
@rahulchaphalkar rahulchaphalkar marked this pull request as ready for review June 27, 2024 16:29
@abrown abrown changed the title Wasi-nn: update openvino backend to v0.7.1, use API 2.0 wasi-nn: update openvino backend to v0.7.2, use API 2.0 Jun 29, 2024
@rahulchaphalkar
Copy link
Contributor Author

@abrown I pushed some changes to fix failures due to some incompatibilities with Id enum. Tests are now passing, but vet step is failing, maybe due to one of my rebases. Can you vet the dependency? Thanks.

@abrown
Copy link
Contributor

abrown commented Jul 3, 2024

I already did... where did that commit go?

@@ -157,24 +148,51 @@ impl From<SetupError> for BackendError {

/// Return the execution target string expected by OpenVINO from the
/// `ExecutionTarget` enum provided by wasi-nn.
fn map_execution_target_to_string(target: ExecutionTarget) -> &'static str {
fn map_execution_target_to_string(target: ExecutionTarget) -> DeviceType<'static> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, let's rewrite this as impl From<ExecutionTarget> for DeviceType<'static>. If not possible then at least change the function name and documentation.

ExecutionTarget::Tpu => unimplemented!("OpenVINO does not support TPU execution targets"),
}
}

/// Return OpenVINO's precision type for the `TensorType` enum provided by
/// wasi-nn.
fn map_tensor_type_to_precision(tensor_type: TensorType) -> openvino::Precision {
fn map_tensor_type_to_precision(tensor_type: TensorType) -> openvino::ElementType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, this could be impl From<TensorType> for ElementType.

}

/// Return the `TensorType` enum provided by wasi-nn for OpenVINO's precision type
fn map_precision_to_tensor_type(element_type: openvino::ElementType) -> TensorType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a TryFrom since it is more useful to return an error to the user than crash Wasmtime with todo!.

ElementType::I32 => TensorType::I32,
ElementType::I64 => TensorType::I64,
ElementType::Bf16 => TensorType::Bf16,
ElementType::Undefined => todo!("not yet supported in wasi-nn `TensorType`"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could get cleaned up to something like: ElementType::Undefined | ElementType::Dynamic | ... => Err(BackendError::SomeNewVariant("{:?} is not yet supported in the openvino backend", element_type))

self.1.set_blob(&input_name, &blob)?;
let shape = Shape::new(&dimensions)?;
let mut new_tensor = OvTensor::new(precision, &shape)?;
let buffer = new_tensor.get_raw_data_mut()?;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no need to specify layout (of input tensor), and there is no PrePostProcessing in the whole file, Does it mean wasm code has to make sure the input tensor matches the requirement of model input? (I assume openvino models requires "NHWC" input)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Liang, yes this requires input tensor layout match the expected layout for model input.

@abrown abrown added this pull request to the merge queue Jul 16, 2024
Merged via the queue into bytecodealliance:main with commit 895183c Jul 16, 2024
120 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants