@@ -94,6 +94,8 @@ def _upload(self):
9494
9595
9696class SmallArtifactUploader (ArtifactUploader ):
97+ """The class helper to upload small model artifacts."""
98+
9799 PROGRESS_STEPS_COUNT = 1
98100
99101 def _upload (self ):
@@ -104,6 +106,39 @@ def _upload(self):
104106
105107
106108class LargeArtifactUploader (ArtifactUploader ):
109+ """
110+ The class helper to upload large model artifacts.
111+
112+ Attributes
113+ ----------
114+ artifact_path: str
115+ The model artifact location.
116+ artifact_zip_path: str
117+ The uri of the zip of model artifact.
118+ auth: dict
119+ The default authetication is set using `ads.set_auth` API.
120+ If you need to override the default, use the `ads.common.auth.api_keys` or
121+ `ads.common.auth.resource_principal` to create appropriate authentication signer
122+ and kwargs required to instantiate IdentityClient object.
123+ bucket_uri: str
124+ The OCI Object Storage URI where model artifacts will be copied to.
125+ The `bucket_uri` is only necessary for uploading large artifacts which
126+ size is greater than 2GB. Example: `oci://<bucket_name>@<namespace>/prefix/`.
127+ dsc_model: OCIDataScienceModel
128+ The data scince model instance.
129+ overwrite_existing_artifact: bool
130+ Overwrite target bucket artifact if exists.
131+ progress: TqdmProgressBar
132+ An instance of the TqdmProgressBar.
133+ region: str
134+ The destination Object Storage bucket region.
135+ By default the value will be extracted from the `OCI_REGION_METADATA` environment variables.
136+ remove_existing_artifact: bool
137+ Wether artifacts uploaded to object storage bucket need to be removed or not.
138+ upload_manager: UploadManager
139+ The uploadManager simplifies interaction with the Object Storage service.
140+ """
141+
107142 PROGRESS_STEPS_COUNT = 4
108143
109144 def __init__ (
@@ -115,6 +150,7 @@ def __init__(
115150 region : Optional [str ] = None ,
116151 overwrite_existing_artifact : Optional [bool ] = True ,
117152 remove_existing_artifact : Optional [bool ] = True ,
153+ parallel_process_count : int = utils .DEFAULT_PARALLEL_PROCESS_COUNT ,
118154 ):
119155 """Initializes `LargeArtifactUploader` instance.
120156
@@ -139,7 +175,9 @@ def __init__(
139175 overwrite_existing_artifact: (bool, optional). Defaults to `True`.
140176 Overwrite target bucket artifact if exists.
141177 remove_existing_artifact: (bool, optional). Defaults to `True`.
142- Wether artifacts uploaded to object storage bucket need to be removed or not.
178+ Whether artifacts uploaded to object storage bucket need to be removed or not.
179+ parallel_process_count: (int, optional).
180+ The number of worker processes to use in parallel for uploading individual parts of a multipart upload.
143181 """
144182 if not bucket_uri :
145183 raise ValueError ("The `bucket_uri` must be provided." )
@@ -150,36 +188,45 @@ def __init__(
150188 self .bucket_uri = bucket_uri
151189 self .overwrite_existing_artifact = overwrite_existing_artifact
152190 self .remove_existing_artifact = remove_existing_artifact
191+ self ._parallel_process_count = parallel_process_count
153192
154193 def _upload (self ):
155194 """Uploads model artifacts to the model catalog."""
156195 self .progress .update ("Copying model artifact to the Object Storage bucket" )
157196
158- try :
159- bucket_uri = self .bucket_uri
160- bucket_uri_file_name = os .path .basename (bucket_uri )
197+ bucket_uri = self .bucket_uri
198+ bucket_uri_file_name = os .path .basename (bucket_uri )
161199
162- if not bucket_uri_file_name :
163- bucket_uri = os .path .join (bucket_uri , f"{ self .dsc_model .id } .zip" )
164- elif not bucket_uri .lower ().endswith (".zip" ):
165- bucket_uri = f"{ bucket_uri } .zip"
200+ if not bucket_uri_file_name :
201+ bucket_uri = os .path .join (bucket_uri , f"{ self .dsc_model .id } .zip" )
202+ elif not bucket_uri .lower ().endswith (".zip" ):
203+ bucket_uri = f"{ bucket_uri } .zip"
166204
167- bucket_file_name = utils .copy_file (
168- self .artifact_zip_path ,
169- bucket_uri ,
170- force_overwrite = self .overwrite_existing_artifact ,
171- auth = self .auth ,
172- progressbar_description = "Copying model artifact to the Object Storage bucket" ,
173- )
174- except FileExistsError :
205+ if not self .overwrite_existing_artifact and utils .is_path_exists (
206+ uri = bucket_uri , auth = self .auth
207+ ):
175208 raise FileExistsError (
176- f"The `{ self .bucket_uri } ` exists. Please use a new file name or "
209+ f"The bucket_uri= `{ self .bucket_uri } ` exists. Please use a new file name or "
177210 "set `overwrite_existing_artifact` to `True` if you wish to overwrite."
178211 )
212+
213+ try :
214+ utils .upload_to_os (
215+ src_uri = self .artifact_zip_path ,
216+ dst_uri = bucket_uri ,
217+ auth = self .auth ,
218+ parallel_process_count = self ._parallel_process_count ,
219+ force_overwrite = self .overwrite_existing_artifact ,
220+ progressbar_description = "Copying model artifact to the Object Storage bucket." ,
221+ )
222+ except Exception as ex :
223+ raise RuntimeError (
224+ f"Failed to upload model artifact to the given Object Storage path `{ self .bucket_uri } `."
225+ f"See Exception: { ex } "
226+ )
227+
179228 self .progress .update ("Exporting model artifact to the model catalog" )
180- self .dsc_model .export_model_artifact (
181- bucket_uri = bucket_file_name , region = self .region
182- )
229+ self .dsc_model .export_model_artifact (bucket_uri = bucket_uri , region = self .region )
183230
184231 if self .remove_existing_artifact :
185232 self .progress .update (
0 commit comments