Skip to content

Commit 7e442d5

Browse files
committed
decouple onnx-download from onnx-cuda feature
1 parent b2b42b9 commit 7e442d5

File tree

4 files changed

+9
-46
lines changed

4 files changed

+9
-46
lines changed

crates/wasi-nn/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ openvino = ["dep:openvino"]
7171
onnx = ["dep:ort"]
7272
# Use prebuilt ONNX Runtime binaries from ort.
7373
onnx-download = ["onnx", "ort/download-binaries"]
74-
# CUDA execution provider for NVIDIA GPU support (download prebuilt binaries)
75-
onnx-cuda = ["onnx", "ort/cuda", "ort/download-binaries"]
74+
# CUDA execution provider for NVIDIA GPU support (requires CUDA toolkit)
75+
onnx-cuda = ["onnx", "ort/cuda"]
7676
# WinML is only available on Windows 10 1809 and later.
7777
winml = ["dep:windows"]
7878
# PyTorch is available on all platforms; requires Libtorch to be installed

crates/wasi-nn/examples/classification-component-onnx/README.md

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ This example demonstrates how to use the `wasi-nn` crate to run a classification
66
It supports CPU and GPU (Nvidia CUDA) execution targets.
77

88
**Note:**
9-
For the wasi-nn GPU execution target, CUDA (onnx-cuda) is the only supported ONNX execution provider (EP).
10-
TPU execution target is not supported and will fall back to CPU execution.
9+
GPU execution target only supports Nvidia CUDA (onnx-cuda) as execution provider (EP) for now.
1110

1211
## Build
1312

@@ -27,7 +26,8 @@ cargo build --features component-model,wasi-nn,wasmtime-wasi-nn/onnx-download
2726

2827
#### For GPU (Nvidia CUDA) support:
2928
```sh
30-
cargo build --features component-model,wasi-nn,wasmtime-wasi-nn/onnx-cuda
29+
# This will automatically download onnxruntime dynamic shared library from cdn.pyke.io
30+
cargo build --features component-model,wasi-nn,wasmtime-wasi-nn/onnx-cuda,wasmtime-wasi-nn/onnx-download
3131
```
3232

3333
### Running with Different Execution Targets
@@ -46,15 +46,6 @@ Arguments:
4646
./crates/wasi-nn/examples/classification-component-onnx/target/wasm32-wasip1/debug/classification-component-onnx.wasm
4747
```
4848

49-
Or explicitly specify CPU:
50-
```sh
51-
./target/debug/wasmtime run \
52-
-Snn \
53-
--dir ./crates/wasi-nn/examples/classification-component-onnx/fixture/::fixture \
54-
./crates/wasi-nn/examples/classification-component-onnx/target/wasm32-wasip1/debug/classification-component-onnx.wasm \
55-
cpu
56-
```
57-
5849
#### GPU (CUDA) Execution:
5950
```sh
6051
# path to `libonnxruntime_providers_cuda.so` downloaded by `ort-sys`
@@ -66,12 +57,6 @@ export LD_LIBRARY_PATH={wasmtime_workspace}/target/debug
6657
./crates/wasi-nn/examples/classification-component-onnx/target/wasm32-wasip1/debug/classification-component-onnx.wasm \
6758
gpu
6859

69-
# With debug logging
70-
WASMTIME_LOG=wasmtime_wasi_nn=debug ./target/debug/wasmtime run -Snn \
71-
--dir ./crates/wasi-nn/examples/classification-component-onnx/fixture/::fixture \
72-
./crates/wasi-nn/examples/classification-component-onnx/target/wasm32-wasip1/debug/classification-component-onnx.wasm \
73-
gpu
74-
7560
```
7661

7762
## Expected Output
@@ -97,12 +82,3 @@ You can monitor GPU usage using cmd `watch -n 1 nvidia-smi`.
9782
- NVIDIA GPU with CUDA support
9883
- CUDA Toolkit 12.x with cuDNN 9.x
9984
- Build wasmtime with `wasmtime-wasi-nn/onnx-cuda` feature
100-
101-
## Troubleshooting
102-
103-
If you see an error like:
104-
```
105-
ONNX GPU execution target requested, but 'onnx-cuda' feature is not enabled
106-
```
107-
108-
Make sure you've built wasmtime with the appropriate feature flag (see "Building Wasmtime" section above).

crates/wasi-nn/examples/classification-component-onnx/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn get_execution_target() -> ExecutionTarget {
3535
return ExecutionTarget::Cpu;
3636
}
3737
_ => {
38-
println!("Unknown/Unsupported execution target '{}', defaulting to CPU", args[1]);
38+
println!("Unknown execution target '{}', defaulting to CPU", args[1]);
3939
}
4040
}
4141
} else {

crates/wasi-nn/src/backend/onnx.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,11 @@ impl BackendInner for OnnxBackend {
3535
// Configure execution providers based on target
3636
let execution_providers = configure_execution_providers(target)?;
3737

38-
tracing::info!(
39-
"Configuring ONNX session with {} execution provider(s)",
40-
execution_providers.len()
41-
);
42-
4338
let session = Session::builder()?
4439
.with_execution_providers(execution_providers)?
4540
.with_optimization_level(GraphOptimizationLevel::Level3)?
4641
.commit_from_memory(builders[0])?;
4742

48-
// Log which execution providers were actually used
49-
tracing::info!(
50-
"ONNX session created successfully. Model inputs: {}, outputs: {}",
51-
session.inputs.len(),
52-
session.outputs.len()
53-
);
54-
5543
let box_: Box<dyn BackendGraph> =
5644
Box::new(OnnxGraph(Arc::new(Mutex::new(session)), target));
5745
Ok(box_.into())
@@ -76,19 +64,18 @@ fn configure_execution_providers(
7664
#[cfg(feature = "onnx-cuda")]
7765
{
7866
// Use CUDA execution provider for GPU acceleration
79-
// Fallback to CPU if CUDA initialization fails
80-
tracing::info!("Configuring CUDA execution provider for GPU target");
67+
tracing::debug!("Configuring ONNX Nvidia CUDA execution provider for GPU target");
8168
Ok(vec![CUDAExecutionProvider::default().build()])
8269
}
8370
#[cfg(not(feature = "onnx-cuda"))]
8471
{
8572
Err(BackendError::BackendAccess(anyhow::anyhow!(
86-
"ONNX GPU execution target requested, but 'onnx-cuda' feature is not enabled"
73+
"GPU execution target is requested, but 'onnx-cuda' feature is not enabled"
8774
)))
8875
}
8976
}
9077
ExecutionTarget::Tpu => {
91-
unimplemented!("ONNX TPU execution target is not supported yet");
78+
unimplemented!("TPU execution target is not supported for ONNX backend yet");
9279
}
9380
}
9481
}

0 commit comments

Comments
 (0)