class_docstr: This module learns positional embeddings up to a fixed maximum size.
class_docstr_tok: ["This","module","learns","positional","embeddings","up","to","a","fixed","maximum","size","."]
docstr: `input_ids_shape` is expected to be [bsz x seqlen].
docstr_tok: ["`","input_ids_shape","`","is","expected","to","be","[","bsz","x","seqlen","]","."]
code: def forward(
      self,
      attention_mask: torch.LongTensor,
      past_key_values_length: int = 0,
  ):
      """`input_ids_shape` is expected to be [bsz x seqlen]."""
      attention_mask = attention_mask.long()
  
      # create positions depending on attention_mask
      positions = (
          torch.cumsum(attention_mask, dim=1).type_as(attention_mask)
          * attention_mask
      ).long() - 1
  
      # cut positions if `past_key_values_length` is > 0
      positions = positions[:, past_key_values_length:]
  
      return super().forward(positions + self.offset)
  
imports: import random
  from typing import List, Optional, Tuple, Union
  import torch
  import torch.utils.checkpoint
  from torch import nn
  from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
  from ...activations import ACT2FN
  from ...modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast, QuestionAnsweringModelOutput, SequenceClassifierOutputWithPast
  from ...modeling_utils import PreTrainedModel
  from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from .configuration_opt import OPTConfig
label_desc: Use image node_id 2 for calling the OPTLearnedPositionalEmbedding obj's underlying member method code with example usage: obj.forward(attention_mask, past_key_values_length) and returns: super