Skip to content

Commit

Permalink
Fix Windows force deserialization by writing ofstream in binary mode (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
stefdoerr authored Feb 20, 2025
1 parent d1861af commit 20d5f3c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion serialization/src/TorchForceProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ void* TorchForceProxy::deserialize(const SerializationNode& node) const {
} else {
const string storedEncodedFile = node.getStringProperty("encodedFileContents");
string fileName = tmpnam(nullptr); // A unique filename
ofstream(fileName) << hexDecode(storedEncodedFile);
ofstream ofs = ofstream(fileName, ios::binary);
ofs << hexDecode(storedEncodedFile);
ofs.close();
auto model = torch::jit::load(fileName);
std::remove(fileName.c_str());
force = new TorchForce(model);
Expand Down

0 comments on commit 20d5f3c

Please sign in to comment.