class_docstr: This module produces sinusoidal positional embeddings of any length.
  
  Padding symbols are ignored.
class_docstr_tok: ["This","module","produces","sinusoidal","positional","embeddings","of","any","length",".","Padding","symbols","are","ignored","."]
docstr: Input is expected to be of size [bsz x seqlen].
docstr_tok: ["Input","is","expected","to","be","of","size","[","bsz","x","seqlen","]","."]
code: def forward(
      self,
      input,
      incremental_state: Optional[Any] = None,
      timestep: Optional[Tensor] = None,
      positions: Optional[Any] = None,
  ):
      """Input is expected to be of size [bsz x seqlen]."""
      bspair = torch.onnx.operators.shape_as_tensor(input)
      bsz, seq_len = bspair[0], bspair[1]
      max_pos = self.padding_idx + 1 + seq_len
      if max_pos > self.weights.size(0):
          # expand embeddings if needed
          self.weights = SinusoidalPositionalEmbedding.get_embedding(
              max_pos, self.embedding_dim, self.padding_idx
          ).to(self.weights)
  
      if incremental_state is not None:
          # positions is the same for every token when decoding a single step
          pos = (
              timestep.view(-1)[0] + 1
              if timestep is not None
              else seq_len
          )
          if self.onnx_trace:
              return (
                  self.weights.index_select(
                      index=self.padding_idx + pos, dim=0
                  )
                  .unsqueeze(1)
                  .repeat(bsz, 1, 1)
              )
          return self.weights[self.padding_idx + pos, :].expand(
              bsz, 1, -1
          )
  
      positions = utils.make_positions(
          input, self.padding_idx, onnx_trace=self.onnx_trace
      )
      if self.onnx_trace:
          flat_embeddings = self.weights.detach().index_select(
              0, positions.view(-1)
          )
          embedding_shape = torch.cat(
              (
                  bsz.view(1),
                  seq_len.view(1),
                  torch.tensor([-1], dtype=torch.long),
              )
          )
          embeddings = torch.onnx.operators.reshape_from_tensor_shape(
              flat_embeddings, embedding_shape
          )
          return embeddings
      return (
          self.weights.index_select(0, positions.view(-1))
          .view(bsz, seq_len, -1)
          .detach()
      )
  
file_path: fairseq/fairseq/modules/sinusoidal_positional_embedding.py
imports: import math
  from typing import Any, Optional
  import torch
  import torch.onnx.operators
  from fairseq import utils
  from torch import nn, Tensor
label_desc: Use image node_id 5 for calling the SinusoidalPositionalEmbedding obj's underlying member method code with example usage: obj.forward(input, incremental_state, timestep, positions) and returns: self, self, embeddings, self