Reza2kn commited on
Commit
9e54b79
·
verified ·
1 Parent(s): af482b4

Encoder: prefer static INT8 (QLinearConv); INT4 fallback. Recovers 92.7%-class quality in browser

Browse files
Files changed (1) hide show
  1. mega-asr.js +12 -10
mega-asr.js CHANGED
@@ -232,21 +232,23 @@ async function loadAll() {
232
  setProgress(30);
233
 
234
  // 3. ONNX sessions
235
- // Try INT8 encoder first (highest quality in browser); fall back to INT4
236
- // encoder if the browser ORT lacks the ConvInteger op (which it does in
237
- // both WebGPU and WASM backends as of 1.20).
238
- setLoaderStatus("audio encoder (INT8 INT4 fallback) ...");
239
- let encLabel = "audio_encoder INT8";
240
- let encUrl = `${HF_ROOT}/onnx/audio_encoder_int8.onnx`;
241
  try {
242
- state.encoder = await createSessionSimple(encUrl, encLabel, p => setProgress(30 + p * 10));
 
 
 
 
243
  } catch (e) {
244
- log(`INT8 encoder unsupported in browser (${e.message}); falling back to INT4 + sidecar`);
245
- encLabel = "audio_encoder INT4";
246
  state.encoder = await createSession(
247
  `${HF_ROOT}/onnx/audio_encoder_int4.onnx`,
248
  `${HF_ROOT}/onnx/audio_encoder_int4.onnx.data`,
249
- encLabel,
250
  p => setProgress(30 + p * 10),
251
  );
252
  }
 
232
  setProgress(30);
233
 
234
  // 3. ONNX sessions
235
+ // Audio encoder: try static INT8 (QLinearConv/QLinearMatMul, browser-OK),
236
+ // then fall back to INT4 (MatMulNBits) if static INT8 also has issues.
237
+ // The OLD audio_encoder_int8.onnx uses ConvInteger (dynamic quant) which
238
+ // onnxruntime-web does NOT support skipping that.
239
+ setLoaderStatus("audio encoder (INT8 static → INT4 fallback) ...");
 
240
  try {
241
+ state.encoder = await createSessionSimple(
242
+ `${HF_ROOT}/onnx/audio_encoder_int8_static.onnx`,
243
+ "audio_encoder INT8 (static)",
244
+ p => setProgress(30 + p * 10),
245
+ );
246
  } catch (e) {
247
+ log(`static INT8 encoder unsupported (${e.message}); falling back to INT4`);
 
248
  state.encoder = await createSession(
249
  `${HF_ROOT}/onnx/audio_encoder_int4.onnx`,
250
  `${HF_ROOT}/onnx/audio_encoder_int4.onnx.data`,
251
+ "audio_encoder INT4",
252
  p => setProgress(30 + p * 10),
253
  );
254
  }