Shortcuts

generate_next_token

torchtune.generation.generate_next_token(model: TransformerDecoder, input_pos: Tensor, x: Tensor, q: Tensor, *, mask: Optional[Tensor] = None, temperature: float = 1.0, top_k: Optional[int] = None) Tuple[Tensor, Tensor][source]

Generates the next tokens given a prompt, and also returns the corresponding logits.

Parameters:
Returns:

tuple of two tensors:
  • tokens (torch.Tensor): tensor with the generated tokens,

    with shape [bsz x 1].

  • logits (torch.Tensor): tensor with the logits associated with the generated tokens,

    with shape [bsz x seq_length x vocab_size].

Return type:

Tuple[torch.Tensor, torch.Tensor]

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources