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
whisper picks a discrete graphics card over an integrated one, and the log says which it took (#10)
christianmat8924cadbd057
diff --git a/app/native/whisper-server.patch b/app/native/whisper-server.patchindex df92d7be..403c2e55 100644--- a/app/native/whisper-server.patch+++ b/app/native/whisper-server.patch@@ -19,3 +19,45 @@ index b745f4d7..013fb37f 100644}const int n_segments = whisper_full_n_segments(ctx);for (int i = 0; i < n_segments; ++i)+diff --git a/src/whisper.cpp b/src/whisper.cpp+index 1675f33a..31995e46 100644+--- a/src/whisper.cpp++++ b/src/whisper.cpp+@@ -1299,6 +1299,19 @@ static size_t aheads_masks_nbytes(struct whisper_aheads_masks & aheads_masks) {+ return size;+ }+++// Yogurt: with a discrete graphics card and an integrated one (a desktop with an iGPU driving the displays, a gaming++// laptop), the integrated one often comes first and transcription ran on it, many times slower. Count only discrete++// cards when there is one; with none, integrated ones count as before (Apple Silicon, most laptops).++static bool whisper_dev_is_counted_gpu(ggml_backend_dev_t dev) {++ const enum ggml_backend_dev_type t = ggml_backend_dev_type(dev);++ if (t == GGML_BACKEND_DEVICE_TYPE_GPU) return true;++ if (t != GGML_BACKEND_DEVICE_TYPE_IGPU) return false;++ for (size_t i = 0; i < ggml_backend_dev_count(); ++i) {++ if (ggml_backend_dev_type(ggml_backend_dev_get(i)) == GGML_BACKEND_DEVICE_TYPE_GPU) return false;++ }++ return true;++}+++ static ggml_backend_t whisper_backend_init_gpu(const whisper_context_params & params) {+ ggml_log_set(g_state.log_callback, g_state.log_callback_user_data);++@@ -1311,7 +1324,7 @@ static ggml_backend_t whisper_backend_init_gpu(const whisper_context_params & pa+ enum ggml_backend_dev_type dev_type = ggml_backend_dev_type(dev_cur);+ const char * dev_name = ggml_backend_dev_name(dev_cur);+ WHISPER_LOG_INFO("%s: device %zu: %s (type: %d)\n", __func__, i, dev_name, dev_type);+- if (dev_type == GGML_BACKEND_DEVICE_TYPE_GPU || dev_type == GGML_BACKEND_DEVICE_TYPE_IGPU) {++ if (whisper_dev_is_counted_gpu(dev_cur)) {+ WHISPER_LOG_INFO("%s: found GPU device %zu: %s (type: %d, cnt: %d)\n", __func__, i, dev_name, dev_type, cnt);+ if (cnt == params.gpu_device) {+ dev = dev_cur;+@@ -1381,7 +1394,7 @@ static buft_list_t make_buft_list(whisper_context_params & params) {+ int cnt = 0;+ for (size_t i = 0; i < ggml_backend_dev_count(); ++i) {+ ggml_backend_dev_t dev = ggml_backend_dev_get(i);+- if (ggml_backend_dev_type(dev) == GGML_BACKEND_DEVICE_TYPE_GPU || ggml_backend_dev_type(dev) == GGML_BACKEND_DEVICE_TYPE_IGPU) {++ if (whisper_dev_is_counted_gpu(dev)) {+ if (cnt == params.gpu_device) {+ auto * buft = ggml_backend_dev_buffer_type(dev);+ if (buft) {diff --git a/app/scripts/native.sh b/app/scripts/native.shindex 3321ed17..efc7842f 100755--- a/app/scripts/native.sh+++ b/app/scripts/native.sh@@ -20,6 +20,7 @@ done# whisper-server: whisper.cpp at a pinned commit, Metal on, the Metal shaders embedded so it is one file.# The clone and build live in native/.whisper-build (gitignored); only the finished program is copied out.# native/whisper-server.patch is applied on top: with VAD on, a chunk with no speech in it crashed the server.+# It also makes whisper pick a discrete graphics card over an integrated one (Windows and Linux; a Mac has one).WHISPER_TAG=v1.9.5WHISPER_COMMIT=d1be6fde11ac6e0407606b4e42fe72d34add8037out=resources/bin/whisper-serverdiff --git a/app/src/main/asr/server.ts b/app/src/main/asr/server.tsindex 8260d35d..599ad03c 100644--- a/app/src/main/asr/server.ts+++ b/app/src/main/asr/server.ts@@ -127,7 +127,13 @@ export function createWhisperServer(o: Opts) {died = falseif (o.pidFile && p.pid) writeFileSync(o.pidFile, String(p.pid))let err = ''- p.stderr?.on('data', (d: Buffer) => { err = (err + d.toString()).slice(-2000) })+ // which graphics card whisper took goes in the log (on a computer with two, it says if it took the right one)+ let told = false+ p.stderr?.on('data', (d: Buffer) => {+ err = (err + d.toString()).slice(-2000)+ const dev = !told && err.match(/whisper_backend_init_gpu: using (\S+) backend/)?.[1]+ if (dev) { told = true; console.info('ASR', `whisper-server runs on ${dev}`) }+ })const gone = new Promise<never>((_, reject) => {p.once('error', (e) => reject(new Error(`whisper-server could not start: ${e.message}`)))p.once('exit', (code, sig) => reject(new Error(`whisper-server exited (${code ?? sig}) ${err.split('\n').filter(Boolean).slice(-2).join(' | ')}`.trim())))diff --git a/app/test/asrServer.test.ts b/app/test/asrServer.test.tsindex 27da582e..85bc6c36 100644--- a/app/test/asrServer.test.ts+++ b/app/test/asrServer.test.ts@@ -1,7 +1,7 @@import { chmodSync, existsSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs'import { availableParallelism, tmpdir } from 'node:os'import { join } from 'node:path'-import { afterEach, describe, expect, it } from 'vitest'+import { afterEach, describe, expect, it, vi } from 'vitest'import { createWhisperServer, killStale, recoverer } from '../src/main/asr/server'import { createTranscriber } from '../src/main/asr/transcribe'@@ -20,6 +20,7 @@ function fakeBinary(loadMs = 0, modes: string[] = ['ok']) {const n = fs.readFileSync(dir + '/launches', 'utf8').trim().split('\\n').lengthconst ms = fs.readFileSync(dir + '/modes', 'utf8').split('\\n'), mode = ms[Math.min(n, ms.length) - 1]const a = process.argv, port = Number(a[a.indexOf('--port') + 1]), host = a[a.indexOf('--host') + 1]+ process.stderr.write('whisper_backend_init_gpu: using Vulkan0 backend\\n')if (mode === 'die-loading') process.exit(1)setTimeout(() => require('http').createServer((q, r) => {if (q.method !== 'POST') return r.end('ok')@@ -128,6 +129,14 @@ describe.skipIf(process.platform === 'win32')('whisper server', () => {expect(JSON.parse(readFileSync(join(bin, '../args'), 'utf8'))).not.toContain('-ng')})+ it('says in the log which graphics card whisper picked', async () => {+ const info = vi.spyOn(console, 'info').mockImplementation(() => {})+ try {+ await make(fakeBinary()).url()+ await vi.waitFor(() => expect(info.mock.calls.map((a) => a.join(' '))).toContain('ASR whisper-server runs on Vulkan0'))+ } finally { info.mockRestore() }+ })+it('never asks for more threads than the computer has', async () => {const bin = fakeBinary()await make(bin).url()