class_docstr: Streaming Positional encoding.
  
  Args:
      d_model (int): Embedding dimension.
      dropout_rate (float): Dropout rate.
      max_len (int): Maximum input length.
class_docstr_tok: ["Streaming","Positional","encoding",".","Args",":","d_model","(","int",")",":","Embedding","dimension",".","dropout_rate","(","float",")",":","Dropout","rate",".","max_len","(","int",")",":","Maximum","input","length","."]
docstr: Reset the positional encodings.
docstr_tok: ["Reset","the","positional","encodings","."]
code: def extend_pe(self, length, device, dtype):
      """Reset the positional encodings."""
      if self.pe is not None:
          if self.pe.size(1) >= length:
              if self.pe.dtype != dtype or self.pe.device != device:
                  self.pe = self.pe.to(dtype=dtype, device=device)
              return
      pe = torch.zeros(length, self.d_model)
      position = torch.arange(0, length, dtype=torch.float32).unsqueeze(
          1
      )
      div_term = torch.exp(
          torch.arange(0, self.d_model, 2, dtype=torch.float32)
          * -(math.log(10000.0) / self.d_model)
      )
      pe[:, 0::2] = torch.sin(position * div_term)
      pe[:, 1::2] = torch.cos(position * div_term)
      pe = pe.unsqueeze(0)
      self.pe = pe.to(device=device, dtype=dtype)
  
imports: import math
  import torch
label_desc: Use image node_id 2 for calling the StreamPositionalEncoding obj's underlying member method code with example usage: obj.extend_pe(length, device, dtype) without return types