@@ -162,7 +162,7 @@ def test_sklearn_with_all_parameters(
162
162
@patch ("os.path.exists" , return_value = True )
163
163
@patch ("os.path.isfile" , return_value = True )
164
164
def test_sklearn_with_all_parameters_via_run_args (
165
- exists_mock , isfile_mock , botocore_resolver , sklearn_version , sagemaker_session
165
+ exists_mock , isfile_mock , botocore_resolver , sklearn_version , sagemaker_session , uploaded_code
166
166
):
167
167
botocore_resolver .return_value .construct_endpoint .return_value = {"hostname" : ECR_HOSTNAME }
168
168
custom_command = ["Rscript" ]
@@ -190,28 +190,31 @@ def test_sklearn_with_all_parameters_via_run_args(
190
190
sagemaker_session = sagemaker_session ,
191
191
)
192
192
193
- # FIXME: to check FrameworkProcessor.get_run_args(), and possibly fix with
194
- # source_dir, dependencies.
195
- run_args = processor .get_run_args (
196
- code = "/local/path/to/processing_code.py" ,
197
- inputs = _get_data_inputs_all_parameters (),
198
- outputs = _get_data_outputs_all_parameters (),
199
- arguments = ["--drop-columns" , "'SelfEmployed'" ],
200
- )
193
+ with patch ("sagemaker.estimator.tar_and_upload_dir" , return_value = uploaded_code ):
194
+ run_args = processor .get_run_args (
195
+ code = "processing_code.py" ,
196
+ source_dir = "/local/path/to/source_dir" ,
197
+ dependencies = ["/local/path/to/dep_01" ],
198
+ git_config = None ,
199
+ inputs = _get_data_inputs_all_parameters (),
200
+ outputs = _get_data_outputs_all_parameters (),
201
+ arguments = ["--drop-columns" , "'SelfEmployed'" ],
202
+ )
201
203
202
- processor .run (
203
- code = run_args .code ,
204
- inputs = run_args .inputs ,
205
- outputs = run_args .outputs ,
206
- arguments = run_args .arguments ,
207
- wait = True ,
208
- logs = False ,
209
- experiment_config = {"ExperimentName" : "AnExperiment" },
210
- )
204
+ processor .run (
205
+ code = run_args .code ,
206
+ inputs = run_args .inputs ,
207
+ outputs = run_args .outputs ,
208
+ arguments = run_args .arguments ,
209
+ wait = True ,
210
+ logs = False ,
211
+ experiment_config = {"ExperimentName" : "AnExperiment" },
212
+ )
211
213
212
214
expected_args = _get_expected_args_all_parameters_modular_code (
213
215
processor ._current_job_name ,
214
216
instance_count = 2 ,
217
+ code_s3_prefix = run_args .code .replace ("/runproc.sh" , "" ),
215
218
)
216
219
sklearn_image_uri = (
217
220
"246618743249.dkr.ecr.us-west-2.amazonaws.com/sagemaker-scikit-learn:{}-cpu-py3"
@@ -235,7 +238,7 @@ def test_sklearn_with_all_parameters_via_run_args(
235
238
@patch ("os.path.exists" , return_value = True )
236
239
@patch ("os.path.isfile" , return_value = True )
237
240
def test_sklearn_with_all_parameters_via_run_args_called_twice (
238
- exists_mock , isfile_mock , botocore_resolver , sklearn_version , sagemaker_session
241
+ exists_mock , isfile_mock , botocore_resolver , sklearn_version , sagemaker_session , uploaded_code
239
242
):
240
243
botocore_resolver .return_value .construct_endpoint .return_value = {"hostname" : ECR_HOSTNAME }
241
244
@@ -261,15 +264,22 @@ def test_sklearn_with_all_parameters_via_run_args_called_twice(
261
264
sagemaker_session = sagemaker_session ,
262
265
)
263
266
264
- run_args = processor .get_run_args (
265
- code = "/local/path/to/processing_code.py" ,
266
- inputs = _get_data_inputs_all_parameters (),
267
- outputs = _get_data_outputs_all_parameters (),
268
- arguments = ["--drop-columns" , "'SelfEmployed'" ],
269
- )
267
+ with patch ("sagemaker.estimator.tar_and_upload_dir" , return_value = uploaded_code ):
268
+ run_args = processor .get_run_args (
269
+ code = "processing_code.py" ,
270
+ source_dir = "/local/path/to/source_dir" ,
271
+ dependencies = ["/local/path/to/dep_01" ],
272
+ git_config = None ,
273
+ inputs = _get_data_inputs_all_parameters (),
274
+ outputs = _get_data_outputs_all_parameters (),
275
+ arguments = ["--drop-columns" , "'SelfEmployed'" ],
276
+ )
270
277
271
278
run_args = processor .get_run_args (
272
279
code = "/local/path/to/processing_code.py" ,
280
+ source_dir = None ,
281
+ dependencies = None ,
282
+ git_config = None ,
273
283
inputs = _get_data_inputs_all_parameters (),
274
284
outputs = _get_data_outputs_all_parameters (),
275
285
arguments = ["--drop-columns" , "'SelfEmployed'" ],
@@ -285,7 +295,10 @@ def test_sklearn_with_all_parameters_via_run_args_called_twice(
285
295
experiment_config = {"ExperimentName" : "AnExperiment" },
286
296
)
287
297
288
- expected_args = _get_expected_args_all_parameters_modular_code (processor ._current_job_name )
298
+ expected_args = _get_expected_args_all_parameters_modular_code (
299
+ processor ._current_job_name ,
300
+ code_s3_prefix = run_args .code .replace ("/runproc.sh" , "" ),
301
+ )
289
302
sklearn_image_uri = (
290
303
"246618743249.dkr.ecr.us-west-2.amazonaws.com/sagemaker-scikit-learn:{}-cpu-py3"
291
304
).format (sklearn_version )
@@ -839,9 +852,14 @@ def _get_data_outputs_all_parameters():
839
852
840
853
841
854
def _get_expected_args_all_parameters_modular_code (
842
- job_name , code_s3_uri = MOCKED_S3_URI , instance_count = 1
855
+ job_name ,
856
+ code_s3_uri = MOCKED_S3_URI ,
857
+ instance_count = 1 ,
858
+ code_s3_prefix = None ,
843
859
):
844
- # Add something to inputs
860
+ if code_s3_prefix is None :
861
+ code_s3_prefix = f"{ code_s3_uri } /{ job_name } /source"
862
+
845
863
return {
846
864
"inputs" : [
847
865
{
@@ -911,7 +929,7 @@ def _get_expected_args_all_parameters_modular_code(
911
929
"InputName" : "code" ,
912
930
"AppManaged" : False ,
913
931
"S3Input" : {
914
- "S3Uri" : f"{ code_s3_uri } / { job_name } /source /sourcedir.tar.gz" ,
932
+ "S3Uri" : f"{ code_s3_prefix } /sourcedir.tar.gz" ,
915
933
"LocalPath" : "/opt/ml/processing/input/code/" ,
916
934
"S3DataType" : "S3Prefix" ,
917
935
"S3InputMode" : "File" ,
@@ -923,7 +941,7 @@ def _get_expected_args_all_parameters_modular_code(
923
941
"InputName" : "entrypoint" ,
924
942
"AppManaged" : False ,
925
943
"S3Input" : {
926
- "S3Uri" : f"{ code_s3_uri } / { job_name } /source /runproc.sh" ,
944
+ "S3Uri" : f"{ code_s3_prefix } /runproc.sh" ,
927
945
"LocalPath" : "/opt/ml/processing/input/entrypoint" ,
928
946
"S3DataType" : "S3Prefix" ,
929
947
"S3InputMode" : "File" ,
0 commit comments