class_docstr: Encoder for the I-JEPA model [0].
  
  Experimental: Support for I-JEPA is experimental, there might be breaking changes
  in the future.
  
  Encodes patch embeddings. Code inspired by [1].
  
  - [0]: Joint-Embedding Predictive Architecture, 2023, https://arxiv.org/abs/2301.08243
  - [1]: https://github.com/facebookresearch/ijepa
  
  Attributes:
      seq_length:
          Token sequence length, including the class token.
      num_layers:
          Number of transformer blocks.
      num_heads:
          Number of attention heads.
      hidden_dim:
          Dimension of the input and output tokens.
      mlp_dim:
          Dimension of the MLP in the transformer block.
      dropout:
          Percentage of elements set to zero after the MLP in the transformer.
      attention_dropout:
          Percentage of elements set to zero after the attention head.
class_docstr_tok: ["Encoder","for","the","I-JEPA","model","[","0","]",".","Experimental",":","Support","for","I-JEPA","is","experimental",",","there","might","be","breaking","changes","in","the","future",".","Encodes","patch","embeddings",".","Code","inspired","by","[","1","]",".","-","[","0","]",":","Joint-Embedding","Predictive","Architecture",",","2023",",","https",":","\/\/arxiv.org\/abs\/2301.08243","-","[","1","]",":","https",":","\/\/github.com\/facebookresearch\/ijepa","Attributes",":","seq_length",":","Token","sequence","length",",","including","the","class","token",".","num_layers",":","Number","of","transformer","blocks",".","num_heads",":","Number","of","attention","heads",".","hidden_dim",":","Dimension","of","the","input","and","output","tokens",".","mlp_dim",":","Dimension","of","the","MLP","in","the","transformer","block",".","dropout",":","Percentage","of","elements","set","to","zero","after","the","MLP","in","the","transformer",".","attention_dropout",":","Percentage","of","elements","set","to","zero","after","the","attention","head","."]
docstr: Returns the interpolated positional embedding for the given input.
  
  This function interpolates self.pos_embedding for all tokens in the input,
  ignoring the class token. This allows encoding variable sized images.
  
  Args:
      input:
         Input tensor with shape (batch_size, num_sequences).
docstr_tok: ["Returns","the","interpolated","positional","embedding","for","the","given","input",".","This","function","interpolates","self.pos_embedding","for","all","tokens","in","the","input",",","ignoring","the","class","token",".","This","allows","encoding","variable","sized","images",".","Args",":","input",":","Input","tensor","with","shape","(","batch_size",",","num_sequences",")","."]
code: def interpolate_pos_encoding(self, input: torch.Tensor):
      """Returns the interpolated positional embedding for the given input.
  
      This function interpolates self.pos_embedding for all tokens in the input,
      ignoring the class token. This allows encoding variable sized images.
  
      Args:
          input:
             Input tensor with shape (batch_size, num_sequences).
  
      """
      # code copied from:
      # https://github.com/facebookresearch/msn/blob/4388dc1eadbe3042b85d3296d41b9b207656e043/src/deit.py#L291
      npatch = input.shape[1] - 1
      N = self.pos_embedding.shape[1] - 1
      if npatch == N:
          return self.pos_embedding
      class_emb = self.pos_embedding[:, 0]
      pos_embedding = self.pos_embedding[:, 1:]
      dim = input.shape[-1]
      pos_embedding = nn.functional.interpolate(
          pos_embedding.reshape(
              1, int(math.sqrt(N)), int(math.sqrt(N)), dim
          ).permute(0, 3, 1, 2),
          scale_factor=math.sqrt(npatch / N),
          mode="bicubic",
      )
      pos_embedding = pos_embedding.permute(0, 2, 3, 1).view(1, -1, dim)
      return torch.cat((class_emb.unsqueeze(0), pos_embedding), dim=1)
  
imports: import math
  from functools import partial
  from typing import Callable, List, Optional
  import numpy
  import torch
  import torch.nn
  from torchvision.models import vision_transformer
  from torchvision.models.vision_transformer import ConvStemConfig
  from lightly.models import utils
label_desc: Use image node_id 4 for calling the IJEPAEncoder obj's underlying member method code with example usage: obj.interpolate_pos_encoding(input) and returns: torch, self