Skip to content

Commit 7afca7e

Browse files
authored
Merge pull request aws#15 from athewsey/feat/fw-processor
Integration test of requirements.txt + script bundle functionality
2 parents dd48ee6 + 782bbd4 commit 7afca7e

File tree

4 files changed

+65
-7
lines changed

4 files changed

+65
-7
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"""A dummy Python module to check importing local files works OK"""
2+
DUMMY_CONSTANT = 1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""A dummy SageMaker job script testing local imports and requirements.txt installs"""
2+
3+
print("This is the print output from dummy_code_bundle_with_reqs/main_script.py")
4+
5+
print("Trying to import local module...")
6+
import local_module
7+
8+
print("Trying to import module from requirements.txt...")
9+
import stepfunctions
10+
11+
print("Done")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# As a test dependency, we'll use the AWS Step Functions Data Science SDK - since it's more of a
2+
# notebook environment tool than a training/processing job library, so shouldn't be in base images
3+
stepfunctions

tests/integ/test_sklearn.py renamed to tests/integ/test_processing_sklearn.py

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
import pytest
1919
import numpy
2020

21-
from sagemaker.sklearn import SKLearn
22-
from sagemaker.sklearn import SKLearnModel
21+
from sagemaker.sklearn import SKLearn, SKLearnModel, SKLearnProcessor
2322
from sagemaker.utils import sagemaker_timestamp, unique_name_from_base
2423
from tests.integ import DATA_DIR, TRAINING_DEFAULT_TIMEOUT_MINUTES
2524
from tests.integ.timeout import timeout, timeout_and_delete_endpoint_by_name
2625

26+
ROLE = "SageMakerRole"
27+
2728

2829
@pytest.fixture(scope="module")
2930
@pytest.mark.skip(
@@ -45,6 +46,20 @@ def sklearn_training_job(
4546
sagemaker_session.boto_region_name
4647

4748

49+
def test_framework_processing_job_with_deps(
50+
sagemaker_session,
51+
sklearn_latest_version,
52+
sklearn_latest_py_version,
53+
cpu_instance_type,
54+
):
55+
return _run_processing_job(
56+
sagemaker_session,
57+
cpu_instance_type,
58+
sklearn_latest_version,
59+
sklearn_latest_py_version,
60+
)
61+
62+
4863
def test_training_with_additional_hyperparameters(
4964
sagemaker_session,
5065
sklearn_latest_version,
@@ -57,7 +72,7 @@ def test_training_with_additional_hyperparameters(
5772

5873
sklearn = SKLearn(
5974
entry_point=script_path,
60-
role="SageMakerRole",
75+
role=ROLE,
6176
instance_type=cpu_instance_type,
6277
framework_version=sklearn_latest_version,
6378
py_version=sklearn_latest_py_version,
@@ -88,7 +103,7 @@ def test_training_with_network_isolation(
88103

89104
sklearn = SKLearn(
90105
entry_point=script_path,
91-
role="SageMakerRole",
106+
role=ROLE,
92107
instance_type=cpu_instance_type,
93108
framework_version=sklearn_latest_version,
94109
py_version=sklearn_latest_py_version,
@@ -145,7 +160,7 @@ def test_deploy_model(
145160
script_path = os.path.join(DATA_DIR, "sklearn_mnist", "mnist.py")
146161
model = SKLearnModel(
147162
model_data,
148-
"SageMakerRole",
163+
ROLE,
149164
entry_point=script_path,
150165
framework_version=sklearn_latest_version,
151166
sagemaker_session=sagemaker_session,
@@ -198,7 +213,7 @@ def test_failed_training_job(
198213

199214
sklearn = SKLearn(
200215
entry_point=script_path,
201-
role="SageMakerRole",
216+
role=ROLE,
202217
framework_version=sklearn_latest_version,
203218
py_version=sklearn_latest_py_version,
204219
instance_count=1,
@@ -215,6 +230,33 @@ def test_failed_training_job(
215230
sklearn.fit(train_input, job_name=job_name)
216231

217232

233+
def _run_processing_job(
234+
sagemaker_session, instance_type, sklearn_version, py_version, wait=True
235+
):
236+
with timeout(minutes=TRAINING_DEFAULT_TIMEOUT_MINUTES):
237+
238+
code_path = os.path.join(DATA_DIR, "dummy_code_bundle_with_reqs")
239+
entry_point = "main_script.py"
240+
241+
processor = SKLearnProcessor(
242+
framework_version=sklearn_version,
243+
py_version=py_version,
244+
role=ROLE,
245+
instance_count=1,
246+
instance_type=instance_type,
247+
sagemaker_session=sagemaker_session,
248+
base_job_name="test-sklearn",
249+
)
250+
251+
processor.run(
252+
code=entry_point,
253+
source_dir=code_path,
254+
inputs=[],
255+
wait=wait,
256+
)
257+
return processor.latest_job.name
258+
259+
218260
def _run_mnist_training_job(
219261
sagemaker_session, instance_type, sklearn_version, py_version, wait=True
220262
):
@@ -226,7 +268,7 @@ def _run_mnist_training_job(
226268

227269
sklearn = SKLearn(
228270
entry_point=script_path,
229-
role="SageMakerRole",
271+
role=ROLE,
230272
framework_version=sklearn_version,
231273
py_version=py_version,
232274
instance_type=instance_type,

0 commit comments

Comments
 (0)