Skip to content

Entity and methods

Model

Bases: MaterialEntity

A class representing a model.

Source code in digitalhub_ml/entities/model/entity/_base.py
class Model(MaterialEntity):
    """
    A class representing a model.
    """

    ENTITY_TYPE = EntityTypes.MODEL.value

    def __init__(
        self,
        project: str,
        name: str,
        uuid: str,
        kind: str,
        metadata: Metadata,
        spec: ModelSpec,
        status: ModelStatus,
        user: str | None = None,
    ) -> None:
        super().__init__(project, name, uuid, kind, metadata, spec, status, user)
        self.spec: ModelSpec
        self.status: ModelStatus

ModelModel

Bases: Model

Model model.

Source code in digitalhub_ml/entities/model/entity/model.py
6
7
8
9
class ModelModel(Model):
    """
    Model model.
    """

ModelMlflow

Bases: Model

Mlflow model.

Source code in digitalhub_ml/entities/model/entity/mlflow.py
6
7
8
9
class ModelMlflow(Model):
    """
    Mlflow model.
    """

ModelSklearn

Bases: Model

SKLearn model.

Source code in digitalhub_ml/entities/model/entity/sklearn.py
6
7
8
9
class ModelSklearn(Model):
    """
    SKLearn model.
    """

ModelHuggingface

Bases: Model

Huggingface model.

Source code in digitalhub_ml/entities/model/entity/huggingface.py
6
7
8
9
class ModelHuggingface(Model):
    """
    Huggingface model.
    """

model_from_dict(obj)

Create a new object from dictionary.

Parameters:

Name Type Description Default
obj dict

Dictionary to create object from.

required

Returns:

Type Description
Model

Object instance.

Source code in digitalhub_ml/entities/model/builder.py
def model_from_dict(obj: dict) -> Model:
    """
    Create a new object from dictionary.

    Parameters
    ----------
    obj : dict
        Dictionary to create object from.

    Returns
    -------
    Model
        Object instance.
    """
    kind = obj.get("kind")
    cls = _choose_model_type(kind)
    return cls.from_dict(obj)

model_from_parameters(project, name, kind, uuid=None, description=None, labels=None, embedded=True, path=None, **kwargs)

Create a new object.

Parameters:

Name Type Description Default
project str

Project name.

required
name str

Object name.

required
kind str

Kind the object.

required
uuid str

ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).

None
labels list[str]

List of labels.

None
description str

Description of the object (human readable).

None
embedded bool

Flag to determine if object spec must be embedded in project spec.

True
path str

Object path on local file system or remote storage. It is also the destination path of upload() method.

None
**kwargs dict

Spec keyword arguments.

{}

Returns:

Type Description
Model

Object instance.

Source code in digitalhub_ml/entities/model/builder.py
def model_from_parameters(
    project: str,
    name: str,
    kind: str,
    uuid: str | None = None,
    description: str | None = None,
    labels: list[str] | None = None,
    embedded: bool = True,
    path: str | None = None,
    **kwargs,
) -> Model:
    """
    Create a new object.

    Parameters
    ----------
    project : str
        Project name.
    name : str
        Object name.
    kind : str
        Kind the object.
    uuid : str
        ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
    labels : list[str]
        List of labels.
    description : str
        Description of the object (human readable).
    embedded : bool
        Flag to determine if object spec must be embedded in project spec.
    path : str
        Object path on local file system or remote storage. It is also the destination path of upload() method.
    **kwargs : dict
        Spec keyword arguments.

    Returns
    -------
    Model
        Object instance.
    """
    if path is None:
        raise EntityError("Path must be provided.")
    name = build_name(name)
    uuid = build_uuid(uuid)
    metadata = build_metadata(
        kind,
        project=project,
        name=name,
        version=uuid,
        description=description,
        labels=labels,
        embedded=embedded,
    )
    spec = build_spec(
        kind,
        path=path,
        **kwargs,
    )
    status = build_status(kind)
    cls = _choose_model_type(kind)
    return cls(
        project=project,
        name=name,
        uuid=uuid,
        kind=kind,
        metadata=metadata,
        spec=spec,
        status=status,
    )