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[Dict[str, Tensor]] = None,
      timestep: Optional[int] = None,
  ):
      """Input is expected to be of size [bsz x seqlen]."""
      bsz, seq_len = input.size()
      max_pos = self.padding_idx + 1 + seq_len
      assert max_pos < self.weights.size(
          0
      ), f"max_pos :{max_pos}, self.weights.size(0): {self.weights.size(0)}"
  
      if incremental_state is not None:
          # Positions is the same for every token when decoding a single step
          # Either its timestep + 1 or len(prev_tokens)
          pos = timestep if timestep is not None else seq_len
          assert pos != 0, "Position cannot start from 0"
          return self.weights[self.padding_idx + pos, :].expand(
              bsz, 1, -1
          )
  
      positions = make_positions(input, self.padding_idx)
      sinusoidal_embedding = (
          self.weights.index_select(0, positions.view(-1))
          .view(bsz, seq_len, -1)
          .detach()
      )
      if self.learned_embed:
          learned_embedding = self.learned_embedding(positions)
          embed_out = torch.cat(
              [sinusoidal_embedding, learned_embedding], dim=-1
          )
      else:
          embed_out = sinusoidal_embedding
      return embed_out
  
imports: import math
  from enum import Enum
  from typing import Dict, Optional
  import torch
  import torch.nn
  import torch.nn.functional
  from pytext.models.representations.transformer import PositionalEmbedding
  from pytext.models.seq_models.base import PlaceholderIdentity
  from torch import Tensor
  from .utils import make_positions
label_desc: Use image node_id 2 for calling the SinusoidalPositionalEmbedding obj's underlying member method code with example usage: obj.forward(input, incremental_state, timestep) and returns: embed_out, self