-
Notifications
You must be signed in to change notification settings - Fork 711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When Attempting to loadSavedModel, I Encountered 'java.lang.Exception: Could Not Retrieve the SavedModelBundle + () #14215
Comments
Hi @TerryLaw535 To import T5 models (fine-tuned or already on HF) you can use one of these 2 notebooks:
Depending on which one you have saved (exported) your T5 model, you can follow the instructions to import your model into Spark NLP. (I personally recommend first trying ONNX, it has a faster inference time) |
Thank you so much for your reply. I tried ONNX and it showed that [ONNXRuntimeError] : 1 : FAIL : Loading the model from onnx_models/google-t5/t5-small/decoder_model_merged.onnx failed:/onnxruntime_src/onnxruntime/core/graph/model.cc:179 onnxruntime::Model::Model(onnx::ModelProto&&, the onnxruntime::PathString&, the onnxruntime::IOnnxRuntimeOpSchemaRegistryList*, the onnxruntime::logging::Logger&, the onnxruntime::ModelOptions&) Unsupported model IR version: 10, max supported IR version: 9. I also tried the TensorFlow method. I completely followed the instructions except for setting tensorflow == 2.8, since this version is too old and no longer available. I tried the code: model.export(EXPORT_PATH, use_cache=True) and it report:
Do you know how to deal with these problems? I think these problems are all related to version issues. Thank you! |
hi maziyarpanahi, thanks for your resource, however, I tried different transformers, tensorflow versions but none of them worked, basically there are all kinds of errors. And the code doesn't work on colab correctly either. Could you please check it out? Thank you so much! |
I will assign someone to have a look at the TensorFlow to Spark NLP, something might have changed in Hugging Face. For the T5, I will ask someone to make a quick test to see if the notebooks are up to date. |
Thank you so much for your help. Apart from that, is it possible for us to directly fine-tune the T5 or BART model through Spark NLP? |
You are welcome. Unfortunately, the fine-tuning is not available on Java bindings or neither TensorFlow, PyTorch, and ONNX. When any of these libraries make the fine-tuning available, we will also implement it. Until then, we usually fine-tune outside and easily scale inside Spark NLP. |
Hi, @maziyarpanahi Thank you so much for your help previously! I have encountered a couple of issues while following the method shared in the https://github.com/JohnSnowLabs/spark-nlp/blob/master/examples/python/transformers/HuggingFace%20in%20Spark%20NLP%20-%20T5.ipynb. I would appreciate your guidance on these:
Issue: While attempting to save the vanilla T5 model using the T5ExportModel class from the notebook (originally used for flan-t5), I encountered a TypeError: Embedding.call() got an unexpected keyword argument 'mode'. I modified the code from logits = self.shared(sequence_output, mode="linear") to logits = self.shared(sequence_output) to bypass this error.
Issue: When trying to import a fine-tuned flan-T5-large model in the same manner, I receive an error: "../transformers/utils/generic.py" line 273, in getitem return self.to_tuple()[k] IndexError: tuple index out of range. We are working under a tight deadline, and your prompt assistance would be greatly appreciated to help us resolve these issues swiftly. Thank you so much! |
Hi @DevinTDHa |
Hi @maziyarpanahi |
Hi @TerryLaw535 |
Hi @maziyarpanahi |
Hi @maziyarpanahi I tried the flan T5 notebook for T5 and I also got the problem above. Please advice. |
Hi Everyone, I looked into this and the TF export seems to indeed have some issues. I believe there are some implementation differences in the transformers library between the older (plain) t5 models. I will look into this. Regarding the ONNX export, the issue above should be fixed with #14234. For the particular issue So for example, while installing the dependencies we need to run ! pip install {OTHER_DEPENDENCIES} onnx==1.14.0 The PR above is not merged yet, but if you pin the onnx version manually, it should work. If possible, we also suggest to use ONNX instead. Let me know if this helps! |
@DevinTDHa Do you have a ONNX example for Bart? Thank you so much for the tip, I got T5 run!! |
@maziyarpanahi @DevinTDHa |
I have also recieved this same error message when trying to fine tune a BertForSequenceClassification model then loading it into SparkNLP I followed the example notebook exactly and have all of my necessary files saved in but when it loads I get |
Is there an existing issue for this?
Who can help?
No response
What are you working on?
I fine-tuned a T5 model from Hugging Face and wanted to import it into Spark NLP.
Current Behavior
I followed the instructions from [https://github.com/JohnSnowLabs/spark-nlp/blob/master/examples/python/transformers/HuggingFace%20in%20Spark%20NLP%20-%20BERT.ipynb], and as I tried to loadSavedModel in Spark NLP, it reported "Py4JJavaError: An error occurred while calling z:com.johnsnowlabs.nlp.annotators.seq2seq.BartTransformer.loadSavedModel: java.lang.Exception: Could not retrieve the SavedModelBundle + ()". Afterward, I attempted to import several other models like t5-base and bart from Hugging Face, and I encountered the same problem.
Expected Behavior
I hope that my fine-tuned T5 model can be successfully loaded in the spark nlp. Or if possible, could anyone make a similar instruction that how to import seq2seq model such as T5 and Bart from huggingface to sparknlp?
Steps To Reproduce
MODEL_NAME = 'google-t5/t5-small'
tokenizer = T5Tokenizer.from_pretrained(MODEL_NAME)
tokenizer.save_pretrained('./{}_tokenizer/'.format(MODEL_NAME))
from transformers import TFAutoModelForSeq2SeqLM, TFT5ForConditionalGeneration
model = TFT5ForConditionalGeneration.from_pretrained(MODEL_NAME)
@tf. function(
input_signature=(
tf.TensorSpec(name="input_ids", shape=(None, None), dtype=tf.int32),
tf.TensorSpec(name="attention_mask", shape=(None, None), dtype=tf.int32)
),
jit_compile=False,
)
def serving_fn(input_ids, attention_mask):
outputs = model.generate(
input_ids=input_ids,
attention_mask=attention_mask,
max_length=512,
min_length=10,
# length_penalty=0.9,
# repetition_penalty=2.0,
# num_beams=4,
# early_stopping=True,
return_dict_in_generate=True,
)
return {"sequences": outputs["sequences"]}
model.save_pretrained("./{}".format(MODEL_NAME), saved_model=True, signatures={'serving_default':serving_fn})
asset_path = '{}/saved_model/1/assets'.format(MODEL_NAME)
!cp {MODEL_NAME}_tokenizer/spiece.model {asset_path}
labels = model.config.id2label
labels = [value for key, value in sorted(labels.items(), reverse=False)]
with open(asset_path+'/labels.txt', 'w') as f:
f.write('\n'.join(labels))
spark = sparknlp.start()
from sparknlp.annotator import *
T5 = T5Transformer.loadSavedModel('{}/saved_model/1'.format(MODEL_NAME), spark)
Spark NLP version and Apache Spark
spark nlp version: '5.3.2'
spark version: '3.5.1'
tensorflow version: '2.15.0'
transformer version: '4.39.1'
Type of Spark Application
Python Application
Java Version
No response
Java Home Directory
No response
Setup and installation
pip
Operating System and Version
Lunix
Link to your project (if available)
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: