The script for ONNX model conversion and ONNX Runtime inference is here.
Input to model
Sequence of words as a string. Example: "Here is some text to encode : Hello World", tokenized by Byte-Pair-Encoding.
input_ids: Indices of input tokens in the vocabulary. It's a long tensor of dynamic shape (batch_size, sequence_length).
Preprocessing steps
Use tokenizer.encode() to encode the input text:
python
1text ="Here is some text to encode : Hello World"2tokenizer = GPT2Tokenizer.from_pretrained('gpt2')3tokens_tensor = torch.tensor([torch.tensor(tokenizer.encode(text))])
Output of model
For GPT-2 model:
last_hidden_state: Sequence of hidden-states at the last layer of the model. It's a float tensor of size (batch_size, sequence_length, hidden_size).
past: pre-computed hidden-states. It's a list of tensors (key and values in the attention blocks) of size (batch_size, num_heads, sequence_length, sequence_length), one per each layer.
Output of this model is the tuple (last_hidden_state, past)
For GPT-2-LM-HEAD model:
prediction_scores: Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax). It's a float tensor of size (batch_size, sequence_length, vocab_size).
past: pre-computed hidden-states. It's a list of tensors (key and values in the attention blocks) of size (batch_size, num_heads, sequence_length, sequence_length), one per each layer.
Output of this model is the tuple (prediction_scores, past)
Note that output_hidden_states=False and output_attentions=False in the PretrainedConfig configs.