def from_vit(
        cls, vit: vision_transformer.VisionTransformer, initialize_weights: bool = True
    ) -> MAEBackbone:
        """Creates a MAEBackbone from a torchvision ViT model.

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

        Returns:
            A MAEBackbone with the same architecture as vit.

        """
        # Create a new instance with dummy values as they will be overwritten
        # by the copied vit_encoder attributes
        backbone = cls(
            image_size=vit.image_size,
            patch_size=vit.patch_size,
            num_layers=1,
            num_heads=1,
            hidden_dim=vit.hidden_dim,
            mlp_dim=vit.mlp_dim,
            dropout=vit.dropout,
            attention_dropout=vit.attention_dropout,
            num_classes=vit.num_classes,
            representation_size=vit.representation_size,
            norm_layer=vit.norm_layer,
        )

        # Copy attributes from the ViT model
        backbone.conv_proj = vit.conv_proj
        backbone.class_token = vit.class_token
        backbone.seq_length = vit.seq_length
        backbone.heads = vit.heads
        backbone.encoder = MAEEncoder.from_vit_encoder(
            vit.encoder, initialize_weights=initialize_weights
        )
        return backbone
Creates a MAEBackbone from a torchvision ViT model.

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

        Returns:
            A MAEBackbone with the same architecture as vit.

        
lightly/models/modules/masked_autoencoder.py