fix: remove missing resource path from tauri.conf; add GPU detection and layer clamping
This commit is contained in:
1 parent
99672b33d0
commit
ae8d79e167
4 files changed
+223
-7
No files matched your search
@@ -4,6 +4,57 @@ use tauri::{Manager, State};
|
|||||||
|
|
||||||
pub struct ServerState(pub Mutex<Option<Child>>);
|
pub struct ServerState(pub Mutex<Option<Child>>);
|
||||||
|
|
||||||
|
/// Query GPU info via nvidia-smi.
|
||||||
|
/// Returns (gpu_name, vram_mib, recommended_layers).
|
||||||
|
/// recommended_layers is estimated as vram_mib / 80 (rough heuristic for 4-bit quant).
|
||||||
|
#[tauri::command]
|
||||||
|
fn query_gpu() -> Result<GpuInfo, String> {
|
||||||
|
let output = Command::new("nvidia-smi")
|
||||||
|
.args([
|
||||||
|
"--query-gpu=name,memory.total",
|
||||||
|
"--format=csv,noheader,nounits",
|
||||||
|
])
|
||||||
|
.output()
|
||||||
|
.map_err(|_| "nvidia-smi not found — no NVIDIA GPU detected".to_string())?;
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
return Err("nvidia-smi failed — no NVIDIA GPU detected".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||||
|
let line = stdout.lines().next().unwrap_or("").trim().to_string();
|
||||||
|
if line.is_empty() {
|
||||||
|
return Err("No GPU found".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format: "GPU Name, 8192"
|
||||||
|
let parts: Vec<&str> = line.splitn(2, ',').collect();
|
||||||
|
if parts.len() < 2 {
|
||||||
|
return Err(format!("Unexpected nvidia-smi output: {line}"));
|
||||||
|
}
|
||||||
|
|
||||||
|
let name = parts[0].trim().to_string();
|
||||||
|
let vram_mib: u32 = parts[1].trim().parse().unwrap_or(0);
|
||||||
|
|
||||||
|
// Heuristic: ~80 MiB per layer for Q4/Q6 models (conservative)
|
||||||
|
// Reserve 1 GiB for OS/other usage
|
||||||
|
let usable = vram_mib.saturating_sub(1024);
|
||||||
|
let recommended_layers = (usable / 80).min(200) as i32;
|
||||||
|
|
||||||
|
Ok(GpuInfo {
|
||||||
|
name,
|
||||||
|
vram_mib,
|
||||||
|
recommended_layers,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Serialize)]
|
||||||
|
pub struct GpuInfo {
|
||||||
|
pub name: String,
|
||||||
|
pub vram_mib: u32,
|
||||||
|
pub recommended_layers: i32,
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn start_server(
|
fn start_server(
|
||||||
state: State<ServerState>,
|
state: State<ServerState>,
|
||||||
@@ -17,7 +68,6 @@ fn start_server(
|
|||||||
return Err("Server is already running".into());
|
return Err("Server is already running".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve binary path relative to the app's resource dir or PATH
|
|
||||||
let binary = if cfg!(target_os = "windows") {
|
let binary = if cfg!(target_os = "windows") {
|
||||||
"localllm.exe"
|
"localllm.exe"
|
||||||
} else {
|
} else {
|
||||||
@@ -70,6 +120,7 @@ pub fn run() {
|
|||||||
.plugin(tauri_plugin_shell::init())
|
.plugin(tauri_plugin_shell::init())
|
||||||
.manage(ServerState(Mutex::new(None)))
|
.manage(ServerState(Mutex::new(None)))
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
|
query_gpu,
|
||||||
start_server,
|
start_server,
|
||||||
stop_server,
|
stop_server,
|
||||||
server_status
|
server_status
|
||||||
|
|||||||
@@ -29,8 +29,7 @@
|
|||||||
"bundle": {
|
"bundle": {
|
||||||
"active": true,
|
"active": true,
|
||||||
"targets": "all",
|
"targets": "all",
|
||||||
"icon": [],
|
"icon": []
|
||||||
"resources": ["../../../target/release/localllm.exe", "../../../target/release/localllm"]
|
|
||||||
},
|
},
|
||||||
"plugins": {
|
"plugins": {
|
||||||
"shell": {
|
"shell": {
|
||||||
|
|||||||
@@ -144,3 +144,90 @@
|
|||||||
.sp-message-error {
|
.sp-message-error {
|
||||||
color: #ef4444;
|
color: #ef4444;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sp-gpu-badge {
|
||||||
|
font-size: 11px;
|
||||||
|
color: #22c55e;
|
||||||
|
background: rgba(34, 197, 94, 0.08);
|
||||||
|
border: 1px solid rgba(34, 197, 94, 0.2);
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 4px 8px;
|
||||||
|
margin-top: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sp-gpu-cpu {
|
||||||
|
color: #9ca3af;
|
||||||
|
background: rgba(156, 163, 175, 0.08);
|
||||||
|
border-color: rgba(156, 163, 175, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sp-gpu-loading {
|
||||||
|
color: #f59e0b;
|
||||||
|
background: rgba(245, 158, 11, 0.08);
|
||||||
|
border-color: rgba(245, 158, 11, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sp-label-hint {
|
||||||
|
color: var(--accent, #5b6af0);
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sp-layers-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sp-btn-max {
|
||||||
|
background: var(--accent, #5b6af0);
|
||||||
|
color: #fff;
|
||||||
|
border: none;
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 5px 10px;
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: opacity 0.15s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sp-btn-max:hover:not(:disabled) {
|
||||||
|
opacity: 0.85;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sp-btn-max:disabled {
|
||||||
|
opacity: 0.4;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sp-layers-hint {
|
||||||
|
font-size: 11px;
|
||||||
|
color: #9ca3af;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sp-vram-bar {
|
||||||
|
position: relative;
|
||||||
|
height: 18px;
|
||||||
|
background: rgba(255,255,255,0.06);
|
||||||
|
border-radius: 4px;
|
||||||
|
overflow: hidden;
|
||||||
|
margin-top: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sp-vram-fill {
|
||||||
|
height: 100%;
|
||||||
|
background: linear-gradient(90deg, var(--accent, #5b6af0), #818cf8);
|
||||||
|
transition: width 0.3s ease;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sp-vram-label {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 10px;
|
||||||
|
color: #e5e7eb;
|
||||||
|
font-weight: 600;
|
||||||
|
text-shadow: 0 1px 2px rgba(0,0,0,0.5);
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { useState } from "react";
|
import { useState, useEffect } from "react";
|
||||||
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import type { ProcessStatus, ServerConfig } from "../hooks/useServerProcess";
|
import type { ProcessStatus, ServerConfig } from "../hooks/useServerProcess";
|
||||||
import "./ServerPanel.css";
|
import "./ServerPanel.css";
|
||||||
|
|
||||||
@@ -9,6 +10,12 @@ interface Props {
|
|||||||
onStop: () => void;
|
onStop: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface GpuInfo {
|
||||||
|
name: string;
|
||||||
|
vram_mib: number;
|
||||||
|
recommended_layers: number;
|
||||||
|
}
|
||||||
|
|
||||||
const STATUS_LABEL: Record<ProcessStatus, string> = {
|
const STATUS_LABEL: Record<ProcessStatus, string> = {
|
||||||
stopped: "Stopped",
|
stopped: "Stopped",
|
||||||
starting: "Starting…",
|
starting: "Starting…",
|
||||||
@@ -35,9 +42,31 @@ export default function ServerPanel({ status, message, onStart, onStop }: Props)
|
|||||||
const [gpuLayers, setGpuLayers] = useState(
|
const [gpuLayers, setGpuLayers] = useState(
|
||||||
() => parseInt(localStorage.getItem("forgelm_gpu_layers") || "0", 10)
|
() => parseInt(localStorage.getItem("forgelm_gpu_layers") || "0", 10)
|
||||||
);
|
);
|
||||||
|
const [gpuInfo, setGpuInfo] = useState<GpuInfo | null>(null);
|
||||||
|
const [gpuError, setGpuError] = useState<string>("");
|
||||||
const [expanded, setExpanded] = useState(false);
|
const [expanded, setExpanded] = useState(false);
|
||||||
|
|
||||||
|
// Detect GPU on mount
|
||||||
|
useEffect(() => {
|
||||||
|
invoke<GpuInfo>("query_gpu")
|
||||||
|
.then((info) => {
|
||||||
|
setGpuInfo(info);
|
||||||
|
// Only auto-set if user hasn't saved a preference yet
|
||||||
|
if (!localStorage.getItem("forgelm_gpu_layers")) {
|
||||||
|
setGpuLayers(info.recommended_layers);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
setGpuError(String(e));
|
||||||
|
// Default to CPU-only if no GPU
|
||||||
|
if (!localStorage.getItem("forgelm_gpu_layers")) {
|
||||||
|
setGpuLayers(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
const isActive = status === "running" || status === "starting" || status === "stopping";
|
const isActive = status === "running" || status === "starting" || status === "stopping";
|
||||||
|
const maxLayers = gpuInfo ? gpuInfo.recommended_layers : 999;
|
||||||
|
|
||||||
const handleStart = () => {
|
const handleStart = () => {
|
||||||
localStorage.setItem("forgelm_model_path", modelPath);
|
localStorage.setItem("forgelm_model_path", modelPath);
|
||||||
@@ -46,6 +75,11 @@ export default function ServerPanel({ status, message, onStart, onStop }: Props)
|
|||||||
onStart({ modelPath, addr, gpuLayers });
|
onStart({ modelPath, addr, gpuLayers });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleLayersChange = (val: number) => {
|
||||||
|
const clamped = Math.max(0, Math.min(val, maxLayers));
|
||||||
|
setGpuLayers(clamped);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="server-panel">
|
<div className="server-panel">
|
||||||
<div className="server-panel-header" onClick={() => setExpanded(!expanded)}>
|
<div className="server-panel-header" onClick={() => setExpanded(!expanded)}>
|
||||||
@@ -64,6 +98,19 @@ export default function ServerPanel({ status, message, onStart, onStop }: Props)
|
|||||||
|
|
||||||
{expanded && (
|
{expanded && (
|
||||||
<div className="server-panel-body">
|
<div className="server-panel-body">
|
||||||
|
{/* GPU info badge */}
|
||||||
|
{gpuInfo ? (
|
||||||
|
<div className="sp-gpu-badge">
|
||||||
|
🎮 {gpuInfo.name} — {(gpuInfo.vram_mib / 1024).toFixed(1)} GB VRAM
|
||||||
|
</div>
|
||||||
|
) : gpuError ? (
|
||||||
|
<div className="sp-gpu-badge sp-gpu-cpu">
|
||||||
|
💻 CPU only — {gpuError.includes("not found") ? "No NVIDIA GPU" : gpuError}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="sp-gpu-badge sp-gpu-loading">🔍 Detecting GPU…</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<label className="sp-label">Model path (.gguf)</label>
|
<label className="sp-label">Model path (.gguf)</label>
|
||||||
<input
|
<input
|
||||||
className="sp-input"
|
className="sp-input"
|
||||||
@@ -84,16 +131,48 @@ export default function ServerPanel({ status, message, onStart, onStop }: Props)
|
|||||||
disabled={isActive}
|
disabled={isActive}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<label className="sp-label">GPU Layers (0 = CPU only)</label>
|
<label className="sp-label">
|
||||||
|
GPU Layers
|
||||||
|
{gpuInfo && (
|
||||||
|
<span className="sp-label-hint"> (max {gpuInfo.recommended_layers} for your GPU)</span>
|
||||||
|
)}
|
||||||
|
</label>
|
||||||
|
<div className="sp-layers-row">
|
||||||
<input
|
<input
|
||||||
className="sp-input sp-input-num"
|
className="sp-input sp-input-num"
|
||||||
type="number"
|
type="number"
|
||||||
min={0}
|
min={0}
|
||||||
max={999}
|
max={maxLayers}
|
||||||
value={gpuLayers}
|
value={gpuLayers}
|
||||||
onChange={(e) => setGpuLayers(parseInt(e.target.value, 10) || 0)}
|
onChange={(e) => handleLayersChange(parseInt(e.target.value, 10) || 0)}
|
||||||
disabled={isActive}
|
disabled={isActive}
|
||||||
/>
|
/>
|
||||||
|
{gpuInfo && (
|
||||||
|
<button
|
||||||
|
className="sp-btn-max"
|
||||||
|
onClick={() => handleLayersChange(gpuInfo.recommended_layers)}
|
||||||
|
disabled={isActive}
|
||||||
|
title="Set to maximum recommended"
|
||||||
|
>
|
||||||
|
Max
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
{gpuLayers === 0 && (
|
||||||
|
<span className="sp-layers-hint">CPU only</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{gpuInfo && gpuLayers > 0 && (
|
||||||
|
<div className="sp-vram-bar">
|
||||||
|
<div
|
||||||
|
className="sp-vram-fill"
|
||||||
|
style={{ width: `${Math.min(100, (gpuLayers / gpuInfo.recommended_layers) * 100)}%` }}
|
||||||
|
/>
|
||||||
|
<span className="sp-vram-label">
|
||||||
|
~{Math.round(gpuLayers * 80)} MB / {gpuInfo.vram_mib} MB VRAM
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="sp-actions">
|
<div className="sp-actions">
|
||||||
{status === "stopped" || status === "error" ? (
|
{status === "stopped" || status === "error" ? (
|
||||||
|
|||||||
Reference in new issue
Block a user