Promoting models between stages in MLOps - Time & Space Complexity
When moving machine learning models from one stage to another, like from testing to production, it's important to know how the time needed grows as more models or stages are involved.
We want to understand how the process time changes when handling more models or stages.
Analyze the time complexity of the following code snippet.
for model in models:
for stage in stages:
promote_model(model, stage)
This code promotes each model through all defined stages one by one.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Calling
promote_modelfor each model and stage combination. - How many times: Once for every model times every stage (models x stages).
As the number of models or stages increases, the total promotions grow by multiplying these counts.
| Input Size (models x stages) | Approx. Operations |
|---|---|
| 10 models x 3 stages | 30 promotions |
| 100 models x 3 stages | 300 promotions |
| 100 models x 10 stages | 1000 promotions |
Pattern observation: The total work grows by multiplying the number of models and stages.
Time Complexity: O(models x stages)
This means the time needed grows proportionally with both the number of models and the number of stages.
[X] Wrong: "Promoting models only depends on the number of models, not stages."
[OK] Correct: Each model must be promoted through every stage, so stages multiply the total work, not just models alone.
Understanding how tasks multiply when combining two lists, like models and stages, helps you explain real-world automation steps clearly and confidently.
"What if we promoted only models that passed tests instead of all models? How would the time complexity change?"