keras-team / keras-nlp

Modular Natural Language Processing workflows with Keras
Apache License 2.0
761 stars 228 forks source link

ModuleNotFoundError: No module named 'keras_nlp.api_export' #1224

Open Alwaysadil opened 1 year ago

Alwaysadil commented 1 year ago

ModuleNotFoundError: No module named 'keras_nlp.api_export'

mattdangerw commented 1 year ago

Can you give any more details?

A colab reproduction would be the most helpful.

Alwaysadil commented 1 year ago

@mattdangerw actually my problem was related to download or install libtensorflowlite_gpu_delegate.so file in google colab and i am using tf version of 2.13.0 please help me to get that for adding that at tflite conversion for getting high performance(faster inference) i'm using this below code for tflite conversion import tensorflow as tf

Define your model and concrete function here

model_beam_search = ...

concrete_func = model_beam_search.call.get_concrete_function()

Create a TFLite converter and set the delegate to TfLiteGpuDelegate

converter = tf.lite.TFLiteConverter.from_concrete_functions([concrete_func], model_beam_search) converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS] converter.optimizations = [tf.lite.Optimize.DEFAULT]

Replace TfLiteFlexDelegate with TfLiteGpuDelegate

gpu_delegate = tf.lite.experimental.load_delegate('libtensorflowlite_gpu_delegate.so') converter.experimental_new_converter = True  # This flag is needed for using the experimental converter converter.experimental_new_quantizer = False  # You can enable quantization if needed converter.experimental_enable_resource_variable = False  # You can enable resource variables if needed converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, gpu_delegate]

tflite_model = converter.convert()

Save the TFLite model to a file

with open('testing_gpu.tflite', 'wb') as f:     f.write(tflite_model)

sachinprasadhs commented 4 months ago

@Alwaysadil , Could you please try with the latest version of TensorFlow and Keras-NLP and let us know the outcome. Thanks