Convert TensorFlow-based GPT-2 models to Pytorch in a breeze
This repository contains a quick-to-use script to convert GPT-2 models from TensorFlow to PyTorch model format.
Collect all your TensorFlow model files into a singular directory, i.e. these files:
model-<number>.meta
vocab.bpe
model-<number>.data-00000-of-00001
model-<number>.index
checkpoint
counter
encoder.json
hparams.json
Clone the repo, install prerequisites with i.e. pip install -r requirements.txt
if needed.
Run the script:
python convert_model.py /path/to/your/model/files
The converted PyTorch model will be saved in the ./converted_model
directory.
Have fun, I probably won't be updating this one much.
This project is licensed under the MIT License.
All code improvements are welcome. This should at least work on all TF1.x-based GPT-2 architecture models.