Private AI meeting notes that stay on your computer. No meeting bot. Free and open source for Mac, Windows and Linux. An alternative to Granola, Otter and Fireflies.
TypeScript ai-meeting-assistantai-notetakerelectrongranola-alternativelinuxllama-cpplocal-ailocal-firstmacosmcpmeeting-minutesmeeting-notesoffline-firstopen-sourceprivacyspeech-to-texttranscriptionwhisperwhisper-cppwindows
On Windows and Linux, when the notes engine's CUDA build finds no graphics card (it can't be tested inside Electron), the card is checked again with Vulkan, and the build that found it is kept for next time (#32)
christianmat76e559577590
diff --git a/app/src/engine/llm.ts b/app/src/engine/llm.tsindex 57178a97..632027aa 100644--- a/app/src/engine/llm.ts+++ b/app/src/engine/llm.ts@@ -22,8 +22,10 @@ export function createLlm() {let main: LlamaContextSequence | undefined/** the embedding model (meaning search across meetings): small, its own context, kept until let go */let embedder: { path: string; model: LlamaModel; context: LlamaEmbeddingContext } | undefined- // YOGURT_ENGINE_GPU=off: the graphics card crashed the engine before, on Windows or Linux (src/main/engine.ts)- const getL = async () => (llama ??= await getLlama(process.env.YOGURT_ENGINE_GPU === 'off' ? { gpu: false } : undefined))+ // YOGURT_ENGINE_GPU=off: the graphics card crashed the engine before, on Windows or Linux; =vulkan: the default+ // (CUDA) build found no card but Vulkan did (#32). Both come from src/main/engine.ts.+ const gpu = process.env.YOGURT_ENGINE_GPU+ const getL = async () => (llama ??= await getLlama(gpu === 'off' ? { gpu: false } : gpu === 'vulkan' ? { gpu: 'vulkan' } : undefined))// Gemma's auto wrapper requests thinking; a zero token budget cuts it off instead of disabling it.const threads = (l: Llama) => { const n = engineThreads(process.platform, l.cpuMathCores, availableParallelism()); return n === undefined ? {} : { threads: n } }const chatWrapper = () => model?.fileInfo.metadata.general.architecture === 'gemma4' ? new Gemma4ChatWrapper({ reasoning: false }) : 'auto' as constdiff --git a/app/src/main/engine.ts b/app/src/main/engine.tsindex a22d0f3a..f1e7cc70 100644--- a/app/src/main/engine.ts+++ b/app/src/main/engine.ts@@ -26,6 +26,17 @@ export const engineShim = (platform: string, candidates: string[], exists: (p: s// LD_PRELOAD splits on spaces and colons, so a path with one would never loadplatform === 'linux' ? candidates.find((p) => !/[\s:]/.test(p) && exists(p)) : undefined+/** what node-llama-cpp runs the model with: its own pick (CUDA first where it finds CUDA), or Vulkan */+export type Backend = 'auto' | 'vulkan'++/**+ * Windows and Linux: the backends to check the graphics with, in order (#32). Inside Electron node-llama-cpp can't test+ * a build before loading it (patches/), so a CUDA build that won't start is kept and finds no card, where plain Node+ * would move on to Vulkan. The one that found the card last time goes first; a NODE_LLAMA_CPP_GPU set by hand is left alone.+ */+export const backendOrder = (platform: string, env: Record<string, string | undefined>, saved?: Backend): Backend[] =>+ platform === 'darwin' || env.NODE_LLAMA_CPP_GPU ? ['auto'] : saved === 'vulkan' ? ['vulkan', 'auto'] : ['auto', 'vulkan']+export type ChatRequest = { messages: EngineMessage[]; maxTokens?: number; thoughtBudget?: number; /** instead of the family's sampling temperature */ temperature?: number }export interface Engine {@@ -63,14 +74,25 @@ export class UtilityEngine implements Engine {private loaded = falseprivate limits: Limits+ private backend: Backend/*** cpuCrashes (Linux without the shim): the engine dies on the processor alone (code 132: Electron's allocator refuses* llama.cpp's single > 2 GiB weight buffer), so a lost graphics card starts the engine again on the card, not without it.* preload: the shim that prevents that crash (engineShim), put in the engine's LD_PRELOAD.+ * backends (backendOrder): what probe() checks the graphics with until one finds a card; onBackend: the one that did.*/- constructor(private workerPath: string, private opts: { gpuFallback?: boolean; cpuCrashes?: boolean; preload?: string } & Partial<Limits> = {}) {+ constructor(private workerPath: string, private opts: { gpuFallback?: boolean; cpuCrashes?: boolean; preload?: string; backends?: Backend[]; onBackend?: (b: Backend) => void } & Partial<Limits> = {}) {this.limits = { ...WATCH, ...opts }+ this.backend = opts.backends?.[0] ?? 'auto'+ }++ /** a different backend means a fresh engine process, and a fresh try on the card */+ private use(b: Backend) {+ if (b === this.backend) return+ this.backend = b+ this.cpuOnly = false+ if (this.proc) this.drop(() => new Error('The notes engine was restarted'))}/**@@ -104,10 +126,12 @@ export class UtilityEngine implements Engine {private ensure(): UtilityProcess {if (this.proc) return this.procconst { preload } = this.opts- const env = preload || this.cpuOnly ? {+ const vulkan = this.backend === 'vulkan'+ const env = preload || this.cpuOnly || vulkan ? {...process.env,...(preload ? { LD_PRELOAD: [preload, process.env.LD_PRELOAD].filter(Boolean).join(':') } : {}),- ...(this.cpuOnly ? { YOGURT_ENGINE_GPU: 'off' } : {}),+ // off wins: without the card is without it, whichever build+ ...(this.cpuOnly ? { YOGURT_ENGINE_GPU: 'off' } : vulkan ? { YOGURT_ENGINE_GPU: 'vulkan' } : {}),} : undefinedconst proc = utilityProcess.fork(this.workerPath, [], { serviceName: 'Yogurt Notes', ...(env ? { env } : {}) })this.loaded = false@@ -156,8 +180,33 @@ export class UtilityEngine implements Engine {return { id, done }}- /** the graphics the engine can use (Windows and Linux, before picking a model) */- probe() {+ /**+ * The graphics the engine can use (Windows and Linux, before picking a model). Each backend in turn until one finds a+ * card (#32); with none, what the first one found, and the engine goes back to it.+ */+ async probe(): Promise<GpuProbe> {+ const order = this.opts.backends ?? [this.backend]+ let first: { probe: GpuProbe } | { error: Error } | undefined+ let firstCpuOnly = false+ for (const [i, b] of order.entries()) {+ this.use(b)+ const r = await this.probeOnce().then((probe) => ({ probe }), (error: Error) => ({ error }))+ if ('probe' in r && r.probe.gpuType) {+ // a change from what was tried first (the one saved last time) is saved for next time+ if (i > 0) this.opts.onBackend?.(b)+ return r.probe+ }+ if (i === 0) { first = r; firstCpuOnly = this.cpuOnly }+ if (i < order.length - 1) console.warn(`notes engine: no graphics card found with ${b === 'auto' ? 'the default build' : b}${'error' in r ? ` (${r.error.message})` : ''}; checking with ${order[i + 1] === 'auto' ? 'the default build' : order[i + 1]}`)+ }+ // the first one again, as it left things (a crash there: without the card)+ this.use(order[0])+ this.cpuOnly = firstCpuOnly+ if (!first || 'error' in first) throw first?.error ?? new Error('No graphics check ran')+ return first.probe+ }++ private probeOnce() {const { id, done } = this.call<GpuProbe>({ type: 'probe' })this.watch(id, 'checking the graphics', this.limits.probeMs, this.limits.probeMs)return donediff --git a/app/src/main/index.ts b/app/src/main/index.tsindex 3387862f..ba28803f 100644--- a/app/src/main/index.ts+++ b/app/src/main/index.ts@@ -70,7 +70,7 @@ import { setJargon, setOwnerName } from './vocab'import { cleanJargon } from '../shared/jargon'import { setGenericTitles } from './titles'import { installAppMenu } from './appMenu'-import { engineShim, SHIM, UtilityEngine } from './engine'+import { backendOrder, engineShim, SHIM, UtilityEngine } from './engine'import { createNotesModel } from './notes/model'import { FakeEngine } from './notes/fake'import { hookNotes } from './notes'@@ -719,7 +719,12 @@ app.whenReady().then(() => {// Linux: the shim that keeps the engine from crashing on the processor (#32); without it, the card is the only wayconst shim = engineShim(process.platform, [process.resourcesPath && join(process.resourcesPath, 'bin', SHIM), join(__dirname, '../../resources/bin', SHIM)].filter((x): x is string => !!x), existsSync)if (process.platform === 'linux') console.info('NOTES', shim ? `big allocations go through ${shim}` : `${SHIM} is missing: the notes engine can crash on the processor`)- const engine = isFake() ? new FakeEngine() : new UtilityEngine(join(__dirname, 'engine.js'), { gpuFallback: process.platform !== 'darwin', cpuCrashes: process.platform === 'linux' && !shim, ...(shim ? { preload: shim } : {}) })+ // Windows and Linux: a CUDA build that won't start finds no card; Vulkan is tried next, and kept when it finds one (#32)+ const backends = backendOrder(process.platform, process.env, loadSettings(settingsFile).notesGpuBackend)+ const engine = isFake() ? new FakeEngine() : new UtilityEngine(join(__dirname, 'engine.js'), {+ gpuFallback: process.platform !== 'darwin', cpuCrashes: process.platform === 'linux' && !shim, ...(shim ? { preload: shim } : {}),+ backends, onBackend: (b) => { console.info('NOTES', `graphics found with ${b === 'auto' ? 'the default build' : b}; kept for next time`); updateSettings(settingsFile, { notesGpuBackend: b === 'vulkan' ? b : undefined }) },+ })if (engine instanceof UtilityEngine) probeGpu = () => engine.probe().then((g) => {console.info('NOTES', `graphics: ${g.gpuType || 'none'}${g.gpuNames.length ? ` (${g.gpuNames.join(', ')})` : ''}, ${g.vramTotalGB.toFixed(1)} GB`)return gdiff --git a/app/src/main/settings.ts b/app/src/main/settings.tsindex d1bfe9bb..e349d61e 100644--- a/app/src/main/settings.ts+++ b/app/src/main/settings.ts@@ -12,6 +12,8 @@ export type Settings = { theme?: 'light' | 'dark'; language?: string; /** what tintroSeen?: boolean/** The optional bigger notes model stays off until explicitly downloaded again. */notesUpgradeSkipped?: boolean+ /** Windows and Linux: the notes engine found the graphics card with Vulkan, not its default (CUDA) build (#32) */+ notesGpuBackend?: 'vulkan'/** home's Finish setup was put away while these were missing; it comes back only when something else is */setupDismissed?: import('./permissions').PermissionKind[]/** opens when the Mac starts; off unless the person said yes */diff --git a/app/test/engineBackend.test.ts b/app/test/engineBackend.test.tsnew file mode 100644index 00000000..33b0ebc5--- /dev/null+++ b/app/test/engineBackend.test.ts@@ -0,0 +1,127 @@+import { EventEmitter } from 'node:events'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'++/** a stand-in utility process: records what it was sent and how it was started; answers only when told */+class Proc extends EventEmitter {+ sent: any[] = []+ killed = false+ constructor(public env?: Record<string, string | undefined>) { super() }+ postMessage(m: any) { this.sent.push(m) }+ kill() { if (this.killed) return true; this.killed = true; queueMicrotask(() => this.emit('exit', 1)); return true }+ answer(type: string, data: unknown = null) { const m = this.sent.find((x) => x.type === type); this.emit('message', { id: m.id, type: 'result', data }) }+ fail(type: string, message: string) { const m = this.sent.find((x) => x.type === type); this.emit('message', { id: m.id, type: 'error', message }) }+}+const procs: Proc[] = []+vi.mock('electron', () => ({ utilityProcess: { fork: (_p: string, _a: string[], o: { env?: Record<string, string> }) => { const p = new Proc(o.env); procs.push(p); return p } } }))+const { UtilityEngine, backendOrder } = await import('../src/main/engine')++const card = { gpuType: 'vulkan', vramTotalGB: 12.9, unifiedGB: 0, gpuNames: ['NVIDIA GeForce RTX 3080 Ti'] }+const none = { gpuType: false, vramTotalGB: 0, unifiedGB: 0, gpuNames: [] }+const backend = (p: Proc) => p.env?.YOGURT_ENGINE_GPU+/** lets the engine move on to the next process, then returns it */+const next = async (n: number) => { await vi.waitFor(() => expect(procs.length).toBe(n)); await vi.waitFor(() => expect(procs[n - 1].sent.length).toBeGreaterThan(0)); return procs[n - 1] }++beforeEach(() => { procs.length = 0; vi.spyOn(console, 'warn').mockImplementation(() => {}); vi.spyOn(console, 'error').mockImplementation(() => {}); vi.spyOn(console, 'info').mockImplementation(() => {}) })+afterEach(() => { vi.restoreAllMocks() })++describe('which graphics backends the notes engine checks (#32)', () => {+ it('Windows and Linux: node-llama-cpp first, then Vulkan; a Mac only ever its own', () => {+ expect(backendOrder('linux', {})).toEqual(['auto', 'vulkan'])+ expect(backendOrder('win32', {})).toEqual(['auto', 'vulkan'])+ expect(backendOrder('darwin', {})).toEqual(['auto'])+ })+ it('the one that worked last time goes first', () => {+ expect(backendOrder('linux', {}, 'vulkan')).toEqual(['vulkan', 'auto'])+ })+ it('a NODE_LLAMA_CPP_GPU the person set is left alone', () => {+ expect(backendOrder('linux', { NODE_LLAMA_CPP_GPU: 'cuda' }, 'vulkan')).toEqual(['auto'])+ })+})++describe('the notes engine finds the graphics card with Vulkan when CUDA does not start (#32)', () => {+ it('no card with the CUDA build: the engine starts again on Vulkan, finds it, keeps it and says so', async () => {+ const saved: string[] = []+ const e = new UtilityEngine('engine.js', { gpuFallback: true, backends: ['auto', 'vulkan'], onBackend: (b) => saved.push(b) })+ const probe = e.probe()+ const first = await next(1)+ expect(backend(first)).toBeUndefined()+ first.answer('probe', none)+ const second = await next(2)+ expect(first.killed).toBe(true)+ expect(backend(second)).toBe('vulkan')+ second.answer('probe', card)+ await expect(probe).resolves.toEqual(card)+ expect(saved).toEqual(['vulkan'])+ // the model loads in the same Vulkan engine+ const load = e.load('m.gguf', 32768, 8192)+ expect(procs).toHaveLength(2)+ second.answer('load', { contextSize: 32768 })+ await expect(load).resolves.toMatchObject({ contextSize: 32768 })+ })++ it('a CUDA build that fails to load (an error, not a crash) tries Vulkan too', async () => {+ const e = new UtilityEngine('engine.js', { gpuFallback: true, backends: ['auto', 'vulkan'] })+ const probe = e.probe()+ ;(await next(1)).fail('probe', 'ggml_cuda_init: failed to initialize CUDA: unknown error')+ ;(await next(2)).answer('probe', card)+ await expect(probe).resolves.toEqual(card)+ })++ it('a crash while checking with CUDA tries Vulkan on the card, not the processor', async () => {+ const e = new UtilityEngine('engine.js', { gpuFallback: true, backends: ['auto', 'vulkan'] })+ const probe = e.probe()+ const first = await next(1)+ first.emit('exit', 132)+ const second = await next(2)+ expect(backend(second)).toBe('vulkan')+ second.answer('probe', card)+ await expect(probe).resolves.toEqual(card)+ })++ it('a card found the first time: one engine, nothing saved', async () => {+ const saved: string[] = []+ const e = new UtilityEngine('engine.js', { gpuFallback: true, backends: ['auto', 'vulkan'], onBackend: (b) => saved.push(b) })+ const probe = e.probe()+ ;(await next(1)).answer('probe', { ...card, gpuType: 'cuda' })+ await expect(probe).resolves.toMatchObject({ gpuType: 'cuda' })+ expect(procs).toHaveLength(1)+ expect(saved).toEqual([])+ })++ it('Vulkan saved from last time, but now only CUDA finds the card: CUDA is kept and saved', async () => {+ const saved: string[] = []+ const e = new UtilityEngine('engine.js', { gpuFallback: true, backends: ['vulkan', 'auto'], onBackend: (b) => saved.push(b) })+ const probe = e.probe()+ const first = await next(1)+ expect(backend(first)).toBe('vulkan')+ first.answer('probe', none)+ const second = await next(2)+ expect(backend(second)).toBeUndefined()+ second.answer('probe', { ...card, gpuType: 'cuda' })+ await expect(probe).resolves.toMatchObject({ gpuType: 'cuda' })+ expect(saved).toEqual(['auto'])+ })++ it('no card with either: what the first check found, and the engine goes back to node-llama-cpp\'s own pick', async () => {+ const saved: string[] = []+ const e = new UtilityEngine('engine.js', { gpuFallback: true, backends: ['auto', 'vulkan'], onBackend: (b) => saved.push(b) })+ const probe = e.probe()+ ;(await next(1)).answer('probe', none)+ ;(await next(2)).fail('probe', 'No prebuilt binaries found')+ await expect(probe).resolves.toEqual(none)+ expect(saved).toEqual([])+ void e.load('m.gguf', 32768, 8192).catch(() => {})+ const third = await next(3)+ expect(backend(third)).toBeUndefined()+ })++ it('without the graphics card, Vulkan or not, the engine runs on the processor', async () => {+ const e = new UtilityEngine('engine.js', { gpuFallback: true, backends: ['vulkan', 'auto'] })+ void e.load('m.gguf', 32768, 8192).catch(() => {})+ const first = await next(1)+ expect(backend(first)).toBe('vulkan')+ first.emit('exit', 1)+ void e.load('m.gguf', 32768, 8192).catch(() => {})+ expect(backend(await next(2))).toBe('off')+ })+})