Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
feat: Adjust RAM/VRAM calculation for unified memory systems (#6687)
Akarshan Biswas0f0ba43b7f88
diff --git a/src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/commands.rs b/src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/commands.rsindex c636fa8bd..61ab6128f 100644--- a/src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/commands.rs+++ b/src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/commands.rs@@ -89,19 +89,25 @@ pub async fn is_model_supported<R: Runtime>();const RESERVE_BYTES: u64 = 2288490189;- let total_system_memory = system_info.total_memory * 1024 * 1024;+ let total_system_memory: u64 = match system_info.gpus.is_empty() {+ // on MacOS with unified memory, treat RAM = 0 for now+ true => 0,+ false => system_info.total_memory * 1024 * 1024,+ };+// Calculate total VRAM from all GPUs- let total_vram: u64 = if system_info.gpus.is_empty() {+ let total_vram: u64 = match system_info.gpus.is_empty() {// On macOS with unified memory, GPU info may be empty// Use total RAM as VRAM since memory is shared- log::info!("No GPUs detected (likely unified memory system), using total RAM as VRAM");- total_system_memory- } else {- system_info+ true => {+ log::info!("No GPUs detected (likely unified memory system), using total RAM as VRAM");+ system_info.total_memory * 1024 * 1024+ }+ false => system_info.gpus.iter().map(|g| g.total_memory * 1024 * 1024)- .sum::<u64>()+ .sum::<u64>(),};log::info!("Total VRAM reported/calculated (in bytes): {}", &total_vram);@@ -115,7 +121,7 @@ pub async fn is_model_supported<R: Runtime>(let usable_total_memory = if total_system_memory > RESERVE_BYTES {(total_system_memory - RESERVE_BYTES) + usable_vram} else {- 0+ usable_vram};log::info!("System RAM: {} bytes", &total_system_memory);log::info!("Total VRAM: {} bytes", &total_vram);diff --git a/src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/model_planner.rs b/src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/model_planner.rsindex 118894871..a03766041 100644--- a/src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/model_planner.rs+++ b/src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/model_planner.rs@@ -82,25 +82,25 @@ pub async fn plan_model_load<R: Runtime>(log::info!("Got GPUs:\n{:?}", &sys_info.gpus);- let total_ram: u64 = sys_info.total_memory * 1024 * 1024;- log::info!(- "Total system memory reported from tauri_plugin_hardware(in bytes): {}",- &total_ram- );-- let total_vram: u64 = if sys_info.gpus.is_empty() {- // On macOS with unified memory, GPU info may be empty- // Use total RAM as VRAM since memory is shared- log::info!("No GPUs detected (likely unified memory system), using total RAM as VRAM");- total_ram- } else {- sys_info+ let total_ram: u64 = match sys_info.gpus.is_empty() {+ // Consider RAM as 0 for unified memory+ true => 0,+ false => sys_info.total_memory * 1024 * 1024,+ };++ // Calculate total VRAM from all GPUs+ let total_vram: u64 = match sys_info.gpus.is_empty() {+ true => {+ log::info!("No GPUs detected (likely unified memory system), using total RAM as VRAM");+ sys_info.total_memory * 1024 * 1024+ }+ false => sys_info.gpus.iter().map(|g| g.total_memory * 1024 * 1024)- .sum::<u64>()+ .sum::<u64>(),};-+ log::info!("Total RAM reported/calculated (in bytes): {}", &total_ram);log::info!("Total VRAM reported/calculated (in bytes): {}", &total_vram);let usable_vram: u64 = if total_vram > RESERVE_BYTES {(((total_vram - RESERVE_BYTES) as f64) * multiplier) as u64