chore: set mindie to backend in ascend
This commit is contained in:
@@ -23,6 +23,7 @@ import {
|
||||
import { FormContext } from '../config/form-context';
|
||||
import { CatalogSpec, FormData, ListItem, SourceType } from '../config/types';
|
||||
import {
|
||||
checkOnlyAscendNPU,
|
||||
useCheckCompatibility,
|
||||
useGenerateFormEditInitialValues
|
||||
} from '../hooks';
|
||||
@@ -77,6 +78,7 @@ const quantiCapitMap: Record<string, string> = {
|
||||
|
||||
const defaultQuant = ['Q4_K_M'];
|
||||
const EmbeddingRerankFirstQuant = ['FP16', 'F16'];
|
||||
const AscendNPUQuant = ['F16', 'FP16', 'Q8_0'];
|
||||
|
||||
const AddModal: React.FC<AddModalProps> = (props) => {
|
||||
const {
|
||||
@@ -137,7 +139,18 @@ const AddModal: React.FC<AddModalProps> = (props) => {
|
||||
return data;
|
||||
};
|
||||
|
||||
const getDefaultQuant = (data: { category: string; quantOption: string }) => {
|
||||
const getDefaultQuant = (data: {
|
||||
category: string;
|
||||
quantOption: string;
|
||||
backend: string;
|
||||
condidateQuant?: string[];
|
||||
}) => {
|
||||
if (
|
||||
data.backend === backendOptionsMap.llamaBox &&
|
||||
checkOnlyAscendNPU(gpuOptions)
|
||||
) {
|
||||
return AscendNPUQuant.includes(_.toUpper(data.quantOption));
|
||||
}
|
||||
if (
|
||||
data.category === modelCategoriesMap.embedding ||
|
||||
data.category === modelCategoriesMap.reranker
|
||||
@@ -282,7 +295,8 @@ const AddModal: React.FC<AddModalProps> = (props) => {
|
||||
_.find(list, (item: { label: string; value: string }) =>
|
||||
getDefaultQuant({
|
||||
category: _.get(current, 'categories.0', ''),
|
||||
quantOption: item.value
|
||||
quantOption: item.value,
|
||||
backend: form.current.getFieldValue('backend')
|
||||
})
|
||||
)?.value ||
|
||||
_.get(list, '0.value', '')
|
||||
@@ -375,7 +389,8 @@ const AddModal: React.FC<AddModalProps> = (props) => {
|
||||
_.find(list, (item: CatalogSpec) => {
|
||||
return getDefaultQuant({
|
||||
category: _.get(current, 'categories.0', ''),
|
||||
quantOption: item.quantization
|
||||
quantOption: item.quantization,
|
||||
backend: item.backend
|
||||
});
|
||||
}) || _.get(res.items, `0`, {});
|
||||
|
||||
|
||||
@@ -91,14 +91,12 @@ const AddModal: FC<AddModalProps> = (props) => {
|
||||
warningStatus,
|
||||
submitAnyway
|
||||
} = useCheckCompatibility();
|
||||
const { onSelectModel } = useSelectModel();
|
||||
const { onSelectModel } = useSelectModel({ gpuOptions: props.gpuOptions });
|
||||
const form = useRef<any>({});
|
||||
const intl = useIntl();
|
||||
const [selectedModel, setSelectedModel] = useState<any>({});
|
||||
const [collapsed, setCollapsed] = useState<boolean>(false);
|
||||
const [isGGUF, setIsGGUF] = useState<boolean>(false);
|
||||
const [isEvaluatModel, setIsEvaluatModel] = useState<boolean>(false);
|
||||
const [isEvaluatModelFile, setIsEvaluatModelFile] = useState<boolean>(false);
|
||||
const modelFileRef = useRef<any>(null);
|
||||
|
||||
const getDefaultSpec = (item: any) => {
|
||||
@@ -244,17 +242,6 @@ const AddModal: FC<AddModalProps> = (props) => {
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (isEvaluatModel || isEvaluatModelFile) {
|
||||
setWarningStatus({
|
||||
show: true,
|
||||
title: '',
|
||||
type: 'transition',
|
||||
message: intl.formatMessage({ id: 'models.form.evaluating' })
|
||||
});
|
||||
}
|
||||
}, [isEvaluatModel, isEvaluatModelFile]);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
handleOnOpen();
|
||||
@@ -312,6 +299,7 @@ const AddModal: FC<AddModalProps> = (props) => {
|
||||
modelSource={props.source}
|
||||
onSelectModel={handleOnSelectModel}
|
||||
displayEvaluateStatus={displayEvaluateStatus}
|
||||
gpuOptions={props.gpuOptions}
|
||||
></SearchModel>
|
||||
</ColumnWrapper>
|
||||
<Separator></Separator>
|
||||
@@ -333,6 +321,7 @@ const AddModal: FC<AddModalProps> = (props) => {
|
||||
onSelectFile={handleSelectModelFile}
|
||||
collapsed={collapsed}
|
||||
displayEvaluateStatus={displayEvaluateStatus}
|
||||
gpuOptions={props.gpuOptions}
|
||||
></HFModelFile>
|
||||
)}
|
||||
</ColumnWrapper>
|
||||
|
||||
@@ -20,6 +20,7 @@ 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';
|
||||
@@ -39,6 +40,7 @@ interface HFModelFileProps {
|
||||
loadingModel?: boolean;
|
||||
modelSource: string;
|
||||
ref: any;
|
||||
gpuOptions?: any[];
|
||||
onSelectFile?: (file: any, evaluate?: boolean) => void;
|
||||
displayEvaluateStatus?: (show?: boolean) => void;
|
||||
}
|
||||
@@ -50,7 +52,13 @@ const includeReg = /\.(safetensors|gguf)$/i;
|
||||
const filterRegGGUF = /\.(gguf)$/i;
|
||||
|
||||
const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
|
||||
const { collapsed, modelSource, isDownload, displayEvaluateStatus } = props;
|
||||
const {
|
||||
collapsed,
|
||||
modelSource,
|
||||
isDownload,
|
||||
gpuOptions,
|
||||
displayEvaluateStatus
|
||||
} = props;
|
||||
const intl = useIntl();
|
||||
const [isEvaluating, setIsEvaluating] = useState(false);
|
||||
const [dataSource, setDataSource] = useState<any>({
|
||||
@@ -229,7 +237,9 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
|
||||
try {
|
||||
const evaluateFileList = list.map((item: any) => {
|
||||
return {
|
||||
backend: backendOptionsMap.llamaBox,
|
||||
backend: checkOnlyAscendNPU(gpuOptions || [])
|
||||
? backendOptionsMap.ascendMindie
|
||||
: backendOptionsMap.llamaBox,
|
||||
source: modelSource,
|
||||
...(modelSource === modelSourceMap.huggingface_value
|
||||
? {
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
modelSourceMap
|
||||
} from '../config';
|
||||
import { handleRecognizeAudioModel } from '../config/audio-catalog';
|
||||
import { checkOnlyAscendNPU } from '../hooks';
|
||||
import SearchStyle from '../style/search-result.less';
|
||||
import SearchInput from './search-input';
|
||||
import SearchResult from './search-result';
|
||||
@@ -39,6 +40,7 @@ interface SearchInputProps {
|
||||
hasLinuxWorker?: boolean;
|
||||
modelSource: string;
|
||||
isDownload?: boolean;
|
||||
gpuOptions?: any[];
|
||||
setLoadingModel?: (flag: boolean) => void;
|
||||
onSourceChange?: (source: string) => void;
|
||||
onSelectModel: (model: any, evaluate?: boolean) => void;
|
||||
@@ -51,6 +53,7 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
|
||||
modelSource,
|
||||
isDownload,
|
||||
hasLinuxWorker,
|
||||
gpuOptions,
|
||||
setLoadingModel,
|
||||
onSelectModel,
|
||||
displayEvaluateStatus
|
||||
@@ -210,8 +213,13 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
|
||||
try {
|
||||
const repoList = list.map((item) => {
|
||||
const res = handleRecognizeAudioModel(item, modelSource);
|
||||
|
||||
let backendObj = {};
|
||||
if (res.isAudio) {
|
||||
if (checkOnlyAscendNPU?.(gpuOptions || [])) {
|
||||
backendObj = {
|
||||
backend: backendOptionsMap.ascendMindie
|
||||
};
|
||||
} else if (res.isAudio) {
|
||||
backendObj = {
|
||||
backend: backendOptionsMap.voxBox
|
||||
};
|
||||
|
||||
@@ -228,6 +228,15 @@ export const useGenerateModelFileOptions = () => {
|
||||
};
|
||||
};
|
||||
|
||||
// handle for ascend npu only
|
||||
export const checkOnlyAscendNPU = (gpuOptions: any[]) => {
|
||||
return gpuOptions?.every?.((item) => {
|
||||
return item.children?.every((child: any) => {
|
||||
return _.toLower(child.vendor) === 'huawei';
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const useCheckCompatibility = () => {
|
||||
const intl = useIntl();
|
||||
const cacheFormValuesRef = useRef<any>({});
|
||||
@@ -535,13 +544,22 @@ export const useCheckCompatibility = () => {
|
||||
};
|
||||
};
|
||||
|
||||
export const useSelectModel = () => {
|
||||
export const useSelectModel = (data: { gpuOptions: any[] }) => {
|
||||
// just for setting the model name or repo_id, and the backend, Since the model type is fixed.
|
||||
const { gpuOptions } = data;
|
||||
|
||||
const onSelectModel = (selectModel: any, source: string) => {
|
||||
let name = _.split(selectModel.name, '/').slice(-1)[0];
|
||||
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);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user