From 1fe15236a00624ea7852666e7e09da164c84e935 Mon Sep 17 00:00:00 2001 From: Faisal Amir Date: Tue, 11 Feb 2025 13:49:51 +0700 Subject: [PATCH] fix: remove toggle enable GPU from setting (#4624) * fix: remove toggle enable GPU * chore: remove logic * chore: fix linter --- web/screens/Settings/Advanced/index.tsx | 325 +----------------------- 1 file changed, 7 insertions(+), 318 deletions(-) diff --git a/web/screens/Settings/Advanced/index.tsx b/web/screens/Settings/Advanced/index.tsx index a3ba76170..cb10a1778 100644 --- a/web/screens/Settings/Advanced/index.tsx +++ b/web/screens/Settings/Advanced/index.tsx @@ -1,32 +1,19 @@ 'use client' -import { useEffect, useState, ChangeEvent } from 'react' +import { ChangeEvent } from 'react' -import { openExternalUrl, AppConfiguration } from '@janhq/core' +import { AppConfiguration } from '@janhq/core' -import { - ScrollArea, - Switch, - Input, - Tooltip, - Checkbox, - useClickOutside, - Button, -} from '@janhq/joi' +import { ScrollArea, Switch, Button } from '@janhq/joi' import { useAtom, useAtomValue, useSetAtom } from 'jotai' -import { ChevronDownIcon, ArrowRightIcon } from 'lucide-react' -import { AlertTriangleIcon, AlertCircleIcon } from 'lucide-react' - -import { twMerge } from 'tailwind-merge' +import { ArrowRightIcon } from 'lucide-react' import { useDebouncedCallback } from 'use-debounce' -import { snackbar, toaster } from '@/containers/Toast' +import { toaster } from '@/containers/Toast' -import { useActiveModel } from '@/hooks/useActiveModel' import { useConfigurations } from '@/hooks/useConfigurations' -import { useSettings } from '@/hooks/useSettings' import ModalDeleteAllThreads from '@/screens/Thread/ThreadLeftPanel/ModalDeleteAllThreads' @@ -36,7 +23,6 @@ import FactoryReset from './FactoryReset' import { experimentalFeatureEnabledAtom, proxyEnabledAtom, - vulkanEnabledAtom, quickAskEnabledAtom, } from '@/helpers/atoms/AppConfig.atom' @@ -44,12 +30,6 @@ import { ThreadModalAction } from '@/helpers/atoms/Thread.atom' import { modalActionThreadAtom } from '@/helpers/atoms/Thread.atom' -type GPU = { - id: string - vram: number | null - name: string -} - /** * Advanced Settings Screen * @returns @@ -58,31 +38,14 @@ const Advanced = ({ setSubdir }: { setSubdir: (subdir: string) => void }) => { const [experimentalEnabled, setExperimentalEnabled] = useAtom( experimentalFeatureEnabledAtom ) - const [vulkanEnabled, setVulkanEnabled] = useAtom(vulkanEnabledAtom) + const [proxyEnabled, setProxyEnabled] = useAtom(proxyEnabledAtom) const quickAskEnabled = useAtomValue(quickAskEnabledAtom) - const [gpuEnabled, setGpuEnabled] = useState(false) - const [gpuList, setGpuList] = useState([]) - const [gpusInUse, setGpusInUse] = useState([]) - const [dropdownOptions, setDropdownOptions] = useState( - null - ) const { configurePullOptions } = useConfigurations() - const [toggle, setToggle] = useState(null) - - const { readSettings, saveSettings } = useSettings() - const { stopModel } = useActiveModel() - const [open, setOpen] = useState(false) const setModalActionThread = useSetAtom(modalActionThreadAtom) - const selectedGpu = gpuList - .filter((x) => gpusInUse.includes(x.id)) - .map((y) => { - return y['name'] - }) - /** * There could be a case where the state update is not synced * so that retrieving state value from other hooks would not be accurate @@ -110,24 +73,6 @@ const Advanced = ({ setSubdir }: { setSubdir: (subdir: string) => void }) => { if (relaunch) window.core?.api?.relaunch() } - /** - * Update Vulkan Enabled - * @param e - * @param relaunch - * @returns void - */ - const updateVulkanEnabled = async (e: boolean, relaunch: boolean = true) => { - toaster({ - title: 'Reload', - description: 'Vulkan settings updated. Reload now to apply the changes.', - }) - stopModel() - setVulkanEnabled(e) - await saveSettings({ vulkan: e }) - // Relaunch to apply settings - if (relaunch) window.location.reload() - } - /** * Update Experimental Enabled * @param e @@ -143,74 +88,11 @@ const Advanced = ({ setSubdir }: { setSubdir: (subdir: string) => void }) => { if (e.target.checked) return // It affects other settings, so we need to reset them - const isRelaunch = quickAskEnabled || vulkanEnabled + const isRelaunch = quickAskEnabled if (quickAskEnabled) await updateQuickAskEnabled(false, false) - if (vulkanEnabled) await updateVulkanEnabled(false, false) if (isRelaunch) window.core?.api?.relaunch() } - /** - * useEffect to set GPU enabled if possible - */ - useEffect(() => { - const setUseGpuIfPossible = async () => { - const settings = await readSettings() - setGpuEnabled( - settings.gpus?.some( - (gpu: { activated: boolean }) => gpu.activated === true - ) === 'gpu' && settings.gpus?.length > 0 - ) - setGpusInUse(settings.gpus_in_use || []) - setVulkanEnabled(settings.vulkan || false) - if (settings.gpus) { - setGpuList(settings.gpus) - } - } - setUseGpuIfPossible() - }, [readSettings, setGpuList, setGpuEnabled, setGpusInUse, setVulkanEnabled]) - - /** - * Handle GPU Change - * @param gpuId - * @returns - */ - const handleGPUChange = async (gpuId: string) => { - let updatedGpusInUse = [...gpusInUse] - if (updatedGpusInUse.includes(gpuId)) { - updatedGpusInUse = updatedGpusInUse.filter((id) => id !== gpuId) - if ( - gpuEnabled && - updatedGpusInUse.length === 0 && - gpuId && - gpuId.trim() - ) { - // Vulkan support only allow 1 active device at a time - if (vulkanEnabled) { - updatedGpusInUse = [] - } - updatedGpusInUse.push(gpuId) - } - } else { - // Vulkan support only allow 1 active device at a time - if (vulkanEnabled) { - updatedGpusInUse = [] - } - if (gpuId && gpuId.trim()) updatedGpusInUse.push(gpuId) - } - setGpusInUse(updatedGpusInUse) - // Reload window to apply changes - // This will trigger engine servers to restart - window.location.reload() - } - - const gpuSelectionPlaceHolder = - gpuList.length > 0 ? 'Select GPU' : "You don't have any compatible GPU" - - /** - * Handle click outside - */ - useClickOutside(() => setOpen(false), null, [dropdownOptions, toggle]) - return (
@@ -234,199 +116,6 @@ const Advanced = ({ setSubdir }: { setSubdir: (subdir: string) => void }) => {
- {/* CPU / GPU switching */} - {!isMac && ( -
-
-
-
-
GPU Acceleration
-
-

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

-
- -
- {gpuList.length > 0 && !gpuEnabled && ( - - } - content="Disabling NVIDIA GPU Acceleration may result in reduced - performance. It is recommended to keep this enabled for - optimal user experience." - /> - )} - { - if (e.target.checked === true) { - setGpuEnabled(true) - snackbar({ - description: - 'Successfully turned on GPU Acceleration', - type: 'success', - }) - } else { - setGpuEnabled(false) - snackbar({ - description: - 'Successfully turned off GPU Acceleration', - type: 'success', - }) - } - // Stop any running model to apply the changes - if (e.target.checked !== gpuEnabled) { - stopModel().finally(() => { - setTimeout(() => { - window.location.reload() - }, 300) - }) - } - }} - /> - } - content="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." - disabled={gpuList.length > 0} - /> -
-
- -
- -
- - } - onClick={() => setOpen(!open)} - /> - {gpuList.length > 0 && ( -
-
-

- {vulkanEnabled ? 'Vulkan Supported GPUs' : 'Nvidia'} -

-
-
- {gpuList - .filter((gpu) => - vulkanEnabled - ? gpu.name - : gpu.name?.toLowerCase().includes('nvidia') - ) - .map((gpu) => ( -
- handleGPUChange(gpu.id)} - label={ - - {gpu.name} - {!vulkanEnabled && ( - {gpu.vram}MB VRAM - )} - - } - /> -
- ))} -
- {gpuEnabled && gpusInUse.length > 1 && ( -
- -

- If multi-GPU is enabled with different GPU models - or without NVLink, it could impact token speed. -

-
- )} -
-
-
- )} -
-
-
- )} - - {/* Vulkan for AMD GPU/ APU and Intel Arc GPU */} - {!isMac && experimentalEnabled && ( -
-
-
-
Vulkan Support
-
-

- Enable Vulkan with AMD GPU/APU and Intel Arc GPU for better - model performance (reload needed). -

-
-
- updateVulkanEnabled(e.target.checked)} - /> -
-
- )} - {/* Proxy Settings Link */}