Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

MLP_DIM in ViT is not adjustable through the config. #564

Open
Jeffkang-94 opened this issue Aug 24, 2022 · 2 comments
Open

MLP_DIM in ViT is not adjustable through the config. #564

Jeffkang-94 opened this issue Aug 24, 2022 · 2 comments

Comments

@Jeffkang-94
Copy link

Instructions To Reproduce the Issue:

Dino configuration contains the parameter named MLP_DIM which looks like being adjustable by the user. But actually, it is hard coded. See the line here

mlp_hidden_dim = int(dim * mlp_ratio)
self.mlp = Mlp(
in_features=dim,
hidden_features=mlp_hidden_dim,
act_layer=act_layer,
drop=drop,
)

I wanted to adjust the mlp_ratio or size of mlp_dim through the configuration as I've met several OOM issues because of the huge dataset,

  MODEL:
    TRUNK:
      NAME: vision_transformer
      VISION_TRANSFORMERS:
        IMAGE_SIZE: 512
        PATCH_SIZE: 16
        NUM_LAYERS: 3
        NUM_HEADS: 12
        HIDDEN_DIM: 192 
        # MLP_DIM: 768 # Not Used!
        CLASSIFIER: token
        DROPOUT_RATE: 0
        ATTENTION_DROPOUT_RATE: 0
        QKV_BIAS: True
        DROP_PATH_RATE: 0.1

But it seems that the mlp_dim is not adjustable through the configuration. Apart from it, it also raises some confusion for the user who wants to change the size of mlp dimension.

Expected behavior:

To be specific, with the configuration

MODEL:
    TRUNK:
      NAME: vision_transformer
      VISION_TRANSFORMERS:
        HIDDEN_DIM: 384
        MLP_DIM: 768 # Not Used!

mlp is supposed to have

mlp dim : Mlp(
  (fc1): Linear(in_features=384, out_features=768, bias=True)
  (act): GELU()
  (fc2): Linear(in_features=768, out_features=384, bias=True)
  (drop): Dropout(p=0, inplace=False)
)

but actually it has

mlp dim : Mlp(
  (fc1): Linear(in_features=384, out_features=1536, bias=True)
  (act): GELU()
  (fc2): Linear(in_features=1536, out_features=384, bias=True)
  (drop): Dropout(p=0, inplace=False)
)

because of the pre-defined value mlp_ratio=4.0 here

self.mlp_ratio = 4.0

@Jeffkang-94 Jeffkang-94 changed the title Please read & provide the following MLP_DIM in ViT is not adjustable Aug 24, 2022
@Jeffkang-94 Jeffkang-94 changed the title MLP_DIM in ViT is not adjustable MLP_DIM in ViT is not adjustable through the config. Aug 24, 2022
@QuentinDuval
Copy link
Contributor

Hello @Jeffkang-94,

Sorry for my delay in the response, and thanks a lot for raising the issue !

It should be solved at : 04788de

I also fixed the configurations that had the wrong MLP_DIM!

Thank you,
Quentin

@Jeffkang-94
Copy link
Author

Jeffkang-94 commented Nov 6, 2023

Thank you for your efforts! I think we can wrap-up this issue then.

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

No branches or pull requests

2 participants