TFLite Op type not registered (RegexSplitWithOffsets) in Swift
@sawantkumar what's the status on this? Is there anything else I can provide to help this along Hi @andrew-lyons ,

I will replicate your issue and will get back to you. Please give me some time while i figure it out. Sorry for the delayed response . Hi @andrew-lyons, can you share your model file -- if you can't share the true model .. can you create a model with just that op that reproduces the issue and share that? Thanks for your help.

Also if you can share what type of model it is? A CV model? an NLP model? An Audio Model? a Video Model? ... generally the more information we have the easier it will be for us. This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. @pkgoogle 

Sure thing, here's an example model: https://drive.google.com/file/d/1L-SfTJz5i4sUBAkozYOG5yaInLkC3Qft/view?usp=drive_link

I also can share some code used to generate this model:

concrete func
```python
@tf.function
def predict(prompt):
  preprocessed = gpt2_preprocessor(prompt)
  tokenized_prompt_shifted = tf.shape(tf.where(preprocessed[1] != 50256))[0]
  input_map = {
      'token_ids': tf.reshape(preprocessed[0]['token_ids'], [1, 255]),
      'padding_mask': tf.reshape(preprocessed[0]['padding_mask'], [1, 255])
  }
  result = gpt2_lm(input_map)[0]
  result = tf.slice(result, [tokenized_prompt_shifted-1, 0], [1, 50256])
  topk = tf.math.top_k(tf.nn.softmax(result), k=25)
  return topk.indices[0]

concrete_func = predict.get_concrete_function(tf.TensorSpec([], tf.string))
```

conversion
```python
gpt2_lm.jit_compile = False
converter = tf.lite.TFLiteConverter.from_concrete_functions([concrete_func], gpt2_lm)
converter.target_spec.supported_ops = [
  tf.lite.OpsSet.TFLITE_BUILTINS, # enable TensorFlow Lite ops.
  tf.lite.OpsSet.SELECT_TF_OPS # enable TensorFlow ops.
]
converter.allow_custom_ops = True
converter.target_spec.experimental_select_user_tf_ops = ["UnsortedSegmentJoin", "UpperBound"]
converter._experimental_guarantee_all_funcs_one_use = True
generate_tflite = converter.convert()
run_inference("I'm enjoying a", generate_tflite)
```

basically just trying to grab the next token, and the top 25 probabilities Hi @andrew-lyons, every time I try to reproduce it, the build fails after adding the TFL Select Ops `'TensorFlowLiteSelectTfOps', '~> 0.0.1-nightly'`

I'm modifying the Bert-QA example as that seems most similar to your use case: https://github.com/tensorflow/examples/tree/master/lite/examples/bert_qa/ios

This is the error I keep getting:

```
Building for 'iOS-simulator', but linking in object file (/Users/xxxxxx/Library/Developer/Xcode/DerivedData/BertQA-eatnorjmqyqinlekyqphgwusovgt/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/TensorFlowLiteSelectTfOps/TensorFlowLiteSelectTfOps.framework/TensorFlowLiteSelectTfOps[872](any.o)) built for 'iOS'
```

@yishuangP can you please take a look? Thanks. @pkgoogle not sure if it matters here but I didn't attempt building on the simulator, only on an iPhone 14. Hi @andrew-lyons, we're wondering if you may be able to resolve your issue by using [AI-Edge-Torch](https://github.com/google-ai-edge/ai-edge-torch), our PyTorch conversion library, you can find more information here: [googleblog](https://developers.googleblog.com/en/ai-edge-torch-high-performance-inference-of-pytorch-models-on-mobile-devices/).

We actually have examples of converting and quantizing decoder-only LLMs here: https://github.com/google-ai-edge/ai-edge-torch/tree/main/ai_edge_torch/generative/examples.

If the conversion is successful, you can also try visualizing the result in [model-explorer](https://github.com/google-ai-edge/model-explorer) as well.

Please try them out and let us know if this resolves your issue. If you still need further help, feel free to open a new issue at the respective repo. Thanks for your help.
**System information**
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): 
    - Macbook M1 Pro
    - XCode version 15.0.1
- TensorFlow installed from (source or binary): 
```
  pod 'TensorFlowLiteSwift', '~> 0.0.1-nightly', :subspecs => ['Metal']
  pod 'TensorFlowLiteSelectTfOps', '~> 0.0.1-nightly'
```

I updated the pods and the nightly versions are as seen in my podfile.lock:

```
PODS:
  // ...
  - TensorFlowLiteC (0.0.1-nightly.20240411):
    - TensorFlowLiteC/Core (= 0.0.1-nightly.20240411)
  - TensorFlowLiteC/Core (0.0.1-nightly.20240411)
  - TensorFlowLiteC/Metal (0.0.1-nightly.20240411):
    - TensorFlowLiteC/Core
  - TensorFlowLiteSelectTfOps (0.0.1-nightly.20240411)
  - TensorFlowLiteSwift/Core (0.0.1-nightly.20240411):
    - TensorFlowLiteC (= 0.0.1-nightly.20240411)
  - TensorFlowLiteSwift/Metal (0.0.1-nightly.20240411):
    - TensorFlowLiteC/Metal (= 0.0.1-nightly.20240411)
    - TensorFlowLiteSwift/Core (= 0.0.1-nightly.20240411)
```

**Standalone code to reproduce the issue** 
Provide a reproducible test case that is the bare minimum necessary to generate
the problem. If possible, please share a link to Colab/Jupyter/any notebook.

Also, please include a link to a GraphDef or the model if possible.

**Any other info / logs**

Include any logs or source code that would be helpful to diagnose the problem.
If including tracebacks, please include the full traceback. Large logs and files
should be attached.

---

I'm only attempting to load a model locally, not sure if an example is necessary. For the code anyway I have this:

```swift
 @objc func initializeODI(_ call: CAPPluginCall) {
  var modelFile = //
    guard let modelPath = Bundle(for: type(of: self)).path(forResource: modelFile.name, ofType: modelFile.ext)
      else {
        fatalError("Failed to load the model file: \(modelFile.description)");
      }
 
    var options = Interpreter.Options();
    do {
      interpreter = try Interpreter(modelPath: modelPath, options: options)
        try interpreter?.allocateTensors();
     } catch {
       print("Error instantiating interpreter...", error);
    }
}
```

gives me this error:

```
2024-04-11 14:33:24.676552: E tensorflow/core/framework/node_def_util.cc:676] NodeDef mentions attribute use_inter_op_parallelism which is not in the op definition: Op<name=MutableHashTableV2; signature= -> table_handle:resource; attr=container:string,default=""; attr=shared_name:string,default=""; attr=use_node_name_sharing:bool,default=false; attr=key_dtype:type; attr=value_dtype:type; is_stateful=true> This may be expected if your graph generating binary is newer  than this binary. Unknown attributes will be ignored. NodeDef: {{node MutableHashTableV2}}
TensorFlow Lite Error: Op type not registered 'RegexSplitWithOffsets' in binary running on localhost. Make sure the Op and Kernel are registered in the binary running in this process. Note that if you are loading a saved graph which used ops from tf.contrib (e.g. `tf.contrib.resampler`), accessing should be done before importing the graph, as contrib ops are lazily registered when the module is first accessed.
TensorFlow Lite Error: Op type not registered 'RegexSplitWithOffsets' in binary running on localhost. Make sure the Op and Kernel are registered in the binary running in this process. Note that if you are loading a saved graph which used ops from tf.contrib (e.g. `tf.contrib.resampler`), accessing should be done before importing the graph, as contrib ops are lazily registered when the module is first accessed.
```