revert num threads; harden cleanup;
This commit is contained in:
+32
-10
@@ -25,9 +25,6 @@ const SMART_TAB_GROUPING_CONFIG = {
|
|||||||
// GeckoView's Android build has no native InferenceSession, so the
|
// GeckoView's Android build has no native InferenceSession, so the
|
||||||
// onnx-native backend always fails. Use the WASM onnx backend directly.
|
// onnx-native backend always fails. Use the WASM onnx backend directly.
|
||||||
backend: "onnx",
|
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",
|
||||||
@@ -38,9 +35,6 @@ const SMART_TAB_GROUPING_CONFIG = {
|
|||||||
// GeckoView's Android build has no native InferenceSession, so the
|
// GeckoView's Android build has no native InferenceSession, so the
|
||||||
// onnx-native backend always fails. Use the WASM onnx backend directly.
|
// onnx-native backend always fails. Use the WASM onnx backend directly.
|
||||||
backend: "onnx",
|
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",
|
||||||
@@ -143,7 +137,6 @@ async function createMlEngine(engineConfig, progressCallback) {
|
|||||||
modelId,
|
modelId,
|
||||||
modelRevision,
|
modelRevision,
|
||||||
backend,
|
backend,
|
||||||
numThreads,
|
|
||||||
} = engineConfig;
|
} = engineConfig;
|
||||||
const initData = {
|
const initData = {
|
||||||
featureId,
|
featureId,
|
||||||
@@ -154,7 +147,6 @@ async function createMlEngine(engineConfig, progressCallback) {
|
|||||||
modelId,
|
modelId,
|
||||||
modelRevision,
|
modelRevision,
|
||||||
backend,
|
backend,
|
||||||
numThreads,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return await createEngine(initData, progressCallback);
|
return await createEngine(initData, progressCallback);
|
||||||
@@ -239,12 +231,42 @@ this.ml = class extends ExtensionAPI {
|
|||||||
return generated;
|
return generated;
|
||||||
},
|
},
|
||||||
async clearCache() {
|
async clearCache() {
|
||||||
|
// Always drop our cached engine references, even if a
|
||||||
|
// later step fails, so the next request rebuilds them.
|
||||||
self.embeddingEngine = null;
|
self.embeddingEngine = null;
|
||||||
self.topicEngine = null;
|
self.topicEngine = null;
|
||||||
|
|
||||||
|
// Tear the engine down first so it releases its OPFS and
|
||||||
|
// IndexedDB handles before we delete the underlying data.
|
||||||
|
// destroyMLEngine() uses Promise.allSettled internally and
|
||||||
|
// never rejects, but guard it anyway.
|
||||||
|
const errors = [];
|
||||||
|
try {
|
||||||
await EngineProcess.destroyMLEngine();
|
await EngineProcess.destroyMLEngine();
|
||||||
await new ModelHub().purgeDatabase();
|
} catch (error) {
|
||||||
await OPFS.remove("mlRuntimeFiles", { recursive: true });
|
errors.push(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run the storage wipes independently: a failure in one
|
||||||
|
// must not skip the other, otherwise the cache is left
|
||||||
|
// half-cleared and the corruption persists.
|
||||||
|
const results = await Promise.allSettled([
|
||||||
|
new ModelHub().purgeDatabase(),
|
||||||
|
OPFS.remove("mlRuntimeFiles", { recursive: true }),
|
||||||
|
]);
|
||||||
|
for (const result of results) {
|
||||||
|
if (result.status === "rejected") {
|
||||||
|
errors.push(result.reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errors.length) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to fully clear ML cache: ${errors
|
||||||
|
.map((e) => e?.message || String(e))
|
||||||
|
.join("; ")}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user