Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: merged resource limit is affected by remaining in the resource group. #2696

Merged
merged 1 commit into from
Sep 9, 2024
Merged
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
43 changes: 19 additions & 24 deletions react/src/hooks/useResourceLimitAndRemaining.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useSuspendedBackendaiClient } from '.';
import { Image } from '../components/ImageEnvironmentSelectFormItems';
import { AUTOMATIC_DEFAULT_SHMEM } from '../components/ResourceAllocationFormItems';
import { addNumberWithUnits, iSizeToSize } from '../helper';
import { useResourceSlots } from '../hooks/backendai';
import { ResourceSlotName, useResourceSlots } from '../hooks/backendai';
import { useSuspenseTanQuery } from './reactQueryAlias';
import _ from 'lodash';
import { useMemo } from 'react';
Expand Down Expand Up @@ -47,9 +47,7 @@ export interface MergedResourceLimits {
}

type ResourceLimits = {
cpu: string | 'Infinity' | 'NaN';
mem: string | 'Infinity' | 'NaN';
'cuda.device': string | 'Infinity' | 'NaN';
[key in ResourceSlotName]?: string | 'Infinity' | 'NaN';
};
type ResourceUsing = ResourceLimits;
type ResourceRemaining = ResourceLimits;
Expand Down Expand Up @@ -237,7 +235,7 @@ export const useResourceLimitAndRemaining = ({
: baiClient._config.maxCPUCoresPerContainer,
limitParser(checkPresetInfo?.keypair_limits.cpu),
limitParser(checkPresetInfo?.group_limits.cpu),
resourceGroupResourceSize?.cpu,
// resourceGroupResourceSize?.cpu,
]),
},
mem:
Expand Down Expand Up @@ -273,20 +271,10 @@ export const useResourceLimitAndRemaining = ({
'g',
)?.number,
// scaling group all mem (using + remaining), string type
resourceGroupResourceSize?.mem &&
iSizeToSize(resourceGroupResourceSize?.mem + '', 'g')?.number,
// resourceGroupResourceSize?.mem &&
// iSizeToSize(resourceGroupResourceSize?.mem + '', 'g')?.number,
]) + 'g',
},
// shmem:
// resourceSlots?.mem === undefined
// ? undefined
// : {
// min: _.max([
// _.find(currentImage?.resource_limits, (i) => i?.key === 'shmem')
// ?.min,
// '64m',
// ]),
// },
accelerators: _.reduce(
acceleratorSlots,
(result, value, key) => {
Expand All @@ -306,8 +294,12 @@ export const useResourceLimitAndRemaining = ({
),
max: _.min([
perContainerLimit || 8,
limitParser(
checkPresetInfo?.keypair_limits[key as ResourceSlotName],
),
limitParser(checkPresetInfo?.group_limits[key as ResourceSlotName]),
// scaling group all cpu (using + remaining), string type
resourceGroupResourceSize.accelerators[key],
// resourceGroupResourceSize.accelerators[key],
]),
};
return result;
Expand All @@ -321,12 +313,15 @@ export const useResourceLimitAndRemaining = ({
(result, value, key) => {
result[key] =
_.min([
// @ts-ignore
_.toNumber(checkPresetInfo?.keypair_remaining[key]),
// @ts-ignore
_.toNumber(checkPresetInfo?.group_remaining[key]),
// @ts-ignore
_.toNumber(checkPresetInfo?.scaling_group_remaining[key]),
_.toNumber(
checkPresetInfo?.keypair_remaining[key as ResourceSlotName],
),
_.toNumber(
checkPresetInfo?.group_remaining[key as ResourceSlotName],
),
_.toNumber(
checkPresetInfo?.scaling_group_remaining[key as ResourceSlotName],
),
]) ?? Number.MAX_SAFE_INTEGER;
return result;
},
Expand Down
Loading