class_docstr: Modified pretraining for depth-recurrent models. Only works with models that expose the ScriptableRecurrentLM interface.
class_docstr_tok: ["Modified","pretraining","for","depth-recurrent","models",".","Only","works","with","models","that","expose","the","ScriptableRecurrentLM","interface","."]
code: def _prediction_dynamic(
      self, outputs: torch.Tensor, labels: Optional[torch.Tensor] = None
  ):
      if labels is not None:
          labels = labels.view(-1)
          mask_positions = labels.view(-1) != self.loss_fn.ignore_index
          outputs = outputs[mask_positions]
          labels = labels[mask_positions]
  
      outputs = self.decoder(self.prediction_head(outputs))
      if labels is not None:
          masked_lm_loss = self.loss_fn(outputs, labels)
      else:
          masked_lm_loss = outputs.new_zeros((1,))
      return masked_lm_loss
  
imports: import torch
  from typing import Optional
  from random import randrange
  from transformers import PretrainedConfig
  from .components import EmbeddingComponent, AttentionComponent, FFNComponent, PredictionHeadComponent, get_extended_attention_mask, _get_norm_fn, _get_nonlin_fn, _init_module
label_desc: Use image node_id 6 for calling the BPTTforPreTraining obj's underlying member method code with example usage: obj._prediction_dynamic(outputs, labels) and returns: masked_lm_loss