File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 16
16
import json
17
17
import os
18
18
from collections import defaultdict
19
+ from typing import Optional
19
20
20
21
from huggingface_hub import hf_hub_download
21
22
from paddlenlp .transformers .configuration_utils import is_standard_config
22
23
from paddlenlp .transformers .model_utils import PretrainedModel
23
- from paddlenlp .transformers .utils import resolve_cache_dir
24
24
from paddlenlp .utils .downloader import (
25
25
COMMUNITY_MODEL_PREFIX ,
26
26
get_path_from_url_with_filelock ,
27
27
hf_file_exists ,
28
28
url_file_exists ,
29
29
)
30
+ from paddlenlp .utils .env import HF_CACHE_HOME as PPNLP_HF_CACHE_HOME
31
+ from paddlenlp .utils .env import MODEL_HOME as PPNLP_MODEL_HOME
30
32
from paddlenlp .utils .import_utils import import_module
31
33
from paddlenlp .utils .log import logger
32
34
57
59
}
58
60
59
61
62
+ def resolve_cache_dir (from_hf_hub : bool , from_aistudio : bool , cache_dir : Optional [str ] = None ) -> str :
63
+ """resolve cache dir for PretrainedModel and PretrainedConfig
64
+
65
+ Args:
66
+ from_hf_hub (bool): if load from huggingface hub
67
+ cache_dir (str): cache_dir for models
68
+ """
69
+ if cache_dir is not None :
70
+ return cache_dir
71
+ if from_aistudio :
72
+ return None
73
+ if from_hf_hub :
74
+ return PPNLP_HF_CACHE_HOME
75
+ return PPNLP_MODEL_HOME
76
+
77
+
60
78
def get_model_mapping ():
61
79
62
80
# 1. search the subdir<model-name> to find model-names
You can’t perform that action at this time.
0 commit comments