Skip to content

change:enable network isolation for amazon estimators #1293

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 3 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/sagemaker/amazon/amazon_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ def __init__(

if "enable_network_isolation" in kwargs:
logger.debug(
"removing unused enable_network_isolation argument: %s",
"removing unused enable_network_isolation argument in base class: %s",
str(kwargs["enable_network_isolation"]),
)
self._enable_network_isolation = kwargs["enable_network_isolation"]
del kwargs["enable_network_isolation"]
else:
self._enable_network_isolation = False

super(AmazonAlgorithmEstimatorBase, self).__init__(
role, train_instance_count, train_instance_type, **kwargs
Expand All @@ -98,6 +101,14 @@ def hyperparameters(self):
"""Placeholder docstring"""
return hp.serialize_all(self)

def enable_network_isolation(self):
"""If this Estimator can use network isolation when running.

Returns:
bool: Whether this Estimator can use network isolation or not.
"""
return self._enable_network_isolation

@property
def data_location(self):
"""Placeholder docstring"""
Expand Down
6 changes: 5 additions & 1 deletion tests/integ/test_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_pca(sagemaker_session, cpu_instance_type):
train_instance_type=cpu_instance_type,
num_components=48,
sagemaker_session=sagemaker_session,
enable_network_isolation=True,
)

pca.algorithm_mode = "randomized"
Expand All @@ -50,7 +51,10 @@ def test_pca(sagemaker_session, cpu_instance_type):

with timeout_and_delete_endpoint_by_name(job_name, sagemaker_session):
pca_model = sagemaker.amazon.pca.PCAModel(
model_data=pca.model_data, role="SageMakerRole", sagemaker_session=sagemaker_session
model_data=pca.model_data,
role="SageMakerRole",
sagemaker_session=sagemaker_session,
enable_network_isolation=True,
)
predictor = pca_model.deploy(
initial_instance_count=1, instance_type=cpu_instance_type, endpoint_name=job_name
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_amazon_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ def test_gov_ecr_uri():
def test_init(sagemaker_session):
pca = PCA(num_components=55, sagemaker_session=sagemaker_session, **COMMON_ARGS)
assert pca.num_components == 55
assert pca.enable_network_isolation() is False


def test_init_enable_network_isolation(sagemaker_session):
pca = PCA(
num_components=55,
sagemaker_session=sagemaker_session,
enable_network_isolation=True,
**COMMON_ARGS
)
assert pca.num_components == 55
assert pca.enable_network_isolation() is True


def test_init_all_pca_hyperparameters(sagemaker_session):
Expand Down