Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
32a227f5
Unverified
Commit
32a227f5
authored
Dec 13, 2018
by
Thomas Wolf
Committed by
GitHub
Dec 13, 2018
Browse files
Merge pull request #113 from hzhwcmhf/master
fix compatibility with python 3.5.2
parents
ffe9075f
485adde7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
3 deletions
+9
-3
pytorch_pretrained_bert/file_utils.py
pytorch_pretrained_bert/file_utils.py
+9
-3
No files found.
pytorch_pretrained_bert/file_utils.py
View file @
32a227f5
...
@@ -45,13 +45,15 @@ def url_to_filename(url: str, etag: str = None) -> str:
...
@@ -45,13 +45,15 @@ def url_to_filename(url: str, etag: str = None) -> str:
return
filename
return
filename
def
filename_to_url
(
filename
:
str
,
cache_dir
:
str
=
None
)
->
Tuple
[
str
,
str
]:
def
filename_to_url
(
filename
:
str
,
cache_dir
:
Union
[
str
,
Path
]
=
None
)
->
Tuple
[
str
,
str
]:
"""
"""
Return the url and etag (which may be ``None``) stored for `filename`.
Return the url and etag (which may be ``None``) stored for `filename`.
Raise ``FileNotFoundError`` if `filename` or its stored metadata do not exist.
Raise ``FileNotFoundError`` if `filename` or its stored metadata do not exist.
"""
"""
if
cache_dir
is
None
:
if
cache_dir
is
None
:
cache_dir
=
PYTORCH_PRETRAINED_BERT_CACHE
cache_dir
=
PYTORCH_PRETRAINED_BERT_CACHE
if
isinstance
(
cache_dir
,
Path
):
cache_dir
=
str
(
cache_dir
)
cache_path
=
os
.
path
.
join
(
cache_dir
,
filename
)
cache_path
=
os
.
path
.
join
(
cache_dir
,
filename
)
if
not
os
.
path
.
exists
(
cache_path
):
if
not
os
.
path
.
exists
(
cache_path
):
...
@@ -69,7 +71,7 @@ def filename_to_url(filename: str, cache_dir: str = None) -> Tuple[str, str]:
...
@@ -69,7 +71,7 @@ def filename_to_url(filename: str, cache_dir: str = None) -> Tuple[str, str]:
return
url
,
etag
return
url
,
etag
def
cached_path
(
url_or_filename
:
Union
[
str
,
Path
],
cache_dir
:
str
=
None
)
->
str
:
def
cached_path
(
url_or_filename
:
Union
[
str
,
Path
],
cache_dir
:
Union
[
str
,
Path
]
=
None
)
->
str
:
"""
"""
Given something that might be a URL (or might be a local path),
Given something that might be a URL (or might be a local path),
determine which. If it's a URL, download the file and cache it, and
determine which. If it's a URL, download the file and cache it, and
...
@@ -80,6 +82,8 @@ def cached_path(url_or_filename: Union[str, Path], cache_dir: str = None) -> str
...
@@ -80,6 +82,8 @@ def cached_path(url_or_filename: Union[str, Path], cache_dir: str = None) -> str
cache_dir
=
PYTORCH_PRETRAINED_BERT_CACHE
cache_dir
=
PYTORCH_PRETRAINED_BERT_CACHE
if
isinstance
(
url_or_filename
,
Path
):
if
isinstance
(
url_or_filename
,
Path
):
url_or_filename
=
str
(
url_or_filename
)
url_or_filename
=
str
(
url_or_filename
)
if
isinstance
(
cache_dir
,
Path
):
cache_dir
=
str
(
cache_dir
)
parsed
=
urlparse
(
url_or_filename
)
parsed
=
urlparse
(
url_or_filename
)
...
@@ -158,13 +162,15 @@ def http_get(url: str, temp_file: IO) -> None:
...
@@ -158,13 +162,15 @@ def http_get(url: str, temp_file: IO) -> None:
progress
.
close
()
progress
.
close
()
def
get_from_cache
(
url
:
str
,
cache_dir
:
str
=
None
)
->
str
:
def
get_from_cache
(
url
:
str
,
cache_dir
:
Union
[
str
,
Path
]
=
None
)
->
str
:
"""
"""
Given a URL, look for the corresponding dataset in the local cache.
Given a URL, look for the corresponding dataset in the local cache.
If it's not there, download it. Then return the path to the cached file.
If it's not there, download it. Then return the path to the cached file.
"""
"""
if
cache_dir
is
None
:
if
cache_dir
is
None
:
cache_dir
=
PYTORCH_PRETRAINED_BERT_CACHE
cache_dir
=
PYTORCH_PRETRAINED_BERT_CACHE
if
isinstance
(
cache_dir
,
Path
):
cache_dir
=
str
(
cache_dir
)
os
.
makedirs
(
cache_dir
,
exist_ok
=
True
)
os
.
makedirs
(
cache_dir
,
exist_ok
=
True
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment