feat: ✨ unload ml engine when model is unselected, reuse ml engine
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0e1bde62b7
commit
96777f9a4b
@ -94,15 +94,20 @@ export function MLEngineContextProvider({ children }: { children: ReactNode }) {
|
||||
if (selectedModel && runningModel !== selectedModel) {
|
||||
(async () => {
|
||||
setLoadingModel(selectedModel);
|
||||
|
||||
const initProgressCallback: InitProgressCallback = async (
|
||||
initProgress
|
||||
) => {
|
||||
setLoadingProgress(initProgress.progress);
|
||||
};
|
||||
|
||||
if (!engine.current) {
|
||||
engine.current = await CreateMLCEngine(selectedModel, {
|
||||
initProgressCallback: initProgressCallback,
|
||||
});
|
||||
} else {
|
||||
await engine.current.reload(selectedModel);
|
||||
}
|
||||
|
||||
setRunningModel(selectedModel);
|
||||
setLoadingModel(null);
|
||||
@ -113,6 +118,8 @@ export function MLEngineContextProvider({ children }: { children: ReactNode }) {
|
||||
setGpuVendor(gpuVendor);
|
||||
}
|
||||
})();
|
||||
} else if (!selectedModel && engine.current) {
|
||||
engine.current.unload();
|
||||
}
|
||||
}, [
|
||||
engine,
|
||||
|
Loading…
Reference in New Issue
Block a user