Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWAG with Vision Transformers #4

Open
ayushp88 opened this issue Jan 17, 2025 · 2 comments
Open

SWAG with Vision Transformers #4

ayushp88 opened this issue Jan 17, 2025 · 2 comments

Comments

@ayushp88
Copy link

Hi, does this repository also contain SWAG with Vision Transformers?

@svirpioj
Copy link
Member

Not at the moment. However, it's pretty easy to wrap any model from the transformers library. For example, this should work for ViT:

from transformers import ViTConfig, ViTModel
from swag_transformers.base import SwagConfig, SwagModel

MODEL_TYPE = 'swag_vit'

class SwagViTConfig(SwagConfig):
    """Config for ViT model averaging with SWAG"""

    model_type = MODEL_TYPE
    internal_config_class = ViTConfig

class SwagViTModel(SwagModel):
    """SWAG ViT model"""

    config_class = SwagViTConfig
    base_model_prefix = MODEL_TYPE
    internal_model_class = ViTModel

model = ViTModel.from_pretrained('WinKawaks/vit-tiny-patch16-224')
swag_model = SwagViTModel.from_base(model, no_cov_mat=False)

I can also add new models to the library via pull requests.

@svirpioj
Copy link
Member

Now there are basic instructions for this in the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants