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
7e60205b
Unverified
Commit
7e60205b
authored
Jan 10, 2019
by
Thomas Wolf
Committed by
GitHub
Jan 10, 2019
Browse files
Merge pull request #179 from likejazz/patch-2
Fix it to run properly even if without `--do_train` param.
parents
0dd5f55a
64326dcc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
2 deletions
+3
-2
examples/run_squad.py
examples/run_squad.py
+3
-2
No files found.
examples/run_squad.py
View file @
7e60205b
...
@@ -782,7 +782,7 @@ def main():
...
@@ -782,7 +782,7 @@ def main():
raise
ValueError
(
raise
ValueError
(
"If `do_predict` is True, then `predict_file` must be specified."
)
"If `do_predict` is True, then `predict_file` must be specified."
)
if
os
.
path
.
exists
(
args
.
output_dir
)
and
os
.
listdir
(
args
.
output_dir
):
if
os
.
path
.
exists
(
args
.
output_dir
)
and
os
.
listdir
(
args
.
output_dir
)
and
args
.
do_train
:
raise
ValueError
(
"Output directory () already exists and is not empty."
)
raise
ValueError
(
"Output directory () already exists and is not empty."
)
os
.
makedirs
(
args
.
output_dir
,
exist_ok
=
True
)
os
.
makedirs
(
args
.
output_dir
,
exist_ok
=
True
)
...
@@ -916,7 +916,8 @@ def main():
...
@@ -916,7 +916,8 @@ def main():
# Save a trained model
# Save a trained model
model_to_save
=
model
.
module
if
hasattr
(
model
,
'module'
)
else
model
# Only save the model it-self
model_to_save
=
model
.
module
if
hasattr
(
model
,
'module'
)
else
model
# Only save the model it-self
output_model_file
=
os
.
path
.
join
(
args
.
output_dir
,
"pytorch_model.bin"
)
output_model_file
=
os
.
path
.
join
(
args
.
output_dir
,
"pytorch_model.bin"
)
torch
.
save
(
model_to_save
.
state_dict
(),
output_model_file
)
if
args
.
do_train
:
torch
.
save
(
model_to_save
.
state_dict
(),
output_model_file
)
# Load a trained model that you have fine-tuned
# Load a trained model that you have fine-tuned
model_state_dict
=
torch
.
load
(
output_model_file
)
model_state_dict
=
torch
.
load
(
output_model_file
)
...
...
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