@@ -62,15 +62,15 @@ def repack(inference_script, model_archive, dependencies=None, source_dir=None):
62
62
with tarfile .open (name = local_path , mode = "r:gz" ) as tf :
63
63
tf .extractall (path = src_dir )
64
64
65
- # copy the custom inference script to code/
66
- entry_point = os .path .join ("/opt/ml/code" , inference_script )
67
- shutil .copy2 (entry_point , os .path .join (src_dir , "code" , inference_script ))
68
-
69
- # copy source_dir to code/
70
65
if source_dir :
66
+ # copy /opt/ml/code to code/
71
67
if os .path .exists (code_dir ):
72
68
shutil .rmtree (code_dir )
73
- shutil .copytree (source_dir , code_dir )
69
+ shutil .copytree ("/opt/ml/code" , code_dir )
70
+ else :
71
+ # copy the custom inference script to code/
72
+ entry_point = os .path .join ("/opt/ml/code" , inference_script )
73
+ shutil .copy2 (entry_point , os .path .join (code_dir , inference_script ))
74
74
75
75
# copy any dependencies to code/lib/
76
76
if dependencies :
@@ -79,13 +79,16 @@ def repack(inference_script, model_archive, dependencies=None, source_dir=None):
79
79
lib_dir = os .path .join (code_dir , "lib" )
80
80
if not os .path .exists (lib_dir ):
81
81
os .mkdir (lib_dir )
82
- if os .path .isdir (actual_dependency_path ):
83
- shutil .copytree (
84
- actual_dependency_path ,
85
- os .path .join (lib_dir , os .path .basename (actual_dependency_path )),
86
- )
87
- else :
82
+ if os .path .isfile (actual_dependency_path ):
88
83
shutil .copy2 (actual_dependency_path , lib_dir )
84
+ else :
85
+ if os .path .exists (lib_dir ):
86
+ shutil .rmtree (lib_dir )
87
+ # a directory is in the dependencies. we have to copy
88
+ # all of /opt/ml/code into the lib dir because the original directory
89
+ # was flattened by the SDK training job upload..
90
+ shutil .copytree ("/opt/ml/code" , lib_dir )
91
+ break
89
92
90
93
# copy the "src" dir, which includes the previous training job's model and the
91
94
# custom inference script, to the output of this training job
0 commit comments