Skip to content

Commit

Permalink
feat: option to disable gpu (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle authored Feb 11, 2025
1 parent f189861 commit 618672d
Show file tree
Hide file tree
Showing 25 changed files with 102 additions and 14 deletions.
2 changes: 1 addition & 1 deletion core/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tracing_test::traced_test;
#[serial]
#[traced_test]
fn test_transcribe() {
let ctx = create_context(&PathBuf::from("../ggml-tiny.bin"), None).unwrap();
let ctx = create_context(&PathBuf::from("../ggml-tiny.bin"), None, None).unwrap();
let options = &TranscribeOptions {
init_prompt: None,
lang: Some("en".into()),
Expand Down
7 changes: 3 additions & 4 deletions core/src/transcribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ use whisper_rs::{FullParams, SamplingStrategy, WhisperContextParameters};
type ProgressCallbackType = once_cell::sync::Lazy<Mutex<Option<Box<dyn Fn(i32) + Send + Sync>>>>;
static PROGRESS_CALLBACK: ProgressCallbackType = once_cell::sync::Lazy::new(|| Mutex::new(None));

pub fn create_context(model_path: &Path, gpu_device: Option<i32>) -> Result<WhisperContext> {
pub fn create_context(model_path: &Path, gpu_device: Option<i32>, use_gpu: Option<bool>) -> Result<WhisperContext> {
whisper_rs::install_whisper_tracing_trampoline();
tracing::debug!("open model...");
if !model_path.exists() {
bail!("whisper file doesn't exist")
}
let mut ctx_params = WhisperContextParameters::default();
if !env!("CUDA_VERSION").is_empty() || !env!("ROCM_VERSION").is_empty() {
// Nvidia or AMD
ctx_params.use_gpu = true;
if let Some(use_gpu) = use_gpu {
ctx_params.use_gpu = use_gpu;
}
// set GPU device number from preference
if let Some(gpu_device) = gpu_device {
Expand Down
2 changes: 2 additions & 0 deletions desktop/src-tauri/locales/en-US/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"copied": "Copied!",
"copy": "Copy",
"copy-logs": "Copy Logs",
"crashed-recently": "Since the app is crashed recently, the GPU is disabled. you can enable it in the settings.",
"custom-ffmpeg-command": "Custom command",
"customize": "Customize",
"customize-info": "Download any supported model in ggml or gguf format (with the file extension ending in '.bin'). Transfer it to the models directory, then select from the dropdown. No need to restart 🌟",
Expand Down Expand Up @@ -157,6 +158,7 @@
"update-version": "Update Vibe",
"updating-modal-body": "Updating Vibe to version {{version}}",
"updating-modal-title": "Updating...",
"use-gpu": "Use GPU",
"use-word-timestamps": "Timestamps per each word",
"when-completing-transcription": "When completing transcription",
"ytdlp-options": "URL Transcription Options",
Expand Down
2 changes: 2 additions & 0 deletions desktop/src-tauri/locales/es-MX/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"copied": "¡Copiado!",
"copy": "Copiar",
"copy-logs": "Copiar Registros",
"crashed-recently": "Dado que la aplicación se bloquea recientemente, la GPU está deshabilitada. \nPuede habilitarlo en la configuración.",
"custom-ffmpeg-command": "Comando personalizado",
"customize": "Personalizar",
"customize-info": "Descarga cualquier modelo soportado en formato ggml o gguf (con la extensión del archivo terminando en '.bin'). Transfiérelo al directorio de los modelos, posteriormente seleccionalo del menú desplegable. No es necesario reiniciar 🌟",
Expand Down Expand Up @@ -157,6 +158,7 @@
"update-version": "Actualizar Vibe",
"updating-modal-body": "Actualizando Vibe a la version {{version}}",
"updating-modal-title": "Actualizando...",
"use-gpu": "Use GPU",
"use-word-timestamps": "Marcas de tiempo por cada palabra",
"when-completing-transcription": "Cuando se complete la transcripción",
"ytdlp-options": "Opciones de transcripción de URL",
Expand Down
2 changes: 2 additions & 0 deletions desktop/src-tauri/locales/fr-FR/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"copied": "Copié !",
"copy": "Copier",
"copy-logs": "Copier les journaux",
"crashed-recently": "Étant donné que l'application est écrasée récemment, le GPU est désactivé. \nVous pouvez l'activer dans les paramètres.",
"custom-ffmpeg-command": "Commande personnalisée",
"customize": "Personnaliser",
"customize-info": "Téléchargez n’importe quel modèle pris en charge au format ggml ou gguf (avec l’extension de fichier se terminant par ‘.bin’). Transférez-le dans le dossier des modèles, puis sélectionnez-le dans la liste déroulante. Pas besoin de redémarrer 🌟",
Expand Down Expand Up @@ -157,6 +158,7 @@
"update-version": "Mettre à jour Vibe",
"updating-modal-body": "Mise à jour de Vibe vers la version {{version}}",
"updating-modal-title": "Mise à jour en cours…",
"use-gpu": "Utiliser le GPU",
"use-word-timestamps": "Horodatages pour chaque mot",
"when-completing-transcription": "Quand la transcription est terminée",
"ytdlp-options": "Options de transcription URL",
Expand Down
2 changes: 2 additions & 0 deletions desktop/src-tauri/locales/he-IL/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"copied": "הועתק!",
"copy": "העתק",
"copy-logs": "העתק יומנים",
"crashed-recently": "מכיוון שהאפליקציה מתרסקת לאחרונה, ה- GPU מושבת. \nאתה יכול לאפשר זאת בהגדרות.",
"custom-ffmpeg-command": "פקודה מותאמת אישית",
"customize": "התאמה אישית",
"customize-info": "הורידו קובץ מודלים (ggml או gguf) עם סיומת .bin, העבירו לתיקיית המודלים ובחרו את הקובץ כאן מהתפריט הנפתח. אין צורך להפעיל מחדש! 🌟",
Expand Down Expand Up @@ -157,6 +158,7 @@
"update-version": "עדכן לגרסה חדשה",
"updating-modal-body": "מעדכן את vibe לגרסה {{version}}",
"updating-modal-title": "מעדכן...",
"use-gpu": "השתמש ב- GPU",
"use-word-timestamps": "חותמות זמן לכל מילה",
"when-completing-transcription": "בעת השלמת התמלול",
"ytdlp-options": "אפשרויות תמלול מאתרים",
Expand Down
2 changes: 2 additions & 0 deletions desktop/src-tauri/locales/hi-IN/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"copied": "कॉपी किया गया!",
"copy": "कॉपी",
"copy-logs": "लॉग कॉपी करें",
"crashed-recently": "चूंकि हाल ही में ऐप दुर्घटनाग्रस्त हो गया है, GPU अक्षम है। \nआप इसे सेटिंग्स में सक्षम कर सकते हैं।",
"custom-ffmpeg-command": "कस्टम आदेश",
"customize": "अनुकूलित करें",
"customize-info": "ड्रॉपडाउन से किसी भी समर्थित मॉडल को ggml या gguf प्रारूप में डाउनलोड करें ('.bin' फ़ाइल एक्सटेंशन से समाप्त होने वाला). इसे मॉडल्स निर्देशिका में स्थानांतरित करें, फिर ड्रॉपडाउन से चुनें। पुनः आरंभ की आवश्यकता नहीं है 🌟",
Expand Down Expand Up @@ -157,6 +158,7 @@
"update-version": "वाइब अपडेट करें",
"updating-modal-body": "वाइब को संस्करण {{version}} में अपडेट किया जा रहा है",
"updating-modal-title": "अपडेट हो रहा है...",
"use-gpu": "GPU का उपयोग करें",
"use-word-timestamps": "प्रत्येक शब्द के टाइमस्टैम्प",
"when-completing-transcription": "लेखन पूरा होने पर",
"ytdlp-options": "URL प्रतिलेखन विकल्प",
Expand Down
2 changes: 2 additions & 0 deletions desktop/src-tauri/locales/it-IT/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"copied": "Copiato!",
"copy": "Copia",
"copy-logs": "Copia registri",
"crashed-recently": "Poiché l'app viene arrestata di recente, la GPU è disabilitata. \nPuoi abilitarlo nelle impostazioni.",
"custom-ffmpeg-command": "Comando personalizzato",
"customize": "Personalizza",
"customize-info": "Scarica un qualunque modello supportato nel formato ggml o gguf (con estensione file '.bin'). Copialo nella cartella dei modelli e,selezionalo dal menù a tendina. Non è richiesto il riavvio 🌟",
Expand Down Expand Up @@ -157,6 +158,7 @@
"update-version": "Aggiorna Vibe",
"updating-modal-body": "Aggiornando Vibe alla versione {{version}}",
"updating-modal-title": "Aggiornamento...",
"use-gpu": "Usa GPU",
"use-word-timestamps": "Timestamp per ogni parola",
"when-completing-transcription": "Quando la trascrizione è completata",
"ytdlp-options": "Opzioni di trascrizione URL",
Expand Down
2 changes: 2 additions & 0 deletions desktop/src-tauri/locales/no-NO/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"copied": "Kopiert!",
"copy": "Kopier",
"copy-logs": "Kopier logger",
"crashed-recently": "Siden appen er krasjet nylig, er GPU deaktivert. \nDu kan aktivere det i innstillingene.",
"custom-ffmpeg-command": "Egendefinert kommando",
"customize": "Tilpass",
"customize-info": "Last ned hvilken som helst støttet modell i ggml- eller gguf-format (med filutvidelse som slutter på «.bin»). Flytt den til modellmappen, og velg deretter fra listen. Ingen behov for omstart 🌟",
Expand Down Expand Up @@ -157,6 +158,7 @@
"update-version": "Oppdater Vibe",
"updating-modal-body": "Oppdaterer Vibe til versjon {{version}}",
"updating-modal-title": "Oppdaterer...",
"use-gpu": "Bruk GPU",
"use-word-timestamps": "Ord-tidsstempler",
"when-completing-transcription": "Ved fullføring av transkripsjonen",
"ytdlp-options": "Alternativer for URL-transkripsjon",
Expand Down
2 changes: 2 additions & 0 deletions desktop/src-tauri/locales/pl-PL/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"copied": "Skopiowano!",
"copy": "Kopiuj",
"copy-logs": "Kopiuj logi",
"crashed-recently": "Ponieważ aplikacja jest ostatnio rozbita, GPU jest wyłączony. \nMożesz włączyć go w ustawieniach.",
"custom-ffmpeg-command": "Niestandardowe polecenie",
"customize": "Dostosuj",
"customize-info": "Pobierz dowolny wspierany model w formacie ggml lub gguf (z rozszerzeniem pliku kończącym się na „.bin”). Przenieś go do folderu modeli, a następnie wybierz z listy. Nie ma potrzeby ponownego uruchamiania 🌟",
Expand Down Expand Up @@ -157,6 +158,7 @@
"update-version": "Zaaktualizuj Vibe",
"updating-modal-body": "Aktualizowanie Vibe do wersji {{version}}",
"updating-modal-title": "Aktualizowanie...",
"use-gpu": "Użyj GPU",
"use-word-timestamps": "Znaczniki czasu dla każdego słowa",
"when-completing-transcription": "Podczas zakończenia transkrypcji",
"ytdlp-options": "Opcje transkrypcji URL",
Expand Down
2 changes: 2 additions & 0 deletions desktop/src-tauri/locales/pt-BR/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"copied": "Copiado!",
"copy": "cópia de",
"copy-logs": "Copiar registros",
"crashed-recently": "Como o aplicativo é travado recentemente, a GPU está desativada. \nVocê pode ativá -lo nas configurações.",
"custom-ffmpeg-command": "Comando personalizado",
"customize": "Personalizar",
"customize-info": "Faça download de qualquer modelo compatível no formato ggml ou gguf (com a extensão de arquivo terminando em '.bin'). Transfira-o para o diretório de modelos e, em seguida, selecione-o na lista suspensa. Não há necessidade de reiniciar 🌟",
Expand Down Expand Up @@ -157,6 +158,7 @@
"update-version": "Atualizar Vibe",
"updating-modal-body": "Atualizando o Vibe para a versão {{version}}",
"updating-modal-title": "Atualizando....",
"use-gpu": "Use GPU",
"use-word-timestamps": "Carimbos de data e hora por cada palavra",
"when-completing-transcription": "Ao completar a transcrição",
"ytdlp-options": "Opções de transcrição de URL",
Expand Down
2 changes: 2 additions & 0 deletions desktop/src-tauri/locales/sv-SE/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"copied": "Kopierade!",
"copy": "Kopiera",
"copy-logs": "Kopiera loggar",
"crashed-recently": "Eftersom appen kraschas nyligen är GPU inaktiverad. \nDu kan aktivera det i inställningarna.",
"custom-ffmpeg-command": "Anpassat kommando",
"customize": "Anpassa",
"customize-info": "Download any supported model in ggml or gguf format (with the file extension ending in '.bin'). Transfer it to the models directory, then select from the dropdown. No need to restart 🌟",
Expand Down Expand Up @@ -157,6 +158,7 @@
"update-version": "Uppdatera Vibe",
"updating-modal-body": "Updaterar Vibe till version {{version}}",
"updating-modal-title": "Uppdaterar...",
"use-gpu": "Använd GPU",
"use-word-timestamps": "Tidsstämplar per ord",
"when-completing-transcription": "När du slutför transkriptionen",
"ytdlp-options": "URL -transkriptionsalternativ",
Expand Down
2 changes: 2 additions & 0 deletions desktop/src-tauri/locales/vi-VN/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"copied": "Đã sao chép!",
"copy": "Sao chép",
"copy-logs": "Sao chép nhật ký",
"crashed-recently": "Vì ứng dụng bị hỏng gần đây, GPU bị vô hiệu hóa. \nBạn có thể kích hoạt nó trong cài đặt.",
"custom-ffmpeg-command": "Lệnh tùy chỉnh",
"customize": "Tùy chỉnh",
"customize-info": "Tải xuống bất kỳ mô hình nào được hỗ trợ ở định dạng ggml hoặc gguf (với phần mở rộng tệp kết thúc bằng '.bin'). Chuyển nó vào thư mục mô hình, sau đó chọn từ danh sách thả xuống. Không cần khởi động lại 🌟",
Expand Down Expand Up @@ -157,6 +158,7 @@
"update-version": "Cập nhật Vibe",
"updating-modal-body": "Đang cập nhật Vibe lên phiên bản {{version}}",
"updating-modal-title": "Đang cập nhật...",
"use-gpu": "Sử dụng GPU",
"use-word-timestamps": "Dấu thời gian cho mỗi từ",
"when-completing-transcription": "Khi hoàn thành việc chép lại",
"ytdlp-options": "Tùy chọn phiên âm URL",
Expand Down
2 changes: 2 additions & 0 deletions desktop/src-tauri/locales/zh-CN/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"copied": "已复制!",
"copy": "复制",
"copy-logs": "复制日志",
"crashed-recently": "由于该应用程序最近崩溃了,因此GPU被禁用。\n您可以在设置中启用它。",
"custom-ffmpeg-command": "自定义命令",
"customize": "自定义",
"customize-info": "下载任何支持的 ggml 或 gguf 格式的模型文件(扩展名以'.bin'结尾),将其放入模型目录,然后从下拉列表中选择即可,无需重启应用🌟",
Expand Down Expand Up @@ -157,6 +158,7 @@
"update-version": "更新 Vibe",
"updating-modal-body": "正在将 Vibe 更新到 {{version}} 版本",
"updating-modal-title": "正在更新...",
"use-gpu": "使用GPU",
"use-word-timestamps": "使用单词级时间戳",
"when-completing-transcription": "完成转录时",
"ytdlp-options": "URL 转录选项",
Expand Down
2 changes: 2 additions & 0 deletions desktop/src-tauri/locales/zh-HK/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"copied": "已複製!",
"copy": "複製",
"copy-logs": "複製日誌",
"crashed-recently": "由於該應用程序最近崩潰了,因此GPU被禁用。\n您可以在設置中啟用它。",
"custom-ffmpeg-command": "自訂指令",
"customize": "自訂",
"customize-info": "下載任何支援的 ggml 或 gguf 格式的模型檔案(副檔名以'.bin'結尾),將其放入模型目錄,然後從下拉清單中選擇即可,無需重啟應用程式🌟",
Expand Down Expand Up @@ -157,6 +158,7 @@
"update-version": "更新 Vibe",
"updating-modal-body": "正在將 Vibe 更新至 {{version}} 版本",
"updating-modal-title": "正在更新...",
"use-gpu": "使用GPU",
"use-word-timestamps": "使用單詞級時間戳",
"when-completing-transcription": "完成轉錄時",
"ytdlp-options": "URL轉錄選項",
Expand Down
2 changes: 1 addition & 1 deletion desktop/src-tauri/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub async fn run(app_handle: &AppHandle) -> Result<()> {

eprintln!("Transcribe... 🔄");
let start = Instant::now(); // Measure start time
let ctx = transcribe::create_context(&model_path, None)?;
let ctx = transcribe::create_context(&model_path, None, None)?;
#[allow(unused_mut)]
let mut transcript = transcribe::transcribe(&ctx, &options, None, None, None, None, None)?;

Expand Down
32 changes: 28 additions & 4 deletions desktop/src-tauri/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use tauri::{
use tauri::{Emitter, Listener, State};
use tauri_plugin_store::StoreExt;
use tokio::sync::Mutex;
use vibe_core::get_vibe_temp_folder;
use vibe_core::transcript::Segment;
use vibe_core::transcript::Transcript;
pub mod audio;
Expand Down Expand Up @@ -424,28 +425,35 @@ pub fn is_avx2_enabled() -> bool {
}

#[tauri::command]
pub async fn load_model(app_handle: tauri::AppHandle, model_path: String, gpu_device: Option<i32>) -> Result<String> {
pub async fn load_model(
app_handle: tauri::AppHandle,
model_path: String,
gpu_device: Option<i32>,
use_gpu: Option<bool>,
) -> Result<String> {
let model_context_state: State<'_, Mutex<Option<ModelContext>>> = app_handle.state();
let mut state_guard = model_context_state.lock().await;
if let Some(state) = state_guard.as_ref() {
// check if new path is different
if model_path != state.path || gpu_device != state.gpu_device {
if model_path != state.path || gpu_device != state.gpu_device || use_gpu != state.use_gpu {
tracing::debug!("model path or gpu device changed. reloading");
// reload
let context = vibe_core::transcribe::create_context(Path::new(&model_path), gpu_device)?;
let context = vibe_core::transcribe::create_context(Path::new(&model_path), gpu_device, use_gpu)?;
*state_guard = Some(ModelContext {
path: model_path.clone(),
handle: context,
gpu_device,
use_gpu,
});
}
} else {
tracing::debug!("loading model first time");
let context = vibe_core::transcribe::create_context(Path::new(&model_path), gpu_device)?;
let context = vibe_core::transcribe::create_context(Path::new(&model_path), gpu_device, use_gpu)?;
*state_guard = Some(ModelContext {
path: model_path.clone(),
handle: context,
gpu_device,
use_gpu,
});
}
Ok(model_path)
Expand Down Expand Up @@ -545,6 +553,22 @@ pub fn get_logs(app_handle: tauri::AppHandle) -> Result<String> {
Ok(content)
}

#[tauri::command]
pub fn is_crashed_recently() -> bool {
tracing::debug!("checking path {}", get_vibe_temp_folder().join("crash.txt").display());
get_vibe_temp_folder().join("crash.txt").exists()
}

#[tauri::command]
pub fn rename_crash_file() -> Result<()> {
std::fs::rename(
get_vibe_temp_folder().join("crash.txt"),
// TODO: save all crashed?
get_vibe_temp_folder().join("crash.1.txt"),
)
.context("Can't delete file")
}

#[tauri::command]
pub fn get_cargo_features() -> Vec<String> {
let mut enabled_features = Vec::new();
Expand Down
2 changes: 2 additions & 0 deletions desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ fn main() -> Result<()> {
cmd::get_ffmpeg_path,
cmd::ytdlp::download_audio,
cmd::ytdlp::get_temp_path,
cmd::is_crashed_recently,
cmd::rename_crash_file,
#[cfg(windows)]
cmd::set_high_gpu_preference
])
Expand Down
7 changes: 6 additions & 1 deletion desktop/src-tauri/src/panic_hook.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use eyre::Result;
use std::{panic, sync::Arc};
use std::{fs, panic, sync::Arc};
use tauri::AppHandle;
use vibe_core::get_vibe_temp_folder;

pub fn set_panic_hook(app: &AppHandle) -> Result<()> {
let log_path = crate::logging::get_log_path(app)?;
Expand All @@ -20,6 +21,10 @@ pub fn set_panic_hook(app: &AppHandle) -> Result<()> {
eprintln!("{}", message);
// do whatever with the message
tracing::error!(message);

// Write to panic.txt
let _ = fs::write(get_vibe_temp_folder().join("crash.txt"), message);

// Open the log path in release mode
if !cfg!(debug_assertions) && !crate::cli::is_cli_detected() {
showfile::show_path_in_file_manager(log_path.as_path());
Expand Down
1 change: 1 addition & 0 deletions desktop/src-tauri/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub static STATIC_APP: Lazy<std::sync::Mutex<Option<tauri::AppHandle>>> = Lazy::
pub struct ModelContext {
pub path: String,
pub gpu_device: Option<i32>,
pub use_gpu: Option<bool>,
pub handle: WhisperContext,
}

Expand Down
2 changes: 1 addition & 1 deletion desktop/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "./gen/schemas/desktop-schema.json",
"productName": "vibe",
"version": "3.0.2",
"version": "3.0.3",
"identifier": "github.com.thewh1teagle.vibe",
"app": {
"windows": [],
Expand Down
2 changes: 1 addition & 1 deletion desktop/src/pages/batch/viewModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function viewModel() {

setInProgress(true)
let localIndex = 0
await invoke('load_model', { modelPath: preference.modelPath, gpuDevice: preference.gpuDevice })
await invoke('load_model', { modelPath: preference.modelPath, gpuDevice: preference.gpuDevice, useGpu: preference.useGpu })
setCurrentIndex(localIndex)
const loopStartTime = performance.now()
for (const file of files) {
Expand Down
Loading

0 comments on commit 618672d

Please sign in to comment.