Merge pull request #4079 from janhq/fix/factory-reset-hang-on-wiping-data
This commit is contained in:
commit
e9de9e728d
@ -83,11 +83,11 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onUnload(): void {
|
async onUnload() {
|
||||||
console.log('Clean up cortex.cpp services')
|
console.log('Clean up cortex.cpp services')
|
||||||
this.shouldReconnect = false
|
this.shouldReconnect = false
|
||||||
this.clean()
|
this.clean()
|
||||||
executeOnMain(NODE, 'dispose')
|
await executeOnMain(NODE, 'dispose')
|
||||||
super.onUnload()
|
super.onUnload()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
27
extensions/inference-cortex-extension/src/node/cpuInfo.ts
Normal file
27
extensions/inference-cortex-extension/src/node/cpuInfo.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { cpuInfo } from 'cpu-instructions'
|
||||||
|
|
||||||
|
// Check the CPU info and determine the supported instruction set
|
||||||
|
const info = cpuInfo.cpuInfo().some((e) => e.toUpperCase() === 'AVX512')
|
||||||
|
? 'avx512'
|
||||||
|
: cpuInfo.cpuInfo().some((e) => e.toUpperCase() === 'AVX2')
|
||||||
|
? 'avx2'
|
||||||
|
: cpuInfo.cpuInfo().some((e) => e.toUpperCase() === 'AVX')
|
||||||
|
? 'avx'
|
||||||
|
: 'noavx'
|
||||||
|
|
||||||
|
// Send the result and wait for confirmation before exiting
|
||||||
|
new Promise<void>((resolve, reject) => {
|
||||||
|
// @ts-ignore
|
||||||
|
process.send(info, (error: Error | null) => {
|
||||||
|
if (error) {
|
||||||
|
reject(error)
|
||||||
|
} else {
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(() => process.exit(0))
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('Failed to send info:', error)
|
||||||
|
process.exit(1)
|
||||||
|
})
|
||||||
@ -1,6 +1,6 @@
|
|||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import { cpuInfo } from 'cpu-instructions'
|
|
||||||
import { GpuSetting, appResourcePath, log } from '@janhq/core/node'
|
import { GpuSetting, appResourcePath, log } from '@janhq/core/node'
|
||||||
|
import { fork } from 'child_process'
|
||||||
|
|
||||||
export interface CortexExecutableOptions {
|
export interface CortexExecutableOptions {
|
||||||
enginePath: string
|
enginePath: string
|
||||||
@ -52,7 +52,9 @@ const extension = (): '.exe' | '' => {
|
|||||||
*/
|
*/
|
||||||
const cudaVersion = (settings?: GpuSetting): '11-7' | '12-0' | undefined => {
|
const cudaVersion = (settings?: GpuSetting): '11-7' | '12-0' | undefined => {
|
||||||
const isUsingCuda =
|
const isUsingCuda =
|
||||||
settings?.vulkan !== true && settings?.run_mode === 'gpu' && !os().includes('mac')
|
settings?.vulkan !== true &&
|
||||||
|
settings?.run_mode === 'gpu' &&
|
||||||
|
!os().includes('mac')
|
||||||
|
|
||||||
if (!isUsingCuda) return undefined
|
if (!isUsingCuda) return undefined
|
||||||
return settings?.cuda?.version === '11' ? '11-7' : '12-0'
|
return settings?.cuda?.version === '11' ? '11-7' : '12-0'
|
||||||
@ -62,15 +64,29 @@ const cudaVersion = (settings?: GpuSetting): '11-7' | '12-0' | undefined => {
|
|||||||
* The CPU instructions that will be set - either 'avx512', 'avx2', 'avx', or 'noavx'.
|
* The CPU instructions that will be set - either 'avx512', 'avx2', 'avx', or 'noavx'.
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const cpuInstructions = (): string => {
|
const cpuInstructions = async (): Promise<string> => {
|
||||||
if (process.platform === 'darwin') return ''
|
if (process.platform === 'darwin') return ''
|
||||||
return cpuInfo.cpuInfo().some((e) => e.toUpperCase() === 'AVX512')
|
|
||||||
? 'avx512'
|
const child = fork(path.join(__dirname, './cpuInfo.js')) // Path to the child process file
|
||||||
: cpuInfo.cpuInfo().some((e) => e.toUpperCase() === 'AVX2')
|
|
||||||
? 'avx2'
|
return new Promise((resolve, reject) => {
|
||||||
: cpuInfo.cpuInfo().some((e) => e.toUpperCase() === 'AVX')
|
child.on('message', (cpuInfo?: string) => {
|
||||||
? 'avx'
|
resolve(cpuInfo ?? 'noavx')
|
||||||
: 'noavx'
|
child.kill() // Kill the child process after receiving the result
|
||||||
|
})
|
||||||
|
|
||||||
|
child.on('error', (err) => {
|
||||||
|
resolve('noavx')
|
||||||
|
child.kill()
|
||||||
|
})
|
||||||
|
|
||||||
|
child.on('exit', (code) => {
|
||||||
|
if (code !== 0) {
|
||||||
|
resolve('noavx')
|
||||||
|
child.kill()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,8 +110,11 @@ export const executableCortexFile = (
|
|||||||
/**
|
/**
|
||||||
* Find which variant to run based on the current platform.
|
* Find which variant to run based on the current platform.
|
||||||
*/
|
*/
|
||||||
export const engineVariant = (gpuSetting?: GpuSetting): string => {
|
export const engineVariant = async (
|
||||||
const cpuInstruction = cpuInstructions()
|
gpuSetting?: GpuSetting
|
||||||
|
): Promise<string> => {
|
||||||
|
const cpuInstruction = await cpuInstructions()
|
||||||
|
log(`[CORTEX]: CPU instruction: ${cpuInstruction}`)
|
||||||
let engineVariant = [
|
let engineVariant = [
|
||||||
os(),
|
os(),
|
||||||
gpuSetting?.vulkan
|
gpuSetting?.vulkan
|
||||||
|
|||||||
@ -17,6 +17,14 @@ jest.mock('@janhq/core', () => ({
|
|||||||
fs: {
|
fs: {
|
||||||
rm: jest.fn(),
|
rm: jest.fn(),
|
||||||
},
|
},
|
||||||
|
EngineManager: {
|
||||||
|
instance: jest.fn().mockReturnValue({
|
||||||
|
get: jest.fn(),
|
||||||
|
engines: {
|
||||||
|
values: jest.fn().mockReturnValue([])
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
describe('useFactoryReset', () => {
|
describe('useFactoryReset', () => {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { useCallback } from 'react'
|
import { useCallback } from 'react'
|
||||||
|
|
||||||
import { fs, AppConfiguration } from '@janhq/core'
|
import { fs, AppConfiguration, EngineManager } from '@janhq/core'
|
||||||
import { atom, useAtomValue, useSetAtom } from 'jotai'
|
import { atom, useAtomValue, useSetAtom } from 'jotai'
|
||||||
|
|
||||||
import { useActiveModel } from './useActiveModel'
|
import { useActiveModel } from './useActiveModel'
|
||||||
@ -37,6 +37,15 @@ export default function useFactoryReset() {
|
|||||||
// 1: Stop running model
|
// 1: Stop running model
|
||||||
setFactoryResetState(FactoryResetState.StoppingModel)
|
setFactoryResetState(FactoryResetState.StoppingModel)
|
||||||
await stopModel()
|
await stopModel()
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
EngineManager.instance()
|
||||||
|
.engines.values()
|
||||||
|
.map(async (engine) => {
|
||||||
|
await engine.onUnload()
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 4000))
|
await new Promise((resolve) => setTimeout(resolve, 4000))
|
||||||
|
|
||||||
// 2: Delete the old jan data folder
|
// 2: Delete the old jan data folder
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user