Skip to content

Instantly share code, notes, and snippets.

@pxanthopoulos
Created October 13, 2024 17:26
Show Gist options
  • Save pxanthopoulos/9f40ba1fdef3a57c9a1b13d75ca37db2 to your computer and use it in GitHub Desktop.
Save pxanthopoulos/9f40ba1fdef3a57c9a1b13d75ca37db2 to your computer and use it in GitHub Desktop.
Export GPT in TF format using huggingface
from transformers import AutoTokenizer, TFOpenAIGPTModel
import tensorflow as tf
model_name = "openai-community/openai-gpt"
model_path = "/workspace/iree/workspace/gpt/gpt-tf"
cache_dir = "/workspace/iree/workspace/gpt/cache"
tokenizer = AutoTokenizer.from_pretrained(model_name, cache_dir=cache_dir)
model = TFOpenAIGPTModel.from_pretrained(model_name, cache_dir=cache_dir)
tf.saved_model.save(model, model_path)
tokenizer.save_pretrained(model_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment