From 6f520b45346b32f6290fe0e53c94ffa43f9870f5 Mon Sep 17 00:00:00 2001 From: Faisal Amir Date: Tue, 13 Feb 2024 15:36:42 +0700 Subject: [PATCH] feat: imporve UI/UX gpu acceleration feature (#1990) --- web/containers/GPUDriverPromptModal/index.tsx | 2 +- web/containers/Layout/BottomBar/index.tsx | 53 +++- web/hooks/useSettings.ts | 2 +- web/screens/LocalServer/index.tsx | 4 +- web/screens/Settings/Advanced/index.tsx | 248 ++++++++++++++---- 5 files changed, 238 insertions(+), 71 deletions(-) diff --git a/web/containers/GPUDriverPromptModal/index.tsx b/web/containers/GPUDriverPromptModal/index.tsx index da20ab332..bdcf1b2f8 100644 --- a/web/containers/GPUDriverPromptModal/index.tsx +++ b/web/containers/GPUDriverPromptModal/index.tsx @@ -36,7 +36,7 @@ const GPUDriverPrompt: React.FC = () => { - + Checking for machine that does not meet the requirements. diff --git a/web/containers/Layout/BottomBar/index.tsx b/web/containers/Layout/BottomBar/index.tsx index 5021b821c..0c2df80fe 100644 --- a/web/containers/Layout/BottomBar/index.tsx +++ b/web/containers/Layout/BottomBar/index.tsx @@ -63,6 +63,17 @@ const BottomBar = () => { return Math.round(((total - free) / total) * 100) } + const calculateUtilization = () => { + let sum = 0 + const util = gpus.map((x) => { + return Number(x['utilization']) + }) + util.forEach((num) => { + sum += num + }) + return sum + } + return (
@@ -126,15 +137,39 @@ const BottomBar = () => {
{gpus.length > 0 && ( -
- {gpus.map((gpu, index) => ( - - ))} -
+ + +
+ +
+
+ {gpus.length > 1 && ( + + + {gpus.map((gpu, index) => ( +
+
+ {gpu.name} + {gpu.vram}MB VRAM +
+ {gpu.utilization}% +
+ ))} +
+ +
+ )} +
)} {/* VERSION is defined by webpack, please see next.config.js */} diff --git a/web/hooks/useSettings.ts b/web/hooks/useSettings.ts index 289355b36..ca84f6b79 100644 --- a/web/hooks/useSettings.ts +++ b/web/hooks/useSettings.ts @@ -24,7 +24,7 @@ export const useSettings = () => { ((settings.nvidia_driver?.exist && !settings.cuda?.exist) || !settings.nvidia_driver?.exist) ) { - setShowNotification(true) + setShowNotification(false) } // Check if run_mode is 'gpu' or 'cpu' and update state accordingly diff --git a/web/screens/LocalServer/index.tsx b/web/screens/LocalServer/index.tsx index 88a9d86ba..3ed1cc610 100644 --- a/web/screens/LocalServer/index.tsx +++ b/web/screens/LocalServer/index.tsx @@ -383,8 +383,8 @@ const LocalServerScreen = () => { xmlns="http://www.w3.org/2000/svg" > diff --git a/web/screens/Settings/Advanced/index.tsx b/web/screens/Settings/Advanced/index.tsx index f6c8fb4d8..e1ccaf6a4 100644 --- a/web/screens/Settings/Advanced/index.tsx +++ b/web/screens/Settings/Advanced/index.tsx @@ -8,12 +8,32 @@ import { ChangeEvent, } from 'react' +import { openExternalUrl } from '@janhq/core' + import { fs } from '@janhq/core' -import { Switch, Button, Input } from '@janhq/uikit' +import { + Switch, + Button, + Input, + Select, + Checkbox, + SelectContent, + SelectGroup, + SelectPortal, + SelectLabel, + SelectTrigger, + SelectValue, + Tooltip, + TooltipArrow, + TooltipContent, + TooltipTrigger, +} from '@janhq/uikit' + +import { AlertTriangleIcon, AlertCircleIcon } from 'lucide-react' import ShortcutModal from '@/containers/ShortcutModal' -import { toaster } from '@/containers/Toast' +import { snackbar, toaster } from '@/containers/Toast' import { FeatureToggleContext } from '@/context/FeatureToggle' @@ -40,6 +60,12 @@ const Advanced = () => { const { readSettings, saveSettings, validateSettings, setShowNotification } = useSettings() + const selectedGpu = gpuList + .filter((x) => gpusInUse.includes(x.id)) + .map((y) => { + return y['name'] + }) + const onProxyChange = useCallback( (event: ChangeEvent) => { const value = event.target.value || '' @@ -77,6 +103,7 @@ const Advanced = () => { } const handleGPUChange = (gpuId: string) => { + // TODO detect current use GPU nvidia or AMD let updatedGpusInUse = [...gpusInUse] if (updatedGpusInUse.includes(gpuId)) { updatedGpusInUse = updatedGpusInUse.filter((id) => id !== gpuId) @@ -127,66 +154,171 @@ const Advanced = () => { {/* CPU / GPU switching */} {!isMac && ( -
-
-
-
Nvidia GPU
-
-

- Enable GPU acceleration for Nvidia GPUs. -

-
- { - if (e === true) { - saveSettings({ runMode: 'gpu' }) - setGpuEnabled(true) - setShowNotification(false) - setTimeout(() => { - validateSettings() - }, 300) - } else { - saveSettings({ runMode: 'cpu' }) - setGpuEnabled(false) - } - }} - /> -
- )} - {/* Directory */} - {gpuEnabled && ( -
- -
- {gpuList.map((gpu) => ( -
- handleGPUChange(gpu.id)} - /> - +
+
+
+
+
+ GPU Acceleration +
- ))} +

+ Enable to enhance model performance by utilizing your devices + GPU for acceleration. Read{' '} + + {' '} + + openExternalUrl( + 'https://jan.ai/guides/troubleshooting/gpu-not-used/' + ) + } + > + troubleshooting guide + {' '} + {' '} + for further assistance. +

+
+ {gpuList.length > 0 && !gpuEnabled && ( + + + + + + + Disabling GPU Acceleration may result in reduced + performance. It is recommended to keep this enabled for + optimal user experience. + + + + + )} + + + + { + if (e === true) { + saveSettings({ runMode: 'gpu' }) + setGpuEnabled(true) + setShowNotification(false) + snackbar({ + description: 'Successfully turned on GPU Accelertion', + type: 'success', + }) + setTimeout(() => { + validateSettings() + }, 300) + } else { + saveSettings({ runMode: 'cpu' }) + setGpuEnabled(false) + snackbar({ + description: 'Successfully turned off GPU Accelertion', + type: 'success', + }) + } + }} + /> + + {gpuList.length === 0 && ( + + + Your current device does not have a compatible GPU for + monitoring. To enable GPU monitoring, please ensure your + device has a supported Nvidia or AMD GPU with updated + drivers. + + + + )} +
+ + {gpuEnabled && ( +
+ + +
+ )}
)} - {/* Warning message */} - {gpuEnabled && gpusInUse.length > 1 && ( -

- If enabling multi-GPU without the same GPU model or without NVLink, it - may affect token speed. -

- )} + {/* Proxy */}