Search code examples
pythonazure-machine-learning-service

Log metrics in PythonScriptStep


In my Azure ML pipeline I've got a PythonScriptStep that is crunching some data. I need to access the Azure ML Logger to track metrics in the step, so I'm trying to import get_azureml_logger but that's bombing out. I'm not sure what dependency I need to install via pip.

from azureml.logging import get_azureml_logger

ModuleNotFoundError: No module named 'azureml.logging'

I came across a similar post but it deals with Azure Notebooks. Anyway, I tried adding that blob to my pip dependency, but it's failing with an Auth error.

Collecting azureml.logging==1.0.79 [91m  ERROR: HTTP error 403 while getting
https://azuremldownloads.blob.core.windows.net/wheels/latest/azureml.logging-1.0.79-py3-none-any.whl?sv=2016-05-31&si=ro-2017&sr=c&sig=xnUdTm0B%2F%2FfknhTaRInBXyu2QTTt8wA3OsXwGVgU%2BJk%3D
[0m91m  ERROR: Could not install requirement azureml.logging==1.0.79 from
https://azuremldownloads.blob.core.windows.net/wheels/latest/azureml.logging-1.0.79-py3-none-any.whl?sv=2016-05-31&si=ro-2017&sr=c&sig=xnUdTm0B%2F%2FfknhTaRInBXyu2QTTt8wA3OsXwGVgU%2BJk%3D
(from -r /azureml-environment-setup/condaenv.g4q7suee.requirements.txt
(line 3)) because of error 403 Client Error:
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. for url:
https://azuremldownloads.blob.core.windows.net/wheels/latest/azureml.logging-1.0.79-py3-none-any.whl?sv=2016-05-31&si=ro-2017&sr=c&sig=xnUdTm0B%2F%2FfknhTaRInBXyu2QTTt8wA3OsXwGVgU%2BJk%3D

I'm not sure how to move on this, all I need to do is to log metrics in the step.


Solution

  • Check out the ScriptRunConfig Section of the Monitor Azure ML experiment runs and metrics. ScriptRunConfig works effectively the same as a PythonScriptStep.

    The idiom is generally to have the following in your the script of your PythonScriptStep:

    from azureml.core.run import Run
    run = Run.get_context()
    run.log('foo_score', "bar")
    

    Side note: You don't need to change your environment dependencies to use this because PythonScriptSteps have azureml-defaults installed automatically as a dependency.