text: 
  
  TITLE
  Tenosrflow Loading the saved Model For GPT2
  
  COMMENTS
  6
  
  REACTIONS
  +1: 0
  -1: 0
  laugh: 0
  hooray: 0
  heart: 0
  rocket: 0
  eyes: 0
  
  BODY
  ```py
  from time import time
  from transformers import TFGPT2LMHeadModel, GPT2Tokenizer
  import tensorflow as tf
  
  tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
  model = TFGPT2LMHeadModel.from_pretrained('gpt2')
  
  text = "What are you doing after you have finished working?"
  generated = tokenizer.encode(text)
  context = tf.constant([generated])
  past = None
  start = time()
  for i in range(100):
      output, past = model([context, past])
      logits = output[0, -1, :]
      tok = tf.argmax(logits)
      generated.append(tok.numpy())
      context = tf.expand_dims(tf.expand_dims(tok, 0), 0)
  sequence = tokenizer.decode(generated)
  print(time() - start, sequence)
  
  #save the model 
  tf.saved_model.save(model,"temp")
  
  #loading back the model
  nm = tf.saved_model.load("temp")
  infer = nm.signatures['serving_default']
  ```
  Not able to call the model as shown below
  
  ```py
  text = "What are you doing after you have finished working?"
  generated = tokenizer.encode(text)
  context = tf.constant([generated])
  past = None
  start = time()
  for i in range(100):
      output, past = **infer**([context, past])
      logits = output[0, -1, :]
      tok = tf.argmax(logits)
      generated.append(tok.numpy())
      context = tf.expand_dims(tf.expand_dims(tok, 0), 0)
  sequence = tokenizer.decode(generated)
  print(time() - start, sequence)
  ```