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"]
docstr: Reset and extend the positional encodings if needed.
docstr_tok: ["Reset","and","extend","the","positional","encodings","if","needed","."]
code: def extend_pe(self, length, device):
      """Reset and extend the positional encodings if needed."""
      if hasattr(self, "pe") and self.pe.size(1) >= length:
          return
      positions = torch.arange(
          0, length, dtype=torch.float32, device=device
      ).unsqueeze(1)
      self.create_pe(positions=positions)
  
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 3 for calling the PositionalEncoding obj's underlying member method code with example usage: obj.extend_pe(length, device) without return types