@@ -837,21 +837,31 @@ def cleanup_local_hf_model_artifact(
837837 """
838838 if local_dir and os .path .exists (local_dir ):
839839 model_dir = os .path .join (local_dir , model_name )
840+ model_dir = (
841+ os .path .dirname (model_dir )
842+ if "/" in model_name or os .sep in model_name
843+ else model_dir
844+ )
845+ shutil .rmtree (model_dir , ignore_errors = True )
840846 if os .path .exists (model_dir ):
841- shutil .rmtree (model_dir )
842- logger .debug (f"Deleted local model artifact directory: { model_dir } " )
843-
844- if not os .listdir (local_dir ):
845- shutil .rmtree (local_dir )
846- logger .debug (f"Deleted local directory { model_dir } as it is empty." )
847+ logger .debug (
848+ f"Could not delete local model artifact directory: { model_dir } "
849+ )
850+ else :
851+ logger .debug (f"Deleted local model artifact directory: { model_dir } ." )
847852
848853 hf_local_path = os .path .join (
849854 HF_HUB_CACHE , repo_folder_name (repo_id = model_name , repo_type = "model" )
850855 )
856+ shutil .rmtree (hf_local_path , ignore_errors = True )
857+
851858 if os .path .exists (hf_local_path ):
852- shutil .rmtree (hf_local_path )
853859 logger .debug (
854- f"Deleted local Hugging Face cache directory { hf_local_path } for the model { model_name } "
860+ f"Could not clear the local Hugging Face cache directory { hf_local_path } for the model { model_name } ."
861+ )
862+ else :
863+ logger .debug (
864+ f"Cleared contents of local Hugging Face cache directory { hf_local_path } for the model { model_name } ."
855865 )
856866
857867
0 commit comments