-
Notifications
You must be signed in to change notification settings - Fork 221
Description
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Debian Buster
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: No
- TensorFlow installed from (source or binary): Maven snapshots
- TensorFlow version (use command below): 0.1.0-SNAPSHOT (tensorflow_text 2.2.1)
- Python version: 3.7 and 3.6
- Bazel version (if compiling from source):
- GCC/Compiler version (if compiling from source):
- CUDA/cuDNN version:
- GPU model and memory:
Describe the current behavior
It crashes with the following output:
2020-07-01 20:14:58.469557: I external/org_tensorflow/tensorflow/cc/saved_model/reader.cc:31] Reading SavedModel from: tokenizer
2020-07-01 20:14:58.474996: I external/org_tensorflow/tensorflow/cc/saved_model/reader.cc:54] Reading meta graph with tags { serve }
2020-07-01 20:14:58.475083: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:295] Reading SavedModel debug info (if present) from: tokenizer
2020-07-01 20:14:58.475670: I external/org_tensorflow/tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-07-01 20:14:58.478426: W external/org_tensorflow/tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2020-07-01 20:14:58.478482: E external/org_tensorflow/tensorflow/stream_executor/cuda/cuda_driver.cc:313] failed call to cuInit: UNKNOWN ERROR (303)
2020-07-01 20:14:58.478517: I external/org_tensorflow/tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (1470715d11a2): /proc/driver/nvidia/version does not exist
2020-07-01 20:14:58.478585: I external/org_tensorflow/tensorflow/core/common_runtime/process_util.cc:147] Creating new thread pool with default inter op setting: 2. Tune using inter_op_parallelism_threads for best performance.
2020-07-01 20:14:58.491011: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:234] Restoring SavedModel bundle.
2020-07-01 20:14:58.522974: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:183] Running initialization op on SavedModel bundle at path: tokenizer
2020-07-01 20:14:58.537814: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:364] SavedModel load for tags { serve }; Status: success: OK. Took 68286 microseconds.
2020-07-01 20:14:59.321091: W external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1753] OP_REQUIRES failed at wordpiece_kernel.cc:204 : Invalid argument: Trying to access resource using the wrong type. Expected N10tensorflow6lookup15LookupInterfaceE got N10tensorflow6lookup15LookupInterfaceE
[WARNING]
org.tensorflow.exceptions.TFInvalidArgumentException: Trying to access resource using the wrong type. Expected N10tensorflow6lookup15LookupInterfaceE got N10tensorflow6lookup15LookupInterfaceE
[[{{node WordpieceTokenizeWithOffsets/WordpieceTokenizeWithOffsets/WordpieceTokenizeWithOffsets}}]]
at org.tensorflow.internal.c_api.AbstractTF_Status.throwExceptionIfNotOK (AbstractTF_Status.java:87)
at org.tensorflow.Session.run (Session.java:595)
at org.tensorflow.Session.access$100 (Session.java:70)
at org.tensorflow.Session$Runner.runHelper (Session.java:335)
at org.tensorflow.Session$Runner.run (Session.java:285)
at Main.main (Main.java:25)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:254)
at java.lang.Thread.run (Thread.java:834)
Describe the expected behavior
Succesful execution of the model
Code to reproduce the issue
import org.tensorflow.SavedModelBundle;
import org.tensorflow.Session;
import org.tensorflow.Tensor;
import org.tensorflow.TensorFlow;
import org.tensorflow.tools.ndarray.NdArrays;
import org.tensorflow.types.TString;
import java.nio.charset.StandardCharsets;
import java.util.List;
public class Main {
public static void main(String[] args) {
TensorFlow.version();
String libDir = "/usr/local/lib/python3.7/dist-packages/tensorflow_text/python/ops/";
TensorFlow.loadLibrary(libDir + "_wordpiece_tokenizer.so");
TensorFlow.loadLibrary(libDir + "_normalize_ops.so");
TensorFlow.loadLibrary(libDir + "_regex_split_ops.so");
SavedModelBundle savedModelBundle = SavedModelBundle.load("tokenizer", "serve");
Session.Runner runner = savedModelBundle.session().runner();
runner.feed("serving_default_text:0", TString.tensorOfBytes(NdArrays.vectorOfObjects("a b c d e".getBytes(StandardCharsets.UTF_8))));
runner.fetch("StatefulPartitionedCall_1:0");
List<Tensor<?>> outputs = runner.run();
System.out.println(outputs);
}
}
The following script can be used to generate a minimal saved model triggering the problem:
from tensorflow.python.framework import dtypes
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import lookup_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import string_ops
from tensorflow_text.python.ops import bert_tokenizer
import tensorflow as tf
vocab = [
b'a', b'b', b'c', b'd'
]
def _create_table(vocab, num_oov=1):
init = lookup_ops.KeyValueTensorInitializer(
vocab,
math_ops.range(
array_ops.size(vocab, out_type=dtypes.int64), dtype=dtypes.int64),
key_dtype=dtypes.string,
value_dtype=dtypes.int64)
return lookup_ops.StaticVocabularyTableV1(
init, num_oov, lookup_key_dtype=dtypes.string)
table = _create_table(vocab)
class Module(tf.Module):
def __init__(self, table):
self.table = table
self.tokenizer = bert_tokenizer.BertTokenizer(
self.table,
token_out_type=dtypes.string,
lower_case=True,
preserve_unused_token=False)
@tf.function(input_signature=[tf.TensorSpec(1, dtype=tf.dtypes.string)])
def serve(self, text):
return self.tokenizer.tokenize(text)
module = Module(table)
tf.saved_model.save(module, 'tokenizer')
model = tf.saved_model.load('tokenizer')
print(model.serve(['a a b c d e']))
Other info / logs
There is an issue in tensorflow-text (tensorflow/text#272) where the same thing happens on macos (while this is on linux). This model works on linux using python to load and execute the model however, so the root cause is most likely different. Looking at the fix for the macos issue (tensorflow/tensorflow@1823f87#diff-991a6b786e16708ba1e6f5c9926cf151) makes me suspect that this may be caused by type ids being generated differently due to tensorflow-java building native tensorflow libs separately in a slightly different way than the python libraries.