caikit.core.model_management

The model management abstractions manage the key lifecycle phases of a concrete model instance and are used by the ModelManager to handle each phase of the model lifecycle.

For architectural details, see docs/adrs/020-model-management-abstractions.md

Submodules

Attributes

job_predictor_factory

model_finder_factory

model_initializer_factory

model_trainer_factory

Classes

JobBase

A class can be constructed by a factory if its constructor takes exactly

JobFutureBase

Every JobBase implementation must have a JobFutureBase class that can access the

JobPredictorBase

A class can be constructed by a factory if its constructor takes exactly

JobPredictorFutureBase

Subclass of JobFutureBase for Job Predictions

JobPredictorInfo

JobPredictorInfo is a remap of JobInfo but for predictors

ModelFinderBase

A class can be constructed by a factory if its constructor takes exactly

ModelInitializerBase

A class can be constructed by a factory if its constructor takes exactly

ModelTrainerBase

A class can be constructed by a factory if its constructor takes exactly

ModelTrainerFutureBase

Every JobBase implementation must have a JobFutureBase class that can access the

TrainingInfo

Package Contents

caikit.core.model_management.job_predictor_factory
caikit.core.model_management.model_finder_factory
caikit.core.model_management.model_initializer_factory
caikit.core.model_management.model_trainer_factory
class caikit.core.model_management.JobBase(config: aconfig.Config, instance_name: str)[source]

Bases: caikit.core.toolkit.factory.FactoryConstructible

A class can be constructed by a factory if its constructor takes exactly one argument that is an aconfig.Config object and it has a name to identify itself with the factory.

abstract get_future(job_id: str) JobFutureBase[source]

Look up the model future for the given id

classmethod get_job_name(job_id: str) str[source]

Un-hash the background’s instance name from the given job id

class caikit.core.model_management.JobFutureBase(future_name: str, future_id: str, use_reversible_hash: bool = True, **kwargs)[source]

Bases: abc.ABC

Every JobBase implementation must have a JobFutureBase class that can access the job information in the infrastructure managed by the task.

ID_DELIMITER = ':'
_id = ''
property id: str

Every job future must have a unique ID that can be used to look up the in-flight background task

abstract get_info() JobInfo[source]

Every model future must be able to poll the status of the background job

abstract cancel()[source]

Terminate the given job

abstract wait()[source]

Block until the job reaches a terminal state

abstract result() Any[source]

Support result() to match concurrent.futures.Future

class caikit.core.model_management.JobPredictorBase(config: aconfig.Config, instance_name: str)[source]

Bases: caikit.core.model_management.job_base.JobBase

A class can be constructed by a factory if its constructor takes exactly one argument that is an aconfig.Config object and it has a name to identify itself with the factory.

__doc__ = Multiline-String
Show Value
"""
A Job Predictor is responsible for managing execution of a prediction jobs running
in the background for a given task method

Configuration for Job Predictors lives under the config as follows:

model_management:
    job_predictors:
        <predictor name>:
            type: <predictor type name>
            config:
                <config option>: <value>
"""
abstract predict(model_instance: caikit.core.modules.ModuleBase, prediction_func_name: str, *args, external_inference_id: str | None = None, **kwargs) JobPredictorFutureBase[source]

Start a prediction with the given model instance and function and return a future to the prediction result

abstract get_prediction_future(future_id: str) JobPredictorFutureBase[source]

Look up the jobs future for the given id

get_future(prediction_id: str) caikit.core.model_management.job_base.JobFutureBase[source]

Look up the job future for the given id

classmethod get_predictor_name(predict_id: str) str[source]

Un-hash the predictors’s instance name from the given prediction id

class caikit.core.model_management.JobPredictorFutureBase(future_name: str, future_id: str, use_reversible_hash: bool = True, **kwargs)[source]

Bases: caikit.core.model_management.job_base.JobFutureBase

Subclass of JobFutureBase for Job Predictions

abstract result() caikit.core.data_model.DataObjectBase[source]

The result of a JobPredictorFutureBase is the result object

class caikit.core.model_management.JobPredictorInfo[source]

Bases: caikit.core.model_management.job_base.JobInfo

JobPredictorInfo is a remap of JobInfo but for predictors

class caikit.core.model_management.ModelFinderBase(config: aconfig.Config, instance_name: str)[source]

Bases: caikit.core.toolkit.factory.FactoryConstructible

A class can be constructed by a factory if its constructor takes exactly one argument that is an aconfig.Config object and it has a name to identify itself with the factory.

__doc__ = Multiline-String
Show Value
"""
A ModelFinder is responsible for finding models based on a unique input string
which may be a path, id, or other identifier.

Configuration for ModelFinders lives under the config as follows:

model_management:
    finders:
        <finder name>:
            type: <finder type name>
            config:
                <config option>: <value>
"""
abstract find_model(model_path: str, **kwargs) caikit.core.modules.ModuleConfig | None[source]

Find any model that can be uniquely identified by the given (logical) path. If found, return the in-memory ModuleConfig.

Args:
model_path (str): The logical path to the model (name, id, file

path, etc…)

**kwargs: All finders must allow additional kwargs through so that

specific finders and loaders can support additional optional arguments.

Returns:
result (Optional[ModuleConfig]): If found, the in-memory config

object for the model. If the model cannot be found, an exception may be raised or None returned.

class caikit.core.model_management.ModelInitializerBase(config: aconfig.Config, instance_name: str)[source]

Bases: caikit.core.toolkit.factory.FactoryConstructible

A class can be constructed by a factory if its constructor takes exactly one argument that is an aconfig.Config object and it has a name to identify itself with the factory.

__doc__ = Multiline-String
Show Value
"""
A ModelInitializer is responsible for taking an in-memory ModuleConfig and
producing a usable Module instance.

Configuration for ModelInitializers lives under the config as follows:

model_management:
    initializers:
        <initializer name>:
            type: <initializer type name>
            config:
                <config option>: <value>
"""
abstract init(model_config: caikit.core.modules.ModuleConfig, **kwargs) caikit.core.modules.ModuleBase | None[source]

Given a ModelConfig, attempt to initialize it for running

Args:
model_config (ModuleConfig): The in-memory model config object for

the model to be loaded

**kwargs: All loaders must allow additional kwargs through so that

specific finders and loaders can support additional optional arguments.

Returns:
model (Optional[ModuleBase]): The in-memory ModuleBase instance that

is ready to run if successful. If unable to load, an exception may be raised, or None may be returned.

class caikit.core.model_management.ModelTrainerBase(config: aconfig.Config, instance_name: str)[source]

Bases: caikit.core.model_management.job_base.JobBase

A class can be constructed by a factory if its constructor takes exactly one argument that is an aconfig.Config object and it has a name to identify itself with the factory.

__doc__ = Multiline-String
Show Value
"""
A Trainer is responsible for managing execution of a training job for a given
module class

Configuration for ModelTrainers lives under the config as follows:

model_management:
    trainers:
        <trainer name>:
            type: <trainer type name>
            config:
                <config option>: <value>
"""
ModelFutureBase
abstract train(module_class: Type[caikit.core.modules.ModuleBase], *args, save_path: str | caikit.interfaces.common.data_model.stream_sources.S3Path | None = None, save_with_id: bool = False, model_name: str | None = None, **kwargs) ModelFutureBase[source]

Start training the given module and return a future to the trained model instance

abstract get_model_future(training_id: str) ModelFutureBase[source]

Look up the model future for the given id

get_future(job_id: str) caikit.core.model_management.job_base.JobFutureBase[source]

Look up the model future for the given id

classmethod get_trainer_name(training_id: str) str[source]

Un-hash the trainer’s instance name from the given training id

class caikit.core.model_management.ModelTrainerFutureBase(*args, **kwargs)[source]

Bases: caikit.core.model_management.job_base.JobFutureBase

Every JobBase implementation must have a JobFutureBase class that can access the job information in the infrastructure managed by the task.

_save_path
property save_path: str | None

If created with a save path, the future must expose it, including any injected background id

abstract load() caikit.core.modules.ModuleBase[source]

A model future must be loadable with no additional arguments. Mainly useful in train results

result() caikit.core.modules.ModuleBase[source]

The result of a model train future is the loaded model

class caikit.core.model_management.TrainingInfo[source]

Bases: caikit.core.model_management.job_base.JobInfo