0
0
MLOpsdevops~10 mins

Logging artifacts and models in MLOps - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Logging artifacts and models
Start Training Model
Generate Artifacts
Log Artifacts
Save Model
Log Model
End Process
The flow shows starting model training, creating artifacts, logging them, saving the model, logging the model, then ending.
Execution Sample
MLOps
import mlflow
import joblib

with mlflow.start_run():
    mlflow.log_artifact('metrics.json')
    joblib.dump(model, 'model.joblib')
    mlflow.log_artifact('model.joblib')
This code logs a metrics file and a trained model to MLflow during a run.
Process Table
StepActionInputOutputSystem State Change
1Start MLflow runNoneRun startedActive run context created
2Generate artifactTraining metricsmetrics.json fileArtifact file created locally
3Log artifactmetrics.jsonArtifact loggedArtifact uploaded to MLflow storage
4Save modelTrained model objectModel saved locallyModel file created
5Log modelModel fileModel loggedModel file uploaded to MLflow storage
6End MLflow runNoneRun endedRun context closed
💡 Run ends after logging artifacts and model successfully.
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5Final
run_activeFalseTrueTrueTrueTrueFalse
artifact_fileNonemetrics.json createdmetrics.json loggedmetrics.json loggedmetrics.json loggedmetrics.json logged
model_fileNoneNoneNoneModel saved locallyModel loggedModel logged
Key Moments - 3 Insights
Why do we need to start a run before logging artifacts or models?
Starting a run creates a context to group logs. Without it, MLflow doesn't know where to save artifacts or models. See execution_table step 1 where the run starts before logging.
Is the artifact file automatically created when logging?
No, the artifact file must exist locally before logging. Step 2 shows the artifact file is created first, then step 3 logs it.
What happens if we log a model without saving it first?
The model must be saved locally before logging. Step 4 saves the model, then step 5 logs it. Skipping save means no file to log.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step is the artifact actually uploaded to MLflow storage?
AStep 2
BStep 4
CStep 3
DStep 5
💡 Hint
Check the 'System State Change' column for artifact upload details.
According to the variable tracker, when does the model_file variable first get a value?
AAfter Step 3
BAfter Step 4
CAfter Step 2
DAfter Step 5
💡 Hint
Look at the 'model_file' row and see when it changes from None.
If the run_active variable stayed True after Step 6, what would that mean?
AThe run is still open
BThe run never started
CThe artifact was not logged
DThe model was not saved
💡 Hint
Check the 'run_active' variable in the variable tracker after Step 6.
Concept Snapshot
Logging artifacts and models:
- Start a run to create context
- Create artifact files locally
- Log artifacts to upload them
- Save model locally
- Log model to upload it
- End run to close context
Full Transcript
This visual execution shows how to log artifacts and models in MLflow. First, a run is started to create a context. Then, artifacts like metrics files are generated locally and logged to MLflow storage. Next, the trained model is saved locally and logged to MLflow. Finally, the run is ended to close the context. Variables like run_active track if the run is open. Artifacts must exist before logging. Models must be saved before logging. This step-by-step process ensures all data is properly stored and tracked.