personalitylinmult.inference.mlflow_pyfunc

Wrap an FI checkpoint as an MLflow pyfunc model and register it.

Training logs raw .ckpt artifacts, which mlflow models serve cannot load on their own. This module wraps a checkpoint in the standard pyfunc flavour — a self-contained model MLflow can serve as a REST endpoint or bake into a Docker image — and registers it in the Model Registry so it carries a version.

Promotion uses aliases (set_champion()), not the deprecated Staging / Production stage mechanism: an alias is scoped to one registered-model name, so each model family (e.g. the AVT fusion model and the audio-only model) keeps its own independent @champion without any conflict, and moving the alias to a new version is a single, deliberate call – never automatic on registration.

The wrapped model consumes the same per-modality features as FiPredictor: at serving time the JSON payload is {"inputs": {"wavlm": [[...]], "emotion2vec": [[...]]}} — one (T, F) array per feature the model expects.

Attributes

logger

Module-level logger.

REGISTRATION_EXPERIMENT

Experiment the pyfunc registration runs log under.

Classes

FiPyfunc

An mlflow.pyfunc.PythonModel around an FI checkpoint.

Functions

log_and_register(→ str)

Log the checkpoint as a pyfunc model and register it.

set_champion(→ None)

Promote a registered version to an alias.

Module Contents

personalitylinmult.inference.mlflow_pyfunc.logger

Module-level logger.

class personalitylinmult.inference.mlflow_pyfunc.FiPyfunc[source]

An mlflow.pyfunc.PythonModel around an FI checkpoint.

Not typed as a subclass at import time so this module stays importable without mlflow installed; log_and_register() binds it to mlflow.pyfunc.PythonModel where mlflow is guaranteed present.

load_context(context: Any) → None[source]

Load the checkpoint packaged with the model.

Parameters:

context – MLflow context; context.artifacts['checkpoint'] is the packaged .ckpt path.

predict(context: Any, model_input: Any, params: Any = None) → list[dict[str, float]][source]

Predict Big Five scores for one or more samples.

Parameters:
  • context – MLflow context (unused; the model is already loaded).

  • model_input – A {feature_name: (T, F) array} mapping for one sample, or a list of such mappings for a batch.

  • params – Optional inference params (unused).

Returns:

One {trait: score} dict per input sample.

Return type:

list[dict[str, float]]

personalitylinmult.inference.mlflow_pyfunc.REGISTRATION_EXPERIMENT = 'FI-Model-Registry'

Experiment the pyfunc registration runs log under.

Set explicitly so registration never falls back to the default experiment (id 0), which may be in a deleted state and would reject a new run.

personalitylinmult.inference.mlflow_pyfunc.log_and_register(checkpoint: str | pathlib.Path, registered_model_name: str, run_id: str | None = None, artifact_path: str = 'pyfunc_model', experiment: str = REGISTRATION_EXPERIMENT) → str[source]

Log the checkpoint as a pyfunc model and register it.

Parameters:
  • checkpoint (str | Path) – Path to the .ckpt to wrap.

  • registered_model_name (str) – Name in the Model Registry (e.g. "fi-bigfive-avt").

  • run_id (str | None) – Existing run to log under; a new run is started under experiment when None.

  • artifact_path (str) – Artifact subpath for the model.

  • experiment (str) – Experiment to log the registration run under when run_id is None.

Returns:

The registered model version.

Return type:

str

Raises:

FileNotFoundError – If the checkpoint does not exist.

personalitylinmult.inference.mlflow_pyfunc.set_champion(registered_model_name: str, version: str, alias: str = 'champion') → None[source]

Promote a registered version to an alias.

A deliberate, separate step from registration: a new version is never auto-promoted, so a run finishing (or even being registered) never silently changes what a deployment currently serves. Aliases are per registered-model name, so multiple model families (AVT, audio-only, …) each carry their own independent @champion with no conflict.

Parameters:
  • registered_model_name (str) – The registered model name.

  • version (str) – The version to promote.

  • alias (str) – Alias to set. Defaults to "champion"; a second alias (e.g. "candidate") can stage a version before promoting it.