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

[Search][Index Management] Removing Model deployment from Kibana #198409

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ import React from 'react';
import { EuiLink } from '@elastic/eui';
import { useEffect, useMemo, useState } from 'react';
import { i18n } from '@kbn/i18n';
import { ModelIdMapEntry } from '../../../../components/mappings_editor/components/document_fields/fields';
import { isSemanticTextField } from '../../../../components/mappings_editor/lib/utils';
import { deNormalize } from '../../../../components/mappings_editor/lib';
import { useMLModelNotificationToasts } from '../../../../../hooks/use_ml_model_status_toasts';
import { useMappingsState } from '../../../../components/mappings_editor/mappings_state_context';
import { useAppContext } from '../../../../app_context';

Expand All @@ -55,15 +53,11 @@ export function TrainedModelsDeploymentModal({
}: TrainedModelsDeploymentModalProps) {
const modalTitleId = useGeneratedHtmlId();
const { fields, inferenceToModelIdMap } = useMappingsState();
const {
plugins: { ml },
url,
} = useAppContext();
const { url } = useAppContext();
const [isModalVisible, setIsModalVisible] = useState<boolean>(false);
const closeModal = () => setIsModalVisible(false);
const [mlManagementPageUrl, setMlManagementPageUrl] = useState<string>('');
const [allowForceSaveMappings, setAllowForceSaveMappings] = useState<boolean>(false);
const { showErrorToasts, showSuccessfullyDeployedToast } = useMLModelNotificationToasts();

useEffect(() => {
const mlLocator = url?.locators.get(ML_APP_LOCATOR);
Expand All @@ -86,25 +80,6 @@ export function TrainedModelsDeploymentModal({

const [pendingDeployments, setPendingDeployments] = useState<string[]>([]);

const startModelAllocation = async (entry: ModelIdMapEntry & { inferenceId: string }) => {
try {
await ml?.mlApi?.trainedModels.startModelAllocation(entry.trainedModelId, {
number_of_allocations: 1,
threads_per_allocation: 1,
priority: 'normal',
deployment_id: entry.inferenceId,
});
showSuccessfullyDeployedToast(entry.trainedModelId);
} catch (error) {
setErrorsInTrainedModelDeployment((previousState) => ({
...previousState,
[entry.inferenceId]: error.message,
}));
showErrorToasts(error);
setIsModalVisible(true);
}
};

useEffect(() => {
const models = inferenceIdsInPendingList.map((inferenceId) =>
inferenceToModelIdMap?.[inferenceId]
Expand All @@ -114,18 +89,6 @@ export function TrainedModelsDeploymentModal({
}
: undefined
); // filter out third-party models
for (const model of models) {
if (
model?.trainedModelId &&
model.isDeployable &&
!model.isDownloading &&
!model.isDeployed
) {
// Sometimes the model gets stuck in a ready to deploy state, so we need to trigger deployment manually
// This is currently the only way to surface a specific error message to the user
startModelAllocation(model);
}
}
const allPendingDeployments = models
.map((model) => {
return model?.trainedModelId && !model?.isDeployed ? model?.inferenceId : '';
Expand All @@ -135,7 +98,6 @@ export function TrainedModelsDeploymentModal({
(deployment, index) => allPendingDeployments.indexOf(deployment) === index
);
setPendingDeployments(uniqueDeployments);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [inferenceIdsInPendingList, inferenceToModelIdMap]);

const erroredDeployments = pendingDeployments.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ const getCustomInferenceIdMap = (
? {
trainedModelId: model.service_settings.model_id,
isDeployable: model.service === Service.elser || model.service === Service.elasticsearch,
isDeployed: modelStatsById[model.inference_id]?.state === 'started',
isDeployed: modelStatsById[model.service_settings.model_id]?.state === 'started',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct. We should be looking at the inference ID, because we don't care about the model in general, we care about the deployment of the model that is specific to the inference ID.

isDownloading: Boolean(downloadStates[model.service_settings.model_id]),
modelStats: modelStatsById[model.inference_id],
modelStats: modelStatsById[model.service_settings.model_id],
}
: {
trainedModelId: '',
Expand Down Expand Up @@ -104,7 +104,7 @@ export const useDetailsPageMappingsModelManagement = () => {
Record<string, TrainedModelStat['deployment_stats'] | undefined>
>((acc, { model_id: modelId, deployment_stats: stats }) => {
if (modelId && stats) {
acc[stats.deployment_id] = stats;
acc[modelId] = stats;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct. Semantic text models should be referenced by their deployment ID, not their model ID, because they only reference the model ID with the deployment ID that is identical to the inference endpoint name.

}
return acc;
}, {}) || {};
Expand Down