-
Notifications
You must be signed in to change notification settings - Fork 11
Add example notebooks to integ tests #198
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import datetime | ||
import time | ||
import unittest | ||
|
||
from sagemaker_core.helper.session_helper import Session, get_execution_role | ||
from sagemaker_core.main.resources import Experiment, Trial, TrialComponent | ||
from sagemaker_core.main.shapes import RawMetricData, TrialComponentParameterValue | ||
from sagemaker_core.main.utils import get_textual_rich_logger | ||
|
||
logger = get_textual_rich_logger(__name__) | ||
|
||
sagemaker_session = Session() | ||
region = sagemaker_session.boto_region_name | ||
role = get_execution_role() | ||
bucket = sagemaker_session.default_bucket() | ||
|
||
|
||
class TestExperimentAndTrial(unittest.TestCase): | ||
def test_experiment_and_trial(self): | ||
experiment_name = "local-pyspark-experiment-example-" + time.strftime( | ||
"%Y-%m-%d-%H-%M-%S", time.gmtime() | ||
) | ||
run_group_name = "Default-Run-Group-" + experiment_name | ||
run_name = "local-experiment-run-" + time.strftime("%Y-%m-%d-%H-%M-%S", time.gmtime()) | ||
|
||
experiment = Experiment.create(experiment_name=experiment_name) | ||
trial = Trial.create(trial_name=run_group_name, experiment_name=experiment_name) | ||
|
||
created_after = datetime.datetime.now() - datetime.timedelta(days=5) | ||
experiments_iterator = Experiment.get_all(created_after=created_after) | ||
experiments = [exp.experiment_name for exp in experiments_iterator] | ||
|
||
assert len(experiments) > 0 | ||
assert experiment.experiment_name in experiments | ||
|
||
trial_component_parameters = { | ||
"num_train_samples": TrialComponentParameterValue(number_value=5), | ||
"num_test_samples": TrialComponentParameterValue(number_value=5), | ||
} | ||
|
||
trial_component = TrialComponent.create( | ||
trial_component_name=run_name, | ||
parameters=trial_component_parameters, | ||
) | ||
trial_component.associate_trail(trial_name=trial.trial_name) | ||
|
||
training_parameters = { | ||
"device": TrialComponentParameterValue(string_value="cpu"), | ||
"data_dir": TrialComponentParameterValue(string_value="test"), | ||
"optimizer": TrialComponentParameterValue(string_value="sgd"), | ||
"epochs": TrialComponentParameterValue(number_value=5), | ||
"hidden_channels": TrialComponentParameterValue(number_value=10), | ||
} | ||
trial_component.update(parameters=training_parameters) | ||
|
||
metrics = [] | ||
for i in range(5): | ||
accuracy_metric = RawMetricData( | ||
metric_name="test:accuracy", | ||
value=i / 10, | ||
step=i, | ||
timestamp=time.time(), | ||
) | ||
metrics.append(accuracy_metric) | ||
|
||
trial_component.batch_put_metrics(metric_data=metrics) | ||
|
||
time.sleep(10) | ||
trial_component.refresh() | ||
|
||
assert len(trial_component.parameters) == 7 | ||
assert len(trial_component.metrics) == 1 | ||
assert trial_component.metrics[0].count == 5 | ||
|
||
trial_component.disassociate_trail(trial_name=trial.trial_name) | ||
trial_component.delete() | ||
trial.delete() | ||
Comment on lines
+75
to
+77
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. Can we move this to 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. TrialComponent must disassociate with Trial first, and they have to be deleted in the order TrialComponent -> Trial -> Experiment. So they can not be deleted in the way of deleting the same type of resources together |
||
experiment.delete() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -500,7 +500,7 @@ def _serialize_dict(value: Dict) -> dict: | |
""" | ||
serialized_dict = {} | ||
for k, v in value.items(): | ||
if serialize_result := serialize(v): | ||
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. The previous condition will miss values like integer 0 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. Can we do 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. updated |
||
if (serialize_result := serialize(v)) is not None: | ||
serialized_dict.update({k: serialize_result}) | ||
return serialized_dict | ||
|
||
|
@@ -517,7 +517,7 @@ def _serialize_list(value: List) -> list: | |
""" | ||
serialized_list = [] | ||
for v in value: | ||
if serialize_result := serialize(v): | ||
if (serialize_result := serialize(v)) is not None: | ||
serialized_list.append(serialize_result) | ||
return serialized_list | ||
|
||
|
@@ -534,7 +534,7 @@ def _serialize_shape(value: Any) -> dict: | |
""" | ||
serialized_dict = {} | ||
for k, v in vars(value).items(): | ||
if serialize_result := serialize(v): | ||
if (serialize_result := serialize(v)) is not None: | ||
key = snake_to_pascal(k) if is_snake_case(k) else k | ||
serialized_dict.update({key[0].upper() + key[1:]: serialize_result}) | ||
return serialized_dict |
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.
Test seems to be failing .
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.
fixed