refactor: gpu selector
This commit is contained in:
@@ -124,7 +124,7 @@ const AutoTooltip: React.FC<AutoTooltipProps> = ({
|
|||||||
style={{
|
style={{
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
right: 8,
|
right: 8,
|
||||||
top: 8
|
top: 7
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
import { isNotEmptyValue } from '@/utils/index';
|
||||||
|
import { useIntl } from '@umijs/max';
|
||||||
|
import type { CascaderAutoProps } from 'antd';
|
||||||
|
import { Cascader, Form } from 'antd';
|
||||||
|
import { cloneDeep } from 'lodash';
|
||||||
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||||
|
import Wrapper from './components/wrapper';
|
||||||
|
import { SealFormItemProps } from './types';
|
||||||
|
|
||||||
|
const SealCascader: React.FC<CascaderAutoProps & SealFormItemProps> = (
|
||||||
|
props
|
||||||
|
) => {
|
||||||
|
const {
|
||||||
|
label,
|
||||||
|
placeholder,
|
||||||
|
children,
|
||||||
|
required,
|
||||||
|
description,
|
||||||
|
options,
|
||||||
|
allowNull,
|
||||||
|
isInFormItems = true,
|
||||||
|
...rest
|
||||||
|
} = props;
|
||||||
|
const intl = useIntl();
|
||||||
|
const [isFocus, setIsFocus] = useState(false);
|
||||||
|
const inputRef = useRef<any>(null);
|
||||||
|
let status = '';
|
||||||
|
|
||||||
|
// the status can be controlled by Form.Item
|
||||||
|
if (isInFormItems) {
|
||||||
|
const statusData = Form?.Item?.useStatus?.();
|
||||||
|
status = statusData?.status || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const _options = useMemo(() => {
|
||||||
|
if (!options?.length) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const list = cloneDeep(options);
|
||||||
|
return list.map((item: any) => {
|
||||||
|
if (item.locale) {
|
||||||
|
item.label = intl.formatMessage({ id: item.label as string });
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
}, [options, intl]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isNotEmptyValue(props.value) || (allowNull && props.value === null)) {
|
||||||
|
setIsFocus(true);
|
||||||
|
}
|
||||||
|
}, [props.value, allowNull]);
|
||||||
|
|
||||||
|
const handleClickWrapper = () => {
|
||||||
|
if (!props.disabled && !isFocus) {
|
||||||
|
inputRef.current?.focus?.();
|
||||||
|
setIsFocus(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChange = (val: any, options: any) => {
|
||||||
|
if (isNotEmptyValue(val) || (allowNull && val === null)) {
|
||||||
|
setIsFocus(true);
|
||||||
|
} else {
|
||||||
|
setIsFocus(false);
|
||||||
|
}
|
||||||
|
props.onChange?.(val, options);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOnFocus = (e: any) => {
|
||||||
|
setIsFocus(true);
|
||||||
|
props.onFocus?.(e);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOnBlur = (e: any) => {
|
||||||
|
if (allowNull && props.value === null) {
|
||||||
|
setIsFocus(true);
|
||||||
|
} else if (!props.value) {
|
||||||
|
setIsFocus(false);
|
||||||
|
}
|
||||||
|
props.onBlur?.(e);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Wrapper
|
||||||
|
status={status}
|
||||||
|
label={label}
|
||||||
|
isFocus={isFocus}
|
||||||
|
required={required}
|
||||||
|
description={description}
|
||||||
|
disabled={props.disabled}
|
||||||
|
onClick={handleClickWrapper}
|
||||||
|
>
|
||||||
|
<Cascader
|
||||||
|
{...rest}
|
||||||
|
ref={inputRef}
|
||||||
|
options={children ? null : _options}
|
||||||
|
onFocus={handleOnFocus}
|
||||||
|
onBlur={handleOnBlur}
|
||||||
|
onChange={handleChange}
|
||||||
|
notFoundContent={null}
|
||||||
|
></Cascader>
|
||||||
|
</Wrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SealCascader;
|
||||||
@@ -777,6 +777,40 @@ body {
|
|||||||
font-weight: var(--font-weight-bold);
|
font-weight: var(--font-weight-bold);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ant-cascader-menu-item.ant-cascader-menu-item-active {
|
||||||
|
background-color: var(--ant-select-option-selected-bg) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cascader-popup-wrapper {
|
||||||
|
.ant-cascader-menu {
|
||||||
|
overflow-x: hidden;
|
||||||
|
|
||||||
|
&::-webkit-scrollbar {
|
||||||
|
width: var(--scrollbar-size);
|
||||||
|
}
|
||||||
|
|
||||||
|
&::-webkit-scrollbar-thumb {
|
||||||
|
background-color: transparent;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&::-webkit-scrollbar-track {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
&::-webkit-scrollbar-thumb {
|
||||||
|
background-color: var(--color-scrollbar-thumb);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-cascader-checkbox.ant-cascader-checkbox-disabled {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.ant-tooltip-content {
|
.ant-tooltip-content {
|
||||||
.ant-tooltip-inner {
|
.ant-tooltip-inner {
|
||||||
a {
|
a {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import AutoTooltip from '@/components/auto-tooltip';
|
import AutoTooltip from '@/components/auto-tooltip';
|
||||||
import LabelSelector from '@/components/label-selector';
|
import LabelSelector from '@/components/label-selector';
|
||||||
import ListInput from '@/components/list-input';
|
import ListInput from '@/components/list-input';
|
||||||
|
import SealCascader from '@/components/seal-form/seal-cascader';
|
||||||
import SealInput from '@/components/seal-form/seal-input';
|
import SealInput from '@/components/seal-form/seal-input';
|
||||||
import SealSelect from '@/components/seal-form/seal-select';
|
import SealSelect from '@/components/seal-form/seal-select';
|
||||||
import TooltipList from '@/components/tooltip-list';
|
import TooltipList from '@/components/tooltip-list';
|
||||||
@@ -122,6 +123,24 @@ const AdvanceConfig: React.FC<AdvanceConfigProps> = (props) => {
|
|||||||
form.setFieldValue('backend_parameters', list);
|
form.setFieldValue('backend_parameters', list);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const gpuOptionRender = (data: any) => {
|
||||||
|
let width = {
|
||||||
|
maxWidth: 180,
|
||||||
|
minWidth: 180
|
||||||
|
};
|
||||||
|
if (!data.parent) {
|
||||||
|
width = { maxWidth: 180, minWidth: 180 };
|
||||||
|
}
|
||||||
|
if (data.parent) {
|
||||||
|
return (
|
||||||
|
<AutoTooltip ghost {...width}>
|
||||||
|
{data.label}
|
||||||
|
</AutoTooltip>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return <GPUCard data={data}></GPUCard>;
|
||||||
|
};
|
||||||
|
|
||||||
const collapseItems = useMemo(() => {
|
const collapseItems = useMemo(() => {
|
||||||
const children = (
|
const children = (
|
||||||
<>
|
<>
|
||||||
@@ -214,47 +233,94 @@ const AdvanceConfig: React.FC<AdvanceConfigProps> = (props) => {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{scheduleType === 'manual' && (
|
{scheduleType === 'manual' && (
|
||||||
<Form.Item<FormData>
|
<>
|
||||||
name={['gpu_selector', 'gpu_ids']}
|
{/* <Form.Item<FormData>
|
||||||
rules={[
|
name={['gpu_selector', 'gpu_ids']}
|
||||||
{
|
rules={[
|
||||||
required: true,
|
{
|
||||||
message: intl.formatMessage(
|
required: true,
|
||||||
{
|
message: intl.formatMessage(
|
||||||
id: 'common.form.rule.select'
|
{
|
||||||
},
|
id: 'common.form.rule.select'
|
||||||
{
|
},
|
||||||
name: intl.formatMessage({ id: 'models.form.gpuselector' })
|
{
|
||||||
}
|
name: intl.formatMessage({
|
||||||
)
|
id: 'models.form.gpuselector'
|
||||||
}
|
})
|
||||||
]}
|
}
|
||||||
>
|
)
|
||||||
<SealSelect
|
}
|
||||||
allowClear
|
]}
|
||||||
label={intl.formatMessage({ id: 'models.form.gpuselector' })}
|
>
|
||||||
required
|
<SealSelect
|
||||||
mode="multiple"
|
label={intl.formatMessage({ id: 'models.form.gpuselector' })}
|
||||||
maxTagCount={1}
|
required
|
||||||
tagRender={(props) => {
|
mode="multiple"
|
||||||
return (
|
maxTagCount={1}
|
||||||
<AutoTooltip
|
tagRender={(props) => {
|
||||||
className="m-r-4"
|
return (
|
||||||
closable={props.closable}
|
<AutoTooltip
|
||||||
onClose={props.onClose}
|
className="m-r-4"
|
||||||
maxWidth={240}
|
closable={props.closable}
|
||||||
>
|
onClose={props.onClose}
|
||||||
{props.label}
|
maxWidth={240}
|
||||||
</AutoTooltip>
|
>
|
||||||
);
|
{props.label}
|
||||||
}}
|
</AutoTooltip>
|
||||||
options={gpuOptions}
|
);
|
||||||
optionRender={(props) => {
|
}}
|
||||||
return <GPUCard data={props.data}></GPUCard>;
|
options={gpuOptions}
|
||||||
}}
|
optionRender={(props) => {
|
||||||
></SealSelect>
|
return <GPUCard data={props.data}></GPUCard>;
|
||||||
</Form.Item>
|
}}
|
||||||
|
></SealSelect>
|
||||||
|
</Form.Item> */}
|
||||||
|
<Form.Item
|
||||||
|
name={['gpu_selector', 'gpu_ids']}
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: intl.formatMessage(
|
||||||
|
{
|
||||||
|
id: 'common.form.rule.select'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: intl.formatMessage({
|
||||||
|
id: 'models.form.gpuselector'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<SealCascader
|
||||||
|
required
|
||||||
|
multiple={backend !== backendOptionsMap.voxBox}
|
||||||
|
popupClassName="cascader-popup-wrapper"
|
||||||
|
maxTagCount="responsive"
|
||||||
|
label={intl.formatMessage({ id: 'models.form.gpuselector' })}
|
||||||
|
options={gpuOptions.map((item) => {
|
||||||
|
item.disableCheckbox = backend !== backendOptionsMap.llamaBox;
|
||||||
|
return item;
|
||||||
|
})}
|
||||||
|
tagRender={(props) => {
|
||||||
|
return (
|
||||||
|
<AutoTooltip
|
||||||
|
className="m-r-4"
|
||||||
|
closable={props.closable}
|
||||||
|
onClose={props.onClose}
|
||||||
|
maxWidth={240}
|
||||||
|
>
|
||||||
|
{props.label}
|
||||||
|
</AutoTooltip>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
optionRender={gpuOptionRender}
|
||||||
|
></SealCascader>
|
||||||
|
</Form.Item>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Form.Item name="backend_version">
|
<Form.Item name="backend_version">
|
||||||
<SealInput.Input
|
<SealInput.Input
|
||||||
label={intl.formatMessage({ id: 'models.form.backendVersion' })}
|
label={intl.formatMessage({ id: 'models.form.backendVersion' })}
|
||||||
|
|||||||
@@ -51,6 +51,13 @@ interface DataFormProps {
|
|||||||
fields?: string[];
|
fields?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface GPUOption {
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
disableCheckbox?: boolean;
|
||||||
|
children: GPUOption[];
|
||||||
|
}
|
||||||
|
|
||||||
const SEARCH_SOURCE = [
|
const SEARCH_SOURCE = [
|
||||||
modelSourceMap.huggingface_value,
|
modelSourceMap.huggingface_value,
|
||||||
modelSourceMap.modelscope_value
|
modelSourceMap.modelscope_value
|
||||||
@@ -72,9 +79,7 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
|
|||||||
} = props;
|
} = props;
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const [gpuOptions, setGpuOptions] = useState<
|
const [gpuOptions, setGpuOptions] = useState<Array<GPUOption>>([]);
|
||||||
Array<GPUListItem & { label: string; value: string }>
|
|
||||||
>([]);
|
|
||||||
const [modelTask, setModelTask] = useState<Record<string, any>>({
|
const [modelTask, setModelTask] = useState<Record<string, any>>({
|
||||||
type: '',
|
type: '',
|
||||||
value: '',
|
value: '',
|
||||||
@@ -114,17 +119,37 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const getGPUList = async () => {
|
const generateCascaderOptions = (list: GPUListItem[]) => {
|
||||||
const data = await queryGPUList();
|
const workerFields = ['worker_name', 'worker_id', 'worker_ip'];
|
||||||
const list = _.map(data.items, (item: GPUListItem) => {
|
|
||||||
|
const workers = _.groupBy(list, 'worker_name');
|
||||||
|
|
||||||
|
const workerList = _.map(workers, (value: GPUListItem[]) => {
|
||||||
return {
|
return {
|
||||||
...item,
|
label: `${value[0].worker_name}`,
|
||||||
title: '',
|
value: value[0].worker_name,
|
||||||
label: ` ${item.name}(${item.worker_name}) [${intl.formatMessage({ id: 'resources.table.index' })}:${item.index}]`,
|
parent: true,
|
||||||
value: item.id
|
disableCheckbox: true,
|
||||||
|
..._.pick(value[0], workerFields),
|
||||||
|
children: _.map(value, (item: GPUListItem) => {
|
||||||
|
return {
|
||||||
|
label: `[
|
||||||
|
${intl.formatMessage({ id: 'resources.table.index' })}:${item.index}] ${item.name}`,
|
||||||
|
value: item.id,
|
||||||
|
disableCheckbox: false,
|
||||||
|
..._.omit(item, workerFields)
|
||||||
|
};
|
||||||
|
})
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
setGpuOptions(list);
|
|
||||||
|
return workerList;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getGPUList = async () => {
|
||||||
|
const data = await queryGPUList();
|
||||||
|
const gpuList = generateCascaderOptions(data.items);
|
||||||
|
setGpuOptions(gpuList);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -470,6 +495,34 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
|
|||||||
props.onBackendChange?.(val);
|
props.onBackendChange?.(val);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const generateGPUIds = (data: FormData) => {
|
||||||
|
const gpu_ids = _.get(data, 'gpu_selector.gpu_ids', []);
|
||||||
|
if (!gpu_ids.length) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
const result: string[] = [];
|
||||||
|
|
||||||
|
_.each(gpu_ids, (item: string[]) => {
|
||||||
|
if (item.length > 1) {
|
||||||
|
result.push(..._.tail(item));
|
||||||
|
}
|
||||||
|
if (item.length === 1) {
|
||||||
|
const worker = _.find(gpuOptions, { value: item[0] });
|
||||||
|
const gpus = _.map(worker?.children, 'value');
|
||||||
|
result.push(...gpus);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.length) {
|
||||||
|
return {
|
||||||
|
gpu_selector: {
|
||||||
|
gpu_ids: result
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
};
|
||||||
|
|
||||||
const handleOk = (formdata: FormData) => {
|
const handleOk = (formdata: FormData) => {
|
||||||
let data = _.cloneDeep(formdata);
|
let data = _.cloneDeep(formdata);
|
||||||
if (data.categories) {
|
if (data.categories) {
|
||||||
@@ -477,8 +530,10 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
|
|||||||
} else {
|
} else {
|
||||||
data.categories = [];
|
data.categories = [];
|
||||||
}
|
}
|
||||||
|
const gpuSelector = generateGPUIds(data);
|
||||||
onOk({
|
onOk({
|
||||||
..._.omit(data, ['scheduleType'])
|
..._.omit(data, ['scheduleType']),
|
||||||
|
...gpuSelector
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -75,18 +75,59 @@ const UpdateModal: React.FC<AddModalProps> = (props) => {
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const localPathCache = useRef<string>('');
|
const localPathCache = useRef<string>('');
|
||||||
|
|
||||||
const getGPUList = async () => {
|
const generateCascaderOptions = (list: GPUListItem[]) => {
|
||||||
const data = await queryGPUList();
|
const workerFields = ['worker_name', 'worker_id', 'worker_ip'];
|
||||||
const list = _.map(data.items, (item: GPUListItem) => {
|
|
||||||
|
const workers = _.groupBy(list, 'worker_name');
|
||||||
|
|
||||||
|
const workerList = _.map(workers, (value: GPUListItem[]) => {
|
||||||
return {
|
return {
|
||||||
...item,
|
label: `${value[0].worker_name}`,
|
||||||
title: '',
|
value: value[0].worker_name,
|
||||||
label: ` ${item.name}(${item.worker_name})[
|
parent: true,
|
||||||
${intl.formatMessage({ id: 'resources.table.index' })}:${item.index}]`,
|
..._.pick(value[0], workerFields),
|
||||||
value: item.id
|
children: _.map(value, (item: GPUListItem) => {
|
||||||
|
return {
|
||||||
|
label: `[
|
||||||
|
${intl.formatMessage({ id: 'resources.table.index' })}:${item.index}] ${item.name}`,
|
||||||
|
value: item.id,
|
||||||
|
..._.omit(item, workerFields)
|
||||||
|
};
|
||||||
|
})
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
setGpuOptions(list);
|
|
||||||
|
return workerList;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getGPUList = async () => {
|
||||||
|
const data = await queryGPUList();
|
||||||
|
const gpuList = generateCascaderOptions(data.items);
|
||||||
|
setGpuOptions(gpuList);
|
||||||
|
};
|
||||||
|
|
||||||
|
const generateGPUSelector = (data: any) => {
|
||||||
|
const gpu_ids = _.get(data, 'gpu_selector.gpu_ids', []);
|
||||||
|
if (gpu_ids.length === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const dataList = _.reduce(
|
||||||
|
gpuOptions,
|
||||||
|
(list: string[], item: any) => {
|
||||||
|
const gpuIds = _.filter(
|
||||||
|
gpu_ids,
|
||||||
|
(id: string) => id.indexOf(item.worker_name) > -1
|
||||||
|
);
|
||||||
|
if (gpuIds.length && gpuIds.length === item.children.length) {
|
||||||
|
list.push(item.worker_name);
|
||||||
|
} else if (gpuIds.length) {
|
||||||
|
list.push(item.worker_name, ...gpuIds);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
return dataList;
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -96,6 +137,10 @@ const UpdateModal: React.FC<AddModalProps> = (props) => {
|
|||||||
props.data
|
props.data
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const gpu_ids = generateGPUSelector(props.data);
|
||||||
|
|
||||||
|
console.log('gpu_ids+++++++++', gpu_ids);
|
||||||
|
|
||||||
const formData = {
|
const formData = {
|
||||||
...result.values,
|
...result.values,
|
||||||
..._.omit(props.data, result.omits),
|
..._.omit(props.data, result.omits),
|
||||||
@@ -104,7 +149,7 @@ const UpdateModal: React.FC<AddModalProps> = (props) => {
|
|||||||
: null,
|
: null,
|
||||||
scheduleType: props.data?.gpu_selector ? 'manual' : 'auto',
|
scheduleType: props.data?.gpu_selector ? 'manual' : 'auto',
|
||||||
gpu_selector: props.data?.gpu_selector || {
|
gpu_selector: props.data?.gpu_selector || {
|
||||||
gpu_ids: []
|
gpu_ids: gpu_ids
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
form.setFieldsValue(formData);
|
form.setFieldsValue(formData);
|
||||||
|
|||||||
@@ -13,8 +13,8 @@
|
|||||||
|
|
||||||
.info {
|
.info {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
flex-direction: column;
|
||||||
flex-wrap: wrap;
|
align-items: flex-start;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
color: var(--ant-color-text-tertiary);
|
color: var(--ant-color-text-tertiary);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user