kempnerforge.metrics.mlflow.publish¶
Append eval metrics to the MLflow run a checkpoint was trained under.
A checkpoint’s metadata.json records the tracking backends that were active when
it was saved. publish_metrics reads the MLflow entry and appends the metrics to
that run at the checkpoint’s step in a single log_batch request, linked to the
checkpoint’s logged model when the entry names one. Inputs are fully validated before
anything is sent, but MLflow’s log_batch permits partial writes, so a request that
fails server side may still have stored some points. The publisher never starts, ends,
or edits a run, never writes the sidecar, and keeps no state of its own, so several
publishers can write to one run at once and the tracking server arbitrates. The call
blocks on the server under MLflow’s own HTTP timeout and retry settings, and
authentication is whatever the MLflow client finds in the environment. It is an offline
tool: call it from one process, never from the training step.
Command line: python -m kempnerforge.metrics.mlflow.publish <checkpoint_dir> --metrics <json>.
Functions
|
Command-line entry point; returns the exit code: 0 published, 2 refused, 1 failed. |
|
Append |
|
Read the MLflow run a checkpoint was trained under from its |
Classes
The MLflow run a checkpoint was trained under, as its sidecar records it. |
Exceptions
Nothing was published: the sidecar, the metrics, or the environment is unusable. |
- exception kempnerforge.metrics.mlflow.publish.PublishRefused[source]¶
Bases:
ValueErrorNothing was published: the sidecar, the metrics, or the environment is unusable.
- class kempnerforge.metrics.mlflow.publish.MlflowTarget[source]¶
Bases:
objectThe MLflow run a checkpoint was trained under, as its sidecar records it.
- kempnerforge.metrics.mlflow.publish.read_mlflow_target(checkpoint_dir)[source]¶
Read the MLflow run a checkpoint was trained under from its
metadata.json.The sidecar needs a non-negative integer
stepand atrackinglist holding exactly one entry withbackend == "mlflow"whoserun_id,experimentandtracking_uriare non-empty strings.model_idandmodel_nameare optional, and non-empty strings when present. A key repeated anywhere in the file is refused, since the last value would silently win. For a Databricks URI it also prepares auth inos.environfor the whole process, the way the training backend does, so artifact uploads made later in the same process authenticate like the tracking client.- Raises:
PublishRefused – Naming each missing or malformed item; nothing is inferred.
- Parameters:
- Return type:
- kempnerforge.metrics.mlflow.publish.publish_metrics(checkpoint_dir, metrics, prefix='eval/')[source]¶
Append
metricsto the MLflow run a checkpoint was trained under.Every metric is logged as
<prefix><name>at the checkpoint’s step by oneMlflowClient.log_batchrequest, on a client bound to the sidecar’s tracking URI (the process-wide MLflow tracking URI is left alone). When the installed MLflow can link metrics to a logged model, they are linked to the sidecar entry’smodel_id; without one, to the run’s model named by itsmodel_namethatfind_or_create_checkpoint_modelsettles on (finishing it if PENDING), which is created (an external model of this checkpoint directory) when the run has none. Otherwise, or when the installed MLflow cannot link, the metrics are published unlinked.- Parameters:
- Returns:
The target the metrics were appended to, with the
model_idthey were linked to (None when unlinked).- Raises:
PublishRefused – The sidecar or the metrics are missing or malformed, mlflow is not installed, or no model can be linked (the sidecar entry gives none, or the installed MLflow cannot link one) while this process has an active MLflow model (which
log_batchwould silently link); nothing was sent. Errors raised by MLflow itself (an invalid metric name, an unreachable server) propagate as raised; a request that fails server side may still have stored some of its points.- Return type: