Using PyTorch model in TensorFlow
Hi,I would like to use a model built using PyTorch (namelythis one) in a Tensorflow environment.More specifically I would like to start by just extract some of the embeddings in the later layers, and then potentially run some fine-tuning.So I have two questions:Is there a way to load and run inference from a PyTorch model in TensorFlow?Is there a way to load and fine-tune a PyTorch model in Tensorflow?Thanks in advance!
2021-03-06T14:32:52Z
Hi@gruffgoran, your use cases sound like a perfect match for theONNXformatHaving said that, you might be able to get a quick win by trying something like the following (seedocs):tf_model = TFBertForSequenceClassification.from_pretrained("KB/bert-base-swedish-cased", from_pt=True)From here you can then run inference / fine-tune etc using TensorFlow.If you want to go the ONNX route, the idea would be to convert PyTorch → ONNX and then load the ONNX model in TensorFlow. Details on doing the conversion can be found here:Exporting transformers models — transformers 4.3.0 documentation
2023-06-07T10:15:58Z
Hello, thanks but the link seems to be broken:https://huggingface.co/transformers/serialization.html#onnx-onnxruntimePlease direct to the correct one.