from azureml.core import Run
run = Run.get_context()
run.log('metric-name', metric_value)
You can log the same metric multiple times within a run; the results will be displayed as a chart.
log_row
¶Log a metric with multiple columns.
from azureml.core import Run
run = Run.get_context()
run.log_row("Y over X", x=1, y=0.4)
:::info More logging options These are arguably the most often used APIs for logging metrics, but a comprehensive list, including logging lists, tables, and pictures, can be found here. :::
Metrics will be provided in the Azure ML Studio by default. Choose a location for your run, such as either simply going to ml.azure.com, or by downloading the SDK:
run.get_workspace_url()
Viewing metrics in a run
metrics = run.get_metrics()
# metrics is of type Dict[str, List[float]] mapping mertic names
# to a list of the values for that metric in the given run.
metrics.get('metric-name')
# list of metrics in the order they were recorded
metrics_including_child_runs = run.get_metrics(recursive=True)
# set 'recursive' boolean parameter to True to also get
# the metrics for child runs
To view all recorded values for a given metric my-metric
in a
given experiment my-experiment
:
experiments = ws.experiments
# of type Dict[str, Experiment] mapping experiment names the
# corresponding Experiment
exp = experiments['my-experiment']
for run in exp.get_runs():
metrics = run.get_metrics()
my_metric = metrics.get('my-metric')
if my_metric:
print(my_metric)
from azureml.core import Run
# connect to the workspace from within your running code
run = Run.get_context()
ws = run.experiment.workspace
# workspace has associated ml-flow-tracking-uri
mlflow_url = ws.get_mlflow_tracking_uri()
This examples:
TensorBoardLogger
-you can refer more about it in [here]MLFlowLogger
using AzureML Run.get_context()
import pytorch_lightning as pl
run = None
try:
from azureml.core.run import Run, _OfflineRun
run = Run.get_context()
if isinstance(run, _OfflineRun):
run = None
except ImportError:
print("Couldn't import azureml.core.run.Run")
def get_logger():
tb_logger = pl.loggers.TensorBoardLogger('logs/')
logger = [tb_logger]
if run is not None:
mlflow_url = run.experiment.workspace.get_mlflow_tracking_uri()
mlf_logger = pl.loggers.MLFlowLogger(
experiment_name=run.experiment.name,
tracking_uri=mlflow_url,
)
mlf_logger._run_id = run.id
logger.append(mlf_logger)
return logger
Now include this logger in the lightning Trainer
class:
logger = get_logger()
trainer = pl.Trainer.from_argparse_args(
args=args,
logger=logger,
)
trainer.fit(model)