import LabelSelector from '@/components/label-selector'; import ListInput from '@/components/list-input'; import SealSelect from '@/components/seal-form/seal-select'; import { PageAction } from '@/config'; import { PageActionType } from '@/config/types'; import { InfoCircleOutlined, RightOutlined } from '@ant-design/icons'; import { useIntl } from '@umijs/max'; import { Checkbox, Collapse, Form, FormInstance, Select, Tooltip, Typography } from 'antd'; import _ from 'lodash'; import React, { useCallback, useMemo } from 'react'; import { backendOptionsMap, placementStrategyOptions } from '../config'; import llamaConfig from '../config/llama-config'; import { FormData } from '../config/types'; import vllmConfig from '../config/vllm-config'; import dataformStyles from '../style/data-form.less'; import GPUCard from './gpu-card'; interface AdvanceConfigProps { isGGUF: boolean; form: FormInstance; gpuOptions: Array; action: PageActionType; } const AdvanceConfig: React.FC = (props) => { const { form, gpuOptions, isGGUF, action } = props; const intl = useIntl(); const wokerSelector = Form.useWatch('worker_selector', form); const scheduleType = Form.useWatch('scheduleType', form); const backend = Form.useWatch('backend', form); const [params, setParams] = React.useState([]); const placementStrategyTips = [ { title: 'Spread', tips: intl.formatMessage({ id: 'resources.form.spread.tips' }) }, { title: 'Binpack', tips: intl.formatMessage({ id: 'resources.form.binpack.tips' }) } ]; const scheduleTypeTips = [ { title: intl.formatMessage({ id: 'models.form.scheduletype.auto' }), tips: intl.formatMessage({ id: 'models.form.scheduletype.auto.tips' }) }, { title: intl.formatMessage({ id: 'models.form.scheduletype.manual' }), tips: intl.formatMessage({ id: 'models.form.scheduletype.manual.tips' }) } ]; const paramsConfig = useMemo(() => { return backend === backendOptionsMap.llamaBox ? llamaConfig : vllmConfig; }, [backend]); const renderSelectTips = (list: Array<{ title: string; tips: string }>) => { return (
{list.map((item, index) => { return (
{item.title}: {item.tips}
); })}
); }; const handleWorkerLabelsChange = useCallback( (labels: Record) => { form.setFieldValue('worker_selector', labels); }, [] ); const handleBackendParametersChange = useCallback((list: string[]) => { form.setFieldValue('backend_parameters', list); }, []); const collapseItems = useMemo(() => { const children = ( <> {scheduleType === 'auto' && ( <> name="placement_strategy"> name="worker_selector" rules={[ ({ getFieldValue }) => ({ validator(rule, value) { if ( getFieldValue('scheduleType') === 'auto' && _.keys(value).length > 0 ) { if (_.some(_.keys(value), (k: string) => !value[k])) { return Promise.reject( intl.formatMessage( { id: 'common.validate.value' }, { name: intl.formatMessage({ id: 'models.form.selector' }) } ) ); } } return Promise.resolve(); } }) ]} > {intl.formatMessage({ id: 'resources.form.workerSelector.description' })} } > )} name="backend_parameters"> {scheduleType === 'manual' && ( name="gpu_selector" rules={[ { required: true, message: intl.formatMessage( { id: 'common.form.rule.select' }, { name: 'gpu_selector' } ) } ]} > {gpuOptions.map((item) => ( ))} )} {isGGUF && (
name="cpu_offloading" valuePropName="checked" style={{ padding: '0 10px', marginBottom: 0 }} noStyle > {intl.formatMessage({ id: 'resources.form.enablePartialOffload' })}
)} {scheduleType === 'auto' && isGGUF && (
name="distributed_inference_across_workers" valuePropName="checked" style={{ padding: '0 10px', marginBottom: 0 }} noStyle > {intl.formatMessage({ id: 'resources.form.enableDistributedInferenceAcrossWorkers' })}
)} ); return [ { key: '1', label: ( {intl.formatMessage({ id: 'resources.form.advanced' })} ), children } ]; }, [ form, intl, gpuOptions, paramsConfig, scheduleType, wokerSelector, isGGUF ]); return ( ( )} items={collapseItems} > ); }; export default React.memo(AdvanceConfig);