Tracker

class smexperiments.tracker.Tracker(trial_component, metrics_writer, artifact_uploader)

Bases: object

“A SageMaker Experiments Tracker.

Use a tracker object to record experiment information to a SageMaker trial component.

A new tracker can be created in two ways:

  • By loading an existing trial component with load()
  • By creating a tracker for a new trial component with create().

When creating a tracker within a SageMaker training or processing job, use the load method with no arguments to track artifacts to the trial component automatically created for your job. When tracking within a Jupyternotebook running in SageMaker, use the create method to automatically create a new trial component.

Trackers are Python context managers and you can use them using the Python with keyword. Exceptions thrown within the with block will cause the tracker’s trial component to be marked as failed. Start and end times are automatically set when using the with statement and the trial component is saved to SageMaker at the end of the block.

with smexperiments.tracker.Tracker.create() as my_tracker:
    my_tracker.log_parameter('learning_rate', 0.01)

    # Perform data-science code within the with block.
trial_component

The trial component tracked.

Type:TrialComponent
trial_component = None
classmethod load(trial_component_name=None, artifact_bucket=None, artifact_prefix=None, boto3_session=None, sagemaker_boto_client=None)

Create a new Tracker by loading an existing trial component.

Parameters:
  • trial_component_name – (str, optional). The name of the trial component to track. If specified, this trial component must exist in SageMaker. If you invoke this method in a running SageMaker training or processing job, then trial_component_name can be left empty. In this case, the Tracker will resolve the trial component automatically created for your SageMaker Job.
  • artifact_bucket – (str, optional) The name of the S3 bucket to store artifacts to.
  • artifact_prefix – (str, optional) The prefix to write artifacts to within artifact_bucket
  • boto3_session – (boto3.Session, optional) The boto3.Session to use to interact with AWS services. If not specified a new default boto3 session will be created.
  • sagemaker_boto_client – (boto3.Client, optional) The SageMaker AWS service client to use. If not specified a new client will be created from the specified boto3_session or default boto3.Session.
Returns:

The tracker for the given trial component.

Return type:

Tracker

Raises:

ValueError – If the trial component failed to load.

classmethod create(display_name=None, artifact_bucket=None, artifact_prefix=None, boto3_session=None, sagemaker_boto_client=None)

Create a new Tracker by creating a new trial component.

Parameters:
  • display_name – (str, optional). The display name of the trial component to track.
  • artifact_bucket – (str, optional) The name of the S3 bucket to store artifacts to.
  • artifact_prefix – (str, optional) The prefix to write artifacts to within artifact_bucket
  • boto3_session – (boto3.Session, optional) The boto3.Session to use to interact with AWS services. If not specified a new default boto3 session will be created.
  • sagemaker_boto_client – (boto3.Client, optional) The SageMaker AWS service client to use. If not specified a new client will be created from the specified boto3_session or default boto3.Session.
Returns:

The tracker for the new trial component.

Return type:

Tracker

log_parameter(name, value)

Record a single parameter value for this trial component.

Overwrites any previous value recorded for the specified parameter name.

Parameters:
  • name (str) – The name of the parameter
  • value (str or numbers.Number) – The value of the parameter
log_parameters(parameters)

Record a collection of parameter values for this trial component.

Parameters:parameters (dict[str, str or numbers.Number]) – The parameters to record.
log_input(name, value, media_type=None)

Record a single input artifact for this trial component.

Overwrites any previous value recorded for the specified input name.

Parameters:
  • name (str) – The name of the input value.
  • value (str) – The value.
  • media_type (str, optional) – The MediaType (MIME type) of the value
log_output(name, value, media_type=None)

Record a single output artifact for this trial component.

Overwrites any previous value recorded for the specified output name.

Parameters:
  • name (str) – The name of the output value.
  • value (str) – The value.
  • media_type (str, optional) – The MediaType (MIME type) of the value.
log_artifact(file_path, name=None, media_type=None)

Upload a local file to s3 and store it as an artifact in this trial component.

Parameters:
  • file_path (str) – The path of the local file to upload.
  • name (str, optional) – The name of the artifact.
  • media_type (str, optional) – The MediaType (MIME type) of the file. If not specified, this library will attempt to infer the media type from the file extension of file_path.
log_metric(metric_name, value, timestamp=None, iteration_number=None)

Record a scalar metric value for this TrialComponent.

Parameters:
  • metric_name (str) – The name of the metric.
  • value (number) – The value of the metric.
  • timestamp (datetime.datetime|number, optional) – The timestamp of the metric. If specified, should either be a datetime.datetime object or a number representing the seconds since the epoch. If not specified, the current local time will be used.
  • iteration_number (number, optional) – The integer iteration number of the metric value.
close()

Close this tracker and save state to SageMaker.