-
Notifications
You must be signed in to change notification settings - Fork 833
feat(inspect): Add train model dialog, job logs and models dataset #3053
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
Merged
MarkRedeman
merged 10 commits into
open-edge-platform:feature/geti-inspect
from
MarkRedeman:mark/geti-inspect/demo
Oct 27, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f74fee8
fix(job_service): Record end_time on terminal job statuses
MarkRedeman 2ff025a
feat(jobs): Show training logs using SSE
MarkRedeman cee0c21
feat(inspect): Use URLSearchParams to decide the tab that's opened
MarkRedeman 9363e06
perf(inspect/dataset-item): Use thumbnail for dataset item media URL
MarkRedeman 52b0c21
feat(train-model): Add Train model UI and dataset training trigger
MarkRedeman 1db5726
feat(inference): Auto-trigger inference on model select
MarkRedeman 2054471
feat(models): Add Models view and refactor training UI
MarkRedeman 1edf7e5
fix(inspect): Improve SSE parse logs and model duration handling
MarkRedeman a6fc18f
refactor(job_service): Use set membership for status checks
MarkRedeman ab1e8c1
Apply code review feedback
MarkRedeman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,13 @@ | ||
| import { Suspense, useEffect, useRef, useState } from 'react'; | ||
| import { ComponentProps, Suspense, useEffect, useRef } from 'react'; | ||
|
|
||
| import { $api } from '@geti-inspect/api'; | ||
| import { SchemaJob as Job } from '@geti-inspect/api/spec'; | ||
| import { SchemaJob as Job, SchemaJob, SchemaJobStatus } from '@geti-inspect/api/spec'; | ||
| import { useProjectIdentifier } from '@geti-inspect/hooks'; | ||
| import { | ||
| Button, | ||
| Content, | ||
| Divider, | ||
| Flex, | ||
| Heading, | ||
| InlineAlert, | ||
| IntelBrandedLoading, | ||
| Item, | ||
| Picker, | ||
| ProgressBar, | ||
| Text, | ||
| } from '@geti/ui'; | ||
| import { Content, Flex, Heading, InlineAlert, IntelBrandedLoading, ProgressBar, Text } from '@geti/ui'; | ||
| import { useQueryClient } from '@tanstack/react-query'; | ||
| import { differenceBy, isEqual } from 'lodash-es'; | ||
| import { isEqual } from 'lodash-es'; | ||
|
|
||
| import { ShowJobLogs } from '../jobs/show-job-logs.component'; | ||
| import { REQUIRED_NUMBER_OF_NORMAL_IMAGES_TO_TRIGGER_TRAINING } from './utils'; | ||
|
|
||
| interface NotEnoughNormalImagesToTrainProps { | ||
|
|
@@ -39,142 +28,69 @@ const NotEnoughNormalImagesToTrain = ({ mediaItemsCount }: NotEnoughNormalImages | |
| ); | ||
| }; | ||
|
|
||
| const useAvailableModels = () => { | ||
| const { data } = $api.useSuspenseQuery('get', '/api/trainable-models', undefined, { | ||
| staleTime: Infinity, | ||
| gcTime: Infinity, | ||
| }); | ||
|
|
||
| return data.trainable_models.map((model) => ({ id: model, name: model })); | ||
| }; | ||
|
|
||
| const ReadyToTrain = () => { | ||
| const startTrainingMutation = $api.useMutation('post', '/api/jobs:train'); | ||
|
|
||
| const availableModels = useAvailableModels(); | ||
| const { projectId } = useProjectIdentifier(); | ||
| const [selectedModel, setSelectedModel] = useState<string>(availableModels[0].id); | ||
|
|
||
| const startTraining = () => { | ||
| startTrainingMutation.mutate({ | ||
| body: { project_id: projectId, model_name: selectedModel }, | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <InlineAlert variant='positive'> | ||
| <Heading>Ready to train</Heading> | ||
| <Content> | ||
| <Flex direction={'column'} gap={'size-200'}> | ||
| <Text>You have enough normal images to train a model.</Text> | ||
|
|
||
| <Flex direction={'row'} alignItems={'end'} width={'100%'} gap={'size-200'} wrap={'wrap'}> | ||
| <Picker | ||
| label={'Model'} | ||
| selectedKey={selectedModel} | ||
| onSelectionChange={(key) => key !== null && setSelectedModel(String(key))} | ||
| > | ||
| {availableModels.map((model) => ( | ||
| <Item key={model.id}>{model.name}</Item> | ||
| ))} | ||
| </Picker> | ||
|
|
||
| <Button isPending={startTrainingMutation.isPending} onPress={startTraining}> | ||
| Start training | ||
| </Button> | ||
| </Flex> | ||
| </Flex> | ||
| </Content> | ||
| </InlineAlert> | ||
| ); | ||
| }; | ||
|
|
||
| interface TrainingInProgressProps { | ||
| job: Job; | ||
| } | ||
|
|
||
| const TrainingInProgress = ({ job }: TrainingInProgressProps) => { | ||
| if (job === undefined) { | ||
| return null; | ||
| } | ||
| const statusToVariant: Record<SchemaJobStatus, ComponentProps<typeof InlineAlert>['variant']> = { | ||
| pending: 'info', | ||
| running: 'info', | ||
| completed: 'positive', | ||
| canceled: 'negative', | ||
| failed: 'negative', | ||
| }; | ||
|
|
||
| function getHeading(job: SchemaJob) { | ||
| if (job.status === 'pending') { | ||
| const heading = `Training will start soon - ${job.payload.model_name}`; | ||
|
|
||
| return ( | ||
| <InlineAlert variant='info'> | ||
| <Heading>{heading}</Heading> | ||
| <Content> | ||
| <Flex direction={'column'} gap={'size-100'}> | ||
| <Text>{job.message}</Text> | ||
| <ProgressBar aria-label='Training progress' isIndeterminate /> | ||
| </Flex> | ||
| </Content> | ||
| </InlineAlert> | ||
| ); | ||
| return `Training will start soon - ${job.payload.model_name}`; | ||
| } | ||
|
|
||
| if (job.status === 'running') { | ||
| const heading = `Training in progress - ${job.payload.model_name}`; | ||
|
|
||
| return ( | ||
| <InlineAlert variant='info'> | ||
| <Heading>{heading}</Heading> | ||
| <Content> | ||
| <Flex direction={'column'} gap={'size-100'}> | ||
| <Text>{job.message}</Text> | ||
| <ProgressBar value={job.progress} aria-label='Training progress' /> | ||
| </Flex> | ||
| </Content> | ||
| </InlineAlert> | ||
| ); | ||
| return `Training in progress - ${job.payload.model_name}`; | ||
| } | ||
|
|
||
| if (job.status === 'failed') { | ||
| const heading = `Training failed - ${job.payload.model_name}`; | ||
|
|
||
| return ( | ||
| <InlineAlert variant='negative'> | ||
| <Heading>{heading}</Heading> | ||
| <Content> | ||
| <Text>{job.message}</Text> | ||
| </Content> | ||
| </InlineAlert> | ||
| ); | ||
| return `Training failed - ${job.payload.model_name}`; | ||
| } | ||
|
|
||
| if (job.status === 'canceled') { | ||
| const heading = `Training canceled - ${job.payload.model_name}`; | ||
|
|
||
| return ( | ||
| <InlineAlert variant='negative'> | ||
| <Heading>{heading}</Heading> | ||
| <Content> | ||
| <Text>{job.message}</Text> | ||
| </Content> | ||
| </InlineAlert> | ||
| ); | ||
| return `Training canceled - ${job.payload.model_name}`; | ||
| } | ||
|
|
||
| if (job.status === 'completed') { | ||
| const heading = `Training completed - ${job.payload.model_name}`; | ||
| return `Training completed - ${job.payload.model_name}`; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <InlineAlert variant='positive'> | ||
| <Heading>{heading}</Heading> | ||
| <Content> | ||
| <Text>{job.message}</Text> | ||
| </Content> | ||
| </InlineAlert> | ||
| ); | ||
| const TrainingInProgress = ({ job }: TrainingInProgressProps) => { | ||
| if (job === undefined) { | ||
| return null; | ||
| } | ||
|
|
||
| return null; | ||
| const variant = statusToVariant[job.status]; | ||
| const heading = getHeading(job); | ||
|
|
||
| return ( | ||
| <InlineAlert variant={variant}> | ||
| <Heading> | ||
| <Flex gap='size-100' alignItems={'center'} justifyContent={'space-between'}> | ||
| {heading} | ||
| {job.id && <ShowJobLogs jobId={job.id} />} | ||
| </Flex> | ||
| </Heading> | ||
| <Content> | ||
| <Flex direction={'column'} gap={'size-100'}> | ||
| <Text>{job.message}</Text> | ||
| {job.status === 'pending' && <ProgressBar aria-label='Training progress' isIndeterminate />} | ||
| </Flex> | ||
| </Content> | ||
| </InlineAlert> | ||
| ); | ||
| }; | ||
|
|
||
| const REFETCH_INTERVAL_WITH_TRAINING = 1_000; | ||
|
|
||
| const useProjectTrainingJobs = () => { | ||
| export const useProjectTrainingJobs = () => { | ||
| const { projectId } = useProjectIdentifier(); | ||
|
|
||
| const { data } = $api.useQuery('get', '/api/jobs', undefined, { | ||
|
|
@@ -191,7 +107,7 @@ const useProjectTrainingJobs = () => { | |
| return { jobs: data?.jobs.filter((job) => job.project_id === projectId) }; | ||
| }; | ||
|
|
||
| const useRefreshModelsOnJobUpdates = (jobs: Job[] | undefined) => { | ||
| export const useRefreshModelsOnJobUpdates = (jobs: Job[] | undefined) => { | ||
| const queryClient = useQueryClient(); | ||
| const { projectId } = useProjectIdentifier(); | ||
| const prevJobsRef = useRef<Job[]>([]); | ||
|
|
@@ -202,8 +118,10 @@ const useRefreshModelsOnJobUpdates = (jobs: Job[] | undefined) => { | |
| } | ||
|
|
||
| if (!isEqual(prevJobsRef.current, jobs)) { | ||
| const differenceInJobsBasedOnStatus = differenceBy(prevJobsRef.current, jobs, (job) => job.status); | ||
| const shouldRefetchModels = differenceInJobsBasedOnStatus.some((job) => job.status === 'completed'); | ||
| const shouldRefetchModels = jobs.some((job, idx) => { | ||
| // NOTE: assuming index stays the same | ||
| return job.status === 'completed' && job.status !== prevJobsRef.current.at(idx)?.status; | ||
MarkRedeman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
Comment on lines
+121
to
+124
|
||
|
|
||
| if (shouldRefetchModels) { | ||
| queryClient.invalidateQueries({ | ||
|
|
@@ -229,12 +147,9 @@ const TrainingInProgressList = () => { | |
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <Flex direction={'column'} gap={'size-50'} height={'size-2000'} UNSAFE_style={{ overflowY: 'auto' }}> | ||
| {jobs?.map((job) => <TrainingInProgress job={job} key={job.id} />)} | ||
| </Flex> | ||
| <Divider size={'S'} /> | ||
| </> | ||
| <Flex direction={'column'} gap={'size-50'} UNSAFE_style={{ overflowY: 'auto' }}> | ||
| {jobs?.map((job) => <TrainingInProgress job={job} key={job.id} />)} | ||
| </Flex> | ||
| ); | ||
| }; | ||
|
|
||
|
|
@@ -250,7 +165,6 @@ export const DatasetStatusPanel = ({ mediaItemsCount }: DatasetStatusPanelProps) | |
| return ( | ||
| <Suspense fallback={<IntelBrandedLoading />}> | ||
| <TrainingInProgressList /> | ||
| <ReadyToTrain /> | ||
| </Suspense> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.