Skip to content

Commit

Permalink
Add state properties for RegisteredModel, ModelVersion, and Inference…
Browse files Browse the repository at this point in the history
…Service (kubeflow#185)

* Add state properties for RegisteredModel, ModelVersion, and InferenceService. Fixes kubeflow#184

* Add property state to mlmd types

* Add openapi to mlmd mapping for states

---------

Co-authored-by: Andrea Lamparelli <[email protected]>
  • Loading branch information
dhirajsb and lampajr authored Nov 23, 2023
1 parent 3f3be43 commit e0f2925
Show file tree
Hide file tree
Showing 22 changed files with 927 additions and 18 deletions.
41 changes: 41 additions & 0 deletions api/openapi/model-registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,35 @@ components:
- ABANDONED
- REFERENCE
type: string
RegisteredModelState:
description: |-
- LIVE: A state indicating that the `RegisteredModel` exists
- ARCHIVED: A state indicating that the `RegisteredModel` has been archived.
default: LIVE
enum:
- LIVE
- ARCHIVED
type: string
ModelVersionState:
description: |-
- LIVE: A state indicating that the `ModelVersion` exists
- ARCHIVED: A state indicating that the `ModelVersion` has been archived.
default: LIVE
enum:
- LIVE
- ARCHIVED
type: string
InferenceServiceState:
description: |-
- DEPLOYED: A state indicating that the `InferenceService` should be deployed.
- UNDEPLOYED: A state indicating that the `InferenceService` should be un-deployed.
The state indicates the desired state of inference service.
See the associated `ServeModel` for the actual status of service deployment action.
default: DEPLOYED
enum:
- DEPLOYED
- UNDEPLOYED
type: string
ExecutionState:
description: |-
The state of the Execution. The state transitions are
Expand Down Expand Up @@ -1103,6 +1132,11 @@ components:
allOf:
-
$ref: '#/components/schemas/BaseResourceUpdate'
-
type: object
properties:
state:
$ref: '#/components/schemas/RegisteredModelState'
ModelVersion:
description: Represents a ModelVersion belonging to a RegisteredModel.
allOf:
Expand All @@ -1128,6 +1162,11 @@ components:
allOf:
-
$ref: '#/components/schemas/BaseResourceUpdate'
-
type: object
properties:
state:
$ref: '#/components/schemas/ModelVersionState'
BaseArtifactCreate:
allOf:
-
Expand Down Expand Up @@ -1534,6 +1573,8 @@ components:
runtime:
description: Model runtime.
type: string
state:
$ref: '#/components/schemas/InferenceServiceState'
InferenceServiceCreate:
description: >-
An `InferenceService` entity in a `ServingEnvironment` represents a deployed `ModelVersion`
Expand Down
3 changes: 3 additions & 0 deletions internal/converter/generated/mlmd_openapi_converter.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions internal/converter/generated/openapi_converter.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions internal/converter/mlmd_converter_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,54 @@ func TestMapMLMDModelArtifactState(t *testing.T) {
assertion.Nil(artifactState)
}

func TestMapRegisteredModelState(t *testing.T) {
assertion := setup(t)

state := MapRegisteredModelState(&proto.Context{Properties: map[string]*proto.Value{
"state": {Value: &proto.Value_StringValue{StringValue: string(openapi.REGISTEREDMODELSTATE_LIVE)}},
}})
assertion.NotNil(state)
assertion.Equal(openapi.REGISTEREDMODELSTATE_LIVE, *state)

state = MapRegisteredModelState(&proto.Context{Properties: map[string]*proto.Value{}})
assertion.Nil(state)

state = MapRegisteredModelState(nil)
assertion.Nil(state)
}

func TestMapModelVersionState(t *testing.T) {
assertion := setup(t)

state := MapModelVersionState(&proto.Context{Properties: map[string]*proto.Value{
"state": {Value: &proto.Value_StringValue{StringValue: string(openapi.MODELVERSIONSTATE_LIVE)}},
}})
assertion.NotNil(state)
assertion.Equal(openapi.MODELVERSIONSTATE_LIVE, *state)

state = MapModelVersionState(&proto.Context{Properties: map[string]*proto.Value{}})
assertion.Nil(state)

state = MapModelVersionState(nil)
assertion.Nil(state)
}

func TestMapInferenceServiceState(t *testing.T) {
assertion := setup(t)

state := MapInferenceServiceState(&proto.Context{Properties: map[string]*proto.Value{
"state": {Value: &proto.Value_StringValue{StringValue: string(openapi.INFERENCESERVICESTATE_DEPLOYED)}},
}})
assertion.NotNil(state)
assertion.Equal(openapi.INFERENCESERVICESTATE_DEPLOYED, *state)

state = MapInferenceServiceState(&proto.Context{Properties: map[string]*proto.Value{}})
assertion.Nil(state)

state = MapInferenceServiceState(nil)
assertion.Nil(state)
}

func TestMapServingEnvironmentType(t *testing.T) {
assertion := setup(t)

Expand Down
3 changes: 3 additions & 0 deletions internal/converter/mlmd_openapi_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import (
// goverter:extend MapMLMDCustomProperties
type MLMDToOpenAPIConverter interface {
// goverter:map Properties Description | MapDescription
// goverter:map . State | MapRegisteredModelState
ConvertRegisteredModel(source *proto.Context) (*openapi.RegisteredModel, error)

// goverter:map Name | MapNameFromOwned
// goverter:map Properties Description | MapDescription
// goverter:map . State | MapModelVersionState
ConvertModelVersion(source *proto.Context) (*openapi.ModelVersion, error)

// goverter:map Name | MapNameFromOwned
Expand All @@ -42,6 +44,7 @@ type MLMDToOpenAPIConverter interface {
// goverter:map Properties ModelVersionId | MapPropertyModelVersionId
// goverter:map Properties RegisteredModelId | MapPropertyRegisteredModelId
// goverter:map Properties ServingEnvironmentId | MapPropertyServingEnvironmentId
// goverter:map . State | MapInferenceServiceState
ConvertInferenceService(source *proto.Context) (*openapi.InferenceService, error)

// goverter:map Name | MapNameFromOwned
Expand Down
39 changes: 39 additions & 0 deletions internal/converter/mlmd_openapi_converter_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,45 @@ func MapArtifactType(source *proto.Artifact) (string, error) {
return "", fmt.Errorf("invalid artifact type found: %v", source.Type)
}

func MapRegisteredModelState(source *proto.Context) *openapi.RegisteredModelState {
if source == nil || source.GetProperties() == nil {
return nil
}

state, ok := source.GetProperties()["state"]
if !ok {
return nil
}
str := state.GetStringValue()
return (*openapi.RegisteredModelState)(&str)
}

func MapModelVersionState(source *proto.Context) *openapi.ModelVersionState {
if source == nil || source.GetProperties() == nil {
return nil
}

state, ok := source.GetProperties()["state"]
if !ok {
return nil
}
str := state.GetStringValue()
return (*openapi.ModelVersionState)(&str)
}

func MapInferenceServiceState(source *proto.Context) *openapi.InferenceServiceState {
if source == nil || source.GetProperties() == nil {
return nil
}

state, ok := source.GetProperties()["state"]
if !ok {
return nil
}
str := state.GetStringValue()
return (*openapi.InferenceServiceState)(&str)
}

func MapMLMDModelArtifactState(source *proto.Artifact_State) *openapi.ArtifactState {
if source == nil {
return nil
Expand Down
25 changes: 25 additions & 0 deletions internal/converter/openapi_mlmd_converter_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ func MapRegisteredModelProperties(source *openapi.RegisteredModel) (map[string]*
},
}
}

if source.State != nil {
props["state"] = &proto.Value{
Value: &proto.Value_StringValue{
StringValue: string(*source.State),
},
}
}
}
return props, nil
}
Expand Down Expand Up @@ -163,6 +171,15 @@ func MapModelVersionProperties(source *OpenAPIModelWrapper[openapi.ModelVersion]
StringValue: *(*source.Model).Name,
},
}

if (*source.Model).State != nil {
props["state"] = &proto.Value{
Value: &proto.Value_StringValue{
StringValue: string(*(*source.Model).State),
},
}
}

// TODO: not available for now
props["author"] = &proto.Value{
Value: &proto.Value_StringValue{
Expand Down Expand Up @@ -317,6 +334,14 @@ func MapInferenceServiceProperties(source *openapi.InferenceService) (map[string
}
}

if source.State != nil {
props["state"] = &proto.Value{
Value: &proto.Value_StringValue{
StringValue: string(*source.State),
},
}
}

registeredModelId, err := StringToInt64(&source.RegisteredModelId)
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions pkg/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func NewModelRegistryService(cc grpc.ClientConnInterface) (api.ModelRegistryApi,
Name: registeredModelTypeName,
Properties: map[string]proto.PropertyType{
"description": proto.PropertyType_STRING,
"state": proto.PropertyType_STRING,
},
},
}
Expand All @@ -56,6 +57,7 @@ func NewModelRegistryService(cc grpc.ClientConnInterface) (api.ModelRegistryApi,
"model_name": proto.PropertyType_STRING,
"version": proto.PropertyType_STRING,
"author": proto.PropertyType_STRING,
"state": proto.PropertyType_STRING,
},
},
}
Expand Down Expand Up @@ -96,6 +98,7 @@ func NewModelRegistryService(cc grpc.ClientConnInterface) (api.ModelRegistryApi,
// same information tracked using ParentContext association
"serving_environment_id": proto.PropertyType_INT,
"runtime": proto.PropertyType_STRING,
"state": proto.PropertyType_STRING,
},
},
}
Expand Down
Loading

0 comments on commit e0f2925

Please sign in to comment.