class_docstr: Perplexity measures how well a language model predicts a text sample. It's calculated as the average number of bits
  per word a model needs to represent the sample.
  Args:
      kwargs:
          Additional keyword arguments, see :ref:`Metric kwargs` for more info.
  Examples:
      >>> import torch
      >>> preds = torch.rand(2, 8, 5, generator=torch.manual_seed(22))
      >>> target = torch.randint(5, (2, 8), generator=torch.manual_seed(22))
      >>> target[0, 6:] = -100
      >>> metric = Perplexity(ignore_index=-100)
      >>> metric(preds, target)
      tensor(5.2545)
docstr: Compute and store intermediate statistics for Perplexity.
  Args:
      preds:
          Probabilities assigned to each token in a sequence with shape [batch_size, seq_len, vocab_size].
      target:
          Ground truth values with a shape [batch_size, seq_len].
docstr_tok: ["Compute","and","store","intermediate","statistics","for","Perplexity",".","Args",":","preds",":","Probabilities","assigned","to","each","token","in","a","sequence","with","shape","[","batch_size",",","seq_len",",","vocab_size","]",".","target",":","Ground","truth","values","with","a","shape","[","batch_size",",","seq_len","]","."]
code: def update(self, preds: Tensor, target: Tensor, loss: Optional[Tensor] = None) -> None:  # type: ignore
      """Compute and store intermediate statistics for Perplexity.
      Args:
          preds:
              Probabilities assigned to each token in a sequence with shape [batch_size, seq_len, vocab_size].
          target:
              Ground truth values with a shape [batch_size, seq_len].
      """
      count = target.numel()
      if loss is None:
          loss = self.loss_fn(preds, target)
      self.total_log_probs += loss.double() * count
      self.count += count
  
file_path: flash-attention/training/src/metrics/perplexity.py
imports: from typing import Any, Dict, Optional
  import torch
  import torch.nn.functional
  from torch import Tensor
  from torchmetrics import Metric
label_desc: Use image node_id 2 for calling the Perplexity obj's underlying member method code with example usage: obj.update(preds, target, loss) without return types