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
f25e9b6f
Commit
f25e9b6f
authored
Dec 19, 2019
by
Julien Chaumond
Browse files
[hf_bucket_url] support for cloudfront urls
parent
a5a06a85
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
transformers/file_utils.py
transformers/file_utils.py
+6
-4
No files found.
transformers/file_utils.py
View file @
f25e9b6f
...
@@ -77,6 +77,7 @@ DUMMY_INPUTS = [[7, 6, 0, 0, 1], [1, 2, 3, 0, 0], [0, 0, 0, 4, 5]]
...
@@ -77,6 +77,7 @@ DUMMY_INPUTS = [[7, 6, 0, 0, 1], [1, 2, 3, 0, 0], [0, 0, 0, 4, 5]]
DUMMY_MASK
=
[[
1
,
1
,
1
,
1
,
1
],
[
1
,
1
,
1
,
0
,
0
],
[
0
,
0
,
0
,
1
,
1
]]
DUMMY_MASK
=
[[
1
,
1
,
1
,
1
,
1
],
[
1
,
1
,
1
,
0
,
0
],
[
0
,
0
,
0
,
1
,
1
]]
S3_BUCKET_PREFIX
=
"https://s3.amazonaws.com/models.huggingface.co/bert"
S3_BUCKET_PREFIX
=
"https://s3.amazonaws.com/models.huggingface.co/bert"
CLOUDFRONT_DISTRIB_PREFIX
=
"https://d2ws9o8vfrpkyk.cloudfront.net"
def
is_torch_available
():
def
is_torch_available
():
...
@@ -114,11 +115,12 @@ def is_remote_url(url_or_filename):
...
@@ -114,11 +115,12 @@ def is_remote_url(url_or_filename):
parsed
=
urlparse
(
url_or_filename
)
parsed
=
urlparse
(
url_or_filename
)
return
parsed
.
scheme
in
(
'http'
,
'https'
,
's3'
)
return
parsed
.
scheme
in
(
'http'
,
'https'
,
's3'
)
def
hf_bucket_url
(
identifier
,
postfix
=
None
):
def
hf_bucket_url
(
identifier
,
postfix
=
None
,
cdn
=
False
):
endpoint
=
CLOUDFRONT_DISTRIB_PREFIX
if
cdn
else
S3_BUCKET_PREFIX
if
postfix
is
None
:
if
postfix
is
None
:
return
"/"
.
join
((
S3_BUCKET_PREFIX
,
identifier
))
return
"/"
.
join
((
endpoint
,
identifier
))
else
:
else
:
return
"/"
.
join
((
S3_BUCKET_PREFIX
,
identifier
,
postfix
))
return
"/"
.
join
((
endpoint
,
identifier
,
postfix
))
def
url_to_filename
(
url
,
etag
=
None
):
def
url_to_filename
(
url
,
etag
=
None
):
...
@@ -126,7 +128,7 @@ def url_to_filename(url, etag=None):
...
@@ -126,7 +128,7 @@ def url_to_filename(url, etag=None):
Convert `url` into a hashed filename in a repeatable way.
Convert `url` into a hashed filename in a repeatable way.
If `etag` is specified, append its hash to the url's, delimited
If `etag` is specified, append its hash to the url's, delimited
by a period.
by a period.
If the url ends with .h5 (Keras HDF5 weights) a
n
ds '.h5' to the name
If the url ends with .h5 (Keras HDF5 weights) a
d
ds '.h5' to the name
so that TF 2.0 can identify it as a HDF5 file
so that TF 2.0 can identify it as a HDF5 file
(see https://github.com/tensorflow/tensorflow/blob/00fad90125b18b80fe054de1055770cfb8fe4ba3/tensorflow/python/keras/engine/network.py#L1380)
(see https://github.com/tensorflow/tensorflow/blob/00fad90125b18b80fe054de1055770cfb8fe4ba3/tensorflow/python/keras/engine/network.py#L1380)
"""
"""
...
...
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