I am trying to run a pre-trained model (The MuRIL model). However, it seems that it requires the tensorflow_text
package.
When running the saved model with python, this is simple:
import tensorflow as tf
import tensorflow_text # important to load RegexSplitWithOffsets
preprocessor = tf.saved_model.load("./preprocess")
muril = tf.saved_model.load("./muril")
input_word = "testing word"
preprocessed = preprocessor([input_word])
output_vec = muril(preprocessed)["pooled_output"]
print(output_vec)
However, when I do something similar with the Tensorflow C API:
#include <stdio.h>
#include <tensorflow/c/c_api.h>
TF_Status* status;
TF_SessionOptions* preprocess_opts;
TF_Graph* preprocess_graph;
TF_Session* preprocess_sess;
TF_SessionOptions* muril_opts;
TF_Graph* muril_graph;
TF_Session* muril_sess;
int load_models() {
// create a status reporter
status = TF_NewStatus();
// the tag is "serve"
const char* tags[] = {"serve"};
// load models
// load preprocessor model
char* preprocess_model_path = "./preprocess";
preprocess_graph = TF_NewGraph();
preprocess_opts = TF_NewSessionOptions();
preprocess_sess = TF_LoadSessionFromSavedModel(preprocess_opts, NULL, preprocess_model_path, tags, 1, preprocess_graph, NULL, status);
if (TF_GetCode(status) != TF_OK) {
printf("Error loading preprocess model.");
return 1;
}
// load main muril model
char* muril_model_path = "./muril";
muril_graph = TF_NewGraph();
muril_opts = TF_NewSessionOptions();
muril_sess = TF_LoadSessionFromSavedModel(muril_opts, NULL, muril_model_path, tags, 1, muril_graph, NULL, status);
if (TF_GetCode(status) != TF_OK) {
printf("Error loading muril model.");
return 1;
}
return 0;
}
I get a runtime error:
fg-shape-inference{graph-version=0},tfg-prepare-attrs-export)} failed: INVALID_ARGUMENT: Unable to find OpDef for RegexSplitWithOffsets
While importing function: __inference__wrapped_model_4156
when importing GraphDef to MLIR module in GrapplerHook
2025-03-10 12:14:25.280346: I tensorflow/cc/saved_model/loader:220] Running initialization op on SavedModel bundle at path: ./preprocess
2025-03-10 12:14:25.300561: E tensorflow/core/grappler/optimizers/tfg_optimizer_hook:135] tfg_optimizer{any(tfg-consolidate-attrs,tfg-toposort,tfg-shape-inference{graph-version=0},tfg-prepare-attrs-export)} failed: INVALID_ARGUMENT: Unable to find OpDef for RegexSplitWithOffsets
While importing function: __inference__wrapped_model_4156
when importing GraphDef to MLIR module in GrapplerHook
2025-03-10 12:14:25.342181: I tensorflow/cc/saved_model/loader:466] SavedModel load for tags { serve }; Status: success: OK. Took 154554 microseconds.
I believe this is due to me not having the tensorflow_text
package installed for C. I followed the instructions on the tensorflow website to install, and unpacked the tar.gz file into /usr/local/lib
which created libtensorflow.so
and libtensorflow.so.2
files. But there isn't any tensorflow_text.
I can't find a guide on how to install tensorflow_text for C; does anyone know how?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744835285a4596226.html
评论列表(0条)