class_docstr: This module produces sinusoidal positional embeddings of any length.
class_docstr_tok: ["This","module","produces","sinusoidal","positional","embeddings","of","any","length","."]
code: def forward(
      self,
      input_ids: torch.Tensor = None,
      inputs_embeds: torch.Tensor = None,
      past_key_values_length: int = 0,
  ):
      if input_ids is not None:
          bsz, seq_len = input_ids.size()
          # Create the position ids from the input token ids. Any padded tokens remain padded.
          position_ids = create_position_ids_from_input_ids(
              input_ids, self.padding_idx, past_key_values_length
          ).to(input_ids.device)
      else:
          bsz, seq_len = inputs_embeds.size()[:-1]
          position_ids = self.create_position_ids_from_inputs_embeds(
              inputs_embeds, past_key_values_length
          )
  
      # expand embeddings if needed
      max_pos = self.padding_idx + 1 + seq_len + past_key_values_length
      if max_pos > self.weights.size(0):
          self.make_weights(
              max_pos + self.offset,
              self.embedding_dim,
              self.padding_idx,
          )
  
      return (
          self.weights.index_select(0, position_ids.view(-1))
          .view(bsz, seq_len, self.weights.shape[-1])
          .detach()
      )
  
imports: import math
  from typing import List, Optional, Tuple, Union
  import torch
  from torch import nn
  from torch.nn import CrossEntropyLoss
  from ...activations import ACT2FN
  from ...integrations.deepspeed import is_deepspeed_zero3_enabled
  from ...modeling_attn_mask_utils import _prepare_4d_attention_mask, _prepare_4d_causal_attention_mask
  from ...modeling_outputs import BaseModelOutput, BaseModelOutputWithPastAndCrossAttentions, Seq2SeqLMOutput, Seq2SeqModelOutput
  from ...modeling_utils import PreTrainedModel
  from ...utils import add_code_sample_docstrings, add_end_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from .configuration_m2m_100 import M2M100Config
label_desc: Use image node_id 4 for calling the M2M100SinusoidalPositionalEmbedding obj's underlying member method code with example usage: obj.forward(input_ids, inputs_embeds, past_key_values_length) and returns: self