import { Button, Dialog, DialogActions, DialogBody, DialogContent, DialogSurface, DialogTitle, DialogTrigger, Dropdown, Input, Label, Option, Select, Switch, Text } from '@fluentui/react-components'; import { AddCircle20Regular, ArrowReset20Regular, DataUsageSettings20Regular, Delete20Regular, Save20Regular } from '@fluentui/react-icons'; import React, { FC } from 'react'; import { Section } from '../components/Section'; import { Labeled } from '../components/Labeled'; import { ToolTipButton } from '../components/ToolTipButton'; import commonStore from '../stores/commonStore'; import { observer } from 'mobx-react-lite'; import { toast } from 'react-toastify'; import { ValuedSlider } from '../components/ValuedSlider'; import { NumberInput } from '../components/NumberInput'; import { Page } from '../components/Page'; import { useNavigate } from 'react-router'; import { RunButton } from '../components/RunButton'; import { updateConfig } from '../apis'; import { ConvertModel, FileExists } from '../../wailsjs/go/backend_golang/App'; import { getStrategy, refreshLocalModels } from '../utils'; import { useTranslation } from 'react-i18next'; import { WindowShow } from '../../wailsjs/runtime/runtime'; import strategyImg from '../assets/images/strategy.jpg'; import strategyZhImg from '../assets/images/strategy_zh.jpg'; export type ApiParameters = { apiPort: number maxResponseToken: number; temperature: number; topP: number; presencePenalty: number; frequencyPenalty: number; } export type Device = 'CPU' | 'CUDA' | 'Custom'; export type Precision = 'fp16' | 'int8' | 'fp32'; export type ModelParameters = { // different models can not have the same name modelName: string; device: Device; precision: Precision; storedLayers: number; maxStoredLayers: number; enableHighPrecisionForLastLayer: boolean; useCustomCuda?: boolean; customStrategy?: string; } export type ModelConfig = { // different configs can have the same name name: string; apiParameters: ApiParameters modelParameters: ModelParameters } export const defaultModelConfigs: ModelConfig[] = [ { name: 'GPU-2G-1B5-EN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-1B5-v12-Eng98%-Other2%-20230520-ctx4096.pth', device: 'CUDA', precision: 'int8', storedLayers: 4, maxStoredLayers: 41, enableHighPrecisionForLastLayer: true, useCustomCuda: true } }, { name: 'GPU-4G-1B5-EN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-1B5-v12-Eng98%-Other2%-20230520-ctx4096.pth', device: 'CUDA', precision: 'int8', storedLayers: 41, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false, useCustomCuda: true } }, { name: 'GPU-4G-3B-EN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-3B-v12-Eng98%-Other2%-20230520-ctx4096.pth', device: 'CUDA', precision: 'int8', storedLayers: 24, maxStoredLayers: 41, enableHighPrecisionForLastLayer: true, useCustomCuda: true } }, { name: 'GPU-4G-3B-CN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-3B-v12-Eng49%-Chn49%-Jpn1%-Other1%-20230527-ctx4096.pth', device: 'CUDA', precision: 'int8', storedLayers: 24, maxStoredLayers: 41, enableHighPrecisionForLastLayer: true, useCustomCuda: true } }, { name: 'GPU-4G-7B-EN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-7B-v12-Eng98%-Other2%-20230521-ctx8192.pth', device: 'CUDA', precision: 'int8', storedLayers: 8, maxStoredLayers: 41, enableHighPrecisionForLastLayer: true, useCustomCuda: true } }, { name: 'GPU-4G-7B-CN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-7B-v12-Eng49%-Chn49%-Jpn1%-Other1%-20230530-ctx8192.pth', device: 'CUDA', precision: 'int8', storedLayers: 8, maxStoredLayers: 41, enableHighPrecisionForLastLayer: true, useCustomCuda: true } }, { name: 'GPU-6G-1B5-EN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-1B5-v12-Eng98%-Other2%-20230520-ctx4096.pth', device: 'CUDA', precision: 'fp16', storedLayers: 41, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false, useCustomCuda: true } }, { name: 'GPU-6G-3B-EN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-3B-v12-Eng98%-Other2%-20230520-ctx4096.pth', device: 'CUDA', precision: 'int8', storedLayers: 41, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false, useCustomCuda: true } }, { name: 'GPU-6G-3B-CN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-3B-v12-Eng49%-Chn49%-Jpn1%-Other1%-20230527-ctx4096.pth', device: 'CUDA', precision: 'int8', storedLayers: 41, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false, useCustomCuda: true } }, { name: 'GPU-6G-7B-EN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-7B-v12-Eng98%-Other2%-20230521-ctx8192.pth', device: 'CUDA', precision: 'int8', storedLayers: 18, maxStoredLayers: 41, enableHighPrecisionForLastLayer: true, useCustomCuda: true } }, { name: 'GPU-6G-7B-CN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-7B-v12-Eng49%-Chn49%-Jpn1%-Other1%-20230530-ctx8192.pth', device: 'CUDA', precision: 'int8', storedLayers: 18, maxStoredLayers: 41, enableHighPrecisionForLastLayer: true, useCustomCuda: true } }, { name: 'GPU-8G-3B-EN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-3B-v12-Eng98%-Other2%-20230520-ctx4096.pth', device: 'CUDA', precision: 'fp16', storedLayers: 41, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false, useCustomCuda: true } }, { name: 'GPU-8G-3B-CN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-3B-v12-Eng49%-Chn49%-Jpn1%-Other1%-20230527-ctx4096.pth', device: 'CUDA', precision: 'fp16', storedLayers: 41, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false, useCustomCuda: true } }, { name: 'GPU-8G-7B-EN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-7B-v12-Eng98%-Other2%-20230521-ctx8192.pth', device: 'CUDA', precision: 'int8', storedLayers: 27, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false, useCustomCuda: true } }, { name: 'GPU-8G-7B-CN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-7B-v12-Eng49%-Chn49%-Jpn1%-Other1%-20230530-ctx8192.pth', device: 'CUDA', precision: 'int8', storedLayers: 27, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false, useCustomCuda: true } }, { name: 'GPU-10G-7B-EN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-7B-v12-Eng98%-Other2%-20230521-ctx8192.pth', device: 'CUDA', precision: 'int8', storedLayers: 41, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false, useCustomCuda: true } }, { name: 'GPU-10G-7B-CN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-7B-v12-Eng49%-Chn49%-Jpn1%-Other1%-20230530-ctx8192.pth', device: 'CUDA', precision: 'int8', storedLayers: 41, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false, useCustomCuda: true } }, { name: 'GPU-12G-14B-EN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-14B-v12-Eng98%-Other2%-20230523-ctx8192.pth', device: 'CUDA', precision: 'int8', storedLayers: 24, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false, useCustomCuda: true } }, { name: 'GPU-16G-7B-EN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-7B-v12-Eng98%-Other2%-20230521-ctx8192.pth', device: 'CUDA', precision: 'fp16', storedLayers: 41, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false, useCustomCuda: true } }, { name: 'GPU-16G-7B-CN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-7B-v12-Eng49%-Chn49%-Jpn1%-Other1%-20230530-ctx8192.pth', device: 'CUDA', precision: 'fp16', storedLayers: 41, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false, useCustomCuda: true } }, { name: 'GPU-16G-14B-EN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-14B-v12-Eng98%-Other2%-20230523-ctx8192.pth', device: 'CUDA', precision: 'int8', storedLayers: 37, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false, useCustomCuda: true } }, { name: 'GPU-18G-14B-EN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-14B-v12-Eng98%-Other2%-20230523-ctx8192.pth', device: 'CUDA', precision: 'int8', storedLayers: 41, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false, useCustomCuda: true } }, { name: 'GPU-32G-14B-EN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-14B-v12-Eng98%-Other2%-20230523-ctx8192.pth', device: 'CUDA', precision: 'fp16', storedLayers: 41, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false, useCustomCuda: true } }, { name: 'CPU-6G-1B5-EN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-1B5-v12-Eng98%-Other2%-20230520-ctx4096.pth', device: 'CPU', precision: 'fp32', storedLayers: 41, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false } }, { name: 'CPU-12G-3B-EN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-3B-v12-Eng98%-Other2%-20230520-ctx4096.pth', device: 'CPU', precision: 'fp32', storedLayers: 41, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false } }, { name: 'CPU-12G-3B-CN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-3B-v12-Eng49%-Chn49%-Jpn1%-Other1%-20230527-ctx4096.pth', device: 'CPU', precision: 'fp32', storedLayers: 41, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false } }, { name: 'CPU-28G-7B-EN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-7B-v12-Eng98%-Other2%-20230521-ctx8192.pth', device: 'CPU', precision: 'fp32', storedLayers: 41, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false } }, { name: 'CPU-28G-7B-CN', apiParameters: { apiPort: 8000, maxResponseToken: 4100, temperature: 1.2, topP: 0.5, presencePenalty: 0.4, frequencyPenalty: 0.4 }, modelParameters: { modelName: 'RWKV-4-Raven-7B-v12-Eng49%-Chn49%-Jpn1%-Other1%-20230530-ctx8192.pth', device: 'CPU', precision: 'fp32', storedLayers: 41, maxStoredLayers: 41, enableHighPrecisionForLastLayer: false } } ]; export const Configs: FC = observer(() => { const { t } = useTranslation(); const [selectedIndex, setSelectedIndex] = React.useState(commonStore.currentModelConfigIndex); const [selectedConfig, setSelectedConfig] = React.useState(commonStore.modelConfigs[selectedIndex]); const [displayStrategyImg, setDisplayStrategyImg] = React.useState(false); const navigate = useNavigate(); const port = selectedConfig.apiParameters.apiPort; const updateSelectedIndex = (newIndex: number) => { setSelectedIndex(newIndex); setSelectedConfig(commonStore.modelConfigs[newIndex]); // if you don't want to update the config used by the current startup in real time, comment out this line commonStore.setCurrentConfigIndex(newIndex); }; const setSelectedConfigName = (newName: string) => { setSelectedConfig({ ...selectedConfig, name: newName }); }; const setSelectedConfigApiParams = (newParams: Partial) => { setSelectedConfig({ ...selectedConfig, apiParameters: { ...selectedConfig.apiParameters, ...newParams } }); }; const setSelectedConfigModelParams = (newParams: Partial) => { setSelectedConfig({ ...selectedConfig, modelParameters: { ...selectedConfig.modelParameters, ...newParams } }); }; const onClickSave = () => { commonStore.setModelConfig(selectedIndex, selectedConfig); updateConfig({ max_tokens: selectedConfig.apiParameters.maxResponseToken, temperature: selectedConfig.apiParameters.temperature, top_p: selectedConfig.apiParameters.topP, presence_penalty: selectedConfig.apiParameters.presencePenalty, frequency_penalty: selectedConfig.apiParameters.frequencyPenalty }); toast(t('Config Saved'), { autoClose: 300, type: 'success' }); }; return (
{ if (data.optionValue) { updateSelectedIndex(Number(data.optionValue)); } }}> {commonStore.modelConfigs.map((config, index) => )} } onClick={() => { commonStore.createModelConfig(); updateSelectedIndex(commonStore.modelConfigs.length - 1); }} /> } onClick={() => { commonStore.deleteModelConfig(selectedIndex); updateSelectedIndex(Math.min(selectedIndex, commonStore.modelConfigs.length - 1)); }} /> } /> {t('Reset All Configs')} {t('Are you sure you want to reset all configs? This will obtain the latest preset configs, but will override your custom configs and cannot be undone.')} } onClick={onClickSave} />
{ setSelectedConfigName(data.value); }} />
{ setSelectedConfigApiParams({ apiPort: data.value }); }} /> } /> { setSelectedConfigApiParams({ maxResponseToken: data.value }); }} /> } /> { setSelectedConfigApiParams({ temperature: data.value }); }} /> } /> { setSelectedConfigApiParams({ topP: data.value }); }} /> } /> { setSelectedConfigApiParams({ presencePenalty: data.value }); }} /> } /> { setSelectedConfigApiParams({ frequencyPenalty: data.value }); }} /> } />
} />
} onClick={() => { navigate({ pathname: '/models' }); }} /> } /> { if (commonStore.platform == 'darwin') { toast(t('MacOS is not yet supported for performing this operation, please do it manually.'), { type: 'info' }); return; } else if (commonStore.platform == 'linux') { toast(t('Linux is not yet supported for performing this operation, please do it manually.'), { type: 'info' }); return; } const modelPath = `${commonStore.settings.customModelsPath}/${selectedConfig.modelParameters.modelName}`; if (await FileExists(modelPath)) { const strategy = getStrategy(selectedConfig); const newModelPath = modelPath + '-' + strategy.replace(/[:> *+]/g, '-'); toast(t('Start Converting'), { autoClose: 1000, type: 'info' }); ConvertModel(commonStore.settings.customPythonPath, modelPath, strategy, newModelPath).then(() => { toast(`${t('Convert Success')} - ${newModelPath}`, { type: 'success' }); refreshLocalModels({ models: commonStore.modelSourceList }, false); }).catch(e => { const errMsg = e.message || e; if (errMsg.includes('path contains space')) toast(`${t('Convert Failed')} - ${t('Path Cannot Contain Space')}`, { type: 'error' }); else toast(`${t('Convert Failed')} - ${e.message || e}`, { type: 'error' }); }); setTimeout(WindowShow, 1000); } else { toast(`${t('Model Not Found')} - ${modelPath}`, { type: 'error' }); } }} /> { if (data.optionValue) { setSelectedConfigModelParams({ device: data.optionValue as Device }); } }}> } /> { selectedConfig.modelParameters.device != 'Custom' && { if (data.optionText) { setSelectedConfigModelParams({ precision: data.optionText as Precision }); } }}> } /> } { selectedConfig.modelParameters.device == 'CUDA' && {getStrategy(selectedConfig)} } /> } { selectedConfig.modelParameters.device == 'CUDA' && { setSelectedConfigModelParams({ storedLayers: data.value }); }} /> } /> } { selectedConfig.modelParameters.device == 'CUDA' && { setSelectedConfigModelParams({ enableHighPrecisionForLastLayer: data.checked }); }} /> } /> } { displayStrategyImg && } { selectedConfig.modelParameters.device == 'Custom' && setDisplayStrategyImg(true)} onMouseLeave={() => setDisplayStrategyImg(false)} content={ { setSelectedConfigModelParams({ customStrategy: data.value }); }} /> } /> } {selectedConfig.modelParameters.device == 'Custom' &&
} { selectedConfig.modelParameters.device != 'CPU' && { setSelectedConfigModelParams({ useCustomCuda: data.checked }); }} /> } /> }
} />
} /> ); });