From 0497e2052d1f61cbb9ff0f8d71011552df038900 Mon Sep 17 00:00:00 2001 From: jialin Date: Thu, 24 Apr 2025 16:59:10 +0800 Subject: [PATCH] fix: audio model use voxbox only --- src/pages/llmodels/components/data-form.tsx | 3 +- .../llmodels/components/hf-model-file.tsx | 5 +-- .../llmodels/components/search-model.tsx | 21 ++++------ src/pages/llmodels/config/form-context.ts | 1 + src/pages/llmodels/forms/local-path.tsx | 11 +++-- src/pages/llmodels/hooks/index.ts | 42 +++++++++++++------ 6 files changed, 49 insertions(+), 34 deletions(-) diff --git a/src/pages/llmodels/components/data-form.tsx b/src/pages/llmodels/components/data-form.tsx index aef876f8..f72d69b7 100644 --- a/src/pages/llmodels/components/data-form.tsx +++ b/src/pages/llmodels/components/data-form.tsx @@ -247,7 +247,8 @@ const DataForm: React.FC = forwardRef((props, ref) => { diff --git a/src/pages/llmodels/components/hf-model-file.tsx b/src/pages/llmodels/components/hf-model-file.tsx index 984174ab..2fd09d90 100644 --- a/src/pages/llmodels/components/hf-model-file.tsx +++ b/src/pages/llmodels/components/hf-model-file.tsx @@ -20,7 +20,6 @@ import { queryModelScopeModelFiles } from '../apis'; import { backendOptionsMap, modelSourceMap } from '../config'; -import { checkOnlyAscendNPU } from '../hooks'; import '../style/hf-model-file.less'; import ModelFileItem from './model-file-item'; import TitleWrapper from './title-wrapper'; @@ -237,9 +236,7 @@ const HFModelFile: React.FC = forwardRef((props, ref) => { try { const evaluateFileList = list.map((item: any) => { return { - backend: checkOnlyAscendNPU(gpuOptions || []) - ? backendOptionsMap.ascendMindie - : backendOptionsMap.llamaBox, + backend: backendOptionsMap.llamaBox, source: modelSource, ...(modelSource === modelSourceMap.huggingface_value ? { diff --git a/src/pages/llmodels/components/search-model.tsx b/src/pages/llmodels/components/search-model.tsx index 939500b2..ad453646 100644 --- a/src/pages/llmodels/components/search-model.tsx +++ b/src/pages/llmodels/components/search-model.tsx @@ -21,11 +21,10 @@ import { ModelScopeSortType, ModelSortType, ModelscopeTaskMap, - backendOptionsMap, modelSourceMap } from '../config'; import { handleRecognizeAudioModel } from '../config/audio-catalog'; -import { checkOnlyAscendNPU } from '../hooks'; +import { checkCurrentbackend } from '../hooks'; import SearchStyle from '../style/search-result.less'; import SearchInput from './search-input'; import SearchResult from './search-result'; @@ -215,17 +214,15 @@ const SearchModel: React.FC = (props) => { const res = handleRecognizeAudioModel(item, modelSource); let backendObj = {}; - if (checkOnlyAscendNPU?.(gpuOptions || [])) { + const backend = checkCurrentbackend({ + isGGUF: item.isGGUF, + isAudio: res.isAudio, + gpuOptions: gpuOptions || [] + }); + + if (backend) { backendObj = { - backend: backendOptionsMap.ascendMindie - }; - } else if (res.isAudio) { - backendObj = { - backend: backendOptionsMap.voxBox - }; - } else if (item.isGGUF) { - backendObj = { - backend: backendOptionsMap.llamaBox + backend: backend }; } diff --git a/src/pages/llmodels/config/form-context.ts b/src/pages/llmodels/config/form-context.ts index 230f1ab2..8e1dd5ec 100644 --- a/src/pages/llmodels/config/form-context.ts +++ b/src/pages/llmodels/config/form-context.ts @@ -13,6 +13,7 @@ interface FormContextProps { interface FormInnerContextProps { onBackendChange?: (backend: string) => void; + gpuOptions?: any[]; } export const FormContext = React.createContext( diff --git a/src/pages/llmodels/forms/local-path.tsx b/src/pages/llmodels/forms/local-path.tsx index f1512b26..243d5ea3 100644 --- a/src/pages/llmodels/forms/local-path.tsx +++ b/src/pages/llmodels/forms/local-path.tsx @@ -12,13 +12,14 @@ import { } from '../config'; import { useFormContext, useFormInnerContext } from '../config/form-context'; import { FormData } from '../config/types'; +import { checkOnlyAscendNPU } from '../hooks'; const LocalPathForm: React.FC = () => { const form = Form.useFormInstance(); const formCtx = useFormContext(); const formInnerCtx = useFormInnerContext(); const source = Form.useWatch('source', form); - const { onBackendChange } = formInnerCtx; + const { onBackendChange, gpuOptions } = formInnerCtx; const { byBuiltIn } = formCtx; const { getRuleMessage } = useAppUtils(); const intl = useIntl(); @@ -37,14 +38,16 @@ const LocalPathForm: React.FC = () => { const isBlobFile = value.split('/').pop().includes('sha256'); let backend = form.getFieldValue('backend'); - if ( + if (isEndwithGGUF || isBlobFile) { + backend = backendOptionsMap.llamaBox; + } else if (checkOnlyAscendNPU(gpuOptions || [])) { + backend = backendOptionsMap.ascendMindie; + } else if ( !isEndwithGGUF && !isBlobFile && backend === backendOptionsMap.llamaBox ) { backend = backendOptionsMap.vllm; - } else if (isEndwithGGUF || isBlobFile) { - backend = backendOptionsMap.llamaBox; } form.setFieldValue('backend', backend); diff --git a/src/pages/llmodels/hooks/index.ts b/src/pages/llmodels/hooks/index.ts index 1f03c585..1ededf10 100644 --- a/src/pages/llmodels/hooks/index.ts +++ b/src/pages/llmodels/hooks/index.ts @@ -243,6 +243,27 @@ export const checkOnlyAscendNPU = (gpuOptions: any[]) => { }); }; +export const checkCurrentbackend = (data: { + isAudio: boolean; + isGGUF: boolean; + gpuOptions: any[]; + defaultBackend?: string; +}) => { + const { isAudio, isGGUF, gpuOptions, defaultBackend } = data; + if (isAudio) { + return backendOptionsMap.voxBox; + } + + if (isGGUF) { + return backendOptionsMap.llamaBox; + } + + if (checkOnlyAscendNPU(gpuOptions)) { + return backendOptionsMap.ascendMindie; + } + return defaultBackend; +}; + export const useCheckCompatibility = () => { const intl = useIntl(); const cacheFormValuesRef = useRef({}); @@ -559,24 +580,19 @@ export const useSelectModel = (data: { gpuOptions: any[] }) => { const reg = /(-gguf)$/i; name = _.toLower(name).replace(reg, ''); - if (checkOnlyAscendNPU(gpuOptions)) { - return { - repo_id: selectModel.name, - name: name, - backend: backendOptionsMap.ascendMindie - }; - } const modelTaskData = handleRecognizeAudioModel(selectModel, source); + const backend = checkCurrentbackend({ + defaultBackend: backendOptionsMap.vllm, + isAudio: modelTaskData.type === modelTaskMap.audio, + isGGUF: selectModel.isGGUF, + gpuOptions: gpuOptions + }); + return { repo_id: selectModel.name, name: name, - backend: - modelTaskData.type === modelTaskMap.audio - ? backendOptionsMap.voxBox - : selectModel.isGGUF - ? backendOptionsMap.llamaBox - : backendOptionsMap.vllm + backend: backend }; };