24
24
import stopit
25
25
26
26
import tests .integ .lock as lock
27
+ from sagemaker .remote_function import remote
27
28
from sagemaker .workflow .step_outputs import get_step
28
29
from tests .integ .sagemaker .conftest import _build_container , DOCKERFILE_TEMPLATE
29
30
from sagemaker .config import SESSION_DEFAULT_S3_BUCKET_PATH
58
59
LOCK_PATH = os .path .join (tempfile .gettempdir (), "sagemaker_test_local_mode_lock" )
59
60
DATA_PATH = os .path .join (DATA_DIR , "iris" , "data" )
60
61
DEFAULT_REGION = "us-west-2"
62
+ ROLE = "SageMakerRole"
61
63
62
64
63
65
class LocalNoS3Session (LocalSession ):
@@ -147,7 +149,7 @@ def _create_model(output_path):
147
149
148
150
mx = MXNet (
149
151
entry_point = script_path ,
150
- role = "SageMakerRole" ,
152
+ role = ROLE ,
151
153
instance_count = 1 ,
152
154
instance_type = "local" ,
153
155
output_path = output_path ,
@@ -218,7 +220,7 @@ def test_mxnet_local_mode(
218
220
219
221
mx = MXNet (
220
222
entry_point = script_path ,
221
- role = "SageMakerRole" ,
223
+ role = ROLE ,
222
224
py_version = mxnet_training_latest_py_version ,
223
225
instance_count = 1 ,
224
226
instance_type = "local" ,
@@ -254,7 +256,7 @@ def test_mxnet_distributed_local_mode(
254
256
255
257
mx = MXNet (
256
258
entry_point = script_path ,
257
- role = "SageMakerRole" ,
259
+ role = ROLE ,
258
260
py_version = mxnet_training_latest_py_version ,
259
261
instance_count = 2 ,
260
262
instance_type = "local" ,
@@ -289,7 +291,7 @@ def test_mxnet_local_data_local_script(
289
291
290
292
mx = MXNet (
291
293
entry_point = script_path ,
292
- role = "SageMakerRole" ,
294
+ role = ROLE ,
293
295
instance_count = 1 ,
294
296
instance_type = "local" ,
295
297
framework_version = mxnet_training_latest_version ,
@@ -324,7 +326,7 @@ def test_mxnet_local_training_env(mxnet_training_latest_version, mxnet_training_
324
326
325
327
mx = MXNet (
326
328
entry_point = script_path ,
327
- role = "SageMakerRole" ,
329
+ role = ROLE ,
328
330
instance_count = 1 ,
329
331
instance_type = "local" ,
330
332
framework_version = mxnet_training_latest_version ,
@@ -347,7 +349,7 @@ def test_mxnet_training_failure(
347
349
348
350
mx = MXNet (
349
351
entry_point = script_path ,
350
- role = "SageMakerRole" ,
352
+ role = ROLE ,
351
353
framework_version = mxnet_training_latest_version ,
352
354
py_version = mxnet_training_latest_py_version ,
353
355
instance_count = 1 ,
@@ -377,7 +379,7 @@ def test_local_transform_mxnet(
377
379
378
380
mx = MXNet (
379
381
entry_point = script_path ,
380
- role = "SageMakerRole" ,
382
+ role = ROLE ,
381
383
instance_count = 1 ,
382
384
instance_type = "local" ,
383
385
framework_version = mxnet_inference_latest_version ,
@@ -426,7 +428,7 @@ def test_local_processing_sklearn(sagemaker_local_session_no_local_code, sklearn
426
428
427
429
sklearn_processor = SKLearnProcessor (
428
430
framework_version = sklearn_latest_version ,
429
- role = "SageMakerRole" ,
431
+ role = ROLE ,
430
432
instance_type = "local" ,
431
433
instance_count = 1 ,
432
434
command = ["python3" ],
@@ -457,7 +459,7 @@ def test_local_processing_script_processor(sagemaker_local_session, sklearn_imag
457
459
input_file_path = os .path .join (DATA_DIR , "dummy_input.txt" )
458
460
459
461
script_processor = ScriptProcessor (
460
- role = "SageMakerRole" ,
462
+ role = ROLE ,
461
463
image_uri = sklearn_image_uri ,
462
464
command = ["python3" ],
463
465
instance_count = 1 ,
@@ -527,7 +529,7 @@ def test_local_pipeline_with_processing_step(sklearn_latest_version, local_pipel
527
529
string_container_arg = ParameterString (name = "ProcessingContainerArg" , default_value = "foo" )
528
530
sklearn_processor = SKLearnProcessor (
529
531
framework_version = sklearn_latest_version ,
530
- role = "SageMakerRole" ,
532
+ role = ROLE ,
531
533
instance_type = "local" ,
532
534
instance_count = 1 ,
533
535
command = ["python3" ],
@@ -549,7 +551,7 @@ def test_local_pipeline_with_processing_step(sklearn_latest_version, local_pipel
549
551
sagemaker_session = local_pipeline_session ,
550
552
parameters = [string_container_arg ],
551
553
)
552
- pipeline .create ("SageMakerRole" , "pipeline for sdk integ testing" )
554
+ pipeline .create (ROLE , "pipeline for sdk integ testing" )
553
555
554
556
with lock .lock (LOCK_PATH ):
555
557
execution = pipeline .start ()
@@ -586,7 +588,7 @@ def test_local_pipeline_with_training_and_transform_steps(
586
588
# define Estimator
587
589
mx = MXNet (
588
590
entry_point = script_path ,
589
- role = "SageMakerRole" ,
591
+ role = ROLE ,
590
592
instance_count = instance_count ,
591
593
instance_type = "local" ,
592
594
framework_version = mxnet_training_latest_version ,
@@ -614,7 +616,7 @@ def test_local_pipeline_with_training_and_transform_steps(
614
616
image_uri = inference_image_uri ,
615
617
model_data = training_step .properties .ModelArtifacts .S3ModelArtifacts ,
616
618
sagemaker_session = session ,
617
- role = "SageMakerRole" ,
619
+ role = ROLE ,
618
620
)
619
621
620
622
# define create model step
@@ -647,7 +649,7 @@ def test_local_pipeline_with_training_and_transform_steps(
647
649
sagemaker_session = session ,
648
650
)
649
651
650
- pipeline .create ("SageMakerRole" , "pipeline for sdk integ testing" )
652
+ pipeline .create (ROLE , "pipeline for sdk integ testing" )
651
653
652
654
with lock .lock (LOCK_PATH ):
653
655
execution = pipeline .start (parameters = {"InstanceCountParam" : 1 })
@@ -667,7 +669,7 @@ def test_local_pipeline_with_training_and_transform_steps(
667
669
def test_local_pipeline_with_eval_cond_fail_steps (sklearn_image_uri , local_pipeline_session ):
668
670
processor = ScriptProcessor (
669
671
image_uri = sklearn_image_uri ,
670
- role = "SageMakerRole" ,
672
+ role = ROLE ,
671
673
instance_count = 1 ,
672
674
instance_type = "local" ,
673
675
sagemaker_session = local_pipeline_session ,
@@ -729,7 +731,7 @@ def test_local_pipeline_with_eval_cond_fail_steps(sklearn_image_uri, local_pipel
729
731
sagemaker_session = local_pipeline_session ,
730
732
)
731
733
732
- pipeline .create ("SageMakerRole" , "pipeline for sdk integ testing" )
734
+ pipeline .create (ROLE , "pipeline for sdk integ testing" )
733
735
734
736
with lock .lock (LOCK_PATH ):
735
737
execution = pipeline .start ()
@@ -763,7 +765,7 @@ def test_local_pipeline_with_step_decorator_and_step_dependency(
763
765
local_pipeline_session , dummy_container
764
766
):
765
767
step_settings = dict (
766
- role = "SageMakerRole" ,
768
+ role = ROLE ,
767
769
instance_type = "ml.m5.xlarge" ,
768
770
image_uri = dummy_container ,
769
771
keep_alive_period_in_seconds = 60 ,
@@ -787,7 +789,7 @@ def sum(a, b):
787
789
sagemaker_session = local_pipeline_session ,
788
790
)
789
791
790
- pipeline .create ("SageMakerRole" , "pipeline for sdk integ testing" )
792
+ pipeline .create (ROLE , "pipeline for sdk integ testing" )
791
793
792
794
with lock .lock (LOCK_PATH ):
793
795
execution = pipeline .start ()
@@ -808,7 +810,7 @@ def test_local_pipeline_with_step_decorator_and_pre_exe_script(
808
810
local_pipeline_session , dummy_container
809
811
):
810
812
step_settings = dict (
811
- role = "SageMakerRole" ,
813
+ role = ROLE ,
812
814
instance_type = "local" ,
813
815
image_uri = dummy_container ,
814
816
keep_alive_period_in_seconds = 60 ,
@@ -833,7 +835,7 @@ def validate_file_exists(files_exists, files_does_not_exist):
833
835
sagemaker_session = local_pipeline_session ,
834
836
)
835
837
836
- pipeline .create ("SageMakerRole" , "pipeline for sdk integ testing" )
838
+ pipeline .create (ROLE , "pipeline for sdk integ testing" )
837
839
838
840
with lock .lock (LOCK_PATH ):
839
841
execution = pipeline .start ()
@@ -851,7 +853,7 @@ def test_local_pipeline_with_step_decorator_and_condition_step(
851
853
local_pipeline_session , dummy_container
852
854
):
853
855
step_settings = dict (
854
- role = "SageMakerRole" ,
856
+ role = ROLE ,
855
857
instance_type = "local" ,
856
858
image_uri = dummy_container ,
857
859
keep_alive_period_in_seconds = 60 ,
@@ -888,7 +890,7 @@ def else_step():
888
890
sagemaker_session = local_pipeline_session ,
889
891
)
890
892
891
- pipeline .create ("SageMakerRole" , "pipeline for sdk integ testing" )
893
+ pipeline .create (ROLE , "pipeline for sdk integ testing" )
892
894
893
895
with lock .lock (LOCK_PATH ):
894
896
execution = pipeline .start ()
@@ -916,7 +918,7 @@ def test_local_pipeline_with_step_decorator_data_referenced_by_other_steps(
916
918
@step (
917
919
name = "step1" ,
918
920
image_uri = dummy_container ,
919
- role = "SageMakerRole" ,
921
+ role = ROLE ,
920
922
instance_type = "ml.m5.xlarge" ,
921
923
keep_alive_period_in_seconds = 60 ,
922
924
)
@@ -933,7 +935,7 @@ def func(var: int):
933
935
934
936
sklearn_processor = SKLearnProcessor (
935
937
framework_version = sklearn_latest_version ,
936
- role = "SageMakerRole" ,
938
+ role = ROLE ,
937
939
instance_type = "local" ,
938
940
instance_count = step_output [1 ],
939
941
command = ["python3" ],
@@ -967,7 +969,7 @@ def func(var: int):
967
969
sagemaker_session = local_pipeline_session ,
968
970
)
969
971
970
- pipeline .create ("SageMakerRole" , "pipeline for sdk integ testing" )
972
+ pipeline .create (ROLE , "pipeline for sdk integ testing" )
971
973
972
974
with lock .lock (LOCK_PATH ):
973
975
execution = pipeline .start ()
@@ -983,3 +985,23 @@ def func(var: int):
983
985
assert exe_step_result ["StepStatus" ] == "Succeeded"
984
986
if exe_step_result ["StepName" ] == cond_step .name :
985
987
assert exe_step_result ["Metadata" ]["Condition" ]["Outcome" ] is True
988
+
989
+
990
+ def test_local_remote_function_with_additional_dependencies (
991
+ local_pipeline_session , dummy_container
992
+ ):
993
+ dependencies_path = os .path .join (DATA_DIR , "remote_function" , "requirements.txt" )
994
+
995
+ @remote (
996
+ role = ROLE ,
997
+ image_uri = dummy_container ,
998
+ dependencies = dependencies_path ,
999
+ instance_type = "local" ,
1000
+ sagemaker_session = local_pipeline_session ,
1001
+ )
1002
+ def cuberoot (x ):
1003
+ from scipy .special import cbrt
1004
+
1005
+ return cbrt (x )
1006
+
1007
+ assert cuberoot (27 ) == 3
0 commit comments