configuration_pvt.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Copyright 2023 Authors: Wenhai Wang, Enze Xie, Xiang Li, Deng-Ping Fan,
  2. # Kaitao Song, Ding Liang, Tong Lu, Ping Luo, Ling Shao and The HuggingFace Inc. team.
  3. # All rights reserved.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. """Pvt model configuration"""
  17. from huggingface_hub.dataclasses import strict
  18. from ...configuration_utils import PreTrainedConfig
  19. from ...utils import auto_docstring
  20. @auto_docstring(checkpoint="Xrenya/pvt-tiny-224")
  21. @strict
  22. class PvtConfig(PreTrainedConfig):
  23. r"""
  24. num_encoder_blocks (`int`, *optional*, defaults to 4):
  25. The number of encoder blocks (i.e. stages in the Mix Transformer encoder).
  26. depths (`list[int]`, *optional*, defaults to `[2, 2, 2, 2]`):
  27. The number of layers in each encoder block.
  28. sequence_reduction_ratios (`list[int]`, *optional*, defaults to `[8, 4, 2, 1]`):
  29. Sequence reduction ratios in each encoder block.
  30. patch_sizes (`list[int]`, *optional*, defaults to `[4, 2, 2, 2]`):
  31. Patch size before each encoder block.
  32. strides (`list[int]`, *optional*, defaults to `[4, 2, 2, 2]`):
  33. Stride before each encoder block.
  34. num_attention_heads (`list[int]`, *optional*, defaults to `[1, 2, 5, 8]`):
  35. Number of attention heads for each attention layer in each block of the Transformer encoder.
  36. mlp_ratios (`list[int]`, *optional*, defaults to `[8, 8, 4, 4]`):
  37. Ratio of the size of the hidden layer compared to the size of the input layer of the Mix FFNs in the
  38. encoder blocks.
  39. num_labels ('int', *optional*, defaults to 1000):
  40. The number of classes.
  41. Example:
  42. ```python
  43. >>> from transformers import PvtModel, PvtConfig
  44. >>> # Initializing a PVT Xrenya/pvt-tiny-224 style configuration
  45. >>> configuration = PvtConfig()
  46. >>> # Initializing a model from the Xrenya/pvt-tiny-224 style configuration
  47. >>> model = PvtModel(configuration)
  48. >>> # Accessing the model configuration
  49. >>> configuration = model.config
  50. ```"""
  51. model_type = "pvt"
  52. image_size: int | list[int] | tuple[int, int] = 224
  53. num_channels: int = 3
  54. num_encoder_blocks: int = 4
  55. depths: list[int] | tuple[int, ...] = (2, 2, 2, 2)
  56. sequence_reduction_ratios: list[int] | tuple[int, ...] = (8, 4, 2, 1)
  57. hidden_sizes: list[int] | tuple[int, ...] = (64, 128, 320, 512)
  58. patch_sizes: list[int] | tuple[int, ...] = (4, 2, 2, 2)
  59. strides: list[int] | tuple[int, ...] = (4, 2, 2, 2)
  60. num_attention_heads: list[int] | tuple[int, ...] = (1, 2, 5, 8)
  61. mlp_ratios: list[int] | tuple[int, ...] = (8, 8, 4, 4)
  62. hidden_act: str = "gelu"
  63. hidden_dropout_prob: float | int = 0.0
  64. attention_probs_dropout_prob: float | int = 0.0
  65. initializer_range: float = 0.02
  66. drop_path_rate: float | int = 0.0
  67. layer_norm_eps: float = 1e-6
  68. qkv_bias: bool = True
  69. num_labels: int = 1000
  70. __all__ = ["PvtConfig"]