Skip to content

Commit

Permalink
Merge pull request caikit#702 from gabe-l-hart/ModelService
Browse files Browse the repository at this point in the history
Model service
  • Loading branch information
gabe-l-hart authored Apr 26, 2024
2 parents 357d821 + 489bce0 commit e7f38bf
Show file tree
Hide file tree
Showing 18 changed files with 1,444 additions and 405 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ __pycache__
.coverage.*
durations/*
coverage*.xml
coverage-*
dist
htmlcov
build
test
training_output

# IDEs
.vscode/
Expand Down
12 changes: 12 additions & 0 deletions caikit/core/toolkit/name_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@
and other Protobuf names
"""

# Standard
import re


def snake_to_upper_camel(string: str) -> str:
"""Simple snake -> upper camel conversion for descriptors"""
return "".join([part[0].upper() + part[1:] for part in string.split("_") if part])


def camel_to_snake_case(string: str, kebab_case: bool = False) -> str:
"""Convert from CamelCase (or camelCase) to snake_case or kebab-case"""
return re.sub(
r"(?<!^)(?=[A-Z])",
"-" if kebab_case else "_",
string,
).lower()
1 change: 1 addition & 0 deletions caikit/interfaces/runtime/data_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
RuntimeInfoRequest,
RuntimeInfoResponse,
)
from .model_management import DeployModelRequest, UndeployModelRequest
from .training_management import (
ModelPointer,
TrainingInfoRequest,
Expand Down
41 changes: 41 additions & 0 deletions caikit/interfaces/runtime/data_model/model_management.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright The Caikit Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Data model objects for the model management service
"""
# Standard
from typing import List

# First Party
from py_to_proto.dataclass_to_proto import Annotated, FieldNumber

# Local
from ....core.data_model import DataObjectBase, dataobject
from ...common.data_model import File
from .package import RUNTIME_PACKAGE


@dataobject(RUNTIME_PACKAGE)
class DeployModelRequest(DataObjectBase):
"""Request to deploy a model"""

model_id: Annotated[str, FieldNumber(1)]
model_files: Annotated[List[File], FieldNumber(2)]


@dataobject(RUNTIME_PACKAGE)
class UndeployModelRequest(DataObjectBase):
"""Request to undeploy a model"""

model_id: Annotated[str, FieldNumber(1)]
21 changes: 21 additions & 0 deletions caikit/interfaces/runtime/data_model/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright The Caikit Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Package constant for all runtime service data model objects
"""

# Local
from caikit.core.data_model import CAIKIT_DATA_MODEL

RUNTIME_PACKAGE = f"{CAIKIT_DATA_MODEL}.runtime"
13 changes: 2 additions & 11 deletions caikit/interfaces/runtime/data_model/training_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,28 @@

# First Party
from py_to_proto.dataclass_to_proto import Annotated, FieldNumber
import alog

# Local
from caikit.core.data_model import DataObjectBase, TrainingStatus, dataobject
from caikit.core.toolkit.wip_decorator import Action, WipCategory, work_in_progress
from ....core.data_model import DataObjectBase, TrainingStatus, dataobject
from .package import RUNTIME_PACKAGE

log = alog.use_channel("MDLOPS")

RUNTIME_PACKAGE = "caikit_data_model.runtime"


@work_in_progress(action=Action.WARNING, category=WipCategory.BETA)
@dataobject(RUNTIME_PACKAGE)
class TrainingInfoRequest(DataObjectBase):
training_id: str


@work_in_progress(action=Action.WARNING, category=WipCategory.BETA)
@dataobject(RUNTIME_PACKAGE)
class TrainingJob(DataObjectBase):
training_id: str
model_name: str


@work_in_progress(action=Action.WARNING, category=WipCategory.BETA)
@dataobject(RUNTIME_PACKAGE)
class ModelPointer(DataObjectBase):
model_id: str


@work_in_progress(action=Action.WARNING, category=WipCategory.BETA)
@dataobject(RUNTIME_PACKAGE)
class TrainingStatusResponse(DataObjectBase):
training_id: Annotated[str, FieldNumber(1)]
Expand Down
16 changes: 16 additions & 0 deletions caikit/runtime/grpc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
from caikit.runtime.servicers.global_predict_servicer import GlobalPredictServicer
from caikit.runtime.servicers.global_train_servicer import GlobalTrainServicer
from caikit.runtime.servicers.info_servicer import InfoServicer
from caikit.runtime.servicers.model_management_servicer import (
ModelManagementServicerImpl,
)
from caikit.runtime.servicers.model_runtime_servicer import ModelRuntimeServicerImpl
from caikit.runtime.servicers.model_train_servicer import ModelTrainServicerImpl
from caikit.runtime.servicers.training_management_servicer import (
Expand Down Expand Up @@ -81,6 +84,8 @@ def __init__(

# Intercept an Inference Service
self._global_predict_servicer = None
self.model_management_service = None
self.training_management_service = None
if self.enable_inference:
log.info("<RUN20247875I>", "Enabling gRPC inference service")
self._global_predict_servicer = GlobalPredictServicer(
Expand All @@ -98,6 +103,17 @@ def __init__(
self.inference_service.service, self.server
)

# Register model management service
self.model_management_service: ServicePackage = (
ServicePackageFactory.get_service_package(
ServicePackageFactory.ServiceType.MODEL_MANAGEMENT,
)
)
service_names.append(self.model_management_service.descriptor.full_name)
self.model_management_service.registration_function(
ModelManagementServicerImpl(), self.server
)

# And intercept a training service, if we have one
if self.enable_training and self.training_service:
log.info("<RUN20247827I>", "Enabling gRPC training service")
Expand Down
2 changes: 2 additions & 0 deletions caikit/runtime/http_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
# Local
from .http_server import (
HEALTH_ENDPOINT,
MODEL_MANAGEMENT_ENDPOINT,
MODELS_INFO_ENDPOINT,
RUNTIME_INFO_ENDPOINT,
TRAINING_MANAGEMENT_ENDPOINT,
RuntimeHTTPServer,
)
from .pydantic_wrapper import dataobject_to_pydantic, pydantic_to_dataobject
Loading

0 comments on commit e7f38bf

Please sign in to comment.