File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ import os
16+ import shutil
17+ import tempfile
1518from functools import lru_cache
1619from pathlib import Path
1720
@@ -444,9 +447,17 @@ def _download_from_bos():
444447 def _download_from_hf ():
445448 local_dir = self ._save_dir / f"{ key } "
446449 try :
447- hf_hub .snapshot_download (
448- repo_id = f"PaddlePaddle/{ key } " , local_dir = local_dir
449- )
450+ if os .path .exists (local_dir ):
451+ hf_hub .snapshot_download (
452+ repo_id = f"PaddlePaddle/{ key } " , local_dir = local_dir
453+ )
454+ else :
455+ with tempfile .TemporaryDirectory () as td :
456+ temp_dir = os .path .join (td , "temp_dir" )
457+ hf_hub .snapshot_download (
458+ repo_id = f"PaddlePaddle/{ key } " , local_dir = temp_dir
459+ )
460+ shutil .move (temp_dir , local_dir )
450461 except Exception as e :
451462 logging .warning (
452463 f"Encounter exception when download model from huggingface: \n { e } .\n PaddleX would try to download from BOS."
You can’t perform that action at this time.
0 commit comments