Model Registry
The Model Registry is a centralized repository where your trained machine learning models are stored, versioned, and prepared for deployment. Models enter the registry primarily through the mlflow tracking integration.
Registering a Model
To ensure maximum interoperability and performance, we recommend exporting models to the ONNX format. Below is a practical example using a small, public dataset (Iris) to train a model and push it to the Model Registry.
The following script trains a simple classifier and logs it as an ONNX artifact.
import mlflow
import mlflow.onnx
import onnx
import numpy as np
from mlflow.models.signature import ModelSignature
from mlflow.types.schema import Schema, TensorSpec
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from skl2onnx import convert_sklearn
from skl2onnx.common.data_types import FloatTensorType
# 1. Prepare data and train a small model
iris = load_iris()
X, y = iris.data, iris.target
model = RandomForestClassifier(n_estimators=10)
model.fit(X, y)
input_schema = Schema([
TensorSpec(np.dtype(np.float32), [1, 4], name="float_input")
])
output_schema = Schema([
TensorSpec(np.dtype(np.int64), [-1], name="label")
])
signature = ModelSignature(inputs=input_schema, outputs=output_schema)
# 2. Convert the Scikit-learn model to ONNX format
initial_type = [('float_input', FloatTensorType([None, 4]))]
options = {type(model): {'zipmap': False}}
onnx_model = convert_sklearn(model, initial_types=initial_type, options=options, target_opset=17)
mlflow.set_experiment("test-experiment")
# Add or update tags to the created experiment.
mlflow.set_experiment_tags({
"project_name": "Fraud Prevention",
"team": "Data Science Core",
"priority": "High"
})
# 3. Log to Fathom via MLflow
with mlflow.start_run():
# Log hyperparameters for context
mlflow.log_param("n_estimators", 10)
# You can tag each run under an experiment independently.
mlflow:set_tag("version", "1.0")
# Register the model in the registry
mlflow.onnx.log_model(
onnx_model=onnx_model,
artifact_path="iris_classifier",
signature=signature,
input_example=X[:1]
)
print("Model successfully pushed to the Fathom Registry.")
Dependencies
To use the example above, ensure you have the conversion libraries installed in your environment:
pip install skl2onnx onnxruntime
Why Signatures Matter
A missing or incorrect signature is the most common cause of Deployment Failures. The platform requires exact tensor specifications (dtype and shape) to prepare the serving infrastructure.Version Compatibility
Unsupported model IR version? If your deployment fails with an “Unsupported IR version” error, it means your local onnx library is newer than the platform’s runtime. Fix: Always specify target_opset=17 (or lower) when converting models to ONNX to ensure compatibility with the production Inference Engine.Dimension Mismatch (1 vs 2)
If your deployment fails with a “1 dimension vs 2” error, it means the auto-batching logic is conflicting with your flat ONNX model. Fix: Set the first dimension of your input to a fixed number (e.g., 1) in the TensorSpec. This disables implicit batching, allowing the engine to map your 1D model correctly.Naming Convention
The default output name for Scikit-learn classifiers in ONNX is label. Ensure your output_schema uses this exact name. Using custom names like output_label will result in an Invalid argument error during inference.Execution
Run the script using the Fathom CLI to ensure the registry context is correctly injected:
fathom intelligence mlflow run python3 train_onnx.py
Listing models
Once the script finishes, you can confirm that the model was received and stored correctly by querying the platform’s model list. This ensures your model is now an immutable asset ready for deployment.
fathom intelligence machine-learning model list