Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/pages/llmodels/components/deploy-builtin-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const AddModal: React.FC<AddModalProps> = (props) => {
setWarningStatus,
handleDoEvalute,
cancelEvaluate,
clearCacheFormValues,
submitAnyway,
handleOnValuesChange,
warningStatus
Expand Down Expand Up @@ -609,6 +610,7 @@ const AddModal: React.FC<AddModalProps> = (props) => {
onBackendChange={handleBackendChange}
onSourceChange={handleSourceChange}
onValuesChange={onValuesChange}
clearCacheFormValues={clearCacheFormValues}
></DataForm>
</>
</ColumnWrapper>
Expand Down
7 changes: 4 additions & 3 deletions src/pages/llmodels/components/deploy-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const AddModal: FC<AddModalProps> = (props) => {
cancelEvaluate,
unlockWarningStatus,
handleOnValuesChange: handleOnValuesChangeBefore,
clearCahceFormValues,
clearCacheFormValues,
warningStatus,
submitAnyway
} = useCheckCompatibility();
Expand Down Expand Up @@ -314,7 +314,7 @@ const AddModal: FC<AddModalProps> = (props) => {
}
console.log('handleOnSelectModel:', item, selectedModel);
setIsGGUF(item.isGGUF);
clearCahceFormValues();
clearCacheFormValues();
unlockWarningStatus();
setEvaluteState({
state: EvaluateProccess.model,
Expand Down Expand Up @@ -511,7 +511,7 @@ const AddModal: FC<AddModalProps> = (props) => {
handleOnOpen();
} else {
cancelEvaluate();
clearCahceFormValues();
clearCacheFormValues();
}
return () => {
setSelectedModel({});
Expand Down Expand Up @@ -645,6 +645,7 @@ const AddModal: FC<AddModalProps> = (props) => {
isGGUF={isGGUF}
onBackendChange={handleBackendChange}
onValuesChange={onValuesChange}
clearCacheFormValues={clearCacheFormValues}
></DataForm>
</>
</ColumnWrapper>
Expand Down
1 change: 1 addition & 0 deletions src/pages/llmodels/config/form-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface FormContextProps {
workerLabelOptions: CascaderOption[];
backendOptions: BackendOption[];
initialValues?: FormData; // for editing model
clearCacheFormValues?: () => void;
onValuesChange?: (changedValues: any, allValues: any) => void;
onBackendChange: (backend: string, option: any) => void;
}
Expand Down
8 changes: 1 addition & 7 deletions src/pages/llmodels/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,6 @@ export const ScheduleValueMap = {
SpecificGPUType: 'specific_gpu_type'
};

export const gpusCountTypeMap = {
Auto: 'auto',
Custom: 'custom'
};

export const scheduleList = [
{
label: 'models.form.scheduletype.auto',
Expand Down Expand Up @@ -347,10 +342,9 @@ export const excludeFields = [
'backend_version',
'ollama_library_model_name',
'scheduleType',
'gpusCountType',
'placement_strategy',
'backend',
'gpu_selector',
'gpu_selector.gpu_ids',
'run_command',
'image_name',
'extended_kv_cache.enabled'
Expand Down
1 change: 0 additions & 1 deletion src/pages/llmodels/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export interface FormData {
cpu_offloading?: boolean;
worker_selector?: object;
scheduleType?: string;
gpusCountType?: string;
name: string;
replicas: number;
description: string;
Expand Down
14 changes: 5 additions & 9 deletions src/pages/llmodels/config/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import _ from 'lodash';
import { gpusCountTypeMap } from '.';
import { backendOptionsMap } from '../config/backend-parameters';
import { FormData } from './types';

Expand Down Expand Up @@ -60,17 +59,14 @@ export const generateGPUIds = (data: FormData) => {
},
[]
);
if (gpusCountTypeMap.Auto === data.gpusCountType) {
return {
gpu_selector: {
gpu_ids: result || []
}
};
}

return {
gpu_selector: {
gpu_ids: result || [],
gpus_per_replica: data.gpu_selector?.gpus_per_replica || null
gpus_per_replica:
data.gpu_selector?.gpus_per_replica === -1
? null
: data.gpu_selector?.gpus_per_replica
}
};
};
17 changes: 10 additions & 7 deletions src/pages/llmodels/forms/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import styled from 'styled-components';
import {
deployFormKeyMap,
excludeFields,
gpusCountTypeMap,
modelSourceMap,
ScheduleValueMap
} from '../config';
Expand Down Expand Up @@ -65,6 +64,7 @@ interface DataFormProps {
sourceList?: Global.BaseOption<string>[];
clusterList: Global.BaseOption<number>[];
fields?: string[];
clearCacheFormValues?: () => void;
onValuesChange?: (changedValues: any, allValues: any) => void;
onSourceChange?: (value: string) => void;
onOk: (values: FormData) => void;
Expand All @@ -82,6 +82,7 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
sourceList,
clusterList = [],
fields = ['source'],
clearCacheFormValues,
onBackendChange,
onSourceChange,
onValuesChange,
Expand Down Expand Up @@ -154,9 +155,9 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {

if (backend === backendOptionsMap.voxBox && gpuids.length > 0) {
return {
gpusCountType: gpusCountTypeMap.Auto,
gpu_selector: {
gpu_ids: [gpuids[0]]
gpu_ids: [gpuids[0]],
gpus_per_replica: -1
}
};
}
Expand Down Expand Up @@ -217,7 +218,7 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
data.categories = data.categories ? [data.categories] : [];
const gpuSelector = generateGPUIds(data);
const allValues = {
..._.omit(data, ['scheduleType', 'gpusCountType']),
..._.omit(data, ['scheduleType']),
...gpuSelector
};

Expand All @@ -235,7 +236,9 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
const getFieldPaths = (obj: Record<string, any>, prefix = ''): string => {
const result = Object.entries(obj).flatMap(([key, value]) => {
const path = prefix ? `${prefix}.${key}` : key;
return typeof value === 'object' && value !== null
return typeof value === 'object' &&
value !== null &&
!Array.isArray(value)
? getFieldPaths(value, path)
: [path];
});
Expand Down Expand Up @@ -328,6 +331,7 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
backendOptions: backendOptions,
workerLabelOptions: workerLabelOptions,
initialValues: initialValues,
clearCacheFormValues: clearCacheFormValues,
onValuesChange: onValuesChange,
onBackendChange: handleBackendChange
}}
Expand All @@ -344,7 +348,7 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
name="deployModel"
form={form}
onFinish={handleOk}
preserve={false}
preserve={true}
clearOnDestroy={true}
onValuesChange={handleOnValuesChange}
onFinishFailed={handleOnFinishFailed}
Expand All @@ -355,7 +359,6 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
placement_strategy: 'spread',
cpu_offloading: true,
scheduleType: ScheduleValueMap.Auto,
gpusCountType: gpusCountTypeMap.Auto,
categories: null,
restart_on_error: true,
distributed_inference_across_workers: true,
Expand Down
7 changes: 4 additions & 3 deletions src/pages/llmodels/forms/kv-cache.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ const KVCacheForm = () => {
const backend = Form.useWatch('backend', form);

const handleOnChange = async (e: any) => {
const extendedKVCache = form.getFieldValue('extended_kv_cache');
if (e.target.checked) {
form.setFieldsValue({
extended_kv_cache: {
enabled: true,
chunk_size: 256,
max_local_cpu_size: 10,
remote_url: ''
chunk_size: extendedKVCache?.chunk_size || 256,
max_local_cpu_size: extendedKVCache?.max_local_cpu_size || 10,
remote_url: extendedKVCache?.remote_url || ''
}
});
}
Expand Down
95 changes: 48 additions & 47 deletions src/pages/llmodels/forms/schedule-type.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import LabelSelector from '@/components/label-selector';
import { LabelSelectorContext } from '@/components/label-selector/context';
import SealInputNumber from '@/components/seal-form/input-number';
import SealCascader from '@/components/seal-form/seal-cascader';
import SealSelect from '@/components/seal-form/seal-select';
import TooltipList from '@/components/tooltip-list';
import { PageAction } from '@/config';
import useAppUtils from '@/hooks/use-app-utils';
import { useIntl } from '@umijs/max';
import { Form } from 'antd';
import { Form, InputNumber } from 'antd';
import _ from 'lodash';
import React from 'react';
import styled from 'styled-components';
import GPUCard from '../components/gpu-card';
import {
gpusCountTypeMap,
placementStrategyOptions,
scheduleList,
ScheduleValueMap
Expand All @@ -21,6 +19,10 @@ import { backendOptionsMap } from '../config/backend-parameters';
import { useFormContext } from '../config/form-context';
import { FormData } from '../config/types';

const InputWrapper = styled.div`
padding: 8px 4px;
`;

const placementStrategyTips = [
{
title: 'Spread',
Expand Down Expand Up @@ -73,31 +75,39 @@ const ScheduleTypeForm: React.FC = () => {
action,
gpuOptions,
workerLabelOptions,
clearCacheFormValues,
initialValues
} = useFormContext();
const { getRuleMessage } = useAppUtils();
const form = Form.useFormInstance();
const scheduleType = Form.useWatch('scheduleType', form);
const gpusCountType = Form.useWatch('gpusCountType', form);
const wokerSelector = Form.useWatch('worker_selector', form);
const workerSelector = Form.useWatch('worker_selector', form);
const GPUsPerReplicas = Form.useWatch(
['gpu_selector', 'gpus_per_replica'],
form
);

const handleScheduleTypeChange = (value: string) => {
if (value === ScheduleValueMap.Auto) {
onValuesChange?.({}, form.getFieldsValue());
return;
}
if (value === ScheduleValueMap.Manual) {
form.setFieldValue(['gpu_selector', 'gpus_per_replica'], -1);
}
};

const handleGpusCountTypeChange = (val: string) => {
if (val === gpusCountTypeMap.Custom) {
form.setFieldValue(['gpu_selector', 'gpus_per_replica'], 1);
}
const handleGpusPerReplicasChange = (val: string | number | null) => {
form.setFieldValue(['gpu_selector', 'gpus_per_replica'], val);

onValuesChange?.({}, form.getFieldsValue());
};

const handleGpuSelectorChange = (value: any[]) => {
if (value.length > 0) {
onValuesChange?.({}, form.getFieldsValue());
} else {
clearCacheFormValues?.();
}
};

Expand Down Expand Up @@ -221,50 +231,41 @@ const ScheduleTypeForm: React.FC = () => {
onChange={handleGpuSelectorChange}
></SealCascader>
</Form.Item>
<Form.Item
name="gpusCountType"
hidden={
action === PageAction.EDIT &&
!!initialValues?.gpu_selector?.gpus_per_replica
}
>
<Form.Item name={['gpu_selector', 'gpus_per_replica']}>
<SealSelect
onChange={handleGpusCountTypeChange}
label={intl.formatMessage({
id: 'models.form.gpusAllocationType'
id: 'models.form.gpusperreplica'
})}
description={
<TooltipList list={gpuAllocateTypeTips}></TooltipList>
}
options={[
{
label: intl.formatMessage({
id: 'models.form.gpusAllocationType.auto'
}),
value: gpusCountTypeMap.Auto
label: intl.formatMessage({ id: 'common.options.auto' }),
value: -1
},
{
label: intl.formatMessage({
id: 'models.form.gpusAllocationType.custom'
}),
value: gpusCountTypeMap.Custom
}
{ label: '1', value: 1 },
{ label: '2', value: 2 },
{ label: '4', value: 4 },
{ label: '8', value: 8 }
]}
></SealSelect>
popupRender={(originNode) => (
<div>
{originNode}
<InputWrapper>
<InputNumber
step={1}
style={{ width: '100%' }}
defaultValue={
GPUsPerReplicas === null ? -1 : GPUsPerReplicas
}
value={GPUsPerReplicas === -1 ? null : GPUsPerReplicas}
onChange={handleGpusPerReplicasChange}
onStep={handleOnStepReplicaStep}
/>
</InputWrapper>
</div>
)}
onChange={handleOnStepReplica}
/>
</Form.Item>
{gpusCountType === gpusCountTypeMap.Custom && (
<Form.Item name={['gpu_selector', 'gpus_per_replica']}>
<SealInputNumber
label={intl.formatMessage({
id: 'models.form.gpusperreplica'
})}
min={1}
step={1}
onChange={handleOnStepReplica}
onStep={handleOnStepReplicaStep}
/>
</Form.Item>
)}
</>
)}
{scheduleType === ScheduleValueMap.Auto && (
Expand Down Expand Up @@ -317,7 +318,7 @@ const ScheduleTypeForm: React.FC = () => {
label={intl.formatMessage({
id: 'resources.form.workerSelector'
})}
labels={wokerSelector}
labels={workerSelector}
onChange={handleWorkerLabelsChange}
onBlur={handleSelectorOnBlur}
onDelete={handleDeleteWorkerSelector}
Expand Down
Loading
Loading