class_docstr: PyTorch implementation containing all the modelling needed for your NLP task. Combines a language
  model and a prediction head. Allows for gradient flow back to the language model component.
class_docstr_tok: ["PyTorch","implementation","containing","all","the","modelling","needed","for","your","NLP","task",".","Combines","a","language","model","and","a","prediction","head",".","Allows","for","gradient","flow","back","to","the","language","model","component","."]
docstr: Get losses from all prediction heads & reduce to single loss *per sample*.
  
  :param logits: logits, can vary in shape and type, depending on task
  :type logits: object
  :param global_step: number of current training step
  :type global_step: int
  :param kwargs: placeholder for passing generic parameters.
                 Note: Contains the batch (as dict of tensors), when called from Trainer.train().
  :type kwargs: object
  :return loss: torch.tensor that is the per sample loss (len: batch_size)
code: def logits_to_loss(self, logits, global_step=None, **kwargs):
      """
      Get losses from all prediction heads & reduce to single loss *per sample*.
  
      :param logits: logits, can vary in shape and type, depending on task
      :type logits: object
      :param global_step: number of current training step
      :type global_step: int
      :param kwargs: placeholder for passing generic parameters.
                     Note: Contains the batch (as dict of tensors), when called from Trainer.train().
      :type kwargs: object
      :return loss: torch.tensor that is the per sample loss (len: batch_size)
      """
      all_losses = self.logits_to_loss_per_head(logits, **kwargs)
      # This aggregates the loss per sample across multiple prediction heads
      # Default is sum(), but you can configure any fn that takes [Tensor, Tensor ...] and returns [Tensor]
      loss = self.loss_aggregation_fn(
          all_losses, global_step=global_step, batch=kwargs
      )
      return loss
  
imports: import copy
  import json
  import logging
  import os
  from pathlib import Path
  import multiprocessing
  import numpy
  import torch
  from torch import nn
  from transformers import AutoConfig
  from transformers.convert_graph_to_onnx import convert, quantize
  from farm.data_handler.processor import Processor
  from farm.modeling.language_model import LanguageModel
  from farm.modeling.prediction_head import PredictionHead, pick_single_fn
  from farm.utils import MLFlowLogger, stack
  import farm.conversion.transformers
label_desc: Use image node_id 7 for calling the AdaptiveModel obj's underlying member method code with example usage: obj.logits_to_loss(logits, global_step) and returns: loss