Enable logging in ML training runs

The Azure Machine Learning Python SDK lets you log real-time information using both the default Python logging package and SDK-specific functionality. You can log locally and send logs to your workspace in the portal.

Logs can help you diagnose errors and warnings, or track performance metrics like parameters and model performance. In this article, you learn how to enable logging in the following scenarios:

  • Interactive training sessions
  • Submitting training jobs using ScriptRunConfig
  • Python native logging settings
  • Logging from additional sources

Tip

This article shows you how to monitor the model training process. If you're interested in monitoring resource usage and events from Azure Machine learning, such as quotas, completed training runs, or completed model deployments, see Monitoring Azure Machine Learning.

Data types

You can log multiple data types including scalar values, lists, tables, images, directories, and more. For more information, and Python code examples for different data types, see the Run class reference page.

Interactive logging session

Interactive logging sessions are typically used in notebook environments. The method Experiment.start_logging() starts an interactive logging session. Any metrics logged during the session are added to the run record in the experiment. The method run.complete() ends the sessions and marks the run as completed.

ScriptRun logs

In this section, you learn how to add logging code inside of runs created when configured with ScriptRunConfig. You can use the ScriptRunConfig class to encapsulate scripts and environments for repeatable runs. You can also use this option to show a visual Jupyter Notebooks widget for monitoring.

This example performs a parameter sweep over alpha values and captures the results using the run.log() method.

  1. Create a training script that includes the logging logic, train.py.

    !code-python

  2. Submit the train.py script to run in a user-managed environment. The entire script folder is submitted for training.

    !notebook-python !notebook-python

    The show_output parameter turns on verbose logging, which lets you see details from the training process as well as information about any remote resources or compute targets. Use the following code to turn on verbose logging when you submit the experiment.

run = exp.submit(src, show_output=True)

You can also use the same parameter in the wait_for_completion function on the resulting run.

run.wait_for_completion(show_output=True)

Native Python logging

Some logs in the SDK may contain an error that instructs you to set the logging level to DEBUG. To set the logging level, add the following code to your script.

import logging
logging.basicConfig(level=logging.DEBUG)

Additional logging sources

Azure Machine Learning can also log information from other sources during training, such as automated machine learning runs, or Docker containers that run the jobs. These logs aren't documented, but if you encounter problems and contact Microsoft support, they may be able to use these logs during troubleshooting.

For information on logging metrics in Azure Machine Learning designer, see How to log metrics in the designer

Example notebooks

The following notebooks demonstrate concepts in this article:

!INCLUDE aml-clone-in-azure-notebook

Next steps

See these articles to learn more on how to use Azure Machine Learning: