code: def logprobs_from_logits(logits, labels, gather=True):
      """
      See: https://github.com/pytorch/pytorch/issues/563#issuecomment-330103591
      """
      logp = F.log_softmax(logits, dim=2)
  
      if not gather:
          return logp
      logpy = torch.gather(logp, 2, labels.unsqueeze(2)).squeeze(-1)
      return logpy
  
imports: import math
  import time
  import warnings
  from collections.abc import Mapping
  from typing import Any, Dict, List, Optional, Union
  import numpy
  import torch
  import torch.nn.functional
  from datasets import Dataset
  from huggingface_hub import PyTorchModelHubMixin
  from torch.cuda.amp import autocast
  from torch.nn.utils.rnn import pad_sequence
  from torch.utils.data import DataLoader
  from transformers import DataCollatorForLanguageModeling, PreTrainedTokenizer, PreTrainedTokenizerFast
  from llm_studio.src.utils.modeling_utils import unwrap_model
label_desc: Use image node_id 3 for calling a global function with example usage: logprobs_from_logits(logits, labels, gather) and returns: logpy, logp