Manjunath Kudlur commited on
Commit
2be96ef
·
1 Parent(s): ce2e9d0

Ensure WebGPU enabled onnx runtime is loaded

Browse files
Files changed (3) hide show
  1. decoder_worker.js +3 -3
  2. encoder_worker.js +19 -3
  3. index.html +1 -1
decoder_worker.js CHANGED
@@ -2,10 +2,10 @@
2
  * Decoder Worker - Runs adapter + decoder in a separate thread
3
  */
4
 
5
- importScripts('https://cdn.jsdelivr.net/npm/onnxruntime-web@1.17.0/dist/ort.min.js');
6
 
7
- // Configure ONNX Runtime to find WASM files from CDN
8
- ort.env.wasm.wasmPaths = 'https://cdn.jsdelivr.net/npm/onnxruntime-web@1.17.0/dist/';
9
 
10
  const MODEL_CACHE_NAME = 'moonshine-models-v1';
11
 
 
2
  * Decoder Worker - Runs adapter + decoder in a separate thread
3
  */
4
 
5
+ importScripts('https://cdn.jsdelivr.net/npm/onnxruntime-web@1.21.0/dist/ort.all.min.js');
6
 
7
+ // Configure ONNX Runtime paths
8
+ ort.env.wasm.wasmPaths = 'https://cdn.jsdelivr.net/npm/onnxruntime-web@1.21.0/dist/';
9
 
10
  const MODEL_CACHE_NAME = 'moonshine-models-v1';
11
 
encoder_worker.js CHANGED
@@ -2,10 +2,10 @@
2
  * Encoder Worker - Runs preprocessor + encoder in a separate thread
3
  */
4
 
5
- importScripts('https://cdn.jsdelivr.net/npm/onnxruntime-web@1.17.0/dist/ort.min.js');
6
 
7
- // Configure ONNX Runtime to find WASM files from CDN
8
- ort.env.wasm.wasmPaths = 'https://cdn.jsdelivr.net/npm/onnxruntime-web@1.17.0/dist/';
9
 
10
  const MODEL_CACHE_NAME = 'moonshine-models-v1';
11
 
@@ -244,7 +244,23 @@ async function processMessage(e) {
244
  const backend = data.backend || 'wasm';
245
  const dtype = 'fp32';
246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  const sessionOptions = { executionProviders: [backend] };
 
248
 
249
  tailLatency = cfg.n_future * cfg.encoder_depth;
250
 
 
2
  * Encoder Worker - Runs preprocessor + encoder in a separate thread
3
  */
4
 
5
+ importScripts('https://cdn.jsdelivr.net/npm/onnxruntime-web@1.21.0/dist/ort.all.min.js');
6
 
7
+ // Configure ONNX Runtime paths
8
+ ort.env.wasm.wasmPaths = 'https://cdn.jsdelivr.net/npm/onnxruntime-web@1.21.0/dist/';
9
 
10
  const MODEL_CACHE_NAME = 'moonshine-models-v1';
11
 
 
244
  const backend = data.backend || 'wasm';
245
  const dtype = 'fp32';
246
 
247
+ // Check WebGPU availability
248
+ if (backend === 'webgpu') {
249
+ if (typeof navigator !== 'undefined' && navigator.gpu) {
250
+ console.log('WebGPU navigator.gpu is available');
251
+ const adapter = await navigator.gpu.requestAdapter();
252
+ if (adapter) {
253
+ console.log('WebGPU adapter obtained:', adapter);
254
+ } else {
255
+ throw new Error('WebGPU adapter not available');
256
+ }
257
+ } else {
258
+ throw new Error('WebGPU not supported (navigator.gpu is undefined)');
259
+ }
260
+ }
261
+
262
  const sessionOptions = { executionProviders: [backend] };
263
+ console.log(`Creating sessions with backend: ${backend}`);
264
 
265
  tailLatency = cfg.n_future * cfg.encoder_depth;
266
 
index.html CHANGED
@@ -705,7 +705,7 @@
705
  </div>
706
  </div>
707
 
708
- <script src="https://cdn.jsdelivr.net/npm/onnxruntime-web@1.17.0/dist/ort.min.js"></script>
709
  <script type="module" src="streaming_asr.js"></script>
710
  </body>
711
  </html>
 
705
  </div>
706
  </div>
707
 
708
+ <script src="https://cdn.jsdelivr.net/npm/onnxruntime-web@1.21.0/dist/ort.all.min.js"></script>
709
  <script type="module" src="streaming_asr.js"></script>
710
  </body>
711
  </html>