Skip to content

Model

CatBoostModel

Bases: ModelInterface

Source code in python/opsml/model/_model.pyi
class CatBoostModel(ModelInterface):
    def __init__(
        self,
        model: Optional[Any] = None,
        preprocessor: Optional[Any] = None,
        sample_data: Optional[Any] = None,
        task_type: Optional[TaskType] = None,
        drift_profile: Optional[DriftProfileType] = None,
    ) -> None:
        """Interface for saving CatBoost models

        Args:
            model:
                Model to associate with the interface. This model must be a CatBoost model.
            preprocessor:
                Preprocessor to associate with the model.
            sample_data:
                Sample data to use to make predictions.
            task_type:
                The type of task the model performs
            drift_profile:
                Drift profile(s) to associate with the model. Must be a dictionary of
                alias and drift profile.
        """

    @property
    def preprocessor(self) -> Optional[Any]:
        """Returns the preprocessor"""

    @preprocessor.setter
    def preprocessor(self, preprocessor: Any) -> None:
        """Sets the preprocessor

        Args:
            preprocessor:
                Preprocessor to associate with the model. This preprocessor must be from the
                scikit-learn ecosystem
        """

    @property
    def preprocessor_name(self) -> Optional[str]:
        """Returns the preprocessor name"""

preprocessor property writable

Returns the preprocessor

preprocessor_name property

Returns the preprocessor name

__init__(model=None, preprocessor=None, sample_data=None, task_type=None, drift_profile=None)

Interface for saving CatBoost models

Parameters:

Name Type Description Default
model Optional[Any]

Model to associate with the interface. This model must be a CatBoost model.

None
preprocessor Optional[Any]

Preprocessor to associate with the model.

None
sample_data Optional[Any]

Sample data to use to make predictions.

None
task_type Optional[TaskType]

The type of task the model performs

None
drift_profile Optional[DriftProfileType]

Drift profile(s) to associate with the model. Must be a dictionary of alias and drift profile.

None
Source code in python/opsml/model/_model.pyi
def __init__(
    self,
    model: Optional[Any] = None,
    preprocessor: Optional[Any] = None,
    sample_data: Optional[Any] = None,
    task_type: Optional[TaskType] = None,
    drift_profile: Optional[DriftProfileType] = None,
) -> None:
    """Interface for saving CatBoost models

    Args:
        model:
            Model to associate with the interface. This model must be a CatBoost model.
        preprocessor:
            Preprocessor to associate with the model.
        sample_data:
            Sample data to use to make predictions.
        task_type:
            The type of task the model performs
        drift_profile:
            Drift profile(s) to associate with the model. Must be a dictionary of
            alias and drift profile.
    """

DataProcessor

Generic class that holds uri information for data preprocessors and postprocessors

Source code in python/opsml/model/_model.pyi
class DataProcessor:
    """Generic class that holds uri information for data preprocessors and postprocessors"""

    name: str
    uri: Path
    type: ProcessorType

    def __init__(self, name: str, uri: Path) -> None:
        """Define a data processor

        Args:
            name:
                Name of the data processor
            uri:
                Path to the data processor
        """

    def __str__(self): ...

__init__(name, uri)

Define a data processor

Parameters:

Name Type Description Default
name str

Name of the data processor

required
uri Path

Path to the data processor

required
Source code in python/opsml/model/_model.pyi
def __init__(self, name: str, uri: Path) -> None:
    """Define a data processor

    Args:
        name:
            Name of the data processor
        uri:
            Path to the data processor
    """

DriftArgs

Source code in python/opsml/model/_model.pyi
class DriftArgs:
    def __init__(self, active: bool = True, deactivate_others: bool = False) -> None:
        """Define a drift config

        Args:
            active (bool):
                Whether to set the drift profile to active
            deactivate_others (bool):
                Whether to deactivate all other drift profiles of the same space and name
        """

    @property
    def active(self) -> bool:
        """Return the active status of the drift profile."""

    @property
    def deactivate_others(self) -> bool:
        """Return the deactivate_others status of the drift profile."""

active property

Return the active status of the drift profile.

deactivate_others property

Return the deactivate_others status of the drift profile.

__init__(active=True, deactivate_others=False)

Define a drift config

Parameters:

Name Type Description Default
active bool

Whether to set the drift profile to active

True
deactivate_others bool

Whether to deactivate all other drift profiles of the same space and name

False
Source code in python/opsml/model/_model.pyi
def __init__(self, active: bool = True, deactivate_others: bool = False) -> None:
    """Define a drift config

    Args:
        active (bool):
            Whether to set the drift profile to active
        deactivate_others (bool):
            Whether to deactivate all other drift profiles of the same space and name
    """

DriftProfileMap

Source code in python/opsml/model/_model.pyi
class DriftProfileMap:
    def __init__(self) -> None:
        """Creates an empty drift profile map"""

    def add_profile(self, alias: str, profile: Any) -> None:
        """Add a drift profile to the map

        Args:
            alias:
                Alias to use for the drift profile
            profile:
                Drift profile to add
        """

    def __getitem__(self, key: str) -> Any:
        """Returns the drift profile at the given key"""

__getitem__(key)

Returns the drift profile at the given key

Source code in python/opsml/model/_model.pyi
def __getitem__(self, key: str) -> Any:
    """Returns the drift profile at the given key"""

__init__()

Creates an empty drift profile map

Source code in python/opsml/model/_model.pyi
def __init__(self) -> None:
    """Creates an empty drift profile map"""

add_profile(alias, profile)

Add a drift profile to the map

Parameters:

Name Type Description Default
alias str

Alias to use for the drift profile

required
profile Any

Drift profile to add

required
Source code in python/opsml/model/_model.pyi
def add_profile(self, alias: str, profile: Any) -> None:
    """Add a drift profile to the map

    Args:
        alias:
            Alias to use for the drift profile
        profile:
            Drift profile to add
    """

Feature

Source code in python/opsml/model/_model.pyi
class Feature:
    feature_type: str
    shape: List[int]
    extra_args: Dict[str, str]

    def __init__(
        self,
        feature_type: str,
        shape: List[int],
        extra_args: Optional[Dict[str, str]] = None,
    ) -> None:
        """Define a feature

        Args:
            feature_type:
                The type of the feature
            shape:
                The shape of the feature
            extra_args:
                Extra arguments to pass to the feature
        """

    def __str__(self) -> str:
        """Return a string representation of the Feature.

        Returns:
            String representation of the Feature.
        """

__init__(feature_type, shape, extra_args=None)

Define a feature

Parameters:

Name Type Description Default
feature_type str

The type of the feature

required
shape List[int]

The shape of the feature

required
extra_args Optional[Dict[str, str]]

Extra arguments to pass to the feature

None
Source code in python/opsml/model/_model.pyi
def __init__(
    self,
    feature_type: str,
    shape: List[int],
    extra_args: Optional[Dict[str, str]] = None,
) -> None:
    """Define a feature

    Args:
        feature_type:
            The type of the feature
        shape:
            The shape of the feature
        extra_args:
            Extra arguments to pass to the feature
    """

__str__()

Return a string representation of the Feature.

Returns:

Type Description
str

String representation of the Feature.

Source code in python/opsml/model/_model.pyi
def __str__(self) -> str:
    """Return a string representation of the Feature.

    Returns:
        String representation of the Feature.
    """

FeatureSchema

Source code in python/opsml/model/_model.pyi
class FeatureSchema:
    def __init__(self, items: Optional[dict[str, Feature]] = None) -> None:
        """Define a feature map

        Args:
            features:
                The features to use in the feature map
        """

    def __str__(self) -> str:
        """Return a string representation of the FeatureSchema."""

    def __getitem__(self, key: str) -> Feature:
        """Returns the feature at the given key."""

__getitem__(key)

Returns the feature at the given key.

Source code in python/opsml/model/_model.pyi
def __getitem__(self, key: str) -> Feature:
    """Returns the feature at the given key."""

__init__(items=None)

Define a feature map

Parameters:

Name Type Description Default
features

The features to use in the feature map

required
Source code in python/opsml/model/_model.pyi
def __init__(self, items: Optional[dict[str, Feature]] = None) -> None:
    """Define a feature map

    Args:
        features:
            The features to use in the feature map
    """

__str__()

Return a string representation of the FeatureSchema.

Source code in python/opsml/model/_model.pyi
def __str__(self) -> str:
    """Return a string representation of the FeatureSchema."""

HuggingFaceModel

Bases: ModelInterface

Source code in python/opsml/model/_model.pyi
class HuggingFaceModel(ModelInterface):
    def __init__(
        self,
        model: Optional[Any] = None,
        tokenizer: Optional[Any] = None,
        feature_extractor: Optional[Any] = None,
        image_processor: Optional[Any] = None,
        sample_data: Optional[Any] = None,
        hf_task: Optional[HuggingFaceTask] = None,
        task_type: Optional[TaskType] = None,
        drift_profile: Optional[DriftProfileType] = None,
    ) -> None:
        """Interface for saving HuggingFace models and pipelines

        Args:
            model:
                Model to associate with interface. This can be a HuggingFace pipeline (inherits from Pipeline),
                or a HuggingFace model (inherits from PreTrainedModel or TFPreTrainedModel).
            tokenizer:
                Tokenizer to associate with the model. This must be a HuggingFace tokenizer (PreTrainedTokenizerBase).
                If using a pipeline that already has a tokenizer, this can be None.
            feature_extractor:
                Feature extractor to associate with the model. This must be a HuggingFace feature extractor
                (PreTrainedFeatureExtractor). If using a pipeline that already has a feature extractor,
                this can be None.
            image_processor:
                Image processor to associate with the model. This must be a HuggingFace image processor
                (BaseImageProcessor). If using a pipeline that already has an image processor,
                this can be None.
            sample_data:
                Sample data to use to convert to ONNX and make sample predictions. This data must be a
                HuggingFace-supported type.
            hf_task:
                HuggingFace task to associate with the model. Defaults to Undefined.
                Accepted tasks are as follows (taken from HuggingFace pipeline docs):
                    - `"audio-classification"`: will return a [`AudioClassificationPipeline`].
                    - `"automatic-speech-recognition"`: will return a [`AutomaticSpeechRecognitionPipeline`].
                    - `"depth-estimation"`: will return a [`DepthEstimationPipeline`].
                    - `"document-question-answering"`: will return a [`DocumentQuestionAnsweringPipeline`].
                    - `"feature-extraction"`: will return a [`FeatureExtractionPipeline`].
                    - `"fill-mask"`: will return a [`FillMaskPipeline`]:.
                    - `"image-classification"`: will return a [`ImageClassificationPipeline`].
                    - `"image-feature-extraction"`: will return an [`ImageFeatureExtractionPipeline`].
                    - `"image-segmentation"`: will return a [`ImageSegmentationPipeline`].
                    - `"image-text-to-text"`: will return a [`ImageTextToTextPipeline`].
                    - `"image-to-image"`: will return a [`ImageToImagePipeline`].
                    - `"image-to-text"`: will return a [`ImageToTextPipeline`].
                    - `"mask-generation"`: will return a [`MaskGenerationPipeline`].
                    - `"object-detection"`: will return a [`ObjectDetectionPipeline`].
                    - `"question-answering"`: will return a [`QuestionAnsweringPipeline`].
                    - `"summarization"`: will return a [`SummarizationPipeline`].
                    - `"table-question-answering"`: will return a [`TableQuestionAnsweringPipeline`].
                    - `"text2text-generation"`: will return a [`Text2TextGenerationPipeline`].
                    - `"text-classification"` (alias `"sentiment-analysis"` available): will return a
                    [`TextClassificationPipeline`].
                    - `"text-generation"`: will return a [`TextGenerationPipeline`]:.
                    - `"text-to-audio"` (alias `"text-to-speech"` available): will return a [`TextToAudioPipeline`]:.
                    - `"token-classification"` (alias `"ner"` available): will return a [`TokenClassificationPipeline`].
                    - `"translation"`: will return a [`TranslationPipeline`].
                    - `"translation_xx_to_yy"`: will return a [`TranslationPipeline`].
                    - `"video-classification"`: will return a [`VideoClassificationPipeline`].
                    - `"visual-question-answering"`: will return a [`VisualQuestionAnsweringPipeline`].
                    - `"zero-shot-classification"`: will return a [`ZeroShotClassificationPipeline`].
                    - `"zero-shot-image-classification"`: will return a [`ZeroShotImageClassificationPipeline`].
                    - `"zero-shot-audio-classification"`: will return a [`ZeroShotAudioClassificationPipeline`].
                    - `"zero-shot-object-detection"`: will return a [`ZeroShotObjectDetectionPipeline`].
            task_type:
                The intended task type for the model. Note: This is the OpsML task type, not the HuggingFace task type.
            drift_profile:
                Drift profile(s) to associate with the model. Must be a dictionary of
                alias and drift profile.
        """

    def save(
        self,
        path: Path,
        save_kwargs: None | ModelSaveKwargs = None,
    ) -> ModelInterfaceMetadata:
        """Save the HuggingFaceModel interface

        Args:
            path (Path):
                Base path to save artifacts
            save_kwargs (ModelSaveKwargs):
                Optional kwargs to pass to the various underlying methods. This is a passthrough object meaning
                that the kwargs will be passed to the underlying methods as is and are expected to be supported by
                the underlying library.

                - model: Kwargs that will be passed to save_model. See save_model for more details.
                - preprocessor: Kwargs that will be passed to save_preprocessor
                - onnx: Kwargs that will be passed when saving the onnx model
                    - For the HuggingFaceModel, this should be an instance of HuggingFaceOnnxArgs
                - save_onnx: Whether to save the onnx model. Defaults to false.
        """

    @property
    def model(self) -> Optional[Any]:
        """Returns as HuggingFace model (PreTrainedModel, TFPreTrainedModel).
        Can be None if the model is a pipeline.
        """

    @model.setter
    def model(self, model: Any) -> None:
        """Sets the model

        Args:
            model:
                Model to associate with the interface. This must be a HuggingFace model (PreTrainedModel, TFPreTrainedModel).
                If using a pipeline that already has a model, this can be None.
        """

    @property
    def tokenizer(self) -> Optional[Any]:
        """Returns the tokenizer. Can be None if the model is a pipeline.
        If present, will be of type PreTrainedTokenizerBase
        """

    @tokenizer.setter
    def tokenizer(self, tokenizer: Any) -> None:
        """Sets the tokenizer

        Args:
            tokenizer:
                Tokenizer to associate with the model. This must be a HuggingFace tokenizer (PreTrainedTokenizerBase).
                If using a pipeline that already has a tokenizer, this can be None.
        """

    @property
    def image_processor(self) -> Optional[Any]:
        """Returns the image processor. Can be None if the model is a pipeline.
        If present, will be of type BaseImageProcessor
        """

    @image_processor.setter
    def image_processor(self, image_processor: Any) -> None:
        """Sets the image processor

        Args:
            image_processor:
                Image processor to associate with the model. This must be a HuggingFace image processor
                (BaseImageProcessor). If using a pipeline that already has an image processor,
                this can be None.
        """

    @property
    def feature_extractor(self) -> Optional[Any]:
        """Returns the feature extractor. Can be None if the model is a pipeline.
        If present, will be of type PreTrainedFeatureExtractor
        """

    @feature_extractor.setter
    def feature_extractor(self, feature_extractor: Any) -> None:
        """Sets the feature extractor

        Args:
            feature_extractor:
                Feature extractor to associate with the model. This must be a HuggingFace feature extractor
                (PreTrainedFeatureExtractor). If using a pipeline that already has a feature extractor,
                this can be None.
        """

feature_extractor property writable

Returns the feature extractor. Can be None if the model is a pipeline. If present, will be of type PreTrainedFeatureExtractor

image_processor property writable

Returns the image processor. Can be None if the model is a pipeline. If present, will be of type BaseImageProcessor

model property writable

Returns as HuggingFace model (PreTrainedModel, TFPreTrainedModel). Can be None if the model is a pipeline.

tokenizer property writable

Returns the tokenizer. Can be None if the model is a pipeline. If present, will be of type PreTrainedTokenizerBase

__init__(model=None, tokenizer=None, feature_extractor=None, image_processor=None, sample_data=None, hf_task=None, task_type=None, drift_profile=None)

Interface for saving HuggingFace models and pipelines

Parameters:

Name Type Description Default
model Optional[Any]

Model to associate with interface. This can be a HuggingFace pipeline (inherits from Pipeline), or a HuggingFace model (inherits from PreTrainedModel or TFPreTrainedModel).

None
tokenizer Optional[Any]

Tokenizer to associate with the model. This must be a HuggingFace tokenizer (PreTrainedTokenizerBase). If using a pipeline that already has a tokenizer, this can be None.

None
feature_extractor Optional[Any]

Feature extractor to associate with the model. This must be a HuggingFace feature extractor (PreTrainedFeatureExtractor). If using a pipeline that already has a feature extractor, this can be None.

None
image_processor Optional[Any]

Image processor to associate with the model. This must be a HuggingFace image processor (BaseImageProcessor). If using a pipeline that already has an image processor, this can be None.

None
sample_data Optional[Any]

Sample data to use to convert to ONNX and make sample predictions. This data must be a HuggingFace-supported type.

None
hf_task Optional[HuggingFaceTask]

HuggingFace task to associate with the model. Defaults to Undefined. Accepted tasks are as follows (taken from HuggingFace pipeline docs): - "audio-classification": will return a [AudioClassificationPipeline]. - "automatic-speech-recognition": will return a [AutomaticSpeechRecognitionPipeline]. - "depth-estimation": will return a [DepthEstimationPipeline]. - "document-question-answering": will return a [DocumentQuestionAnsweringPipeline]. - "feature-extraction": will return a [FeatureExtractionPipeline]. - "fill-mask": will return a [FillMaskPipeline]:. - "image-classification": will return a [ImageClassificationPipeline]. - "image-feature-extraction": will return an [ImageFeatureExtractionPipeline]. - "image-segmentation": will return a [ImageSegmentationPipeline]. - "image-text-to-text": will return a [ImageTextToTextPipeline]. - "image-to-image": will return a [ImageToImagePipeline]. - "image-to-text": will return a [ImageToTextPipeline]. - "mask-generation": will return a [MaskGenerationPipeline]. - "object-detection": will return a [ObjectDetectionPipeline]. - "question-answering": will return a [QuestionAnsweringPipeline]. - "summarization": will return a [SummarizationPipeline]. - "table-question-answering": will return a [TableQuestionAnsweringPipeline]. - "text2text-generation": will return a [Text2TextGenerationPipeline]. - "text-classification" (alias "sentiment-analysis" available): will return a [TextClassificationPipeline]. - "text-generation": will return a [TextGenerationPipeline]:. - "text-to-audio" (alias "text-to-speech" available): will return a [TextToAudioPipeline]:. - "token-classification" (alias "ner" available): will return a [TokenClassificationPipeline]. - "translation": will return a [TranslationPipeline]. - "translation_xx_to_yy": will return a [TranslationPipeline]. - "video-classification": will return a [VideoClassificationPipeline]. - "visual-question-answering": will return a [VisualQuestionAnsweringPipeline]. - "zero-shot-classification": will return a [ZeroShotClassificationPipeline]. - "zero-shot-image-classification": will return a [ZeroShotImageClassificationPipeline]. - "zero-shot-audio-classification": will return a [ZeroShotAudioClassificationPipeline]. - "zero-shot-object-detection": will return a [ZeroShotObjectDetectionPipeline].

None
task_type Optional[TaskType]

The intended task type for the model. Note: This is the OpsML task type, not the HuggingFace task type.

None
drift_profile Optional[DriftProfileType]

Drift profile(s) to associate with the model. Must be a dictionary of alias and drift profile.

None
Source code in python/opsml/model/_model.pyi
def __init__(
    self,
    model: Optional[Any] = None,
    tokenizer: Optional[Any] = None,
    feature_extractor: Optional[Any] = None,
    image_processor: Optional[Any] = None,
    sample_data: Optional[Any] = None,
    hf_task: Optional[HuggingFaceTask] = None,
    task_type: Optional[TaskType] = None,
    drift_profile: Optional[DriftProfileType] = None,
) -> None:
    """Interface for saving HuggingFace models and pipelines

    Args:
        model:
            Model to associate with interface. This can be a HuggingFace pipeline (inherits from Pipeline),
            or a HuggingFace model (inherits from PreTrainedModel or TFPreTrainedModel).
        tokenizer:
            Tokenizer to associate with the model. This must be a HuggingFace tokenizer (PreTrainedTokenizerBase).
            If using a pipeline that already has a tokenizer, this can be None.
        feature_extractor:
            Feature extractor to associate with the model. This must be a HuggingFace feature extractor
            (PreTrainedFeatureExtractor). If using a pipeline that already has a feature extractor,
            this can be None.
        image_processor:
            Image processor to associate with the model. This must be a HuggingFace image processor
            (BaseImageProcessor). If using a pipeline that already has an image processor,
            this can be None.
        sample_data:
            Sample data to use to convert to ONNX and make sample predictions. This data must be a
            HuggingFace-supported type.
        hf_task:
            HuggingFace task to associate with the model. Defaults to Undefined.
            Accepted tasks are as follows (taken from HuggingFace pipeline docs):
                - `"audio-classification"`: will return a [`AudioClassificationPipeline`].
                - `"automatic-speech-recognition"`: will return a [`AutomaticSpeechRecognitionPipeline`].
                - `"depth-estimation"`: will return a [`DepthEstimationPipeline`].
                - `"document-question-answering"`: will return a [`DocumentQuestionAnsweringPipeline`].
                - `"feature-extraction"`: will return a [`FeatureExtractionPipeline`].
                - `"fill-mask"`: will return a [`FillMaskPipeline`]:.
                - `"image-classification"`: will return a [`ImageClassificationPipeline`].
                - `"image-feature-extraction"`: will return an [`ImageFeatureExtractionPipeline`].
                - `"image-segmentation"`: will return a [`ImageSegmentationPipeline`].
                - `"image-text-to-text"`: will return a [`ImageTextToTextPipeline`].
                - `"image-to-image"`: will return a [`ImageToImagePipeline`].
                - `"image-to-text"`: will return a [`ImageToTextPipeline`].
                - `"mask-generation"`: will return a [`MaskGenerationPipeline`].
                - `"object-detection"`: will return a [`ObjectDetectionPipeline`].
                - `"question-answering"`: will return a [`QuestionAnsweringPipeline`].
                - `"summarization"`: will return a [`SummarizationPipeline`].
                - `"table-question-answering"`: will return a [`TableQuestionAnsweringPipeline`].
                - `"text2text-generation"`: will return a [`Text2TextGenerationPipeline`].
                - `"text-classification"` (alias `"sentiment-analysis"` available): will return a
                [`TextClassificationPipeline`].
                - `"text-generation"`: will return a [`TextGenerationPipeline`]:.
                - `"text-to-audio"` (alias `"text-to-speech"` available): will return a [`TextToAudioPipeline`]:.
                - `"token-classification"` (alias `"ner"` available): will return a [`TokenClassificationPipeline`].
                - `"translation"`: will return a [`TranslationPipeline`].
                - `"translation_xx_to_yy"`: will return a [`TranslationPipeline`].
                - `"video-classification"`: will return a [`VideoClassificationPipeline`].
                - `"visual-question-answering"`: will return a [`VisualQuestionAnsweringPipeline`].
                - `"zero-shot-classification"`: will return a [`ZeroShotClassificationPipeline`].
                - `"zero-shot-image-classification"`: will return a [`ZeroShotImageClassificationPipeline`].
                - `"zero-shot-audio-classification"`: will return a [`ZeroShotAudioClassificationPipeline`].
                - `"zero-shot-object-detection"`: will return a [`ZeroShotObjectDetectionPipeline`].
        task_type:
            The intended task type for the model. Note: This is the OpsML task type, not the HuggingFace task type.
        drift_profile:
            Drift profile(s) to associate with the model. Must be a dictionary of
            alias and drift profile.
    """

save(path, save_kwargs=None)

Save the HuggingFaceModel interface

Parameters:

Name Type Description Default
path Path

Base path to save artifacts

required
save_kwargs ModelSaveKwargs

Optional kwargs to pass to the various underlying methods. This is a passthrough object meaning that the kwargs will be passed to the underlying methods as is and are expected to be supported by the underlying library.

  • model: Kwargs that will be passed to save_model. See save_model for more details.
  • preprocessor: Kwargs that will be passed to save_preprocessor
  • onnx: Kwargs that will be passed when saving the onnx model
    • For the HuggingFaceModel, this should be an instance of HuggingFaceOnnxArgs
  • save_onnx: Whether to save the onnx model. Defaults to false.
None
Source code in python/opsml/model/_model.pyi
def save(
    self,
    path: Path,
    save_kwargs: None | ModelSaveKwargs = None,
) -> ModelInterfaceMetadata:
    """Save the HuggingFaceModel interface

    Args:
        path (Path):
            Base path to save artifacts
        save_kwargs (ModelSaveKwargs):
            Optional kwargs to pass to the various underlying methods. This is a passthrough object meaning
            that the kwargs will be passed to the underlying methods as is and are expected to be supported by
            the underlying library.

            - model: Kwargs that will be passed to save_model. See save_model for more details.
            - preprocessor: Kwargs that will be passed to save_preprocessor
            - onnx: Kwargs that will be passed when saving the onnx model
                - For the HuggingFaceModel, this should be an instance of HuggingFaceOnnxArgs
            - save_onnx: Whether to save the onnx model. Defaults to false.
    """

HuggingFaceOnnxArgs

Source code in python/opsml/model/_model.pyi
class HuggingFaceOnnxArgs:
    ort_type: HuggingFaceORTModel
    provider: str
    quantize: bool
    export: bool
    config: Optional[Any]
    extra_kwargs: Optional[Dict[str, Any]]

    def __init__(
        self,
        ort_type: HuggingFaceORTModel,
        provider: str,
        quantize: bool = False,
        config: Optional[Any] = None,
        extra_kwargs: Optional[Dict[str, Any]] = None,
    ) -> None:
        """Optional Args to use with a huggingface model

        Args:
            ort_type:
                Optimum onnx class name
            provider:
                Onnx runtime provider to use
            config:
                Optional optimum config to use
            quantize:
                Whether to quantize the model
            extra_kwargs:
                Extra kwargs to pass to the onnx conversion (save_pretrained method for ort models)

        """

__init__(ort_type, provider, quantize=False, config=None, extra_kwargs=None)

Optional Args to use with a huggingface model

Parameters:

Name Type Description Default
ort_type HuggingFaceORTModel

Optimum onnx class name

required
provider str

Onnx runtime provider to use

required
config Optional[Any]

Optional optimum config to use

None
quantize bool

Whether to quantize the model

False
extra_kwargs Optional[Dict[str, Any]]

Extra kwargs to pass to the onnx conversion (save_pretrained method for ort models)

None
Source code in python/opsml/model/_model.pyi
def __init__(
    self,
    ort_type: HuggingFaceORTModel,
    provider: str,
    quantize: bool = False,
    config: Optional[Any] = None,
    extra_kwargs: Optional[Dict[str, Any]] = None,
) -> None:
    """Optional Args to use with a huggingface model

    Args:
        ort_type:
            Optimum onnx class name
        provider:
            Onnx runtime provider to use
        config:
            Optional optimum config to use
        quantize:
            Whether to quantize the model
        extra_kwargs:
            Extra kwargs to pass to the onnx conversion (save_pretrained method for ort models)

    """

LightGBMModel

Bases: ModelInterface

Source code in python/opsml/model/_model.pyi
class LightGBMModel(ModelInterface):
    def __init__(
        self,
        model: Optional[Any] = None,
        preprocessor: Optional[Any] = None,
        sample_data: Optional[Any] = None,
        task_type: Optional[TaskType] = None,
        drift_profile: Optional[DriftProfileType] = None,
    ) -> None:
        """Instantiate a LightGBMModel interface

        Args:
            model:
                Model to associate with interface. This model must be a lightgbm booster.
            preprocessor:
                Preprocessor to associate with the model.
            sample_data:
                Sample data to use to make predictions
            task_type:
                The type of task the model performs
            drift_profile:
                Drift profile(s) to associate with the model. Must be a dictionary of
                alias and drift profile.
        """

    @property
    def preprocessor(self) -> Optional[Any]:
        """Returns the preprocessor"""

    @preprocessor.setter
    def preprocessor(self, preprocessor: Any) -> None:
        """Sets the preprocessor

        Args:
            preprocessor:
                Preprocessor to associate with the model. This preprocessor must be from the
                scikit-learn ecosystem
        """

    @property
    def preprocessor_name(self) -> Optional[str]:
        """Returns the preprocessor name"""

preprocessor property writable

Returns the preprocessor

preprocessor_name property

Returns the preprocessor name

__init__(model=None, preprocessor=None, sample_data=None, task_type=None, drift_profile=None)

Instantiate a LightGBMModel interface

Parameters:

Name Type Description Default
model Optional[Any]

Model to associate with interface. This model must be a lightgbm booster.

None
preprocessor Optional[Any]

Preprocessor to associate with the model.

None
sample_data Optional[Any]

Sample data to use to make predictions

None
task_type Optional[TaskType]

The type of task the model performs

None
drift_profile Optional[DriftProfileType]

Drift profile(s) to associate with the model. Must be a dictionary of alias and drift profile.

None
Source code in python/opsml/model/_model.pyi
def __init__(
    self,
    model: Optional[Any] = None,
    preprocessor: Optional[Any] = None,
    sample_data: Optional[Any] = None,
    task_type: Optional[TaskType] = None,
    drift_profile: Optional[DriftProfileType] = None,
) -> None:
    """Instantiate a LightGBMModel interface

    Args:
        model:
            Model to associate with interface. This model must be a lightgbm booster.
        preprocessor:
            Preprocessor to associate with the model.
        sample_data:
            Sample data to use to make predictions
        task_type:
            The type of task the model performs
        drift_profile:
            Drift profile(s) to associate with the model. Must be a dictionary of
            alias and drift profile.
    """

LightningModel

Bases: ModelInterface

Source code in python/opsml/model/_model.pyi
class LightningModel(ModelInterface):
    def __init__(
        self,
        trainer: Optional[Any] = None,
        preprocessor: Optional[Any] = None,
        sample_data: Optional[Any] = None,
        task_type: Optional[TaskType] = None,
        drift_profile: Optional[DriftProfileType] = None,
    ) -> None:
        """Interface for saving PyTorch Lightning models

        Args:
            trainer:
                Pytorch lightning trainer to associate with interface.
            preprocessor:
                Preprocessor to associate with model.
            sample_data:
                Sample data to use to convert to ONNX and make sample predictions. This data must be a
                pytorch-supported type. TorchData interface, torch tensor, torch dataset, Dict[str, torch.Tensor],
                List[torch.Tensor], Tuple[torch.Tensor].
            task_type:
                The intended task type of the model.
            drift_profile:
                Drift profile(s) to associate with the model. Must be a dictionary of
                alias and drift profile.
        """

    @property
    def trainer(self) -> None:
        """Returns the trainer"""

    @trainer.setter
    def trainer(self, trainer: Any) -> None:
        """Sets the trainer"""

    @property
    def preprocessor(self) -> Optional[Any]:
        """Returns the preprocessor"""

    @preprocessor.setter
    def preprocessor(self, preprocessor: Any) -> None:
        """Sets the preprocessor

        Args:
            preprocessor:
                Preprocessor to associate with the model. This preprocessor must be from the
                scikit-learn ecosystem
        """

    @property
    def preprocessor_name(self) -> Optional[str]:
        """Returns the preprocessor name"""

    def save(
        self,
        path: Path,
        save_kwargs: None | ModelSaveKwargs = None,
    ) -> ModelInterfaceMetadata:
        """Save the LightningModel interface. Lightning models are saved via checkpoints.

        Args:
            path (Path):
                Base path to save artifacts
            save_kwargs (ModelSaveKwargs):
                Optional kwargs to pass to the various underlying methods. This is a passthrough object meaning
                that the kwargs will be passed to the underlying methods as is and are expected to be supported by
                the underlying library.

                - model: Kwargs that will be passed to save_model. See save_model for more details.
                - preprocessor: Kwargs that will be passed to save_preprocessor
                - onnx: Library specific kwargs to pass to the onnx conversion. Independent of save_onnx.
                - save_onnx: Whether to save the onnx model. Defaults to false.
        """

preprocessor property writable

Returns the preprocessor

preprocessor_name property

Returns the preprocessor name

trainer property writable

Returns the trainer

__init__(trainer=None, preprocessor=None, sample_data=None, task_type=None, drift_profile=None)

Interface for saving PyTorch Lightning models

Parameters:

Name Type Description Default
trainer Optional[Any]

Pytorch lightning trainer to associate with interface.

None
preprocessor Optional[Any]

Preprocessor to associate with model.

None
sample_data Optional[Any]

Sample data to use to convert to ONNX and make sample predictions. This data must be a pytorch-supported type. TorchData interface, torch tensor, torch dataset, Dict[str, torch.Tensor], List[torch.Tensor], Tuple[torch.Tensor].

None
task_type Optional[TaskType]

The intended task type of the model.

None
drift_profile Optional[DriftProfileType]

Drift profile(s) to associate with the model. Must be a dictionary of alias and drift profile.

None
Source code in python/opsml/model/_model.pyi
def __init__(
    self,
    trainer: Optional[Any] = None,
    preprocessor: Optional[Any] = None,
    sample_data: Optional[Any] = None,
    task_type: Optional[TaskType] = None,
    drift_profile: Optional[DriftProfileType] = None,
) -> None:
    """Interface for saving PyTorch Lightning models

    Args:
        trainer:
            Pytorch lightning trainer to associate with interface.
        preprocessor:
            Preprocessor to associate with model.
        sample_data:
            Sample data to use to convert to ONNX and make sample predictions. This data must be a
            pytorch-supported type. TorchData interface, torch tensor, torch dataset, Dict[str, torch.Tensor],
            List[torch.Tensor], Tuple[torch.Tensor].
        task_type:
            The intended task type of the model.
        drift_profile:
            Drift profile(s) to associate with the model. Must be a dictionary of
            alias and drift profile.
    """

save(path, save_kwargs=None)

Save the LightningModel interface. Lightning models are saved via checkpoints.

Parameters:

Name Type Description Default
path Path

Base path to save artifacts

required
save_kwargs ModelSaveKwargs

Optional kwargs to pass to the various underlying methods. This is a passthrough object meaning that the kwargs will be passed to the underlying methods as is and are expected to be supported by the underlying library.

  • model: Kwargs that will be passed to save_model. See save_model for more details.
  • preprocessor: Kwargs that will be passed to save_preprocessor
  • onnx: Library specific kwargs to pass to the onnx conversion. Independent of save_onnx.
  • save_onnx: Whether to save the onnx model. Defaults to false.
None
Source code in python/opsml/model/_model.pyi
def save(
    self,
    path: Path,
    save_kwargs: None | ModelSaveKwargs = None,
) -> ModelInterfaceMetadata:
    """Save the LightningModel interface. Lightning models are saved via checkpoints.

    Args:
        path (Path):
            Base path to save artifacts
        save_kwargs (ModelSaveKwargs):
            Optional kwargs to pass to the various underlying methods. This is a passthrough object meaning
            that the kwargs will be passed to the underlying methods as is and are expected to be supported by
            the underlying library.

            - model: Kwargs that will be passed to save_model. See save_model for more details.
            - preprocessor: Kwargs that will be passed to save_preprocessor
            - onnx: Library specific kwargs to pass to the onnx conversion. Independent of save_onnx.
            - save_onnx: Whether to save the onnx model. Defaults to false.
    """

ModelInterface

Source code in python/opsml/model/_model.pyi
class ModelInterface:
    def __init__(
        self,
        model: Any = None,
        sample_data: Any = None,
        task_type: Optional[TaskType] = None,
        drift_profile: Optional[DriftProfileType] = None,
    ) -> None:
        """Base class for ModelInterface

        Args:
            model:
                Model to associate with interface.
            sample_data:
                Sample data to use to make predictions
            task_type:
                The type of task the model performs
            drift_profile:
                Drift profile(s) to associate with the model. Must be a dictionary of
                alias and drift profile.
        """

    @property
    def model(self) -> None | Any:
        """Returns the model"""

    @model.setter
    def model(self, model: Any) -> None:
        """Sets the model"""

    @property
    def sample_data(self) -> None | Any:
        """Returns the sample data"""

    @sample_data.setter
    def sample_data(self, sample_data: Any) -> None:
        """Sets the sample data"""

    @property
    def data_type(self) -> DataType:
        """Returns the task type"""

    @property
    def task_type(self) -> TaskType:
        """Returns the task type"""

    @property
    def schema(self) -> FeatureSchema:
        """Returns the feature schema"""

    @property
    def model_type(self) -> ModelType:
        """Returns the model type"""

    @property
    def interface_type(self) -> ModelInterfaceType:
        """Returns the model type"""

    @property
    def drift_profile(
        self,
    ) -> DriftProfileMap:
        """Returns the drift profile mapping"""

    @property
    def onnx_session(self) -> None | OnnxSession:
        """Returns the onnx session if it exists"""

    @onnx_session.setter
    def onnx_session(self, session: None | OnnxSession) -> None:
        """Sets the onnx session


        Args:
            session:
                Onnx session
        """

    @overload
    def create_drift_profile(
        self,
        alias: str,
        data: CustomMetric | List[CustomMetric],
        config: CustomMetricDriftConfig,
        data_type: Optional[DataType] = None,
    ) -> CustomDriftProfile: ...
    @overload
    def create_drift_profile(
        self,
        alias: str,
        data: Any,
        config: SpcDriftConfig,
        data_type: Optional[DataType] = None,
    ) -> SpcDriftProfile: ...
    @overload
    def create_drift_profile(
        self,
        alias: str,
        data: Any,
        config: PsiDriftConfig,
        data_type: Optional[DataType] = None,
    ) -> PsiDriftProfile: ...
    @overload
    def create_drift_profile(
        self,
        alias: str,
        data: Any,
        data_type: Optional[DataType] = None,
    ) -> SpcDriftProfile: ...
    def create_drift_profile(  # type: ignore
        self,
        alias: str,
        data: Any,
        config: None | SpcDriftConfig | PsiDriftConfig | CustomMetricDriftConfig = None,
        data_type: None | DataType = None,
    ) -> Any:
        """Create a drift profile and append it to the drift profile list

        Args:
            alias:
                Alias to use for the drift profile
            data:
                Data to use to create the drift profile. Can be a pandas dataframe,
                polars dataframe, pyarrow table or numpy array.
            config:
                Drift config to use. If None, defaults to SpcDriftConfig.
            data_type:
                Data type to use. If None, data_type will be inferred from the data.

        Returns:
            Drift profile SPcDriftProfile, PsiDriftProfile or CustomDriftProfile
        """

    def save(
        self,
        path: Path,
        save_kwargs: None | ModelSaveKwargs = None,
    ) -> ModelInterfaceMetadata:
        """Save the model interface

        Args:
            path (Path):
                Path to save the model
            save_kwargs (ModelSaveKwargs):
                Optional kwargs to pass to the various underlying methods. This is a passthrough object meaning
                that the kwargs will be passed to the underlying methods as is and are expected to be supported by
                the underlying library.

                - model: Kwargs that will be passed to save_model. See save_model for more details.
                - preprocessor: Kwargs that will be passed to save_preprocessor
                - onnx: Library specific kwargs to pass to the onnx conversion. Independent of save_onnx.
                - save_onnx: Whether to save the onnx model. Defaults to false.
        """

    def load(
        self,
        path: Path,
        metadata: ModelInterfaceSaveMetadata,
        load_kwargs: None | ModelLoadKwargs = None,
    ) -> None:
        """Load ModelInterface components

        Args:
            path (Path):
                Path to load the model
            metadata (ModelInterfaceSaveMetadata):
                Metadata to use to load the model
            load_kwargs (ModelLoadKwargs):
                Optional load kwargs to pass to the different load methods
        """

    @staticmethod
    def from_metadata(metadata: ModelInterfaceMetadata) -> "ModelInterface":
        """Create a ModelInterface from metadata

        Args:
            metadata:
                Model interface metadata

        Returns:
            Model interface
        """

data_type property

Returns the task type

drift_profile property

Returns the drift profile mapping

interface_type property

Returns the model type

model property writable

Returns the model

model_type property

Returns the model type

onnx_session property writable

Returns the onnx session if it exists

sample_data property writable

Returns the sample data

schema property

Returns the feature schema

task_type property

Returns the task type

__init__(model=None, sample_data=None, task_type=None, drift_profile=None)

Base class for ModelInterface

Parameters:

Name Type Description Default
model Any

Model to associate with interface.

None
sample_data Any

Sample data to use to make predictions

None
task_type Optional[TaskType]

The type of task the model performs

None
drift_profile Optional[DriftProfileType]

Drift profile(s) to associate with the model. Must be a dictionary of alias and drift profile.

None
Source code in python/opsml/model/_model.pyi
def __init__(
    self,
    model: Any = None,
    sample_data: Any = None,
    task_type: Optional[TaskType] = None,
    drift_profile: Optional[DriftProfileType] = None,
) -> None:
    """Base class for ModelInterface

    Args:
        model:
            Model to associate with interface.
        sample_data:
            Sample data to use to make predictions
        task_type:
            The type of task the model performs
        drift_profile:
            Drift profile(s) to associate with the model. Must be a dictionary of
            alias and drift profile.
    """

create_drift_profile(alias, data, config=None, data_type=None)

create_drift_profile(
    alias: str,
    data: CustomMetric | List[CustomMetric],
    config: CustomMetricDriftConfig,
    data_type: Optional[DataType] = None,
) -> CustomDriftProfile
create_drift_profile(
    alias: str,
    data: Any,
    config: SpcDriftConfig,
    data_type: Optional[DataType] = None,
) -> SpcDriftProfile
create_drift_profile(
    alias: str,
    data: Any,
    config: PsiDriftConfig,
    data_type: Optional[DataType] = None,
) -> PsiDriftProfile
create_drift_profile(
    alias: str,
    data: Any,
    data_type: Optional[DataType] = None,
) -> SpcDriftProfile

Create a drift profile and append it to the drift profile list

Parameters:

Name Type Description Default
alias str

Alias to use for the drift profile

required
data Any

Data to use to create the drift profile. Can be a pandas dataframe, polars dataframe, pyarrow table or numpy array.

required
config None | SpcDriftConfig | PsiDriftConfig | CustomMetricDriftConfig

Drift config to use. If None, defaults to SpcDriftConfig.

None
data_type None | DataType

Data type to use. If None, data_type will be inferred from the data.

None

Returns:

Type Description
Any

Drift profile SPcDriftProfile, PsiDriftProfile or CustomDriftProfile

Source code in python/opsml/model/_model.pyi
def create_drift_profile(  # type: ignore
    self,
    alias: str,
    data: Any,
    config: None | SpcDriftConfig | PsiDriftConfig | CustomMetricDriftConfig = None,
    data_type: None | DataType = None,
) -> Any:
    """Create a drift profile and append it to the drift profile list

    Args:
        alias:
            Alias to use for the drift profile
        data:
            Data to use to create the drift profile. Can be a pandas dataframe,
            polars dataframe, pyarrow table or numpy array.
        config:
            Drift config to use. If None, defaults to SpcDriftConfig.
        data_type:
            Data type to use. If None, data_type will be inferred from the data.

    Returns:
        Drift profile SPcDriftProfile, PsiDriftProfile or CustomDriftProfile
    """

from_metadata(metadata) staticmethod

Create a ModelInterface from metadata

Parameters:

Name Type Description Default
metadata ModelInterfaceMetadata

Model interface metadata

required

Returns:

Type Description
ModelInterface

Model interface

Source code in python/opsml/model/_model.pyi
@staticmethod
def from_metadata(metadata: ModelInterfaceMetadata) -> "ModelInterface":
    """Create a ModelInterface from metadata

    Args:
        metadata:
            Model interface metadata

    Returns:
        Model interface
    """

load(path, metadata, load_kwargs=None)

Load ModelInterface components

Parameters:

Name Type Description Default
path Path

Path to load the model

required
metadata ModelInterfaceSaveMetadata

Metadata to use to load the model

required
load_kwargs ModelLoadKwargs

Optional load kwargs to pass to the different load methods

None
Source code in python/opsml/model/_model.pyi
def load(
    self,
    path: Path,
    metadata: ModelInterfaceSaveMetadata,
    load_kwargs: None | ModelLoadKwargs = None,
) -> None:
    """Load ModelInterface components

    Args:
        path (Path):
            Path to load the model
        metadata (ModelInterfaceSaveMetadata):
            Metadata to use to load the model
        load_kwargs (ModelLoadKwargs):
            Optional load kwargs to pass to the different load methods
    """

save(path, save_kwargs=None)

Save the model interface

Parameters:

Name Type Description Default
path Path

Path to save the model

required
save_kwargs ModelSaveKwargs

Optional kwargs to pass to the various underlying methods. This is a passthrough object meaning that the kwargs will be passed to the underlying methods as is and are expected to be supported by the underlying library.

  • model: Kwargs that will be passed to save_model. See save_model for more details.
  • preprocessor: Kwargs that will be passed to save_preprocessor
  • onnx: Library specific kwargs to pass to the onnx conversion. Independent of save_onnx.
  • save_onnx: Whether to save the onnx model. Defaults to false.
None
Source code in python/opsml/model/_model.pyi
def save(
    self,
    path: Path,
    save_kwargs: None | ModelSaveKwargs = None,
) -> ModelInterfaceMetadata:
    """Save the model interface

    Args:
        path (Path):
            Path to save the model
        save_kwargs (ModelSaveKwargs):
            Optional kwargs to pass to the various underlying methods. This is a passthrough object meaning
            that the kwargs will be passed to the underlying methods as is and are expected to be supported by
            the underlying library.

            - model: Kwargs that will be passed to save_model. See save_model for more details.
            - preprocessor: Kwargs that will be passed to save_preprocessor
            - onnx: Library specific kwargs to pass to the onnx conversion. Independent of save_onnx.
            - save_onnx: Whether to save the onnx model. Defaults to false.
    """

ModelInterfaceMetadata

Source code in python/opsml/model/_model.pyi
class ModelInterfaceMetadata:
    task_type: TaskType
    model_type: ModelType
    data_type: DataType
    onnx_session: Optional[OnnxSession]
    schema: FeatureSchema
    save_metadata: ModelInterfaceSaveMetadata
    extra_metadata: dict[str, str]

    def __init__(
        self,
        save_metadata: ModelInterfaceSaveMetadata,
        task_type: TaskType = TaskType.Undefined,
        model_type: ModelType = ModelType.Unknown,
        data_type: DataType = DataType.NotProvided,
        schema: FeatureSchema = FeatureSchema(),
        onnx_session: Optional[OnnxSession] = None,
        extra_metadata: dict[str, str] = {},  # type: ignore
    ) -> None:
        """Define a model interface

        Args:
            task_type:
                Task type
            model_type:
                Model type
            data_type:
                Data type
            onnx_session:
                Onnx session
            schema:
                Feature schema
            data_type:
                Sample data type
            save_metadata:
                Save metadata
            extra_metadata:
                Extra metadata. Must be a dictionary of strings
        """

    def __str__(self) -> str:
        """Return the string representation of the model interface metadata"""

    def model_dump_json(self) -> str:
        """Dump the model interface metadata to json"""

    @staticmethod
    def model_validate_json(json_string: str) -> "ModelInterfaceMetadata":
        """Validate the model interface metadata json"""

__init__(save_metadata, task_type=TaskType.Undefined, model_type=ModelType.Unknown, data_type=DataType.NotProvided, schema=FeatureSchema(), onnx_session=None, extra_metadata={})

Define a model interface

Parameters:

Name Type Description Default
task_type TaskType

Task type

Undefined
model_type ModelType

Model type

Unknown
data_type DataType

Data type

NotProvided
onnx_session Optional[OnnxSession]

Onnx session

None
schema FeatureSchema

Feature schema

FeatureSchema()
data_type DataType

Sample data type

NotProvided
save_metadata ModelInterfaceSaveMetadata

Save metadata

required
extra_metadata dict[str, str]

Extra metadata. Must be a dictionary of strings

{}
Source code in python/opsml/model/_model.pyi
def __init__(
    self,
    save_metadata: ModelInterfaceSaveMetadata,
    task_type: TaskType = TaskType.Undefined,
    model_type: ModelType = ModelType.Unknown,
    data_type: DataType = DataType.NotProvided,
    schema: FeatureSchema = FeatureSchema(),
    onnx_session: Optional[OnnxSession] = None,
    extra_metadata: dict[str, str] = {},  # type: ignore
) -> None:
    """Define a model interface

    Args:
        task_type:
            Task type
        model_type:
            Model type
        data_type:
            Data type
        onnx_session:
            Onnx session
        schema:
            Feature schema
        data_type:
            Sample data type
        save_metadata:
            Save metadata
        extra_metadata:
            Extra metadata. Must be a dictionary of strings
    """

__str__()

Return the string representation of the model interface metadata

Source code in python/opsml/model/_model.pyi
def __str__(self) -> str:
    """Return the string representation of the model interface metadata"""

model_dump_json()

Dump the model interface metadata to json

Source code in python/opsml/model/_model.pyi
def model_dump_json(self) -> str:
    """Dump the model interface metadata to json"""

model_validate_json(json_string) staticmethod

Validate the model interface metadata json

Source code in python/opsml/model/_model.pyi
@staticmethod
def model_validate_json(json_string: str) -> "ModelInterfaceMetadata":
    """Validate the model interface metadata json"""

ModelInterfaceSaveMetadata

Source code in python/opsml/model/_model.pyi
class ModelInterfaceSaveMetadata:
    model_uri: Path
    data_processor_map: Dict[str, DataProcessor]
    sample_data_uri: Path
    onnx_model_uri: Optional[Path]
    drift_profile_uri_map: Optional[Dict[str, DriftProfileUri]]
    extra: Optional[ExtraMetadata]
    save_kwargs: Optional[ModelSaveKwargs]

    def __init__(
        self,
        model_uri: Path,
        data_processor_map: Optional[Dict[str, DataProcessor]] = {},  # type: ignore
        sample_data_uri: Optional[Path] = None,
        onnx_model_uri: Optional[Path] = None,
        drift_profile_uri_map: Optional[Dict[str, DriftProfileUri]] = None,
        extra: Optional[ExtraMetadata] = None,
        save_kwargs: Optional[ModelSaveKwargs] = None,
    ) -> None:
        """Define model interface save arguments

        Args:
            model_uri:
                Path to the model
            data_processor_map:
                Dictionary of data processors
            sample_data_uri:
                Path to the sample data
            onnx_model_uri:
                Path to the onnx model
            drift_profile_uri_map:
                Dictionary of drift profiles
            extra_metadata:
                Extra metadata
            save_kwargs:
                Optional save args
        """

    def __str__(self): ...
    def model_dump_json(self) -> str: ...

__init__(model_uri, data_processor_map={}, sample_data_uri=None, onnx_model_uri=None, drift_profile_uri_map=None, extra=None, save_kwargs=None)

Define model interface save arguments

Parameters:

Name Type Description Default
model_uri Path

Path to the model

required
data_processor_map Optional[Dict[str, DataProcessor]]

Dictionary of data processors

{}
sample_data_uri Optional[Path]

Path to the sample data

None
onnx_model_uri Optional[Path]

Path to the onnx model

None
drift_profile_uri_map Optional[Dict[str, DriftProfileUri]]

Dictionary of drift profiles

None
extra_metadata

Extra metadata

required
save_kwargs Optional[ModelSaveKwargs]

Optional save args

None
Source code in python/opsml/model/_model.pyi
def __init__(
    self,
    model_uri: Path,
    data_processor_map: Optional[Dict[str, DataProcessor]] = {},  # type: ignore
    sample_data_uri: Optional[Path] = None,
    onnx_model_uri: Optional[Path] = None,
    drift_profile_uri_map: Optional[Dict[str, DriftProfileUri]] = None,
    extra: Optional[ExtraMetadata] = None,
    save_kwargs: Optional[ModelSaveKwargs] = None,
) -> None:
    """Define model interface save arguments

    Args:
        model_uri:
            Path to the model
        data_processor_map:
            Dictionary of data processors
        sample_data_uri:
            Path to the sample data
        onnx_model_uri:
            Path to the onnx model
        drift_profile_uri_map:
            Dictionary of drift profiles
        extra_metadata:
            Extra metadata
        save_kwargs:
            Optional save args
    """

ModelLoadKwargs

Source code in python/opsml/model/_model.pyi
class ModelLoadKwargs:
    onnx: Optional[Dict]
    model: Optional[Dict]
    preprocessor: Optional[Dict]
    load_onnx: bool

    def __init__(
        self,
        onnx: Optional[Dict] = None,
        model: Optional[Dict] = None,
        preprocessor: Optional[Dict] = None,
        load_onnx: bool = False,
    ) -> None:
        """Optional arguments to pass to load_model

        Args:
            onnx (Dict):
                Optional onnx arguments to use when loading
            model (Dict):
                Optional model arguments to use when loading
            preprocessor (Dict):
                Optional preprocessor arguments to use when loading
            load_onnx (bool):
                Whether to load the onnx model. Defaults to false unless onnx args are
                provided. If true, the onnx model will be loaded.

        """

__init__(onnx=None, model=None, preprocessor=None, load_onnx=False)

Optional arguments to pass to load_model

Parameters:

Name Type Description Default
onnx Dict

Optional onnx arguments to use when loading

None
model Dict

Optional model arguments to use when loading

None
preprocessor Dict

Optional preprocessor arguments to use when loading

None
load_onnx bool

Whether to load the onnx model. Defaults to false unless onnx args are provided. If true, the onnx model will be loaded.

False
Source code in python/opsml/model/_model.pyi
def __init__(
    self,
    onnx: Optional[Dict] = None,
    model: Optional[Dict] = None,
    preprocessor: Optional[Dict] = None,
    load_onnx: bool = False,
) -> None:
    """Optional arguments to pass to load_model

    Args:
        onnx (Dict):
            Optional onnx arguments to use when loading
        model (Dict):
            Optional model arguments to use when loading
        preprocessor (Dict):
            Optional preprocessor arguments to use when loading
        load_onnx (bool):
            Whether to load the onnx model. Defaults to false unless onnx args are
            provided. If true, the onnx model will be loaded.

    """

ModelSaveKwargs

Source code in python/opsml/model/_model.pyi
class ModelSaveKwargs:
    def __init__(
        self,
        onnx: Optional[Dict | HuggingFaceOnnxArgs] = None,
        model: Optional[Dict] = None,
        preprocessor: Optional[Dict] = None,
        save_onnx: bool = False,
        drift: Optional[DriftArgs] = None,
    ) -> None:
        """Optional arguments to pass to save_model

        Args:
            onnx (Dict or HuggingFaceOnnxArgs):
                Optional onnx arguments to use when saving model to onnx format
            model (Dict):
                Optional model arguments to use when saving
            preprocessor (Dict):
                Optional preprocessor arguments to use when saving
            save_onnx (bool):
                Whether to save the onnx model. Defaults to false. This is independent of the
                onnx argument since it's possible to convert a model to onnx without additional kwargs.
                If onnx args are provided, this will be set to true.
            drift (DriftArgs):
                Optional drift args to use when saving and registering a model.
        """

    def __str__(self): ...
    def model_dump_json(self) -> str: ...
    @staticmethod
    def model_validate_json(json_string: str) -> "ModelSaveKwargs": ...

__init__(onnx=None, model=None, preprocessor=None, save_onnx=False, drift=None)

Optional arguments to pass to save_model

Parameters:

Name Type Description Default
onnx Dict or HuggingFaceOnnxArgs

Optional onnx arguments to use when saving model to onnx format

None
model Dict

Optional model arguments to use when saving

None
preprocessor Dict

Optional preprocessor arguments to use when saving

None
save_onnx bool

Whether to save the onnx model. Defaults to false. This is independent of the onnx argument since it's possible to convert a model to onnx without additional kwargs. If onnx args are provided, this will be set to true.

False
drift DriftArgs

Optional drift args to use when saving and registering a model.

None
Source code in python/opsml/model/_model.pyi
def __init__(
    self,
    onnx: Optional[Dict | HuggingFaceOnnxArgs] = None,
    model: Optional[Dict] = None,
    preprocessor: Optional[Dict] = None,
    save_onnx: bool = False,
    drift: Optional[DriftArgs] = None,
) -> None:
    """Optional arguments to pass to save_model

    Args:
        onnx (Dict or HuggingFaceOnnxArgs):
            Optional onnx arguments to use when saving model to onnx format
        model (Dict):
            Optional model arguments to use when saving
        preprocessor (Dict):
            Optional preprocessor arguments to use when saving
        save_onnx (bool):
            Whether to save the onnx model. Defaults to false. This is independent of the
            onnx argument since it's possible to convert a model to onnx without additional kwargs.
            If onnx args are provided, this will be set to true.
        drift (DriftArgs):
            Optional drift args to use when saving and registering a model.
    """

OnnxModel

Bases: ModelInterface

Source code in python/opsml/model/_model.pyi
class OnnxModel(ModelInterface):
    def __init__(
        self,
        model: Optional[Any] = None,
        sample_data: Optional[Any] = None,
        task_type: Optional[TaskType] = None,
        drift_profile: Optional[DriftProfileType] = None,
    ) -> None:
        """Interface for saving an OnnxModel

        Args:
            model:
                Onnx model to associate with the interface. This model must be an Onnx ModelProto
            sample_data:
                Sample data to use to make predictions
            task_type:
                The type of task the model performs
            drift_profile:
                Drift profile(s) to associate with the model. Must be a dictionary of
                alias and drift profile.

        Example:
            ```python
            from sklearn.datasets import load_iris  # type: ignore
            from sklearn.model_selection import train_test_split  # type: ignore
            from sklearn.ensemble import RandomForestClassifier  # type: ignore
            from skl2onnx import to_onnx  # type: ignore
            import onnxruntime as rt  # type: ignore

            iris = load_iris()

            X, y = iris.data, iris.target
            X = X.astype(np.float32)
            X_train, X_test, y_train, y_test = train_test_split(X, y)
            clr = RandomForestClassifier()
            clr.fit(X_train, y_train)

            onx = to_onnx(clr, X[:1])

            interface = OnnxModel(model=onx, sample_data=X_train)
            ```
        """

    @property
    def session(self) -> OnnxSession:
        """Returns the onnx session. This will error if the OnnxSession is not set"""

session property

Returns the onnx session. This will error if the OnnxSession is not set

__init__(model=None, sample_data=None, task_type=None, drift_profile=None)

Interface for saving an OnnxModel

Parameters:

Name Type Description Default
model Optional[Any]

Onnx model to associate with the interface. This model must be an Onnx ModelProto

None
sample_data Optional[Any]

Sample data to use to make predictions

None
task_type Optional[TaskType]

The type of task the model performs

None
drift_profile Optional[DriftProfileType]

Drift profile(s) to associate with the model. Must be a dictionary of alias and drift profile.

None
Example
from sklearn.datasets import load_iris  # type: ignore
from sklearn.model_selection import train_test_split  # type: ignore
from sklearn.ensemble import RandomForestClassifier  # type: ignore
from skl2onnx import to_onnx  # type: ignore
import onnxruntime as rt  # type: ignore

iris = load_iris()

X, y = iris.data, iris.target
X = X.astype(np.float32)
X_train, X_test, y_train, y_test = train_test_split(X, y)
clr = RandomForestClassifier()
clr.fit(X_train, y_train)

onx = to_onnx(clr, X[:1])

interface = OnnxModel(model=onx, sample_data=X_train)
Source code in python/opsml/model/_model.pyi
def __init__(
    self,
    model: Optional[Any] = None,
    sample_data: Optional[Any] = None,
    task_type: Optional[TaskType] = None,
    drift_profile: Optional[DriftProfileType] = None,
) -> None:
    """Interface for saving an OnnxModel

    Args:
        model:
            Onnx model to associate with the interface. This model must be an Onnx ModelProto
        sample_data:
            Sample data to use to make predictions
        task_type:
            The type of task the model performs
        drift_profile:
            Drift profile(s) to associate with the model. Must be a dictionary of
            alias and drift profile.

    Example:
        ```python
        from sklearn.datasets import load_iris  # type: ignore
        from sklearn.model_selection import train_test_split  # type: ignore
        from sklearn.ensemble import RandomForestClassifier  # type: ignore
        from skl2onnx import to_onnx  # type: ignore
        import onnxruntime as rt  # type: ignore

        iris = load_iris()

        X, y = iris.data, iris.target
        X = X.astype(np.float32)
        X_train, X_test, y_train, y_test = train_test_split(X, y)
        clr = RandomForestClassifier()
        clr.fit(X_train, y_train)

        onx = to_onnx(clr, X[:1])

        interface = OnnxModel(model=onx, sample_data=X_train)
        ```
    """

OnnxSchema

Source code in python/opsml/model/_model.pyi
class OnnxSchema:
    def __init__(
        self,
        input_features: FeatureSchema,
        output_features: FeatureSchema,
        onnx_version: str,
        feature_names: Optional[List[str]] = None,
    ) -> None:
        """Define an onnx schema

        Args:
            input_features (FeatureSchema):
                The input features of the onnx schema
            output_features (FeatureSchema):
                The output features of the onnx schema
            onnx_version (str):
                The onnx version of the schema
            feature_names (List[str] | None):
                The feature names and order for onnx.

        """

    def __str__(self) -> str:
        """Return a string representation of the OnnxSchema.

        Returns:
            String representation of the OnnxSchema.
        """

    @property
    def input_features(self) -> FeatureSchema:
        """Return the input features of the OnnxSchema."""

    @property
    def output_features(self) -> FeatureSchema:
        """Return the output features of the OnnxSchema."""

    @property
    def onnx_version(self) -> str:
        """Return the onnx version of the OnnxSchema."""

    @property
    def feature_names(self) -> List[str]:
        """Return the feature names and order for onnx."""

feature_names property

Return the feature names and order for onnx.

input_features property

Return the input features of the OnnxSchema.

onnx_version property

Return the onnx version of the OnnxSchema.

output_features property

Return the output features of the OnnxSchema.

__init__(input_features, output_features, onnx_version, feature_names=None)

Define an onnx schema

Parameters:

Name Type Description Default
input_features FeatureSchema

The input features of the onnx schema

required
output_features FeatureSchema

The output features of the onnx schema

required
onnx_version str

The onnx version of the schema

required
feature_names List[str] | None

The feature names and order for onnx.

None
Source code in python/opsml/model/_model.pyi
def __init__(
    self,
    input_features: FeatureSchema,
    output_features: FeatureSchema,
    onnx_version: str,
    feature_names: Optional[List[str]] = None,
) -> None:
    """Define an onnx schema

    Args:
        input_features (FeatureSchema):
            The input features of the onnx schema
        output_features (FeatureSchema):
            The output features of the onnx schema
        onnx_version (str):
            The onnx version of the schema
        feature_names (List[str] | None):
            The feature names and order for onnx.

    """

__str__()

Return a string representation of the OnnxSchema.

Returns:

Type Description
str

String representation of the OnnxSchema.

Source code in python/opsml/model/_model.pyi
def __str__(self) -> str:
    """Return a string representation of the OnnxSchema.

    Returns:
        String representation of the OnnxSchema.
    """

OnnxSession

Source code in python/opsml/model/_model.pyi
class OnnxSession:
    @property
    def schema(self) -> OnnxSchema:
        """Returns the onnx schema"""

    @property
    def session(self) -> Any:
        """Returns the onnx session"""

    @session.setter
    def session(self, session: Any) -> None:
        """Sets the onnx session

        Args:
            session:
                Onnx session
        """

    def run(
        self,
        input_feed: Dict[str, Any],
        output_names: Optional[list[str]] = None,
        run_options: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Run the onnx session

        Args:
            input_feed:
                Dictionary of input data
            output_names:
                List of output names
            run_options:
                Optional run options

        Returns:
            Output data
        """

    def model_dump_json(self) -> str:
        """Dump the onnx model to json"""

    @staticmethod
    def model_validate_json(json_string: str) -> "OnnxSession":
        """Validate the onnx model json"""

schema property

Returns the onnx schema

session property writable

Returns the onnx session

model_dump_json()

Dump the onnx model to json

Source code in python/opsml/model/_model.pyi
def model_dump_json(self) -> str:
    """Dump the onnx model to json"""

model_validate_json(json_string) staticmethod

Validate the onnx model json

Source code in python/opsml/model/_model.pyi
@staticmethod
def model_validate_json(json_string: str) -> "OnnxSession":
    """Validate the onnx model json"""

run(input_feed, output_names=None, run_options=None)

Run the onnx session

Parameters:

Name Type Description Default
input_feed Dict[str, Any]

Dictionary of input data

required
output_names Optional[list[str]]

List of output names

None
run_options Optional[Dict[str, Any]]

Optional run options

None

Returns:

Type Description
Any

Output data

Source code in python/opsml/model/_model.pyi
def run(
    self,
    input_feed: Dict[str, Any],
    output_names: Optional[list[str]] = None,
    run_options: Optional[Dict[str, Any]] = None,
) -> Any:
    """Run the onnx session

    Args:
        input_feed:
            Dictionary of input data
        output_names:
            List of output names
        run_options:
            Optional run options

    Returns:
        Output data
    """

SklearnModel

Bases: ModelInterface

Source code in python/opsml/model/_model.pyi
class SklearnModel(ModelInterface):
    def __init__(
        self,
        model: Optional[Any] = None,
        preprocessor: Optional[Any] = None,
        sample_data: Optional[Any] = None,
        task_type: Optional[TaskType] = None,
        drift_profile: Optional[DriftProfileType] = None,
    ) -> None:
        """Instantiate an SklearnModel interface

        Args:
            model:
                Model to associate with interface. This model must be from the
                scikit-learn ecosystem
            preprocessor:
                Preprocessor to associate with the model. This preprocessor must be from the
                scikit-learn ecosystem
            sample_data:
                Sample data to use to make predictions
            task_type:
                The type of task the model performs
            drift_profile:
                Drift profile(s) to associate with the model. Must be a dictionary of
                alias and drift profile.
        """

    @property
    def preprocessor(self) -> Optional[Any]:
        """Returns the preprocessor"""

    @preprocessor.setter
    def preprocessor(self, preprocessor: Any) -> None:
        """Sets the preprocessor

        Args:
            preprocessor:
                Preprocessor to associate with the model. This preprocessor must be from the
                scikit-learn ecosystem
        """

    @property
    def preprocessor_name(self) -> Optional[str]:
        """Returns the preprocessor name"""

preprocessor property writable

Returns the preprocessor

preprocessor_name property

Returns the preprocessor name

__init__(model=None, preprocessor=None, sample_data=None, task_type=None, drift_profile=None)

Instantiate an SklearnModel interface

Parameters:

Name Type Description Default
model Optional[Any]

Model to associate with interface. This model must be from the scikit-learn ecosystem

None
preprocessor Optional[Any]

Preprocessor to associate with the model. This preprocessor must be from the scikit-learn ecosystem

None
sample_data Optional[Any]

Sample data to use to make predictions

None
task_type Optional[TaskType]

The type of task the model performs

None
drift_profile Optional[DriftProfileType]

Drift profile(s) to associate with the model. Must be a dictionary of alias and drift profile.

None
Source code in python/opsml/model/_model.pyi
def __init__(
    self,
    model: Optional[Any] = None,
    preprocessor: Optional[Any] = None,
    sample_data: Optional[Any] = None,
    task_type: Optional[TaskType] = None,
    drift_profile: Optional[DriftProfileType] = None,
) -> None:
    """Instantiate an SklearnModel interface

    Args:
        model:
            Model to associate with interface. This model must be from the
            scikit-learn ecosystem
        preprocessor:
            Preprocessor to associate with the model. This preprocessor must be from the
            scikit-learn ecosystem
        sample_data:
            Sample data to use to make predictions
        task_type:
            The type of task the model performs
        drift_profile:
            Drift profile(s) to associate with the model. Must be a dictionary of
            alias and drift profile.
    """

TensorFlowModel

Bases: ModelInterface

Source code in python/opsml/model/_model.pyi
class TensorFlowModel(ModelInterface):
    def __init__(
        self,
        model: Optional[Any] = None,
        preprocessor: Optional[Any] = None,
        sample_data: Optional[Any] = None,
        task_type: Optional[TaskType] = None,
        drift_profile: Optional[DriftProfileType] = None,
    ) -> None:
        """Interface for saving PyTorch models

        Args:
            model:
                Model to associate with interface. This model must inherit from tensorflow.keras.Model
            preprocessor:
                Preprocessor to associate with model.
            sample_data:
                Sample data to use to convert to ONNX and make sample predictions. This data must be a
                tensorflow-supported type. numpy array, tf.Tensor, torch dataset, Dict[str, tf.Tensor],
                List[tf.Tensor], Tuple[tf.Tensor].
            task_type:
                The intended task type of the model.
            drift_profile:
                Drift profile(s) to associate with the model. Must be a dictionary of
                alias and drift profile.
        """

    @property
    def preprocessor(self) -> Optional[Any]:
        """Returns the preprocessor"""

    @preprocessor.setter
    def preprocessor(self, preprocessor: Any) -> None:
        """Sets the preprocessor

        Args:
            preprocessor:
                Preprocessor to associate with the model
        """

    @property
    def preprocessor_name(self) -> Optional[str]:
        """Returns the preprocessor name"""

preprocessor property writable

Returns the preprocessor

preprocessor_name property

Returns the preprocessor name

__init__(model=None, preprocessor=None, sample_data=None, task_type=None, drift_profile=None)

Interface for saving PyTorch models

Parameters:

Name Type Description Default
model Optional[Any]

Model to associate with interface. This model must inherit from tensorflow.keras.Model

None
preprocessor Optional[Any]

Preprocessor to associate with model.

None
sample_data Optional[Any]

Sample data to use to convert to ONNX and make sample predictions. This data must be a tensorflow-supported type. numpy array, tf.Tensor, torch dataset, Dict[str, tf.Tensor], List[tf.Tensor], Tuple[tf.Tensor].

None
task_type Optional[TaskType]

The intended task type of the model.

None
drift_profile Optional[DriftProfileType]

Drift profile(s) to associate with the model. Must be a dictionary of alias and drift profile.

None
Source code in python/opsml/model/_model.pyi
def __init__(
    self,
    model: Optional[Any] = None,
    preprocessor: Optional[Any] = None,
    sample_data: Optional[Any] = None,
    task_type: Optional[TaskType] = None,
    drift_profile: Optional[DriftProfileType] = None,
) -> None:
    """Interface for saving PyTorch models

    Args:
        model:
            Model to associate with interface. This model must inherit from tensorflow.keras.Model
        preprocessor:
            Preprocessor to associate with model.
        sample_data:
            Sample data to use to convert to ONNX and make sample predictions. This data must be a
            tensorflow-supported type. numpy array, tf.Tensor, torch dataset, Dict[str, tf.Tensor],
            List[tf.Tensor], Tuple[tf.Tensor].
        task_type:
            The intended task type of the model.
        drift_profile:
            Drift profile(s) to associate with the model. Must be a dictionary of
            alias and drift profile.
    """

TorchModel

Bases: ModelInterface

Source code in python/opsml/model/_model.pyi
class TorchModel(ModelInterface):
    def __init__(
        self,
        model: Optional[Any] = None,
        preprocessor: Optional[Any] = None,
        sample_data: Optional[Any] = None,
        task_type: Optional[TaskType] = None,
        drift_profile: Optional[DriftProfileType] = None,
    ) -> None:
        """Interface for saving PyTorch models

        Args:
            model:
                Model to associate with interface. This model must inherit from torch.nn.Module.
            preprocessor:
                Preprocessor to associate with model.
            sample_data:
                Sample data to use to convert to ONNX and make sample predictions. This data must be a
                pytorch-supported type. TorchData interface, torch tensor, torch dataset, Dict[str, torch.Tensor],
                List[torch.Tensor], Tuple[torch.Tensor].
            task_type:
                The intended task type of the model.
            drift_profile:
                Drift profile(s) to associate with the model. Must be a dictionary of
                alias and drift profile.
        """

    @property
    def preprocessor(self) -> Optional[Any]:
        """Returns the preprocessor"""

    @preprocessor.setter
    def preprocessor(self, preprocessor: Any) -> None:
        """Sets the preprocessor

        Args:
            preprocessor:
                Preprocessor to associate with the model. This preprocessor must be from the
                scikit-learn ecosystem
        """

    @property
    def preprocessor_name(self) -> Optional[str]:
        """Returns the preprocessor name"""

    def save(
        self,
        path: Path,
        save_kwargs: None | ModelSaveKwargs = None,
    ) -> ModelInterfaceMetadata:
        """Save the TorchModel interface. Torch models are saved
        as state_dicts as is the standard for PyTorch.

        Args:
            path (Path):
                Base path to save artifacts
            save_kwargs (ModelSaveKwargs):
                Optional kwargs to pass to the various underlying methods. This is a passthrough object meaning
                that the kwargs will be passed to the underlying methods as is and are expected to be supported by
                the underlying library.
        """

preprocessor property writable

Returns the preprocessor

preprocessor_name property

Returns the preprocessor name

__init__(model=None, preprocessor=None, sample_data=None, task_type=None, drift_profile=None)

Interface for saving PyTorch models

Parameters:

Name Type Description Default
model Optional[Any]

Model to associate with interface. This model must inherit from torch.nn.Module.

None
preprocessor Optional[Any]

Preprocessor to associate with model.

None
sample_data Optional[Any]

Sample data to use to convert to ONNX and make sample predictions. This data must be a pytorch-supported type. TorchData interface, torch tensor, torch dataset, Dict[str, torch.Tensor], List[torch.Tensor], Tuple[torch.Tensor].

None
task_type Optional[TaskType]

The intended task type of the model.

None
drift_profile Optional[DriftProfileType]

Drift profile(s) to associate with the model. Must be a dictionary of alias and drift profile.

None
Source code in python/opsml/model/_model.pyi
def __init__(
    self,
    model: Optional[Any] = None,
    preprocessor: Optional[Any] = None,
    sample_data: Optional[Any] = None,
    task_type: Optional[TaskType] = None,
    drift_profile: Optional[DriftProfileType] = None,
) -> None:
    """Interface for saving PyTorch models

    Args:
        model:
            Model to associate with interface. This model must inherit from torch.nn.Module.
        preprocessor:
            Preprocessor to associate with model.
        sample_data:
            Sample data to use to convert to ONNX and make sample predictions. This data must be a
            pytorch-supported type. TorchData interface, torch tensor, torch dataset, Dict[str, torch.Tensor],
            List[torch.Tensor], Tuple[torch.Tensor].
        task_type:
            The intended task type of the model.
        drift_profile:
            Drift profile(s) to associate with the model. Must be a dictionary of
            alias and drift profile.
    """

save(path, save_kwargs=None)

Save the TorchModel interface. Torch models are saved as state_dicts as is the standard for PyTorch.

Parameters:

Name Type Description Default
path Path

Base path to save artifacts

required
save_kwargs ModelSaveKwargs

Optional kwargs to pass to the various underlying methods. This is a passthrough object meaning that the kwargs will be passed to the underlying methods as is and are expected to be supported by the underlying library.

None
Source code in python/opsml/model/_model.pyi
def save(
    self,
    path: Path,
    save_kwargs: None | ModelSaveKwargs = None,
) -> ModelInterfaceMetadata:
    """Save the TorchModel interface. Torch models are saved
    as state_dicts as is the standard for PyTorch.

    Args:
        path (Path):
            Base path to save artifacts
        save_kwargs (ModelSaveKwargs):
            Optional kwargs to pass to the various underlying methods. This is a passthrough object meaning
            that the kwargs will be passed to the underlying methods as is and are expected to be supported by
            the underlying library.
    """

XGBoostModel

Bases: ModelInterface

Source code in python/opsml/model/_model.pyi
class XGBoostModel(ModelInterface):
    def __init__(
        self,
        model: Optional[Any] = None,
        preprocessor: Optional[Any] = None,
        sample_data: Optional[Any] = None,
        task_type: Optional[TaskType] = None,
        drift_profile: Optional[DriftProfileType] = None,
    ) -> None:
        """Interface for saving XGBoost Booster models

        Args:
            model:
                Model to associate with interface. This model must be an xgboost booster.
            preprocessor:
                Preprocessor to associate with the model.
            sample_data:
                Sample data to use to make predictions.
            task_type:
                The type of task the model performs
            drift_profile:
                Drift profile(s) to associate with the model. Must be a dictionary of
                alias and drift profile.
        """

    @property
    def preprocessor(self) -> Optional[Any]:
        """Returns the preprocessor"""

    @preprocessor.setter
    def preprocessor(self, preprocessor: Any) -> None:
        """Sets the preprocessor

        Args:
            preprocessor:
                Preprocessor to associate with the model. This preprocessor must be from the
                scikit-learn ecosystem
        """

    @property
    def preprocessor_name(self) -> Optional[str]:
        """Returns the preprocessor name"""

preprocessor property writable

Returns the preprocessor

preprocessor_name property

Returns the preprocessor name

__init__(model=None, preprocessor=None, sample_data=None, task_type=None, drift_profile=None)

Interface for saving XGBoost Booster models

Parameters:

Name Type Description Default
model Optional[Any]

Model to associate with interface. This model must be an xgboost booster.

None
preprocessor Optional[Any]

Preprocessor to associate with the model.

None
sample_data Optional[Any]

Sample data to use to make predictions.

None
task_type Optional[TaskType]

The type of task the model performs

None
drift_profile Optional[DriftProfileType]

Drift profile(s) to associate with the model. Must be a dictionary of alias and drift profile.

None
Source code in python/opsml/model/_model.pyi
def __init__(
    self,
    model: Optional[Any] = None,
    preprocessor: Optional[Any] = None,
    sample_data: Optional[Any] = None,
    task_type: Optional[TaskType] = None,
    drift_profile: Optional[DriftProfileType] = None,
) -> None:
    """Interface for saving XGBoost Booster models

    Args:
        model:
            Model to associate with interface. This model must be an xgboost booster.
        preprocessor:
            Preprocessor to associate with the model.
        sample_data:
            Sample data to use to make predictions.
        task_type:
            The type of task the model performs
        drift_profile:
            Drift profile(s) to associate with the model. Must be a dictionary of
            alias and drift profile.
    """