How to get logits from generate() method ?
Hello, 

I am using RL to train Seq2Seq models and I need logits from generate method ? Since in RL we need to sample from current policy? 
Does anyone know how I can adapt generate method to get logits ?

Specifically I am using BART based models. 
If you guys could give a code snippet or something. That will be a lo of help.

Please let me know. 
Hi,

This can be done easily by setting the `output_scores` flag of the [generate](https://huggingface.co/transformers/main_classes/model.html?highlight=generate#transformers.generation_utils.GenerationMixin.generate) method to `True`.<|||||>output_scores will be of shape ```(max_length-input_ids.shape[-1], )``` with each tensor of shape ```(bs, config.vocab_size)```. 
How do I convert output_scores to log probabilities ?
<|||||>The logits are just the raw scores, you can get log probabilities by applying a `log_softmax` (which is a softmax followed by a logarithm) on the last dimension, i.e.

```
import torch

logits = torch.randn((batch_size, vocab_size)
log_probs = torch.nn.functional.log_softmax(logits, dim=-1)
```<|||||>Thanks. That helps.<|||||>@Atharva-Phatak @NielsRogge Where are these logits returned to? 

out = model.generate(
            input_ids, 
            attention_mask=attention_mask,
            max_length=max_target_length,
            output_scores = True
        )


Here out still only contains predictions.<|||||>I believe you have to also specify `return_dict_in_generate=True` to get a `ModelOutput`.<|||||>Thanks!<|||||>@Atharva-Phatak Did you publish your RL training experiments? Sounds interesting !