enhancement: filter active gpu on system monitor
This commit is contained in:
parent
19fc399ae1
commit
3a197d56c0
@ -11,6 +11,7 @@ import { getActiveModels, stopModel } from '@/services/models'
|
|||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { useTranslation } from '@/i18n/react-i18next-compat'
|
import { useTranslation } from '@/i18n/react-i18next-compat'
|
||||||
import { toNumber } from '@/utils/number'
|
import { toNumber } from '@/utils/number'
|
||||||
|
import { useModelProvider } from '@/hooks/useModelProvider'
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
export const Route = createFileRoute(route.systemMonitor as any)({
|
export const Route = createFileRoute(route.systemMonitor as any)({
|
||||||
@ -19,28 +20,85 @@ export const Route = createFileRoute(route.systemMonitor as any)({
|
|||||||
|
|
||||||
function SystemMonitor() {
|
function SystemMonitor() {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { hardwareData, systemUsage, setHardwareData, updateSystemUsage } =
|
const { hardwareData, systemUsage, updateHardwareDataPreservingGpuOrder, updateSystemUsage, updateGPUActivationFromDeviceString } =
|
||||||
useHardware()
|
useHardware()
|
||||||
const [activeModels, setActiveModels] = useState<string[]>([])
|
const [activeModels, setActiveModels] = useState<string[]>([])
|
||||||
|
const { providers, getProviderByName } = useModelProvider()
|
||||||
|
const [isInitialized, setIsInitialized] = useState(false)
|
||||||
|
|
||||||
|
// Determine backend type and filter GPUs accordingly (same logic as hardware.tsx)
|
||||||
|
const llamacpp = providers.find((p) => p.provider === 'llamacpp')
|
||||||
|
const versionBackend = llamacpp?.settings.find((s) => s.key === "version_backend")?.controller_props.value
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Initial data fetch
|
// Initial data fetch - use updateHardwareDataPreservingGpuOrder like hardware.tsx
|
||||||
getHardwareInfo().then((data) => {
|
getHardwareInfo().then((data) => {
|
||||||
setHardwareData(data as unknown as HardwareData)
|
updateHardwareDataPreservingGpuOrder(data as unknown as HardwareData)
|
||||||
})
|
})
|
||||||
getActiveModels().then(setActiveModels)
|
getActiveModels().then(setActiveModels)
|
||||||
|
|
||||||
// Set up interval for real-time updates
|
// Set up interval for real-time updates
|
||||||
const intervalId = setInterval(() => {
|
const intervalId = setInterval(() => {
|
||||||
getSystemUsage().then((data) => {
|
getSystemUsage().then((data) => {
|
||||||
// setHardwareData(data as unknown as HardwareData)
|
|
||||||
updateSystemUsage(data)
|
updateSystemUsage(data)
|
||||||
})
|
})
|
||||||
getActiveModels().then(setActiveModels)
|
getActiveModels().then(setActiveModels)
|
||||||
}, 5000)
|
}, 5000)
|
||||||
|
|
||||||
return () => clearInterval(intervalId)
|
return () => clearInterval(intervalId)
|
||||||
}, [setHardwareData, setActiveModels, updateSystemUsage])
|
}, [updateHardwareDataPreservingGpuOrder, setActiveModels, updateSystemUsage])
|
||||||
|
|
||||||
|
// Initialize GPU activations from device setting on first load (same logic as hardware.tsx)
|
||||||
|
useEffect(() => {
|
||||||
|
if (hardwareData.gpus.length > 0 && !isInitialized) {
|
||||||
|
const llamacppProvider = getProviderByName('llamacpp')
|
||||||
|
const currentDeviceSetting = llamacppProvider?.settings.find(s => s.key === 'device')?.controller_props.value as string
|
||||||
|
|
||||||
|
if (currentDeviceSetting) {
|
||||||
|
updateGPUActivationFromDeviceString(currentDeviceSetting)
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsInitialized(true)
|
||||||
|
}
|
||||||
|
}, [hardwareData.gpus.length, isInitialized, getProviderByName, updateGPUActivationFromDeviceString])
|
||||||
|
|
||||||
|
// Sync device setting when GPU activations change (only after initialization) - same logic as hardware.tsx
|
||||||
|
const { getActivatedDeviceString } = useHardware()
|
||||||
|
const { updateProvider } = useModelProvider()
|
||||||
|
const gpuActivationStates = hardwareData.gpus.map(gpu => gpu.activated)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isInitialized && hardwareData.gpus.length > 0) {
|
||||||
|
const llamacppProvider = getProviderByName('llamacpp')
|
||||||
|
const backendType = llamacppProvider?.settings.find(s => s.key === 'version_backend')?.controller_props.value as string
|
||||||
|
const deviceString = getActivatedDeviceString(backendType)
|
||||||
|
|
||||||
|
if (llamacppProvider) {
|
||||||
|
const currentDeviceSetting = llamacppProvider.settings.find(s => s.key === 'device')
|
||||||
|
|
||||||
|
// Sync device string when GPU activations change (only after initialization)
|
||||||
|
if (currentDeviceSetting && currentDeviceSetting.controller_props.value !== deviceString) {
|
||||||
|
|
||||||
|
const updatedSettings = llamacppProvider.settings.map(setting => {
|
||||||
|
if (setting.key === 'device') {
|
||||||
|
return {
|
||||||
|
...setting,
|
||||||
|
controller_props: {
|
||||||
|
...setting.controller_props,
|
||||||
|
value: deviceString
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return setting
|
||||||
|
})
|
||||||
|
|
||||||
|
updateProvider('llamacpp', {
|
||||||
|
settings: updatedSettings
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [isInitialized, gpuActivationStates, versionBackend, getActivatedDeviceString, updateProvider, getProviderByName, hardwareData.gpus.length])
|
||||||
|
|
||||||
const stopRunningModel = (modelId: string) => {
|
const stopRunningModel = (modelId: string) => {
|
||||||
stopModel(modelId)
|
stopModel(modelId)
|
||||||
@ -61,6 +119,33 @@ function SystemMonitor() {
|
|||||||
hardwareData.total_memory
|
hardwareData.total_memory
|
||||||
) * 100
|
) * 100
|
||||||
|
|
||||||
|
// Determine backend type and filter GPUs accordingly
|
||||||
|
const isCudaBackend = typeof versionBackend === 'string' && versionBackend.includes('cuda')
|
||||||
|
const isVulkanBackend = typeof versionBackend === 'string' && versionBackend.includes('vulkan')
|
||||||
|
|
||||||
|
// Check if GPU should be active based on backend compatibility
|
||||||
|
const isGPUCompatible = (gpu: any) => {
|
||||||
|
if (isCudaBackend) {
|
||||||
|
return gpu.nvidia_info !== null
|
||||||
|
} else if (isVulkanBackend) {
|
||||||
|
return gpu.vulkan_info !== null
|
||||||
|
} else {
|
||||||
|
// No valid backend - all GPUs are inactive
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if GPU is actually activated
|
||||||
|
const isGPUActive = (gpu: any) => {
|
||||||
|
const compatible = isGPUCompatible(gpu)
|
||||||
|
const activated = gpu.activated ?? false
|
||||||
|
const result = compatible && activated
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter to show only active GPUs
|
||||||
|
const activeGPUs = hardwareData.gpus.filter(gpu => isGPUActive(gpu))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col h-full bg-main-view overflow-y-auto p-6">
|
<div className="flex flex-col h-full bg-main-view overflow-y-auto p-6">
|
||||||
<div className="flex items-center mb-4 gap-2">
|
<div className="flex items-center mb-4 gap-2">
|
||||||
@ -220,11 +305,18 @@ function SystemMonitor() {
|
|||||||
<h2 className="text-base font-semibold text-main-view-fg mb-4">
|
<h2 className="text-base font-semibold text-main-view-fg mb-4">
|
||||||
{t('system-monitor:activeGpus')}
|
{t('system-monitor:activeGpus')}
|
||||||
</h2>
|
</h2>
|
||||||
{hardwareData.gpus.length > 0 ? (
|
{!isInitialized ? (
|
||||||
|
<div className="text-center text-main-view-fg/50 py-4">
|
||||||
|
Initializing GPU states...
|
||||||
|
</div>
|
||||||
|
) : activeGPUs.length > 0 ? (
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
{hardwareData.gpus
|
{activeGPUs.map((gpu, index) => {
|
||||||
// .filter((gpu) => gpu.activated)
|
// Find the corresponding system usage data for this GPU
|
||||||
.map((gpu, index) => (
|
const gpuUsage = systemUsage.gpus.find(usage => usage.uuid === gpu.uuid)
|
||||||
|
const gpuIndex = hardwareData.gpus.findIndex(hwGpu => hwGpu.uuid === gpu.uuid)
|
||||||
|
|
||||||
|
return (
|
||||||
<div
|
<div
|
||||||
key={gpu.uuid || index}
|
key={gpu.uuid || index}
|
||||||
className="bg-main-view-fg/3 rounded-lg p-4"
|
className="bg-main-view-fg/3 rounded-lg p-4"
|
||||||
@ -243,11 +335,17 @@ function SystemMonitor() {
|
|||||||
{t('system-monitor:vramUsage')}
|
{t('system-monitor:vramUsage')}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-main-view-fg">
|
<span className="text-main-view-fg">
|
||||||
{formatMegaBytes(
|
{gpuUsage ? (
|
||||||
gpu.total_memory -
|
<>
|
||||||
systemUsage.gpus[index]?.used_memory
|
{formatMegaBytes(gpuUsage.used_memory)}{' '}
|
||||||
)}{' '}
|
/ {formatMegaBytes(gpu.total_memory)}
|
||||||
/ {formatMegaBytes(gpu.total_memory)}
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
{formatMegaBytes(0)}{' '}
|
||||||
|
/ {formatMegaBytes(gpu.total_memory)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between items-center">
|
<div className="flex justify-between items-center">
|
||||||
@ -264,23 +362,22 @@ function SystemMonitor() {
|
|||||||
</span>
|
</span>
|
||||||
<span className="text-main-view-fg">
|
<span className="text-main-view-fg">
|
||||||
{gpu.nvidia_info?.compute_capability ||
|
{gpu.nvidia_info?.compute_capability ||
|
||||||
gpu.vulkan_info.api_version}
|
gpu.vulkan_info?.api_version || '-'}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-2">
|
<div className="mt-2">
|
||||||
<Progress
|
<Progress
|
||||||
value={
|
value={
|
||||||
((gpu.total_memory -
|
gpuUsage ?
|
||||||
systemUsage.gpus[index]?.used_memory) /
|
((gpuUsage.used_memory / gpu.total_memory) * 100) : 0
|
||||||
gpu.total_memory) *
|
|
||||||
100
|
|
||||||
}
|
}
|
||||||
className="h-2 w-full"
|
className="h-2 w-full"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
)
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="text-center text-main-view-fg/50 py-4">
|
<div className="text-center text-main-view-fg/50 py-4">
|
||||||
@ -288,6 +385,7 @@ function SystemMonitor() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user