configuration_cvt.py 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # Copyright 2022 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. """CvT 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="microsoft/cvt-13")
  19. @strict
  20. class CvtConfig(PreTrainedConfig):
  21. r"""
  22. patch_stride (`list[int]`, *optional*, defaults to `[4, 2, 2]`):
  23. The stride size of each encoder's patch embedding.
  24. patch_padding (`list[int]`, *optional*, defaults to `[2, 1, 1]`):
  25. The padding size of each encoder's patch embedding.
  26. depth (`list[int]`, *optional*, defaults to `[1, 2, 10]`):
  27. The number of layers in each encoder block.
  28. attention_drop_rate (`list[float]`, *optional*, defaults to `[0.0, 0.0, 0.0]`):
  29. The dropout ratio for the attention probabilities.
  30. drop_rate (`list[float]`, *optional*, defaults to `[0.0, 0.0, 0.0]`):
  31. The dropout ratio for the patch embeddings probabilities.
  32. cls_token (`list[bool]`, *optional*, defaults to `[False, False, True]`):
  33. Whether or not to add a classification token to the output of each of the last 3 stages.
  34. qkv_projection_method (`list[string]`, *optional*, defaults to ["dw_bn", "dw_bn", "dw_bn"]`):
  35. The projection method for query, key and value Default is depth-wise convolutions with batch norm. For
  36. Linear projection use "avg".
  37. kernel_qkv (`list[int]`, *optional*, defaults to `[3, 3, 3]`):
  38. The kernel size for query, key and value in attention layer
  39. padding_kv (`list[int]`, *optional*, defaults to `[1, 1, 1]`):
  40. The padding size for key and value in attention layer
  41. stride_kv (`list[int]`, *optional*, defaults to `[2, 2, 2]`):
  42. The stride size for key and value in attention layer
  43. padding_q (`list[int]`, *optional*, defaults to `[1, 1, 1]`):
  44. The padding size for query in attention layer
  45. stride_q (`list[int]`, *optional*, defaults to `[1, 1, 1]`):
  46. The stride size for query in attention layer
  47. Example:
  48. ```python
  49. >>> from transformers import CvtConfig, CvtModel
  50. >>> # Initializing a Cvt msft/cvt style configuration
  51. >>> configuration = CvtConfig()
  52. >>> # Initializing a model (with random weights) from the msft/cvt style configuration
  53. >>> model = CvtModel(configuration)
  54. >>> # Accessing the model configuration
  55. >>> configuration = model.config
  56. ```"""
  57. model_type = "cvt"
  58. num_channels: int = 3
  59. patch_sizes: list[int] | tuple[int, ...] = (7, 3, 3)
  60. patch_stride: list[int] | tuple[int, ...] = (4, 2, 2)
  61. patch_padding: list[int] | tuple[int, ...] = (2, 1, 1)
  62. embed_dim: list[int] | tuple[int, ...] = (64, 192, 384)
  63. num_heads: list[int] | tuple[int, ...] = (1, 3, 6)
  64. depth: list[int] | tuple[int, ...] = (1, 2, 10)
  65. mlp_ratio: list[float] | tuple[float, ...] = (4.0, 4.0, 4.0)
  66. attention_drop_rate: list[float] | tuple[float, ...] = (0.0, 0.0, 0.0)
  67. drop_rate: list[float] | tuple[float, ...] = (0.0, 0.0, 0.0)
  68. drop_path_rate: list[float] | tuple[float, ...] = (0.0, 0.0, 0.1)
  69. qkv_bias: list[bool] | tuple[bool, ...] = (True, True, True)
  70. cls_token: list[bool] | tuple[bool, ...] = (False, False, True)
  71. qkv_projection_method: list[str] | tuple[str, ...] = ("dw_bn", "dw_bn", "dw_bn")
  72. kernel_qkv: list[int] | tuple[int, ...] = (3, 3, 3)
  73. padding_kv: list[int] | tuple[int, ...] = (1, 1, 1)
  74. stride_kv: list[int] | tuple[int, ...] = (2, 2, 2)
  75. padding_q: list[int] | tuple[int, ...] = (1, 1, 1)
  76. stride_q: list[int] | tuple[int, ...] = (1, 1, 1)
  77. initializer_range: float = 0.02
  78. layer_norm_eps: float = 1e-12
  79. __all__ = ["CvtConfig"]