switch ml engine backend
This commit is contained in:
+14
-25
@@ -19,8 +19,12 @@ const SMART_TAB_GROUPING_CONFIG = {
|
|||||||
taskName: ML_TASK_FEATURE_EXTRACTION,
|
taskName: ML_TASK_FEATURE_EXTRACTION,
|
||||||
featureId: "smart-tab-embedding",
|
featureId: "smart-tab-embedding",
|
||||||
engineId: FEATURES["smart-tab-embedding"].engineId,
|
engineId: FEATURES["smart-tab-embedding"].engineId,
|
||||||
backend: "onnx-native",
|
// GeckoView's Android build has no native InferenceSession, so the
|
||||||
fallbackBackend: "onnx",
|
// onnx-native backend always fails. Use the WASM onnx backend directly.
|
||||||
|
backend: "onnx",
|
||||||
|
// The threaded WASM runtime can't spawn worker threads in the GeckoView
|
||||||
|
// ML worker context, so force single-threaded execution.
|
||||||
|
numThreads: 1,
|
||||||
},
|
},
|
||||||
topicGeneration: {
|
topicGeneration: {
|
||||||
dtype: "q8",
|
dtype: "q8",
|
||||||
@@ -28,8 +32,12 @@ const SMART_TAB_GROUPING_CONFIG = {
|
|||||||
taskName: ML_TASK_TEXT2TEXT,
|
taskName: ML_TASK_TEXT2TEXT,
|
||||||
featureId: "smart-tab-topic",
|
featureId: "smart-tab-topic",
|
||||||
engineId: FEATURES["smart-tab-topic"].engineId,
|
engineId: FEATURES["smart-tab-topic"].engineId,
|
||||||
backend: "onnx-native",
|
// GeckoView's Android build has no native InferenceSession, so the
|
||||||
fallbackBackend: "onnx",
|
// onnx-native backend always fails. Use the WASM onnx backend directly.
|
||||||
|
backend: "onnx",
|
||||||
|
// The threaded WASM runtime can't spawn worker threads in the GeckoView
|
||||||
|
// ML worker context, so force single-threaded execution.
|
||||||
|
numThreads: 1,
|
||||||
},
|
},
|
||||||
// dataConfig: {
|
// dataConfig: {
|
||||||
// titleKey: "label",
|
// titleKey: "label",
|
||||||
@@ -132,7 +140,7 @@ async function createMlEngine(engineConfig, progressCallback) {
|
|||||||
modelId,
|
modelId,
|
||||||
modelRevision,
|
modelRevision,
|
||||||
backend,
|
backend,
|
||||||
fallbackBackend,
|
numThreads,
|
||||||
} = engineConfig;
|
} = engineConfig;
|
||||||
const initData = {
|
const initData = {
|
||||||
featureId,
|
featureId,
|
||||||
@@ -143,29 +151,10 @@ async function createMlEngine(engineConfig, progressCallback) {
|
|||||||
modelId,
|
modelId,
|
||||||
modelRevision,
|
modelRevision,
|
||||||
backend,
|
backend,
|
||||||
|
numThreads,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
|
||||||
return await createEngine(initData, progressCallback);
|
return await createEngine(initData, progressCallback);
|
||||||
} catch (error) {
|
|
||||||
if (!fallbackBackend || fallbackBackend === backend) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return await createEngine(
|
|
||||||
{
|
|
||||||
...initData,
|
|
||||||
backend: fallbackBackend,
|
|
||||||
},
|
|
||||||
progressCallback
|
|
||||||
);
|
|
||||||
} catch (fallbackError) {
|
|
||||||
throw new Error(
|
|
||||||
`Failed to create ML engine with ${backend} (${error?.message || error}) or ${fallbackBackend} (${fallbackError?.message || fallbackError})`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ml = class extends ExtensionAPI {
|
this.ml = class extends ExtensionAPI {
|
||||||
|
|||||||
Reference in New Issue
Block a user