-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Make the metric_names list optional in TrainingJobAnalytics object. #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
from six import with_metaclass | ||
|
||
from sagemaker.session import Session | ||
from sagemaker.utils import DeferredError | ||
from sagemaker.utils import DeferredError, extract_name_from_job_arn | ||
|
||
try: | ||
import pandas as pd | ||
|
@@ -201,12 +201,13 @@ class TrainingJobAnalytics(AnalyticsMetricsBase): | |
|
||
CLOUDWATCH_NAMESPACE = '/aws/sagemaker/HyperParameterTuningJobs' | ||
|
||
def __init__(self, training_job_name, metric_names, sagemaker_session=None): | ||
def __init__(self, training_job_name, metric_names=None, sagemaker_session=None): | ||
"""Initialize a ``TrainingJobAnalytics`` instance. | ||
|
||
Args: | ||
training_job_name (str): name of the TrainingJob to analyze. | ||
metric_names (list): string names of all the metrics to collect for this training job | ||
metric_names (list, optional): string names of all the metrics to collect for this training job. | ||
If not specified, then it will use all metric names configured for this job. | ||
sagemaker_session (sagemaker.session.Session): Session object which manages interactions with | ||
Amazon SageMaker APIs and any other AWS services needed. If not specified, one is specified | ||
using the default AWS configuration chain. | ||
|
@@ -215,7 +216,10 @@ def __init__(self, training_job_name, metric_names, sagemaker_session=None): | |
self._sage_client = sagemaker_session.sagemaker_client | ||
self._cloudwatch = sagemaker_session.boto_session.client('cloudwatch') | ||
self._training_job_name = training_job_name | ||
self._metric_names = metric_names | ||
if metric_names: | ||
self._metric_names = metric_names | ||
else: | ||
self._metric_names = self._metric_names_for_training_job() | ||
self.clear_cache() | ||
|
||
@property | ||
|
@@ -297,3 +301,22 @@ def _add_single_metric(self, timestamp, metric_name, value): | |
self._data['timestamp'].append(timestamp) | ||
self._data['metric_name'].append(metric_name) | ||
self._data['value'].append(value) | ||
|
||
def _metric_names_for_training_job(self): | ||
"""Helper method to discover the metrics defined for a training job. | ||
""" | ||
# First look up the tuning job | ||
training_description = self._sage_client.describe_training_job(TrainingJobName=self._training_job_name) | ||
tuning_job_arn = training_description.get('TuningJobArn', None) | ||
if not tuning_job_arn: | ||
raise ValueError( | ||
"No metrics available. Training Job Analytics only available through Hyperparameter Tuning Jobs" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. single quotes |
||
) | ||
tuning_job_name = extract_name_from_job_arn(tuning_job_arn) | ||
tuning_job_description = self._sage_client.describe_hyper_parameter_tuning_job( | ||
HyperParameterTuningJobName=tuning_job_name | ||
) | ||
training_job_definition = tuning_job_description['TrainingJobDefinition'] | ||
metric_definitions = training_job_definition['AlgorithmSpecification']['MetricDefinitions'] | ||
metric_names = [md['Name'] for md in metric_definitions] | ||
return metric_names |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be done in one line: