ArtifactSchemaDataset

pydantic model mlopus.kedro.ArtifactSchemaDataset[source]

Bases: MlflowRunMixin, EmptyStrAsMissing, EmptyDictAsMissing, ExcludeEmptyMixin, AbstractDataset[A, A], Generic[A, D, L]

Saves/loads data using inferred or explicitly specified artifact schema.

See also

Usage with explicit schema

# conf/<env>/catalog.yml
model:
    type: mlopus.kedro.ArtifactSchemaDataset
    path: data/model
    schema: my_package.artschema:TorchModelSchema  # fully qualified class name

Usage with inferred schema

  1. Register the schema in the model’s tags (also valid for experiments, runs and model versions):

    import mlopus
    
    mlopus.artschema.Tags() \
        .with(
            my_package.artschema.TorchModelSchema,
            aliased_as="torch_model",
        ) \
        .register(
            mlopus.mlflow.get_api().get_or_create_model("my_lang_model")
        )
    
  2. Reference the schema by alias:

    # conf/<env>/catalog.yml
    model:
        type: mlopus.kedro.ArtifactSchemaDataset
        path: data/model
        schema: torch_model                   # Get schema with this alias
        subject: {model_name: my_lang_model}  # from this model's tags
        mlflow: ${globals:mlflow}             # using this MLflow API handle.
    
field dumper: Optional[dict] = None

See dumper

field loader: Optional[dict] = None

See loader

field overwrite: bool = True

Overwrite path if exists.

field path: Path [Required]

Target path for saving/loading artifact file or dir.

field run_manager: MlflowRunManager | None [Required] (alias 'mlflow')

Instance or dict to be parsed into instance of MlflowRunManager

field schema_: Union[str, None, Schema, Type[Schema]] [Required] (alias 'schema')

See schema

field skip_reqs_check: bool = False

See skip_reqs_check

field subject: UnionType[ExpSubject, RunSubject, ModelSubject, None] = None

If schema_ is an alias to a previously registered artifact schema, load the respective schema class from this subject’s tags. See also parse_subject().

class Config

Bases: object

Pydantic class config.

pydantic model mlopus.kedro.datasets.artschema.ExpSubject[source]

Bases: SchemaSubject[ExpApi]

Specifies an experiment as subject for artifact schema inferrence.

field exp_name: str [Required]

Experiment name. Defaults to the experiment used in the run_manager

pydantic model mlopus.kedro.datasets.artschema.RunSubject[source]

Bases: SchemaSubject[RunApi]

Specifies a run as subject for artifact schema inferrence.

field run_id: str [Required]

Run ID. Defaults to the run used in the run_manager

pydantic model mlopus.kedro.datasets.artschema.ModelSubject[source]

Bases: SchemaSubject[~M]

Specifies a registered model or model version as subject for artifact schema inferrence.

field model_name: str [Required]

Registered model name.

field model_version: Optional[str] = None

Model version.