4040 AQUA_MODEL_ARTIFACT_CONFIG_MODEL_TYPE ,
4141 AQUA_MODEL_ARTIFACT_FILE ,
4242 AQUA_MODEL_TYPE_CUSTOM ,
43+ HF_METADATA_FOLDER ,
4344 LICENSE_TXT ,
4445 MODEL_BY_REFERENCE_OSS_PATH_KEY ,
4546 README ,
@@ -1274,6 +1275,8 @@ def _download_model_from_hf(
12741275 model_name : str ,
12751276 os_path : str ,
12761277 local_dir : str = None ,
1278+ allow_patterns : List [str ] = None ,
1279+ ignore_patterns : List [str ] = None ,
12771280 ) -> str :
12781281 """This helper function downloads the model artifact from Hugging Face to a local folder, then uploads
12791282 to object storage location.
@@ -1283,6 +1286,8 @@ def _download_model_from_hf(
12831286 model_name (str): The huggingface model name.
12841287 os_path (str): The OS path where the model files are located.
12851288 local_dir (str): The local temp dir to store the huggingface model.
1289+ allow_patterns (list): Model files matching at least one pattern are downloaded.
1290+ ignore_patterns (list): Model files matching any of the patterns are not downloaded.
12861291
12871292 Returns
12881293 -------
@@ -1293,30 +1298,19 @@ def _download_model_from_hf(
12931298 if not local_dir :
12941299 local_dir = os .path .join (os .path .expanduser ("~" ), "cached-model" )
12951300 local_dir = os .path .join (local_dir , model_name )
1296- retry = 10
1297- i = 0
1298- huggingface_download_err_message = None
1299- while i < retry :
1300- try :
1301- # Download to cache folder. The while loop retries when there is a network failure
1302- snapshot_download (repo_id = model_name )
1303- except Exception as e :
1304- huggingface_download_err_message = str (e )
1305- i += 1
1306- else :
1307- break
1308- if i == retry :
1309- raise Exception (
1310- f"Could not download the model { model_name } from https://huggingface.co with message { huggingface_download_err_message } "
1311- )
13121301 os .makedirs (local_dir , exist_ok = True )
1313- # Copy the model from the cache to destination
1314- snapshot_download (repo_id = model_name , local_dir = local_dir )
1315- # Upload to object storage
1302+ snapshot_download (
1303+ repo_id = model_name ,
1304+ local_dir = local_dir ,
1305+ allow_patterns = allow_patterns ,
1306+ ignore_patterns = ignore_patterns ,
1307+ )
1308+ # Upload to object storage and skip .cache/huggingface/ folder
13161309 model_artifact_path = upload_folder (
13171310 os_path = os_path ,
13181311 local_dir = local_dir ,
13191312 model_name = model_name ,
1313+ exclude_pattern = f"{ HF_METADATA_FOLDER } *"
13201314 )
13211315
13221316 return model_artifact_path
@@ -1381,6 +1375,8 @@ def register(
13811375 model_name = model_name ,
13821376 os_path = import_model_details .os_path ,
13831377 local_dir = import_model_details .local_dir ,
1378+ allow_patterns = import_model_details .allow_patterns ,
1379+ ignore_patterns = import_model_details .ignore_patterns ,
13841380 ).rstrip ("/" )
13851381 else :
13861382 artifact_path = import_model_details .os_path .rstrip ("/" )
0 commit comments