configuration_deit.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Copyright 2021 Facebook AI Research (FAIR) and The HuggingFace Inc. team. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """DeiT model configuration"""
  15. from huggingface_hub.dataclasses import strict
  16. from ...configuration_utils import PreTrainedConfig
  17. from ...utils import auto_docstring
  18. @auto_docstring(checkpoint="facebook/deit-base-distilled-patch16-224")
  19. @strict
  20. class DeiTConfig(PreTrainedConfig):
  21. r"""
  22. encoder_stride (`int`, *optional*, defaults to 16):
  23. Factor to increase the spatial resolution by in the decoder head for masked image modeling.
  24. pooler_output_size (`int`, *optional*):
  25. Dimensionality of the pooler layer. If None, defaults to `hidden_size`.
  26. pooler_act (`str`, *optional*, defaults to `"tanh"`):
  27. The activation function to be used by the pooler.
  28. Example:
  29. ```python
  30. >>> from transformers import DeiTConfig, DeiTModel
  31. >>> # Initializing a DeiT deit-base-distilled-patch16-224 style configuration
  32. >>> configuration = DeiTConfig()
  33. >>> # Initializing a model (with random weights) from the deit-base-distilled-patch16-224 style configuration
  34. >>> model = DeiTModel(configuration)
  35. >>> # Accessing the model configuration
  36. >>> configuration = model.config
  37. ```"""
  38. model_type = "deit"
  39. hidden_size: int = 768
  40. num_hidden_layers: int = 12
  41. num_attention_heads: int = 12
  42. intermediate_size: int = 3072
  43. hidden_act: str = "gelu"
  44. hidden_dropout_prob: float | int = 0.0
  45. attention_probs_dropout_prob: float | int = 0.0
  46. initializer_range: float = 0.02
  47. layer_norm_eps: float = 1e-12
  48. image_size: int | list[int] | tuple[int, int] = 224
  49. patch_size: int | list[int] | tuple[int, int] = 16
  50. num_channels: int = 3
  51. qkv_bias: bool = True
  52. encoder_stride: int = 16
  53. pooler_output_size: int | None = None
  54. pooler_act: str = "tanh"
  55. def __post_init__(self, **kwargs):
  56. self.pooler_output_size = self.pooler_output_size if self.pooler_output_size else self.hidden_size
  57. super().__post_init__(**kwargs)
  58. __all__ = ["DeiTConfig"]