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, past_key_values_length: int = 0
  ):
      bsz, seq_len = input_ids.size()
      # Create the position ids from the input token ids. Any padded tokens remain padded.
      position_ids = self.create_position_ids_from_input_ids(
          input_ids, self.padding_idx, past_key_values_length
      ).to(input_ids.device)
  
      # expand embeddings if needed
      max_pos = self.padding_idx + 1 + seq_len
      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, -1)
          .detach()
      )
  
imports: import copy
  import math
  import random
  from typing import Optional, Tuple
  import torch
  from torch import nn
  from torch.nn import CrossEntropyLoss
  from ...activations import ACT2FN
  from ...modeling_outputs import BaseModelOutputWithPastAndCrossAttentions, CausalLMOutputWithCrossAttentions
  from ...modeling_utils import PreTrainedModel
  from ...utils import add_start_docstrings, logging, replace_return_docstrings
  from .configuration_speech_to_text_2 import Speech2Text2Config
label_desc: Use image node_id 4 for calling the Speech2Text2SinusoidalPositionalEmbedding obj's underlying member method code with example usage: obj.forward(input_ids, past_key_values_length) and returns: self