fix: gpu selector issues

This commit is contained in:
jialin
2025-10-28 11:17:29 +08:00
parent 697f1f9c25
commit a86bed294e
7 changed files with 52 additions and 30 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ const BackendFields: React.FC = () => {
const {
isGGUF,
formKey,
pageAction: action,
action,
source,
gpuOptions,
onValuesChange,
+3 -2
View File
@@ -55,7 +55,7 @@ const SegmentedHeader = styled.div<{ $top?: number }>`
`;
interface DataFormProps {
initialValues?: any;
initialValues?: FormData;
ref?: any;
source: SourceType;
action: PageActionType;
@@ -323,10 +323,11 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
isGGUF: isGGUF,
formKey: formKey,
source: props.source,
pageAction: action,
action: action,
gpuOptions: gpuOptions,
backendOptions: backendOptions,
workerLabelOptions: workerLabelOptions,
initialValues: initialValues,
onValuesChange: onValuesChange,
onBackendChange: handleBackendChange
}}
+5 -5
View File
@@ -13,7 +13,7 @@ const HuggingFaceForm: React.FC = () => {
const formInstance = Form.useFormInstance();
const formCtx = useFormContext();
const { getRuleMessage } = useAppUtils();
const { formKey, pageAction, isGGUF, onValuesChange } = formCtx;
const { formKey, action, isGGUF, onValuesChange } = formCtx;
const source = Form.useWatch('source');
if (
@@ -47,7 +47,7 @@ const HuggingFaceForm: React.FC = () => {
<SealInput.Input
label={intl.formatMessage({ id: 'models.form.repoid' })}
required
disabled={pageAction === PageAction.CREATE}
disabled={action === PageAction.CREATE}
onBlur={handleOnBlur}
></SealInput.Input>
</Form.Item>
@@ -58,7 +58,7 @@ const HuggingFaceForm: React.FC = () => {
>
<SealInput.Input
label={intl.formatMessage({ id: 'models.form.filename' })}
disabled={pageAction === PageAction.CREATE}
disabled={action === PageAction.CREATE}
></SealInput.Input>
</Form.Item>
)}
@@ -78,7 +78,7 @@ const HuggingFaceForm: React.FC = () => {
<SealInput.Input
required
label={intl.formatMessage({ id: 'models.form.repoid' })}
disabled={pageAction === PageAction.CREATE}
disabled={action === PageAction.CREATE}
onBlur={handleOnBlur}
></SealInput.Input>
</Form.Item>
@@ -89,7 +89,7 @@ const HuggingFaceForm: React.FC = () => {
>
<SealInput.Input
label={intl.formatMessage({ id: 'models.form.filename' })}
disabled={pageAction === PageAction.CREATE}
disabled={action === PageAction.CREATE}
></SealInput.Input>
</Form.Item>
)}
+29 -14
View File
@@ -4,6 +4,7 @@ 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';
@@ -67,7 +68,13 @@ const gpuAllocateTypeTips = [
const ScheduleTypeForm: React.FC = () => {
const intl = useIntl();
const { onValuesChange, gpuOptions, workerLabelOptions } = useFormContext();
const {
onValuesChange,
action,
gpuOptions,
workerLabelOptions,
initialValues
} = useFormContext();
const { getRuleMessage } = useAppUtils();
const form = Form.useFormInstance();
const scheduleType = Form.useWatch('scheduleType', form);
@@ -88,39 +95,41 @@ const ScheduleTypeForm: React.FC = () => {
onValuesChange?.({}, form.getFieldsValue());
};
const handleBeforeGpuSelectorChange = (gpuIds: any[]) => {};
const handleGpuSelectorChange = (value: any[]) => {
handleBeforeGpuSelectorChange(value);
onValuesChange?.({}, form.getFieldsValue());
if (value.length > 0) {
onValuesChange?.({}, form.getFieldsValue());
}
};
const handleOnStepReplicaStep = (
value: number,
info: { offset: number; type: 'up' | 'down' }
value: number | string | null,
info: { offset: number | string | null; type: 'up' | 'down' }
) => {
let newValue = value;
const isPowerOfTwo = (n: number) => (n & (n - 1)) === 0 && n !== 0; // check power of two
if (!isPowerOfTwo(value)) {
if (!isPowerOfTwo(value as number)) {
if (info.type === 'up') {
newValue = Math.pow(2, Math.ceil(Math.log2(value)));
newValue = Math.pow(2, Math.ceil(Math.log2(value as number)));
} else {
newValue = Math.pow(2, Math.floor(Math.log2(value)));
newValue = Math.pow(2, Math.floor(Math.log2(value as number)));
}
}
form.setFieldValue(['gpu_selector', 'gpus_per_replica'], newValue);
onValuesChange?.({}, form.getFieldsValue());
};
const handleOnStepReplica = (value: number | null) => {
const handleOnStepReplica = async (value: number | string | null) => {
if (value === null) {
await new Promise((resolve) => {
setTimeout(resolve, 200);
});
form.setFieldValue(['gpu_selector', 'gpus_per_replica'], 1);
return;
}
const isPowerOfTwo = (n: number) => (n & (n - 1)) === 0 && n !== 0; // check power of two
if (!isPowerOfTwo(value)) {
const newValue = Math.pow(2, Math.round(Math.log2(value)));
if (!isPowerOfTwo(value as number)) {
const newValue = Math.pow(2, Math.round(Math.log2(value as number)));
form.setFieldValue(['gpu_selector', 'gpus_per_replica'], newValue);
onValuesChange?.({}, form.getFieldsValue());
}
@@ -212,7 +221,13 @@ const ScheduleTypeForm: React.FC = () => {
onChange={handleGpuSelectorChange}
></SealCascader>
</Form.Item>
<Form.Item name="gpusCountType">
<Form.Item
name="gpusCountType"
hidden={
action === PageAction.EDIT &&
!!initialValues?.gpu_selector?.gpus_per_replica
}
>
<SealSelect
onChange={handleGpusCountTypeChange}
label={intl.formatMessage({