1616
1717import sagemaker
1818
19- from sagemaker . local import LocalSession
20- from sagemaker . fw_utils import tar_and_upload_dir , parse_s3_url , model_code_key_prefix
21- from sagemaker . session import Session
22- from sagemaker . utils import name_from_image , get_config_value
19+ from sagemaker import local
20+ from sagemaker import fw_utils
21+ from sagemaker import session
22+ from sagemaker import utils
2323
2424
2525class Model (object ):
@@ -96,12 +96,12 @@ def deploy(self, initial_instance_count, instance_type, endpoint_name=None, tags
9696 """
9797 if not self .sagemaker_session :
9898 if instance_type in ('local' , 'local_gpu' ):
99- self .sagemaker_session = LocalSession ()
99+ self .sagemaker_session = local . LocalSession ()
100100 else :
101- self .sagemaker_session = Session ()
101+ self .sagemaker_session = session . Session ()
102102
103103 container_def = self .prepare_container_def (instance_type )
104- self .name = self .name or name_from_image (container_def ['Image' ])
104+ self .name = self .name or utils . name_from_image (container_def ['Image' ])
105105 self .sagemaker_session .create_model (self .name , self .role , container_def , vpc_config = self .vpc_config )
106106 production_variant = sagemaker .production_variant (self .name , instance_type , initial_instance_count )
107107 self .endpoint_name = endpoint_name or self .name
@@ -127,7 +127,7 @@ class FrameworkModel(Model):
127127
128128 def __init__ (self , model_data , image , role , entry_point , source_dir = None , predictor_cls = None , env = None , name = None ,
129129 enable_cloudwatch_metrics = False , container_log_level = logging .INFO , code_location = None ,
130- sagemaker_session = None , lib_dirs = None , ** kwargs ):
130+ sagemaker_session = None , dependencies = None , ** kwargs ):
131131 """Initialize a ``FrameworkModel``.
132132
133133 Args:
@@ -140,14 +140,14 @@ def __init__(self, model_data, image, role, entry_point, source_dir=None, predic
140140 source code dependencies aside from tne entry point file (default: None). Structure within this
141141 directory will be preserved when training on SageMaker.
142142 If the directory points to S3, no code will be uploaded and the S3 location will be used instead.
143- lib_dirs (list[str]): A list of paths to directories (absolute or relative) with
143+ dependencies (list[str]): A list of paths to directories (absolute or relative) with
144144 any additional libraries that will be exported to the container (default: []).
145145 The library folders will be copied to SageMaker in the same folder where the entrypoint is copied.
146146 If the ```source_dir``` points to S3, code will be uploaded and the S3 location will be used
147147 instead. Example:
148148
149149 The following call
150- >>> Estimator(entry_point='train.py', lib_dirs =['my/libs/common', 'virtual-env'])
150+ >>> Estimator(entry_point='train.py', dependencies =['my/libs/common', 'virtual-env'])
151151 results in the following inside the container:
152152
153153 >>> $ ls
@@ -177,11 +177,11 @@ def __init__(self, model_data, image, role, entry_point, source_dir=None, predic
177177 sagemaker_session = sagemaker_session , ** kwargs )
178178 self .entry_point = entry_point
179179 self .source_dir = source_dir
180- self .lib_dirs = lib_dirs or []
180+ self .dependencies = dependencies or []
181181 self .enable_cloudwatch_metrics = enable_cloudwatch_metrics
182182 self .container_log_level = container_log_level
183183 if code_location :
184- self .bucket , self .key_prefix = parse_s3_url (code_location )
184+ self .bucket , self .key_prefix = fw_utils . parse_s3_url (code_location )
185185 else :
186186 self .bucket , self .key_prefix = None , None
187187 self .uploaded_code = None
@@ -197,23 +197,24 @@ def prepare_container_def(self, instance_type): # pylint disable=unused-argumen
197197 Returns:
198198 dict[str, str]: A container definition object usable with the CreateModel API.
199199 """
200- deploy_key_prefix = model_code_key_prefix (self .key_prefix , self .name , self .image )
200+ deploy_key_prefix = fw_utils . model_code_key_prefix (self .key_prefix , self .name , self .image )
201201 self ._upload_code (deploy_key_prefix )
202202 deploy_env = dict (self .env )
203203 deploy_env .update (self ._framework_env_vars ())
204204 return sagemaker .container_def (self .image , self .model_data , deploy_env )
205205
206206 def _upload_code (self , key_prefix ):
207- local_code = get_config_value ('local.local_code' , self .sagemaker_session .config )
207+ local_code = utils . get_config_value ('local.local_code' , self .sagemaker_session .config )
208208 if self .sagemaker_session .local_mode and local_code :
209209 self .uploaded_code = None
210210 else :
211- self .uploaded_code = tar_and_upload_dir (session = self .sagemaker_session .boto_session ,
212- bucket = self .bucket or self .sagemaker_session .default_bucket (),
213- s3_key_prefix = key_prefix ,
214- script = self .entry_point ,
215- directory = self .source_dir ,
216- lib_dirs = self .lib_dirs )
211+ bucket = self .bucket or self .sagemaker_session .default_bucket ()
212+ self .uploaded_code = fw_utils .tar_and_upload_dir (session = self .sagemaker_session .boto_session ,
213+ bucket = bucket ,
214+ s3_key_prefix = key_prefix ,
215+ script = self .entry_point ,
216+ directory = self .source_dir ,
217+ dependencies = self .dependencies )
217218
218219 def _framework_env_vars (self ):
219220 if self .uploaded_code :
0 commit comments