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
b1b8222d
Unverified
Commit
b1b8222d
authored
Jul 11, 2022
by
Sylvain Gugger
Committed by
GitHub
Jul 11, 2022
Browse files
Add filename to info diaplyed when downloading things in from_pretrained (#18099)
parent
6c8017a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
3 deletions
+19
-3
src/transformers/utils/hub.py
src/transformers/utils/hub.py
+19
-3
No files found.
src/transformers/utils/hub.py
View file @
b1b8222d
...
@@ -422,7 +422,14 @@ def _raise_for_status(response: Response):
...
@@ -422,7 +422,14 @@ def _raise_for_status(response: Response):
response
.
raise_for_status
()
response
.
raise_for_status
()
def
http_get
(
url
:
str
,
temp_file
:
BinaryIO
,
proxies
=
None
,
resume_size
=
0
,
headers
:
Optional
[
Dict
[
str
,
str
]]
=
None
):
def
http_get
(
url
:
str
,
temp_file
:
BinaryIO
,
proxies
=
None
,
resume_size
=
0
,
headers
:
Optional
[
Dict
[
str
,
str
]]
=
None
,
file_name
:
Optional
[
str
]
=
None
,
):
"""
"""
Download remote file. Do not gobble up errors.
Download remote file. Do not gobble up errors.
"""
"""
...
@@ -441,7 +448,7 @@ def http_get(url: str, temp_file: BinaryIO, proxies=None, resume_size=0, headers
...
@@ -441,7 +448,7 @@ def http_get(url: str, temp_file: BinaryIO, proxies=None, resume_size=0, headers
unit_divisor
=
1024
,
unit_divisor
=
1024
,
total
=
total
,
total
=
total
,
initial
=
resume_size
,
initial
=
resume_size
,
desc
=
"Downloading"
,
desc
=
f
"Downloading
{
file_name
}
"
if
file_name
is
not
None
else
"Downloading"
,
)
)
for
chunk
in
r
.
iter_content
(
chunk_size
=
1024
):
for
chunk
in
r
.
iter_content
(
chunk_size
=
1024
):
if
chunk
:
# filter out keep-alive new chunks
if
chunk
:
# filter out keep-alive new chunks
...
@@ -591,7 +598,16 @@ def get_from_cache(
...
@@ -591,7 +598,16 @@ def get_from_cache(
with
temp_file_manager
()
as
temp_file
:
with
temp_file_manager
()
as
temp_file
:
logger
.
info
(
f
"
{
url
}
not found in cache or force_download set to True, downloading to
{
temp_file
.
name
}
"
)
logger
.
info
(
f
"
{
url
}
not found in cache or force_download set to True, downloading to
{
temp_file
.
name
}
"
)
http_get
(
url_to_download
,
temp_file
,
proxies
=
proxies
,
resume_size
=
resume_size
,
headers
=
headers
)
# The url_to_download might be messy, so we extract the file name from the original url.
file_name
=
url
.
split
(
"/"
)[
-
1
]
http_get
(
url_to_download
,
temp_file
,
proxies
=
proxies
,
resume_size
=
resume_size
,
headers
=
headers
,
file_name
=
file_name
,
)
logger
.
info
(
f
"storing
{
url
}
in cache at
{
cache_path
}
"
)
logger
.
info
(
f
"storing
{
url
}
in cache at
{
cache_path
}
"
)
os
.
replace
(
temp_file
.
name
,
cache_path
)
os
.
replace
(
temp_file
.
name
,
cache_path
)
...
...
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