Hey @azhx,
if you are on master then you can also use the ModelOutput object, which is a dict  like object which lets you access the output as out.attentions, out.hidden_states etc. For GPT2Model model, it returns BaseModelOutputWithPast. You can find the docs here 14