-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: Add support for actions in debugger rules. #2047
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 all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
dd7e28c
Allow user to specify actions in debugger rules
ndodda-amazon 096de11
pin smdebug rules config
ndodda-amazon 1914cac
update validate function
ndodda-amazon 3807439
new line
ndodda-amazon eaa56f5
fix merge conflict
ndodda-amazon b185d28
default actions to None in constructor
ndodda-amazon 899c3f4
Merge branch 'master' into actions
metrizable 82cf222
address comments
ndodda-amazon beed15a
fix reformatting error
ndodda-amazon 12570a2
Merge branch 'master' into actions
metrizable 1f88c27
Merge branch 'master' into actions
metrizable 54e1455
add sanity integ tests
ndodda-amazon 9576ac4
Merge branch 'actions' of github.com:ndodda-amazon/sagemaker-python-s…
ndodda-amazon c0346ac
Merge branch 'master' into actions
ndodda-amazon 2c7fc1c
update helper function
ndodda-amazon 9cd4e69
Merge branch 'actions' of github.com:ndodda-amazon/sagemaker-python-s…
ndodda-amazon 9db9f16
Merge branch 'master' into actions
metrizable 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
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 |
---|---|---|
|
@@ -60,6 +60,15 @@ | |
# TODO-reinvent-2019: test get_debugger_artifacts_path and get_tensorboard_artifacts_path | ||
|
||
|
||
@pytest.fixture | ||
def actions(): | ||
return rule_configs.ActionList( | ||
rule_configs.StopTraining(), | ||
rule_configs.Email("[email protected]"), | ||
rule_configs.SMS("+01234567890"), | ||
) | ||
|
||
|
||
def test_mxnet_with_rules( | ||
sagemaker_session, | ||
mxnet_training_latest_version, | ||
|
@@ -125,6 +134,74 @@ def test_mxnet_with_rules( | |
_wait_and_assert_that_no_rule_jobs_errored(training_job=mx.latest_training_job) | ||
|
||
|
||
def test_mxnet_with_rules_and_actions( | ||
sagemaker_session, | ||
mxnet_training_latest_version, | ||
mxnet_training_latest_py_version, | ||
cpu_instance_type, | ||
actions, | ||
): | ||
with timeout(minutes=TRAINING_DEFAULT_TIMEOUT_MINUTES): | ||
rules = [ | ||
Rule.sagemaker(rule_configs.vanishing_gradient(), actions=actions), | ||
Rule.sagemaker( | ||
base_config=rule_configs.all_zero(), | ||
rule_parameters={"tensor_regex": ".*"}, | ||
actions=actions, | ||
), | ||
Rule.sagemaker(rule_configs.loss_not_decreasing(), actions=actions), | ||
] | ||
|
||
script_path = os.path.join(DATA_DIR, "mxnet_mnist", "mnist_gluon.py") | ||
data_path = os.path.join(DATA_DIR, "mxnet_mnist") | ||
|
||
mx = MXNet( | ||
entry_point=script_path, | ||
role="SageMakerRole", | ||
framework_version=mxnet_training_latest_version, | ||
py_version=mxnet_training_latest_py_version, | ||
instance_count=1, | ||
instance_type=cpu_instance_type, | ||
sagemaker_session=sagemaker_session, | ||
rules=rules, | ||
) | ||
|
||
train_input = mx.sagemaker_session.upload_data( | ||
path=os.path.join(data_path, "train"), key_prefix="integ-test-data/mxnet_mnist/train" | ||
) | ||
test_input = mx.sagemaker_session.upload_data( | ||
path=os.path.join(data_path, "test"), key_prefix="integ-test-data/mxnet_mnist/test" | ||
) | ||
|
||
mx.fit({"train": train_input, "test": test_input}) | ||
|
||
job_description = mx.latest_training_job.describe() | ||
|
||
for index, rule in enumerate(rules): | ||
assert ( | ||
job_description["DebugRuleConfigurations"][index]["RuleConfigurationName"] | ||
== rule.name | ||
) | ||
assert ( | ||
job_description["DebugRuleConfigurations"][index]["RuleEvaluatorImage"] | ||
== rule.image_uri | ||
) | ||
assert job_description["DebugRuleConfigurations"][index]["VolumeSizeInGB"] == 0 | ||
assert ( | ||
job_description["DebugRuleConfigurations"][index]["RuleParameters"][ | ||
"rule_to_invoke" | ||
] | ||
== rule.rule_parameters["rule_to_invoke"] | ||
) | ||
|
||
assert ( | ||
_get_rule_evaluation_statuses(job_description) | ||
== mx.latest_training_job.rule_job_summary() | ||
) | ||
|
||
_wait_and_assert_that_no_rule_jobs_errored(training_job=mx.latest_training_job) | ||
|
||
|
||
def test_mxnet_with_custom_rule( | ||
sagemaker_session, | ||
mxnet_training_latest_version, | ||
|
@@ -178,6 +255,60 @@ def test_mxnet_with_custom_rule( | |
_wait_and_assert_that_no_rule_jobs_errored(training_job=mx.latest_training_job) | ||
|
||
|
||
def test_mxnet_with_custom_rule_and_actions( | ||
sagemaker_session, | ||
mxnet_training_latest_version, | ||
mxnet_training_latest_py_version, | ||
cpu_instance_type, | ||
actions, | ||
): | ||
with timeout(minutes=TRAINING_DEFAULT_TIMEOUT_MINUTES): | ||
rules = [_get_custom_rule(sagemaker_session, actions)] | ||
|
||
script_path = os.path.join(DATA_DIR, "mxnet_mnist", "mnist_gluon.py") | ||
data_path = os.path.join(DATA_DIR, "mxnet_mnist") | ||
|
||
mx = MXNet( | ||
entry_point=script_path, | ||
role="SageMakerRole", | ||
framework_version=mxnet_training_latest_version, | ||
py_version=mxnet_training_latest_py_version, | ||
instance_count=1, | ||
instance_type=cpu_instance_type, | ||
sagemaker_session=sagemaker_session, | ||
rules=rules, | ||
) | ||
|
||
train_input = mx.sagemaker_session.upload_data( | ||
path=os.path.join(data_path, "train"), key_prefix="integ-test-data/mxnet_mnist/train" | ||
) | ||
test_input = mx.sagemaker_session.upload_data( | ||
path=os.path.join(data_path, "test"), key_prefix="integ-test-data/mxnet_mnist/test" | ||
) | ||
|
||
mx.fit({"train": train_input, "test": test_input}) | ||
|
||
job_description = mx.latest_training_job.describe() | ||
|
||
for index, rule in enumerate(rules): | ||
assert ( | ||
job_description["DebugRuleConfigurations"][index]["RuleConfigurationName"] | ||
== rule.name | ||
) | ||
assert ( | ||
job_description["DebugRuleConfigurations"][index]["RuleEvaluatorImage"] | ||
== rule.image_uri | ||
) | ||
assert job_description["DebugRuleConfigurations"][index]["VolumeSizeInGB"] == 30 | ||
|
||
assert ( | ||
_get_rule_evaluation_statuses(job_description) | ||
== mx.latest_training_job.rule_job_summary() | ||
) | ||
|
||
_wait_and_assert_that_no_rule_jobs_errored(training_job=mx.latest_training_job) | ||
|
||
|
||
def test_mxnet_with_debugger_hook_config( | ||
sagemaker_session, | ||
mxnet_training_latest_version, | ||
|
@@ -514,7 +645,7 @@ def _get_rule_evaluation_statuses(job_description): | |
return debug_rule_eval_statuses + profiler_rule_eval_statuses | ||
|
||
|
||
def _get_custom_rule(session): | ||
def _get_custom_rule(session, actions=None): | ||
script_path = os.path.join(DATA_DIR, "mxnet_mnist", "my_custom_rule.py") | ||
|
||
return Rule.custom( | ||
|
@@ -526,6 +657,7 @@ def _get_custom_rule(session): | |
image_uri=CUSTOM_RULE_REPO_WITH_PLACEHOLDERS.format( | ||
CUSTOM_RULE_CONTAINERS_ACCOUNTS_MAP[session.boto_region_name], session.boto_region_name | ||
), | ||
actions=actions, | ||
) | ||
|
||
|
||
|
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 |
---|---|---|
|
@@ -385,6 +385,58 @@ def test_framework_with_only_debugger_rule(sagemaker_session): | |
} | ||
|
||
|
||
def test_framework_with_debugger_rule_and_single_action(sagemaker_session): | ||
stop_training_action = rule_configs.StopTraining() | ||
f = DummyFramework( | ||
entry_point=SCRIPT_PATH, | ||
role=ROLE, | ||
sagemaker_session=sagemaker_session, | ||
instance_count=INSTANCE_COUNT, | ||
instance_type=INSTANCE_TYPE, | ||
rules=[Rule.sagemaker(rule_configs.stalled_training_rule(), actions=stop_training_action)], | ||
) | ||
f.fit("s3://mydata") | ||
sagemaker_session.train.assert_called_once() | ||
_, args = sagemaker_session.train.call_args | ||
assert args["debugger_rule_configs"][0]["RuleParameters"] == { | ||
"rule_to_invoke": "StalledTrainingRule", | ||
"action_json": stop_training_action.serialize(), | ||
} | ||
assert stop_training_action.action_parameters["training_job_prefix"] == f._current_job_name | ||
assert args["debugger_hook_config"] == { | ||
"S3OutputPath": "s3://{}/".format(BUCKET_NAME), | ||
"CollectionConfigurations": [], | ||
} | ||
|
||
|
||
def test_framework_with_debugger_rule_and_multiple_actions(sagemaker_session): | ||
action_list = rule_configs.ActionList( | ||
rule_configs.StopTraining(), | ||
rule_configs.Email("[email protected]"), | ||
rule_configs.SMS("+1234567890"), | ||
) | ||
f = DummyFramework( | ||
entry_point=SCRIPT_PATH, | ||
role=ROLE, | ||
sagemaker_session=sagemaker_session, | ||
instance_count=INSTANCE_COUNT, | ||
instance_type=INSTANCE_TYPE, | ||
rules=[Rule.sagemaker(rule_configs.stalled_training_rule(), actions=action_list)], | ||
) | ||
f.fit("s3://mydata") | ||
sagemaker_session.train.assert_called_once() | ||
_, args = sagemaker_session.train.call_args | ||
assert args["debugger_rule_configs"][0]["RuleParameters"] == { | ||
"rule_to_invoke": "StalledTrainingRule", | ||
"action_json": action_list.serialize(), | ||
} | ||
assert action_list.actions[0].action_parameters["training_job_prefix"] == f._current_job_name | ||
assert args["debugger_hook_config"] == { | ||
"S3OutputPath": "s3://{}/".format(BUCKET_NAME), | ||
"CollectionConfigurations": [], | ||
} | ||
|
||
|
||
def test_framework_with_only_debugger_hook_config(sagemaker_session): | ||
hook_config = DebuggerHookConfig( | ||
s3_output_path="s3://output", collection_configs=[CollectionConfig(name="weights")] | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.