Segmentation fault when using tflite_model_maker searcher.TextDataLoader.create(EmbeddingModel, l2_normalize=True)
Hi **@ankur2210** ,

Sorry for the delay, I reproduced the code shared but facing different error .Could you please share the colab gist with all the dependencies to analyze more of it. And could you please execute your code using Latest Version (2.16.1) and let us know if the issue still persists?

Thank you! > Hi **@ankur2210** ,
> 
> Sorry for the delay, I reproduced the code shared but facing different error .Could you please share the colab gist with all the dependencies to analyze more of it. And could you please execute your code using Latest Version (2.16.1) and let us know if the issue still persists?
> 
> Thank you!

Hi @Venkat6871 
Thanks for the reply.

I am using 'tflite_model_maker' library to create the searcher model.
from tflite_model_maker import searcher

on installing 'tflite_model_maker' using `pip install tflite-model-maker`

It install tensorflow 2.8.4 and uninstalls latest tensorflow.


 @Venkat6871 Did you check the Segmentation fault issue ? Hi @ankur2210 ,

I will replicate the issue and will get back to you.  Hi @ankur2210 ,

I am having issues installing tensorflow_text using pip . Did you face any such issue ? Either way i will get back to you once i am able to reproduce the issue .
### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

No

### Source

binary

### TensorFlow version

2.8.4

### Custom code

Yes

### OS platform and distribution

Ubuntu 22.04

### Mobile device

Ubuntu 22.04

### Python version

3.9.19

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

I am trying to make TextSearcher object using tflite_model_maker python library.
`data_loader = searcher.TextDataLoader.create(EmbeddingModel, l2_normalize=True)`
At this step, getting segmentation fault error.

Embedding model is tflite model converted from https://www.kaggle.com/models/google/universal-sentence-encoder/tensorFlow2/multilingual
using below code -
`import tensorflow as tf
# These imports are required to load operators' definition.
import tensorflow_text as tf_text
import sentencepiece as spm

path = '/path/to/embedding/model'
converter = tf.lite.TFLiteConverter.from_saved_model(path)
converter.target_spec.supported_ops = [
  tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS
]
model_data = converter.convert()
with open('model.tflite', 'wb') as f:
  f.write(model_data)`
  
  
  On analysing tflite model using - 
  `import tensorflow as tf
tf.lite.experimental.Analyzer.analyze('model.tflite')`
  
  getting following output -
  ---------------------------------------------------------------
Your TFLite model has ‘1’ signature_def(s).

Signature#0 key: 'serving_default'
- Subgraph: Subgraph#0
- Inputs:
    'inputs' : T#0
- Outputs:
    'outputs' : T#399

---------------------------------------------------------------
              Model size:  278328956 bytes
    Non-data buffer size:    2616702 bytes (00.94 %)
  Total data buffer size:  275712254 bytes (99.06 %)
    (Zero value buffers):       3085 bytes (00.00 %)
  

### Standalone code to reproduce the issue

```shell
Mentioned above
```


### Relevant log output

```shell
Backtrace of segmentation fault-

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
0x00007fff518df70d in tflite::Subgraph::ReplaceNodeSubsetsWithDelegateKernels(TfLiteRegistration, TfLiteIntArray const*, TfLiteDelegate*) () from python3.9/site-packages/tensorflow_lite_support/python/task/text/pybinds/_pywrap_text_embedder.so
(gdb) stacktrace
Undefined command: "stacktrace".  Try "help".
(gdb) backtrace
#0  0x00007fff518df70d in tflite::Subgraph::ReplaceNodeSubsetsWithDelegateKernels(TfLiteRegistration, TfLiteIntArray const*, TfLiteDelegate*) ()
   from python3.9/site-packages/tensorflow_lite_support/python/task/text/pybinds/_pywrap_text_embedder.so
#1  0x00007fff64064dc1 in tflite::(anonymous namespace)::DelegatePrepare(TfLiteContext*, TfLiteDelegate*) () from python3.9/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so
#2  0x00007fff518e05ee in tflite::Subgraph::ModifyGraphWithDelegateImpl(TfLiteDelegate*) ()
   from python3.9/site-packages/tensorflow_lite_support/python/task/text/pybinds/_pywrap_text_embedder.so
#3  0x00007fff518e097f in tflite::Subgraph::ModifyGraphWithDelegate(TfLiteDelegate*) () from python3.9/site-packages/tensorflow_lite_support/python/task/text/pybinds/_pywrap_text_embedder.so   
#4  0x00007fff518d17b0 in tflite::impl::Interpreter::ModifyGraphWithDelegateImpl(TfLiteDelegate*) ()
   from python3.9/site-packages/tensorflow_lite_support/python/task/text/pybinds/_pywrap_text_embedder.so
#5  0x00007fff518d66f1 in tflite::impl::InterpreterBuilder::ApplyDelegates(tflite::impl::Interpreter*) ()
   from python3.9/site-packages/tensorflow_lite_support/python/task/text/pybinds/_pywrap_text_embedder.so
#6  0x00007fff518d81a9 in tflite::impl::InterpreterBuilder::operator()(std::unique_ptr<tflite::impl::Interpreter, std::default_delete<tflite::impl::Interpreter> >*) ()
   from python3.9/site-packages/tensorflow_lite_support/python/task/text/pybinds/_pywrap_text_embedder.so
#7  0x00007fff514ee774 in tflite::task::core::TfLiteEngine::InitInterpreter(tflite::proto::ComputeSettings const&)::{lambda(tflite::support::InterpreterCreationResources const&, std::unique_ptr<tflite::impl::Interpreter, std::default_delete<tflite::impl::Interpreter> >*)#1}::operator()(tflite::support::InterpreterCreationResources const&, std::unique_ptr<tflite::impl::Interpreter, std::default_delete<tflite::impl::Interpreter> >*) const [clone .isra.0] ()
   from python3.9/site-packages/tensorflow_lite_support/python/task/text/pybinds/_pywrap_text_embedder.so
#8  0x00007fff514ee8e5 in std::_Function_handler<absl::lts_20210324::Status (tflite::support::InterpreterCreationResources const&, std::unique_ptr<tflite::impl::Interpreter, std::default_delete<tflite::impl::Interpreter> >*), tflite::task::core::TfLiteEngine::InitInterpreter(tflite::proto::ComputeSettings const&)::{lambda(tflite::support::InterpreterCreationResources const&, std::unique_ptr<tflite::impl::Interpreter, std::default_delete<tflite::impl::Interpreter> 
>*)#1}>::_M_invoke(std::_Any_data const&, tflite::support::InterpreterCreationResources const&, std::unique_ptr<tflite::impl::Interpreter, std::default_delete<tflite::impl::Interpreter> >*&&) ()
   from python3.9/site-packages/tensorflow_lite_support/python/task/text/pybinds/_pywrap_text_embedder.so
#9  0x00007fff514fbda2 in tflite::support::TfLiteInterpreterWrapper::InitializeWithFallbackAndResize(std::function<absl::lts_20210324::Status (tflite::impl::Interpreter*)>) ()
   from python3.9/site-packages/tensorflow_lite_support/python/task/text/pybinds/_pywrap_text_embedder.so
#10 0x00007fff514fd1c1 in tflite::support::TfLiteInterpreterWrapper::InitializeWithFallback(std::function<absl::lts_20210324::Status (tflite::support::InterpreterCreationResources const&, std::unique_ptr<tflite::impl::Interpreter, std::default_delete<tflite::impl::Interpreter> >*)>, tflite::proto::ComputeSettings const&) ()
   from python3.9/site-packages/tensorflow_lite_support/python/task/text/pybinds/_pywrap_text_embedder.so
#11 0x00007fff514eef21 in tflite::task::core::TfLiteEngine::InitInterpreter(tflite::proto::ComputeSettings const&) ()
   from python3.9/site-packages/tensorflow_lite_support/python/task/text/pybinds/_pywrap_text_embedder.so
#12 0x00007fff5148350e in absl::lts_20210324::StatusOr<std::unique_ptr<tflite::task::text::TextEmbedder, std::default_delete<tflite::task::text::TextEmbedder> > > tflite::task::core::TaskAPIFactory::CreateFromBaseOptions<tflite::task::text::TextEmbedder, (void*)0>(tflite::task::core::BaseOptions const*, std::unique_ptr<tflite::OpResolver, std::default_delete<tflite::OpResolver> >) ()
   from python3.9/site-packages/tensorflow_lite_support/python/task/text/pybinds/_pywrap_text_embedder.so
#13 0x00007fff5148488a in tflite::task::text::TextEmbedder::CreateFromOptions(tflite::task::text::TextEmbedderOptions const&, std::unique_ptr<tflite::OpResolver, std::default_delete<tflite::OpResolver> >) ()
   from python3.9/site-packages/tensorflow_lite_support/python/task/text/pybinds/_pywrap_text_embedder.so
#14 0x00007fff51480c07 in pybind11::cpp_function::initialize<tflite::task::text::pybind11_init__pywrap_text_embedder(pybind11::module_&)::{lambda(tflite::python::task::core::BaseOptions const&, tflite::task::processor::EmbeddingOptions const&)#1}, std::unique_ptr<tflite::task::text::TextEmbedder, std::default_delete<tflite::task::text::TextEmbedder> >, tflite::python::task::core::BaseOptions const&, tflite::task::processor::EmbeddingOptions const&, pybind11::name, pybind11::scope, pybind11::sibling>(tflite::task::text::pybind11_init__pywrap_text_embedder(pybind11::module_&)::{lambda(tflite::python::task::core::BaseOptions const&, tflite::task::processor::EmbeddingOptions const&)#1}&&, std::unique_ptr<tflite::task::text::TextEmbedder, std::default_delete<tflite::task::text::TextEmbedder> > (*)(tflite::python::task::core::BaseOptions const&, tflite::task::processor::EmbeddingOptions const&), pybind11::name const&, pybind11::scope const&, pybind11::sibling const&)::{lambda(pybind11::detail::function_call&)#3}::_FUN(pybind11::detail::function_call&) ()
   from python3.9/site-packages/tensorflow_lite_support/python/task/text/pybinds/_pywrap_text_embedder.so
#15 0x00007fff5147b016 in pybind11::cpp_function::dispatcher(_object*, _object*, _object*) ()
   from python3.9/site-packages/tensorflow_lite_support/python/task/text/pybinds/_pywrap_text_embedder.so
#16 0x00005555556a26b6 in cfunction_call (func=0x7ffff348aa40, args=<optimized out>, kwargs=<optimized out>) at /usr/local/src/conda/python-3.9.19/Objects/methodobject.c:543
#17 0x000055555568b7ac in _PyObject_MakeTpCall (tstate=0x5555559378f0, callable=0x7ffff348aa40, args=<optimized out>, nargs=<optimized out>, keywords=0x0) at /usr/local/src/conda/python-3.9.19/Objects/call.c:191
#18 0x0000555555687f10 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=<optimized out>, callable=0x7ffff348aa40, tstate=<optimized out>) at /usr/local/src/conda/python-3.9.19/Include/cpython/abstract.h:116    
#19 _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x7fffbc66c1d0, callable=0x7ffff348aa40, tstate=<optimized out>) at /usr/local/src/conda/python-3.9.19/Include/cpython/abstract.h:103
#20 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x7fffbc66c1d0, callable=0x7ffff348aa40) at /usr/local/src/conda/python-3.9.19/Include/cpython/abstract.h:127
#21 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, tstate=0x5555559378f0) at /usr/local/src/conda/python-3.9.19/Python/ceval.c:5077
#22 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=0x7fffbc66c040, throwflag=<optimized out>) at /usr/local/src/conda/python-3.9.19/Python/ceval.c:3489
#23 0x0000555555693802 in _PyEval_EvalFrame (throwflag=0, f=0x7fffbc66c040, tstate=0x5555559378f0) at /usr/local/src/conda/python-3.9.19/Include/internal/pycore_ceval.h:40
--Type <RET> for more, q to quit, c to continue without paging--
#24 function_code_fastcall (tstate=0x5555559378f0, co=0x7ffff348e240, args=<optimized out>, nargs=2, globals=0x7ffff3486b40) at /usr/local/src/conda/python-3.9.19/Objects/call.c:330
#25 0x00005555556a094e in _PyFunction_Vectorcall (kwnames=0x0, nargsf=<optimized out>, stack=0x55555b824af8, func=0x7ffff3484dc0) at /usr/local/src/conda/python-3.9.19/Objects/call.c:367
#26 _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x55555b824af8, callable=0x7ffff3484dc0, tstate=0x5555559378f0) at /usr/local/src/conda/python-3.9.19/Include/cpython/abstract.h:118
#27 method_vectorcall (method=<optimized out>, args=0x55555b824b00, nargsf=<optimized out>, kwnames=0x0) at /usr/local/src/conda/python-3.9.19/Objects/classobject.c:53
#28 0x0000555555687a2e in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x55555b824b00, callable=0x7fffbc318c40, tstate=0x5555559378f0) at /usr/local/src/conda/python-3.9.19/Include/cpython/abstract.h:118
#29 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x55555b824b00, callable=0x7fffbc318c40) at /usr/local/src/conda/python-3.9.19/Include/cpython/abstract.h:127
#30 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, tstate=0x5555559378f0) at /usr/local/src/conda/python-3.9.19/Python/ceval.c:5077
#31 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=0x55555b824950, throwflag=<optimized out>) at /usr/local/src/conda/python-3.9.19/Python/ceval.c:3489
#32 0x0000555555682184 in _PyEval_EvalFrame (throwflag=0, f=0x55555b824950, tstate=0x5555559378f0) at /usr/local/src/conda/python-3.9.19/Include/internal/pycore_ceval.h:40
#33 _PyEval_EvalCode (tstate=0x5555559378f0, _co=<optimized out>, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=<optimized out>, kwnames=0x7ffff7e40508, kwargs=0x55555591d428, kwcount=1, kwstep=1,    
    defs=0x7fffbc39cdd8, defcount=<optimized out>, kwdefs=0x0, closure=0x0, name=0x7ffff748c3b0, qualname=0x7fffbc3b0030) at /usr/local/src/conda/python-3.9.19/Python/ceval.c:4329
#34 0x00005555556a09fb in _PyFunction_Vectorcall (kwnames=<optimized out>, nargsf=<optimized out>, stack=0x55555591d418, func=0x7fffbc3a2e50) at /usr/local/src/conda/python-3.9.19/Objects/call.c:396
#35 _PyObject_VectorcallTstate (kwnames=<optimized out>, nargsf=<optimized out>, args=0x55555591d418, callable=0x7fffbc3a2e50, tstate=0x5555559378f0) at /usr/local/src/conda/python-3.9.19/Include/cpython/abstract.h:118
#36 method_vectorcall (method=<optimized out>, args=0x55555591d420, nargsf=<optimized out>, kwnames=<optimized out>) at /usr/local/src/conda/python-3.9.19/Objects/classobject.c:53
#37 0x0000555555684162 in _PyObject_VectorcallTstate (kwnames=0x7ffff7e404f0, nargsf=<optimized out>, args=<optimized out>, callable=0x7fffbc318800, tstate=0x5555559378f0)
    at /usr/local/src/conda/python-3.9.19/Include/cpython/abstract.h:118
#38 PyObject_Vectorcall (kwnames=0x7ffff7e404f0, nargsf=<optimized out>, args=<optimized out>, callable=0x7fffbc318800) at /usr/local/src/conda/python-3.9.19/Include/cpython/abstract.h:127
#39 call_function (kwnames=0x7ffff7e404f0, oparg=<optimized out>, pp_stack=<synthetic pointer>, tstate=<optimized out>) at /usr/local/src/conda/python-3.9.19/Python/ceval.c:5077
#40 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=0x55555591d2b0, throwflag=<optimized out>) at /usr/local/src/conda/python-3.9.19/Python/ceval.c:3537
#41 0x0000555555682184 in _PyEval_EvalFrame (throwflag=0, f=0x55555591d2b0, tstate=0x5555559378f0) at /usr/local/src/conda/python-3.9.19/Include/internal/pycore_ceval.h:40
#42 _PyEval_EvalCode (tstate=0x5555559378f0, _co=<optimized out>, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=<optimized out>, kwnames=0x0, kwargs=0x0, kwcount=0, kwstep=2, defs=0x0,
    defcount=<optimized out>, kwdefs=0x0, closure=0x0, name=0x0, qualname=0x0) at /usr/local/src/conda/python-3.9.19/Python/ceval.c:4329
#43 0x0000555555681e58 in _PyEval_EvalCodeWithName (_co=<optimized out>, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=<optimized out>, kwnames=<optimized out>, kwargs=0x0, kwcount=0, kwstep=2,       
    defs=0x0, defcount=0, kwdefs=0x0, closure=0x0, name=0x0, qualname=0x0) at /usr/local/src/conda/python-3.9.19/Python/ceval.c:4361
#44 0x0000555555681e09 in PyEval_EvalCodeEx (_co=<optimized out>, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, kwdefs=0x0,      
    closure=0x0) at /usr/local/src/conda/python-3.9.19/Python/ceval.c:4377
#45 0x000055555572f4ab in PyEval_EvalCode (co=co@entry=0x7ffff75c7920, globals=globals@entry=0x7ffff7bb9fc0, locals=locals@entry=0x7ffff7bb9fc0) at /usr/local/src/conda/python-3.9.19/Python/ceval.c:828
#46 0x000055555575c87a in run_eval_code_obj (tstate=0x5555559378f0, co=0x7ffff75c7920, globals=0x7ffff7bb9fc0, locals=0x7ffff7bb9fc0) at /usr/local/src/conda/python-3.9.19/Python/pythonrun.c:1221
#47 0x0000555555758c03 in run_mod (mod=<optimized out>, filename=<optimized out>, globals=0x7ffff7bb9fc0, locals=0x7ffff7bb9fc0, flags=<optimized out>, arena=<optimized out>)
    at /usr/local/src/conda/python-3.9.19/Python/pythonrun.c:1242
#48 0x00005555555ec175 in pyrun_file (fp=0x55555591dc90, filename=0x7ffff7e59930, start=<optimized out>, globals=0x7ffff7bb9fc0, locals=0x7ffff7bb9fc0, closeit=1, flags=0x7fffffffaef8)
    at /usr/local/src/conda/python-3.9.19/Python/pythonrun.c:1140
#49 0x0000555555752841 in pyrun_simple_file (flags=0x7fffffffaef8, closeit=1, filename=0x7ffff7e59930, fp=0x55555591dc90) at /usr/local/src/conda/python-3.9.19/Python/pythonrun.c:450
#50 PyRun_SimpleFileExFlags (fp=0x55555591dc90, filename=<optimized out>, closeit=1, flags=0x7fffffffaef8) at /usr/local/src/conda/python-3.9.19/Python/pythonrun.c:483
#51 0x000055555574fc6d in pymain_run_file (cf=0x7fffffffaef8, config=0x55555590ea90) at /usr/local/src/conda/python-3.9.19/Modules/main.c:377
#52 pymain_run_python (exitcode=0x7fffffffaef0) at /usr/local/src/conda/python-3.9.19/Modules/main.c:602
#53 Py_RunMain () at /usr/local/src/conda/python-3.9.19/Modules/main.c:681
#54 0x00005555557232e7 in Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at /usr/local/src/conda/python-3.9.19/Modules/main.c:1101
#55 0x00007ffff7c29d90 in __libc_start_call_main (main=main@entry=0x5555557232a0 <main>, argc=argc@entry=2, argv=argv@entry=0x7fffffffb128) at ../sysdeps/nptl/libc_start_call_main.h:58
#56 0x00007ffff7c29e40 in __libc_start_main_impl (main=0x5555557232a0 <main>, argc=2, argv=0x7fffffffb128, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffb118) at ../csu/libc-start.c:392
#57 0x00005555557231e1 in _start ()
```
