|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
| 14 | +import hashlib |
| 15 | +import json |
14 | 16 | import os
|
15 |
| -import sys |
16 | 17 | import os.path as osp
|
17 |
| -from typing import Optional |
18 | 18 | import shutil
|
19 |
| -import json |
20 |
| -import requests |
21 |
| -import hashlib |
| 19 | +import sys |
22 | 20 | import tarfile
|
23 |
| -import zipfile |
| 21 | +import threading |
24 | 22 | import time
|
25 | 23 | import uuid
|
26 |
| -import threading |
| 24 | +import zipfile |
27 | 25 | from collections import OrderedDict
|
28 |
| -from .env import DOWNLOAD_SERVER, SUCCESS_STATUS, FAILED_STATUS |
| 26 | +from typing import Optional |
| 27 | + |
| 28 | +import requests |
| 29 | + |
| 30 | +from .env import DOWNLOAD_SERVER, FAILED_STATUS, LOCK_FILE_HOME, SUCCESS_STATUS |
| 31 | +from .file_lock import FileLock |
29 | 32 |
|
30 | 33 | try:
|
31 | 34 | from tqdm import tqdm
|
@@ -117,7 +120,7 @@ def get_weights_path_from_url(url, md5sum=None):
|
117 | 120 | Args:
|
118 | 121 | url (str): download url
|
119 | 122 | md5sum (str): md5 sum of download package
|
120 |
| - |
| 123 | +
|
121 | 124 | Returns:
|
122 | 125 | str: a local path to save downloaded weights.
|
123 | 126 | Examples:
|
@@ -147,7 +150,7 @@ def get_path_from_url(url, root_dir, md5sum=None, check_exist=True):
|
147 | 150 | root_dir (str): root dir for downloading, it should be
|
148 | 151 | WEIGHTS_HOME or DATASET_HOME
|
149 | 152 | md5sum (str): md5 sum of download package
|
150 |
| - |
| 153 | +
|
151 | 154 | Returns:
|
152 | 155 | str: a local path to save downloaded models & weights & datasets.
|
153 | 156 | """
|
@@ -192,11 +195,13 @@ def get_path_from_url_with_filelock(url: str,
|
192 | 195 | os.makedirs(root_dir, exist_ok=True)
|
193 | 196 |
|
194 | 197 | # create lock file, which is empty, under the `LOCK_FILE_HOME` directory.
|
195 |
| - lock_file_path = os.path.join(LOCK_FILE_HOME, |
196 |
| - f"{str(hash(url + root_dir))}") |
| 198 | + lock_file_name = hashlib.md5((url + root_dir).encode("utf-8")).hexdigest() |
| 199 | + lock_file_path = os.path.join(LOCK_FILE_HOME, lock_file_name) |
| 200 | + |
197 | 201 | with FileLock(lock_file_path):
|
198 | 202 | # import get_path_from_url from paddle framework
|
199 |
| - from paddle.utils.download import get_path_from_url as _get_path_from_url |
| 203 | + from paddle.utils.download import \ |
| 204 | + get_path_from_url as _get_path_from_url |
200 | 205 | result = _get_path_from_url(url=url,
|
201 | 206 | root_dir=root_dir,
|
202 | 207 | md5sum=md5sum,
|
@@ -435,6 +440,7 @@ def request_check(self, task, command, addition):
|
435 | 440 | extra.update({"addition": addition})
|
436 | 441 | try:
|
437 | 442 | import paddle
|
| 443 | + |
438 | 444 | import paddlenlp
|
439 | 445 | payload['hub_version'] = " "
|
440 | 446 | payload['ppnlp_version'] = paddlenlp.__version__
|
|
0 commit comments