Skip to content

Commit

Permalink
Switch back to using a numerical value
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewballantyne committed Nov 15, 2024
1 parent 31eb80d commit 5283004
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,11 @@ const ModelServingPlatform: React.FC = () => {
const emptyTemplates = templatesEnabled.length === 0;
const emptyModelServer = servingRuntimes.length === 0;

const {
platform: currentProjectServingPlatform,
hasMultiplePlatformOptions,
noPlatformsActive,
error: platformError,
} = getProjectModelServingPlatform(currentProject, servingPlatformStatuses);
const { platform: currentProjectServingPlatform, error: platformError } =
getProjectModelServingPlatform(currentProject, servingPlatformStatuses);

const shouldShowPlatformSelection =
(!!hasMultiplePlatformOptions || !!noPlatformsActive) && !currentProjectServingPlatform;
servingPlatformStatuses.platformEnabledCount !== 1 && !currentProjectServingPlatform;

const isProjectModelMesh = currentProjectServingPlatform === ServingRuntimePlatform.MULTI;

Expand Down Expand Up @@ -259,7 +255,7 @@ const ModelServingPlatform: React.FC = () => {
isEmpty={shouldShowPlatformSelection}
loadError={platformError || servingRuntimeError || templateError}
emptyState={
hasMultiplePlatformOptions ? (
servingPlatformStatuses.platformEnabledCount > 1 ? (
<Flex alignItems={{ default: 'alignItemsCenter' }} gap={{ default: 'gapLg' }}>
<FlexItem
flex={{ default: 'flex_1' }}
Expand Down Expand Up @@ -334,7 +330,7 @@ const ModelServingPlatform: React.FC = () => {
? 'Multi-model serving enabled'
: 'Single-model serving enabled'}
</Label>
{emptyModelServer && hasMultiplePlatformOptions && (
{emptyModelServer && servingPlatformStatuses.platformEnabledCount > 1 && (
<ModelServingPlatformSelectButton
namespace={currentProject.metadata.name}
servingPlatform={NamespaceApplicationCase.RESET_MODEL_SERVING_PLATFORM}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const getMockServingPlatformStatuses = ({
enabled: modelMeshEnabled,
installed: modelMeshInstalled,
},
platformEnabledCount: [kServeEnabled, nimEnabled, modelMeshEnabled].filter(Boolean).length,
});

describe('getProjectModelServingPlatform', () => {
Expand All @@ -91,45 +92,29 @@ describe('getProjectModelServingPlatform', () => {
mockProjectK8sResource({}),
getMockServingPlatformStatuses({ kServeEnabled: false, modelMeshEnabled: false }),
),
).toStrictEqual({
hasMultiplePlatformOptions: false,
noPlatformsActive: true,
});
).toStrictEqual({});
});
it('should return undefined if both KServe and ModelMesh are enabled, and project has no platform label', () => {
expect(
getProjectModelServingPlatform(
mockProjectK8sResource({}),
getMockServingPlatformStatuses({}),
),
).toStrictEqual({
hasMultiplePlatformOptions: true,
noPlatformsActive: false,
});
).toStrictEqual({});
});
it('should return Single Platform if has platform label set to false and KServe is installed', () => {
expect(
getProjectModelServingPlatform(
mockProjectK8sResource({ enableModelMesh: false }),
getMockServingPlatformStatuses({}),
),
).toStrictEqual({
platform: ServingRuntimePlatform.SINGLE,
hasMultiplePlatformOptions: true,
noPlatformsActive: false,
error: undefined,
});
).toStrictEqual({ platform: ServingRuntimePlatform.SINGLE, error: undefined });
expect(
getProjectModelServingPlatform(
mockProjectK8sResource({ enableModelMesh: false }),
getMockServingPlatformStatuses({ kServeEnabled: false }),
),
).toStrictEqual({
platform: ServingRuntimePlatform.SINGLE,
hasMultiplePlatformOptions: false,
noPlatformsActive: false,
error: undefined,
});
).toStrictEqual({ platform: ServingRuntimePlatform.SINGLE, error: undefined });
});
it('should give error if has platform label set to false and KServe is not installed', () => {
expect(
Expand All @@ -145,23 +130,13 @@ describe('getProjectModelServingPlatform', () => {
mockProjectK8sResource({ enableModelMesh: true }),
getMockServingPlatformStatuses({}),
),
).toStrictEqual({
platform: ServingRuntimePlatform.MULTI,
hasMultiplePlatformOptions: true,
noPlatformsActive: false,
error: undefined,
});
).toStrictEqual({ platform: ServingRuntimePlatform.MULTI, error: undefined });
expect(
getProjectModelServingPlatform(
mockProjectK8sResource({ enableModelMesh: true }),
getMockServingPlatformStatuses({ modelMeshEnabled: false }),
),
).toStrictEqual({
platform: ServingRuntimePlatform.MULTI,
hasMultiplePlatformOptions: false,
noPlatformsActive: false,
error: undefined,
});
).toStrictEqual({ platform: ServingRuntimePlatform.MULTI, error: undefined });
});
it('should give error if has platform label set to true and ModelMesh is not installed', () => {
expect(
Expand All @@ -177,23 +152,15 @@ describe('getProjectModelServingPlatform', () => {
mockProjectK8sResource({}),
getMockServingPlatformStatuses({ modelMeshEnabled: false }),
),
).toStrictEqual({
platform: ServingRuntimePlatform.SINGLE,
hasMultiplePlatformOptions: false,
noPlatformsActive: false,
});
).toStrictEqual({ platform: ServingRuntimePlatform.SINGLE });
});
it('should return Multi Platform if only ModelMesh is enabled, and project has no platform label', () => {
expect(
getProjectModelServingPlatform(
mockProjectK8sResource({}),
getMockServingPlatformStatuses({ kServeEnabled: false }),
),
).toStrictEqual({
platform: ServingRuntimePlatform.MULTI,
hasMultiplePlatformOptions: false,
noPlatformsActive: false,
});
).toStrictEqual({ platform: ServingRuntimePlatform.MULTI });
});
});

Expand Down
31 changes: 8 additions & 23 deletions frontend/src/pages/modelServing/screens/projects/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,61 +295,46 @@ export const useCreateInferenceServiceObject = (
export const getProjectModelServingPlatform = (
project: ProjectKind | null,
platformStatuses: ServingPlatformStatuses,
): {
platform?: ServingRuntimePlatform;
hasMultiplePlatformOptions?: boolean;
noPlatformsActive?: boolean;
error?: Error;
} => {
): { platform?: ServingRuntimePlatform; error?: Error } => {
const {
kServe: { enabled: kServeEnabled, installed: kServeInstalled },
kServeNIM: { enabled: nimEnabled, installed: nimInstalled },
kServeNIM: { enabled: nimEnabled },
modelMesh: { enabled: modelMeshEnabled, installed: modelMeshInstalled },
platformEnabledCount,
} = platformStatuses;

if (!project) {
// Likely temporary or a bad usage of the hook
return {};
}

const allProjectsEnabledState = [kServeEnabled, modelMeshEnabled, nimEnabled];
const hasMultiplePlatformOptions = allProjectsEnabledState.filter(Boolean).length >= 2;
const noPlatformsActive = allProjectsEnabledState.filter(Boolean).length === 0;

const data: ReturnType<typeof getProjectModelServingPlatform> = {
hasMultiplePlatformOptions,
noPlatformsActive,
};

if (project.metadata.labels?.[KnownLabels.MODEL_SERVING_PROJECT] === undefined) {
// Auto-select logic
if (hasMultiplePlatformOptions || noPlatformsActive) {
return data;
if (platformEnabledCount !== 1) {
return {};
}
if (modelMeshEnabled) {
return { ...data, platform: ServingRuntimePlatform.MULTI };
return { platform: ServingRuntimePlatform.MULTI };
}
if (kServeEnabled) {
return { ...data, platform: ServingRuntimePlatform.SINGLE };
return { platform: ServingRuntimePlatform.SINGLE };
}
if (nimEnabled) {
// TODO: this is weird, it relies on KServe today... so it's never "only installed"
return { ...data, platform: ServingRuntimePlatform.SINGLE };
return { platform: ServingRuntimePlatform.SINGLE };
}

// TODO: unreachable code unless adding a new platform? probably should throw an error
} else if (project.metadata.labels[KnownLabels.MODEL_SERVING_PROJECT] === 'true') {
// Model mesh logic
return {
...data,
platform: ServingRuntimePlatform.MULTI,
error: modelMeshInstalled ? undefined : new Error('Multi-model platform is not installed'),
};
}

// KServe logic
return {
...data,
platform: ServingRuntimePlatform.SINGLE,
error: kServeInstalled ? undefined : new Error('Single-model platform is not installed'),
};
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/modelServing/screens/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export type ServingPlatformStatuses = {
kServe: PlatformStatus;
kServeNIM: PlatformStatus;
modelMesh: PlatformStatus;
platformEnabledCount: number;
};

export type LabeledDataConnection = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const useServingPlatformStatuses = (): ServingPlatformStatuses => {
enabled: modelMeshEnabled,
installed: modelMeshInstalled,
},
platformEnabledCount: [kServeEnabled, isNIMAvailable, modelMeshEnabled].filter(Boolean).length,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ const ServeModelsSection: React.FC = () => {
const servingPlatformStatuses = useServingPlatformStatuses();
const {
modelMesh: { enabled: modelMeshEnabled },
platformEnabledCount,
} = servingPlatformStatuses;

const { currentProject } = React.useContext(ProjectDetailsContext);

const {
platform: currentProjectServingPlatform,
noPlatformsActive,
hasMultiplePlatformOptions,
} = getProjectModelServingPlatform(currentProject, servingPlatformStatuses);
const { platform: currentProjectServingPlatform } = getProjectModelServingPlatform(
currentProject,
servingPlatformStatuses,
);

if (hasMultiplePlatformOptions && !currentProjectServingPlatform) {
if (platformEnabledCount > 1 && !currentProjectServingPlatform) {
return <PlatformSelectSection />;
}

if (noPlatformsActive) {
if (platformEnabledCount === 1) {
return <NoProjectServingEnabledSection />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const DeployedModelsSection: React.FC<DeployedModelsSectionProps> = ({ isMultiPl
} = React.useContext(ProjectDetailsContext);

const servingPlatformStatuses = useServingPlatformStatuses();
const { hasMultiplePlatformOptions, error: platformError } = getProjectModelServingPlatform(
const { error: platformError } = getProjectModelServingPlatform(
currentProject,
servingPlatformStatuses,
);
Expand Down Expand Up @@ -129,7 +129,7 @@ const DeployedModelsSection: React.FC<DeployedModelsSectionProps> = ({ isMultiPl
headerInfo={
<Flex gap={{ default: 'gapSm' }}>
<Label>Multi-model serving enabled</Label>
{hasMultiplePlatformOptions && (
{servingPlatformStatuses.platformEnabledCount > 1 && (
<ModelServingPlatformSelectButton
namespace={currentProject.metadata.name}
servingPlatform={NamespaceApplicationCase.RESET_MODEL_SERVING_PLATFORM}
Expand Down Expand Up @@ -193,7 +193,7 @@ const DeployedModelsSection: React.FC<DeployedModelsSectionProps> = ({ isMultiPl
<Label>
{isMultiPlatform ? 'Multi-model serving enabled' : 'Single-model serving enabled'}
</Label>
{hasMultiplePlatformOptions && (
{servingPlatformStatuses.platformEnabledCount > 1 && (
<ModelServingPlatformSelectButton
namespace={currentProject.metadata.name}
servingPlatform={NamespaceApplicationCase.RESET_MODEL_SERVING_PLATFORM}
Expand Down

0 comments on commit 5283004

Please sign in to comment.