EasyMLOps

Model Versioning

MLOps

Easy

Problem

Select one model record for production using three ordered criteria: highest accuracy, then lowest latency, then latest ISO-format timestamp. Dates use YYYY-MM-DD, so their strings can be compared chronologically. Return only the selected model’s name.

Theory

In any serious ML system, you will have multiple model versions. Each time you retrain, experiment with new features, or tune hyperparameters, you create a new candidate. But only one model can serve production traffic at a time. How do you decide which one to promote?

This is the core challenge of model versioning: tracking model artifacts, their performance metrics, and making principled promotion decisions.


What is a Model Registry?

A model registry is a centralized repository that stores:

Popular tools like MLflow, Weights & Biases, and cloud-native solutions (AWS SageMaker, Azure ML, Vertex AI) all provide model registry functionality.

The registry enables teams to:


The Promotion Decision

When choosing which model to promote, you typically consider multiple factors in a prioritized order:

1. Primary metric (Accuracy): The model core performance measure. Higher accuracy means better predictions. This is almost always the first filter.

2. Secondary metric (Latency): How fast the model responds. In real-time systems, a slightly less accurate model that responds in 10ms may be preferable to a more accurate model that takes 500ms.

3. Recency (Timestamp): All else being equal, newer models are preferred. They were trained on more recent data and reflect the latest code improvements.


Multi-Criteria Comparison

When comparing models, you create a ranking based on multiple criteria. The key insight is that criteria have priorities:

\text{Best Model} = \arg\max_m \left( \text{accuracy}(m), -\text{latency}(m), \text{timestamp}(m) \right)

The negative sign on latency converts "lower is better" to "higher is better" for consistent comparison.

This is a lexicographic ordering: first sort by accuracy (descending), then by latency (ascending), then by timestamp (descending). The first model in this sorted order is the winner.


Step-by-Step Selection Process

Given a list of model versions, each with (name, accuracy, latency, timestamp):

Step 1: Sort all models by accuracy in descending order (highest first)

Step 2: Among models with equal accuracy, sort by latency in ascending order (lowest first)

Step 3: Among models with equal accuracy AND latency, sort by timestamp in descending order (most recent first)

Step 4: The first model in this sorted list is promoted to production


A Concrete Example

Consider three model versions:

Step 1: Sort by accuracy descending

Step 2: v2 and v3 are tied on accuracy. Sort them by latency ascending:

Result: v3 is promoted. It has the highest accuracy AND the lowest latency among top-accuracy models.


Why Not Just Use Accuracy?

If accuracy were the only metric, you could deploy a model that takes 30 seconds per prediction. In production, this creates:

Similarly, if you only optimized for latency, you might deploy a trivial model that always predicts the majority class.

The multi-criteria approach balances these trade-offs systematically.


Where Model Versioning Shows Up

Continuous Training Pipelines: Automated systems that retrain models daily or weekly need automated promotion logic to decide when a new model is ready.

A/B Testing: Before full promotion, a new model version might be deployed to a small percentage of traffic. The registry tracks which version is in each stage.

Rollbacks: When a production issue is detected, the registry provides the previous stable version to roll back to immediately.

Compliance and Auditing: Regulated industries require documentation of which model version made which predictions, and why it was chosen over alternatives.

Examples

Example 1

Input
models = [{"name": "v1", "accuracy": 0.85, "latency": 120, "timestamp": "2024-01-15"}, {"name": "v2", "accuracy": 0.91, "latency": 95, "timestamp": "2024-02-20"}]
Output
"v2"
Explanation
Accuracy is the primary criterion, and v2 has the higher value.

Example 2

Input
models = [{"name": "v1", "accuracy": 0.9, "latency": 100, "timestamp": "2024-01-10"}, {"name": "v2", "accuracy": 0.9, "latency": 80, "timestamp": "2024-03-05"}]
Output
"v2"

Hints

  1. Maintain the best record while scanning the list once.
  2. Compare accuracy first, then latency only on a tie, then timestamp only if both remain tied.

Requirements

Constraints

Starter Code

def promote_model(models: list) -> str:
    """
    Returns the model name as a string.
    """
    # Write code here
    pass

Test Cases

CaseMatches
basicpublic
latency tiebreakpublic