Skip to content

Commit 20d5f3c

Browse files
authored
Fix Windows force deserialization by writing ofstream in binary mode (#166)
* remove the path from the force.pt files to test if that's the erro cause * flush the ofstream before reading it in torch * Revert "remove the path from the force.pt files to test if that's the erro cause" This reverts commit 23206b5. * close the file handler * write to file in binary mode. might be required for line breaks on Windows
1 parent d1861af commit 20d5f3c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

serialization/src/TorchForceProxy.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ void* TorchForceProxy::deserialize(const SerializationNode& node) const {
111111
} else {
112112
const string storedEncodedFile = node.getStringProperty("encodedFileContents");
113113
string fileName = tmpnam(nullptr); // A unique filename
114-
ofstream(fileName) << hexDecode(storedEncodedFile);
114+
ofstream ofs = ofstream(fileName, ios::binary);
115+
ofs << hexDecode(storedEncodedFile);
116+
ofs.close();
115117
auto model = torch::jit::load(fileName);
116118
std::remove(fileName.c_str());
117119
force = new TorchForce(model);

0 commit comments

Comments
 (0)