class_docstr: Fixed sinusoidal positional encoding.
  Args:
      d_model (int): embedding dim
      dropout_rate (float): dropout rate
      max_len (int): maximum input length
      xscale (bool): whether to scale the input by sqrt(d_model)
      dropout_rate_emb (float): dropout rate for the positional embeddings
class_docstr_tok: ["Fixed","sinusoidal","positional","encoding",".","Args",":","d_model","(","int",")",":","embedding","dim","dropout_rate","(","float",")",":","dropout","rate","max_len","(","int",")",":","maximum","input","length","xscale","(","bool",")",":","whether","to","scale","the","input","by","sqrt","(","d_model",")","dropout_rate_emb","(","float",")",":","dropout","rate","for","the","positional","embeddings"]
code: def create_pe(self, positions):
      pos_length = positions.size(0)
      pe = torch.zeros(
          pos_length, self.d_model, device=positions.device
      )
      div_term = torch.exp(
          torch.arange(
              0,
              self.d_model,
              2,
              dtype=torch.float32,
              device=positions.device,
          )
          * -(math.log(10000.0) / self.d_model)
      )
      pe[:, 0::2] = torch.sin(positions * div_term)
      pe[:, 1::2] = torch.cos(positions * div_term)
      pe = pe.unsqueeze(0)
      if hasattr(self, "pe"):
          self.pe = pe
      else:
          self.register_buffer("pe", pe, persistent=False)
  
imports: import math
  from functools import lru_cache
  from typing import List, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from nemo.utils import avoid_float16_autocast_context
label_desc: Use image node_id 2 for calling the PositionalEncoding obj's underlying member method code with example usage: obj.create_pe(positions) without return types