Introduction to Logging Your ML Story
Welcome to Chapter 3! In the previous chapter, we got Trackio up and running and initialized our first experiment. Now, it’s time to make that experiment meaningful by recording what truly matters: your model’s performance, the settings you used, and the decisions you made along the way.
This chapter is all about teaching you the art of logging. You’ll learn how to capture crucial information like metrics (how well your model is doing), parameters (the knobs and dials you tweaked), and configurations (the overall setup of your experiment). Think of it as writing a detailed lab report for every single machine learning run, but Trackio does most of the heavy lifting!
By the end of this chapter, you’ll be able to:
- Understand the difference between metrics, parameters, and configurations in the context of ML experiments.
- Use Trackio’s core API to log these different types of data.
- View your logged data directly in the Trackio dashboard.
Ready to turn your experiments into data-rich stories? Let’s dive in!
Core Concepts: What to Log and Why
Before we start writing code, let’s clarify what we mean by metrics, parameters, and configurations, and why each is vital for effective experiment tracking.
Metrics: The Scorecard of Your Model
What they are: Metrics are numerical values that quantify the performance or behavior of your model. Examples include accuracy, loss, precision, recall, F1-score, BLEU score, or even custom values like training_time.
Why they matter: Metrics tell you how good your model is. By tracking them over time (e.g., per epoch) and across different experiments, you can compare models, identify trends, and understand the impact of your changes. Without metrics, you’re flying blind!
Parameters: The Knobs and Dials of Your Experiment
What they are: Parameters, often called hyperparameters in machine learning, are settings that are external to the model and whose values cannot be estimated from data. They are set before the training process begins. Common examples include learning_rate, batch_size, number_of_epochs, dropout_rate, or number_of_layers.
Why they matter: Parameters are critical for reproducibility and understanding. If you get a great result, you need to know exactly which parameters led to it. If a model performs poorly, analyzing the parameters can help you debug. Logging them ensures your experiments are fully documented and repeatable.
Configurations: The Blueprint of Your Setup
What they are: Configurations are a broader set of settings that define the environment or overall setup of your experiment. This can include the optimizer_type, model_architecture, dataset_path, feature_engineering_steps, or even the GPU_device used.
Why they matter: Configurations provide context. They describe the blueprint of your entire experiment, allowing you to understand how the experiment was set up, beyond just the core hyperparameters. This is invaluable for debugging and sharing your work.
Trackio’s Approach to Logging
Trackio provides straightforward functions to log all this information:
trackio.log(): Your go-to function for logging metrics that typically change over time (e.g., loss per epoch).trackio.config.update(): Used to store parameters and static configuration details that usually remain constant throughout a single experiment run.
Let’s visualize the flow of information in a typical Trackio experiment:
This diagram shows how trackio.init() kicks things off, trackio.config.update() captures your initial setup, trackio.log() records your progress within the loop, and trackio.finish() wraps it all up for viewing.
Step-by-Step Implementation: Building Our First Logged Experiment
Let’s create a simple Python script that simulates a machine learning training process and uses Trackio to log its progress.
First, make sure you have Trackio installed (if you haven’t already from Chapter 2):
pip install trackio==0.2.1 # As of 2026-01-01, this is the latest stable version.
Now, create a new Python file named simple_training.py.
Step 1: Initialize Trackio
We’ll start by importing trackio and random (for simulating data) and initializing our experiment. Remember, trackio.init() creates a new run.
# simple_training.py
import trackio
import random
import time
print("Initializing Trackio run...")
# Initialize Trackio for a new experiment
# The 'project' groups related experiments, 'name' identifies this specific run.
trackio.init(project="my-first-trackio-project", name="simple-experiment-001")
print("Trackio run initialized!")
Explanation:
import trackio: Brings the Trackio library into our script.import random, time: These are standard Python libraries we’ll use to simulate a training process later.randomwill generate mock metric values, andtime.sleepwill make our script pause, simulating work.trackio.init(...): This crucial call starts a new experiment run.project="my-first-trackio-project": This is a string that groups related experiments together. All runs under this project will appear in the same dashboard view.name="simple-experiment-001": This is a unique identifier for this specific experiment run within the project. It’s good practice to make these descriptive.
Step 2: Logging Parameters and Configurations
Next, we’ll define some mock hyperparameters and configuration settings and log them using trackio.config.update(). This is typically done once at the beginning of an experiment.
# simple_training.py (continue adding to the file)
# ... (previous code for imports and trackio.init)
# Define some hyperparameters and configuration settings
# These are static for the entire run.
config_settings = {
"learning_rate": 0.005,
"batch_size": 64,
"epochs": 10,
"optimizer": "AdamW",
"model_architecture": "SimpleMLP",
"dataset_version": "v1.2_cleaned"
}
# Log these configurations to Trackio
trackio.config.update(config_settings)
print("Configuration and parameters logged!")
# ... (rest of the script will go here)
Explanation:
config_settings = {...}: We create a Python dictionary to hold all our key-value pairs for parameters and configurations.trackio.config.update(config_settings): This line takes our dictionary and stores it as the configuration for the current Trackio run. These values will be visible in the “Config” or “Parameters” section of your Trackio dashboard.trackio.configacts like a dictionary itself, so you can also update individual keys liketrackio.config.learning_rate = 0.005. Usingupdate()is convenient for logging many at once.
Step 3: Simulating Training and Logging Metrics
Now for the dynamic part: simulating a training loop and logging metrics at each step or epoch. We’ll use trackio.log() for this.
# simple_training.py (continue adding to the file)
# ... (previous code for imports, trackio.init, and trackio.config.update)
print("Simulating training and logging metrics...")
# Simulate a training loop
for epoch in range(trackio.config.epochs): # We can access logged config directly!
# Simulate training progress for each epoch
simulated_loss = 1.0 / (epoch + 1) + random.uniform(-0.1, 0.1) # Loss decreases
simulated_accuracy = 0.5 + (epoch * 0.05) + random.uniform(-0.03, 0.03) # Accuracy increases
# Log metrics for the current epoch
# We log a dictionary where keys are metric names and values are their current readings.
trackio.log({
"epoch": epoch + 1, # Log epoch number starting from 1
"loss": simulated_loss,
"accuracy": simulated_accuracy,
"learning_rate": trackio.config.learning_rate # Can log config values alongside metrics
})
print(f"Epoch {epoch+1}: Loss = {simulated_loss:.4f}, Accuracy = {simulated_accuracy:.4f}")
time.sleep(0.3) # Simulate some work being done
print("Experiment simulation finished and metrics logged!")
# ... (finalizing step will go here)
Explanation:
for epoch in range(trackio.config.epochs): Notice how we can directly access theepochsvalue we logged earlier viatrackio.config.epochs. This is a handy way to keep your script consistent with your logged parameters.simulated_lossandsimulated_accuracy: These lines generate some fake, but plausible, metric values. Loss generally decreases, and accuracy generally increases over epochs.trackio.log({...}): This is the core function for logging dynamic metrics.- It takes a dictionary where keys are the metric names (e.g.,
"loss","accuracy") and values are their current numerical readings. - Trackio automatically associates these logs with the current run and tracks them over time (e.g., by step or epoch).
- We also included
learning_ratein thelogcall. While it’s a config value, logging it withtrackio.logmeans it will appear as a time-series plot in the dashboard, which can be useful if you’re doing learning rate scheduling.
- It takes a dictionary where keys are the metric names (e.g.,
Step 4: Finalizing the Run
Once your experiment is complete, it’s good practice to explicitly tell Trackio that the run has ended.
# simple_training.py (continue adding to the file)
# ... (previous code for imports, init, config.update, and logging loop)
# Finish the Trackio run
# This uploads any buffered data and marks the run as complete.
trackio.finish()
print("Trackio run finalized. You can now view it in the dashboard!")
Explanation:
trackio.finish(): This call signals to Trackio that the current experiment run is complete. It ensures all buffered data is saved and the run’s status is updated in the backend. If you forget this, your run might appear as “running” indefinitely in the dashboard, or some logs might not be fully saved.
Step 5: Running the Script and Viewing the Dashboard
Now, let’s execute our script and see the magic happen!
Run your Python script: Open your terminal or command prompt, navigate to the directory where you saved
simple_training.py, and run:python simple_training.pyYou’ll see the print statements indicating initialization, config logging, and epoch-by-epoch metric logging.
Launch the Trackio Dashboard: In a separate terminal window, launch the Trackio dashboard:
trackio dashboardThis command will start a local web server, usually on
http://localhost:8080(or similar). It will print the exact URL in your terminal. Open this URL in your web browser.Explore Your Experiment:
- You should see your “my-first-trackio-project” listed. Click on it.
- Inside the project, you’ll find “simple-experiment-001”. Click on that.
- You’ll see graphs for
loss,accuracy, andlearning_rateplotted overepoch. - Look for tabs or sections displaying “Config” or “Parameters” to see
learning_rate,batch_size,optimizer, etc. - There will also be a “Summary” section showing the final values of your metrics.
Congratulations! You’ve successfully logged your first experiment data with Trackio and visualized it in the dashboard.
Mini-Challenge: Expanding Your Experiment Logs
It’s your turn to get hands-on!
Challenge:
Modify the simple_training.py script to:
- Add a new configuration parameter: Include
activation_function(e.g., set it to “ReLU”) to yourconfig_settingsdictionary. - Log an additional metric: Inside the training loop, simulate and log a
validation_lossmetric. Make it follow a similar decreasing trend asloss, but perhaps slightly higher or with more variance. - Observe: Run your modified script, launch the dashboard, and verify that your new
activation_functionparameter appears in the config, and thevalidation_lossmetric is plotted over epochs.
Hint:
- For the new configuration, remember to update the
config_settingsdictionary and pass it totrackio.config.update(). - For the new metric, generate a
simulated_validation_lossvalue within the loop and add it to the dictionary passed totrackio.log().
Give it a try! This is how you build muscle memory for effective tracking.
Common Pitfalls & Troubleshooting
Even with a simple API, it’s easy to stumble. Here are a few common issues and how to resolve them:
“My logs aren’t showing up!”
- Check
trackio.init(): Did you forget to calltrackio.init()at the beginning of your script? Trackio needs an active run to log data. - Check
trackio.finish(): If your script crashes beforetrackio.finish()is called, or if you simply omit it, some buffered logs might not be saved, and the run might appear incomplete. - Dashboard not refreshed: Sometimes the dashboard needs a manual refresh (F5 or Ctrl+R) to show the latest runs, especially if you ran the script while the dashboard was already open.
- Project/Name Mismatch: Ensure you’re looking at the correct project and run name in the dashboard.
- Check
KeyErrororAttributeErrorwhen accessingtrackio.config:- Config not set: Did you call
trackio.config.update()before trying to accesstrackio.config.epochs? The config object is populated by yourupdatecall. - Typo: Double-check the key names. Python is case-sensitive!
trackio.config.batch_sizeis different fromtrackio.config.Batch_Size.
- Config not set: Did you call
“My metrics are not plotting correctly or look flat!”
- Logging frequency: Are you logging metrics inside a loop (e.g., per epoch or step)? If you only log a metric once, it will appear as a single point or a flat line in a time-series plot.
- Data type: Ensure the values you’re passing to
trackio.log()are numerical (integers or floats). Logging strings or other complex objects will likely not plot.
Summary
You’ve taken a crucial step in becoming an experiment tracking master! In this chapter, we covered:
- The fundamental differences and importance of metrics, parameters, and configurations in machine learning experiments.
- How to initialize an experiment run using
trackio.init(). - How to log static experiment settings and hyperparameters using
trackio.config.update(). - How to record dynamic performance data (metrics) over time using
trackio.log(). - The importance of
trackio.finish()to finalize your runs. - How to launch the Trackio dashboard and view your logged data.
By consistently logging this information, you build a comprehensive history of your work, making it easier to compare, debug, and reproduce your results. This is the cornerstone of efficient ML development!
What’s Next? In Chapter 4, we’ll delve into more advanced logging techniques, including logging custom objects, media, and exploring richer dashboard features to get even more insights from your experiments.
References
This page is AI-assisted and reviewed. It references official documentation and recognized resources where relevant.