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
f0bf81e1
Commit
f0bf81e1
authored
Feb 09, 2019
by
thomwolf
Browse files
back compatibility with Path inputs in fle_utils
parent
9f9909ea
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
0 deletions
+9
-0
pytorch_pretrained_bert/file_utils.py
pytorch_pretrained_bert/file_utils.py
+9
-0
No files found.
pytorch_pretrained_bert/file_utils.py
View file @
f0bf81e1
...
@@ -12,6 +12,7 @@ import shutil
...
@@ -12,6 +12,7 @@ import shutil
import
tempfile
import
tempfile
from
functools
import
wraps
from
functools
import
wraps
from
hashlib
import
sha256
from
hashlib
import
sha256
import
sys
from
io
import
open
from
io
import
open
import
boto3
import
boto3
...
@@ -60,6 +61,8 @@ def filename_to_url(filename, cache_dir=None):
...
@@ -60,6 +61,8 @@ def filename_to_url(filename, cache_dir=None):
"""
"""
if
cache_dir
is
None
:
if
cache_dir
is
None
:
cache_dir
=
PYTORCH_PRETRAINED_BERT_CACHE
cache_dir
=
PYTORCH_PRETRAINED_BERT_CACHE
if
sys
.
version_info
[
0
]
==
3
and
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
):
...
@@ -86,6 +89,10 @@ def cached_path(url_or_filename, cache_dir=None):
...
@@ -86,6 +89,10 @@ def cached_path(url_or_filename, cache_dir=None):
"""
"""
if
cache_dir
is
None
:
if
cache_dir
is
None
:
cache_dir
=
PYTORCH_PRETRAINED_BERT_CACHE
cache_dir
=
PYTORCH_PRETRAINED_BERT_CACHE
if
sys
.
version_info
[
0
]
==
3
and
isinstance
(
url_or_filename
,
Path
):
url_or_filename
=
str
(
url_or_filename
)
if
sys
.
version_info
[
0
]
==
3
and
isinstance
(
cache_dir
,
Path
):
cache_dir
=
str
(
cache_dir
)
parsed
=
urlparse
(
url_or_filename
)
parsed
=
urlparse
(
url_or_filename
)
...
@@ -171,6 +178,8 @@ def get_from_cache(url, cache_dir=None):
...
@@ -171,6 +178,8 @@ def get_from_cache(url, cache_dir=None):
"""
"""
if
cache_dir
is
None
:
if
cache_dir
is
None
:
cache_dir
=
PYTORCH_PRETRAINED_BERT_CACHE
cache_dir
=
PYTORCH_PRETRAINED_BERT_CACHE
if
sys
.
version_info
[
0
]
==
3
and
isinstance
(
cache_dir
,
Path
):
cache_dir
=
str
(
cache_dir
)
if
not
os
.
path
.
exists
(
cache_dir
):
if
not
os
.
path
.
exists
(
cache_dir
):
os
.
makedirs
(
cache_dir
)
os
.
makedirs
(
cache_dir
)
...
...
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