Framework
- mlopus.artschema.framework.A
Invariant
TypeVar
bound toobject
.Type of artifact
- mlopus.artschema.framework.D
Invariant
TypeVar
bound tomlopus.artschema.framework.Dumper
.Type of
Dumper
- mlopus.artschema.framework.L
Invariant
TypeVar
bound tomlopus.artschema.framework.Loader
.Type of
Loader
- pydantic model mlopus.artschema.Dumper[source]
Bases:
BaseModel
,BaseParamsMixin
,ABC
,Generic
[A
]Base class for artifact dumpers.
- dump(path, artifact, overwrite=False)[source]
Save artifact to
path
as file or dir.If possible, also saves a file with this dumper’s conf.
- pydantic model mlopus.artschema.Loader[source]
Bases:
BaseModel
,BaseParamsMixin
,ABC
,Generic
[A
,D
]Base class for artifact loaders.
- abstract _load(path, dumper)[source]
Load artifact from
path
.- Parameters:
- Return type:
Union
[TypeVar
(A
, bound=object
),dict
]- Returns:
- load(path, dry_run=False)[source]
Load artifact from
path
.As a side effect, this will use a
Dumper
toverify()
thepath
. Ifpath
is a dir containing a dumper conf file, the usedDumper
is equivalent to the one that was originally used to save the artifact. Otherwise, it’s aDumper
initialized with empty params.
- pydantic model mlopus.artschema.Schema[source]
Bases:
BaseModel
,BaseParamsMixin
,Generic
[A
,D
,L
]Base class for artifact schemas.
Serves for putting together the types of
Artifact
,Dumper
andLoader
.Example:
class Artifact(pydantic.BaseModel): some_data: dict[str, str] class Dumper(mlopus.artschema.Dumper[Artifact]): encoding: str = "UTF-8" def _dump(self, path: Path, artifact: A) -> None: # save `artifact.some_data` inside `path` using `self.encoding` class Loader(mlopus.artschema.Loader[Artifact, Dumper]): max_files: int | None = None def _load(self, path: Path, dumper: Dumper) -> Artifact: # load instance of `Artifact` from `path` using `self.max_files` and `dumper.encoding` class Schema(mlopus.artschema.Schema[Artifact, Dumper, Loader]): pass # No methods needed here, but the type params are important! # Instantiate artifact = Artifact(some_data={...}) # Dump dumper = Schema().get_dumper(artifact, encoding="...") dumper(path) # Load loader = Schema().get_loader(max_files=3) loader(path) # Returns: Artifact # Combine with MlflowApi with mlopus.mlflow \ .get_api(...) \ .get_exp(...) \ .start_run(...): run.log_artifact(dumper, path_in_run="foobar") run.load_artifact(loader, path_in_run="foobar") # Same applies when using `log_model_version` and `load_model_artifact`
- get_dumper(artifact, dumper=None, **dumper_kwargs)[source]
Get a dumper callback.