Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Franck Dary
macaon
Commits
a4487b91
Commit
a4487b91
authored
Jul 07, 2020
by
Franck Dary
Browse files
Sending torch object to CPU before saving them to disk
parent
51f41f87
Changes
2
Hide whitespace changes
Inline
Side-by-side
reading_machine/src/Classifier.cpp
View file @
a4487b91
...
...
@@ -229,12 +229,16 @@ std::string Classifier::getLastFilename() const
void
Classifier
::
saveBest
()
{
getNN
()
->
to
(
torch
::
kCPU
);
torch
::
save
(
getNN
(),
getBestFilename
());
getNN
()
->
to
(
NeuralNetworkImpl
::
device
);
}
void
Classifier
::
saveLast
()
{
getNN
()
->
to
(
torch
::
kCPU
);
torch
::
save
(
getNN
(),
getLastFilename
());
getNN
()
->
to
(
NeuralNetworkImpl
::
device
);
saveOptimizer
();
}
trainer/src/Trainer.cpp
View file @
a4487b91
...
...
@@ -296,7 +296,7 @@ void Trainer::Examples::saveIfNeeded(const std::string & state, std::filesystem:
int
nbClasses
=
classes
[
0
].
size
(
0
);
auto
tensorToSave
=
torch
::
cat
({
torch
::
stack
(
contexts
),
torch
::
stack
(
classes
)},
1
);
auto
tensorToSave
=
torch
::
cat
({
torch
::
stack
(
contexts
),
torch
::
stack
(
classes
)},
1
)
.
to
(
torch
::
kCPU
)
;
auto
filename
=
fmt
::
format
(
"{}-{}_{}-{}.{}.{}.tensor"
,
state
,
nbClasses
,
lastSavedIndex
,
currentExampleIndex
-
1
,
epoch
,
dynamicOracle
);
torch
::
save
(
tensorToSave
,
dir
/
filename
);
lastSavedIndex
=
currentExampleIndex
;
...
...
Write
Preview
Supports
Markdown
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