def from_vit_encoder(
        cls, vit_encoder: vision_transformer.Encoder, initialize_weights: bool = True
    ) -> MAEEncoder:
        """Creates a MAEEncoder from a torchvision ViT encoder.

        Args:
            vit_encoder:
                A torchvision ViT encoder.
            initialize_weights:
                If True, then all weights are initialized as in MAE paper. Set this to
                False if vit_encoder is pretrained.

        Returns:
            A MAEEncoder with the same architecture as vit_encoder.
        """

        # Create a new instance with dummy values as they will be overwritten
        # by the copied vit_encoder attributes
        encoder = cls(
            seq_length=197,
            num_layers=12,
            num_heads=12,
            hidden_dim=768,
            mlp_dim=3072,
            dropout=0,
            attention_dropout=0,
        )

        # Copy attributes from the ViT encoder
        encoder.pos_embedding = vit_encoder.pos_embedding
        encoder.dropout = vit_encoder.dropout
        encoder.layers = vit_encoder.layers
        encoder.ln = vit_encoder.ln

        if initialize_weights:
            encoder._initialize_weights()
        return encoder
Creates a MAEEncoder from a torchvision ViT encoder.

        Args:
            vit_encoder:
                A torchvision ViT encoder.
            initialize_weights:
                If True, then all weights are initialized as in MAE paper. Set this to
                False if vit_encoder is pretrained.

        Returns:
            A MAEEncoder with the same architecture as vit_encoder.
        
lightly/models/modules/masked_autoencoder.py