Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cc: reimplement read_file_to_string without calling TensorFlow #3176

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions source/api_cc/src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <fcntl.h>

#include <cstring>
#include <fstream>
#include <sstream>
#include <string>

#include "AtomMap.h"
#include "device.h"
Expand Down Expand Up @@ -1112,12 +1115,16 @@ template void deepmd::select_map_inv<deepmd::STRINGTYPE>(
#endif

void deepmd::read_file_to_string(std::string model, std::string& file_content) {
#ifdef BUILD_TENSORFLOW
deepmd::check_status(tensorflow::ReadFileToString(tensorflow::Env::Default(),
model, &file_content));
#else
throw deepmd::deepmd_exception("TODO: read_file_to_string only support TF");
#endif
// generated by GitHub Copilot
std::ifstream file(model);
if (file.is_open()) {
std::stringstream buffer;
buffer << file.rdbuf();
file_content = buffer.str();
file.close();
} else {
throw deepmd::deepmd_exception("Failed to open file: " + model);
}
}

void deepmd::convert_pbtxt_to_pb(std::string fn_pb_txt, std::string fn_pb) {
Expand Down
Loading