Converting GPT2 to JavaScript?
Hello everyone,I am contemplating converting my trained GPT2 model to JavaScript to go wild. The model has been trained in its PyTorch variant.I have an idea of how to map it to JavaScript and would like to ask your opinion.Maybe this is a little to much overkill:Save PyTorch GPT2 as pretrained.Load the TensorFlow GPT2 from the file I have just saved. (Believing the binaries are framework agnostic).Convert the TensorFlow model to TensorflowJS.Would that work?
2021-04-17T16:08:59Z
hey@TristanBehrens, your approach sounds sensible (although i don’t know anything about the TF → TFJS step). to load the pytorch model in tf, you’ll just need to add afrom_pt=Trueargument, e.g.tf_model = TFDistilBertForSequenceClassification.from_pretrained("path/to/pytorch-model", from_pt=True)an alternative would be to use onnx as the intermediate representation (seeherefor the export), but your approach seems simpler