configuration_slanext.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  2. # This file was automatically generated from src/transformers/models/slanext/modular_slanext.py.
  3. # Do NOT edit this file manually as any edits will be overwritten by the generation of
  4. # the file from the modular. If any change should be done, please apply the change to the
  5. # modular_slanext.py file directly. One of our CI enforces this.
  6. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  7. # Copyright 2026 The PaddlePaddle Team and The HuggingFace Inc. team. All rights reserved.
  8. #
  9. # Licensed under the Apache License, Version 2.0 (the "License");
  10. # you may not use this file except in compliance with the License.
  11. # You may obtain a copy of the License at
  12. #
  13. # http://www.apache.org/licenses/LICENSE-2.0
  14. #
  15. # Unless required by applicable law or agreed to in writing, software
  16. # distributed under the License is distributed on an "AS IS" BASIS,
  17. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. # See the License for the specific language governing permissions and
  19. # limitations under the License.
  20. from huggingface_hub.dataclasses import strict
  21. from ...configuration_utils import PreTrainedConfig
  22. from ...utils import auto_docstring
  23. @auto_docstring(checkpoint="PaddlePaddle/SLANeXt_wired_safetensors")
  24. @strict
  25. class SLANeXtVisionConfig(PreTrainedConfig):
  26. r"""
  27. output_channels (`int`, *optional*, defaults to 256):
  28. Dimensionality of the output channels in the Patch Encoder.
  29. use_abs_pos (`bool`, *optional*, defaults to `True`):
  30. Whether to use absolute position embedding.
  31. use_rel_pos (`bool`, *optional*, defaults to `True`):
  32. Whether to use relative position embedding.
  33. window_size (`int`, *optional*, defaults to 14):
  34. Window size for relative position.
  35. global_attn_indexes (`list[int]`, *optional*, defaults to `[2, 5, 8, 11]`):
  36. The indexes of the global attention layers.
  37. mlp_dim (`int`, *optional*, defaults to 3072):
  38. The dimensionality of the MLP layer in the Transformer encoder.
  39. """
  40. base_config_key = "vision_config"
  41. hidden_size: int = 768
  42. output_channels: int = 256
  43. num_hidden_layers: int = 12
  44. num_attention_heads: int = 12
  45. num_channels: int = 3
  46. image_size: int = 512
  47. patch_size: int | list[int] | tuple[int, int] = 16
  48. hidden_act: str = "gelu"
  49. layer_norm_eps: float = 1e-06
  50. attention_dropout: float | int = 0.0
  51. initializer_range: float = 1e-10
  52. qkv_bias: bool = True
  53. use_abs_pos: bool = True
  54. use_rel_pos: bool = True
  55. window_size: int = 14
  56. global_attn_indexes: list[int] | tuple[int, ...] = (2, 5, 8, 11)
  57. mlp_dim: int = 3072
  58. @auto_docstring(checkpoint="PaddlePaddle/SLANeXt_wired_safetensors")
  59. @strict
  60. class SLANeXtConfig(PreTrainedConfig):
  61. r"""
  62. vision_config (`dict` or [`SLANeXtVisionConfig`], *optional*):
  63. Configuration for the vision encoder. If `None`, a default [`SLANeXtVisionConfig`] is used.
  64. post_conv_in_channels (`int`, *optional*, defaults to 256):
  65. Number of input channels for the post-encoder convolution layer.
  66. post_conv_out_channels (`int`, *optional*, defaults to 512):
  67. Number of output channels for the post-encoder convolution layer.
  68. out_channels (`int`, *optional*, defaults to 50):
  69. Vocabulary size for the table structure token prediction head, i.e., the number of distinct structure
  70. tokens the model can predict.
  71. hidden_size (`int`, *optional*, defaults to 512):
  72. Dimensionality of the hidden states in the attention GRU cell and the structure/location prediction heads.
  73. max_text_length (`int`, *optional*, defaults to 500):
  74. Maximum number of autoregressive decoding steps (tokens) for the structure and location decoder.
  75. """
  76. model_type = "slanext"
  77. sub_configs = {"vision_config": SLANeXtVisionConfig}
  78. vision_config: dict | SLANeXtVisionConfig | None = None
  79. post_conv_in_channels: int = 256
  80. post_conv_out_channels: int = 512
  81. out_channels: int = 50
  82. hidden_size: int = 512
  83. max_text_length: int = 500
  84. def __post_init__(self, **kwargs):
  85. if self.vision_config is None:
  86. self.vision_config = SLANeXtVisionConfig()
  87. elif isinstance(self.vision_config, dict):
  88. self.vision_config = SLANeXtVisionConfig(**self.vision_config)
  89. super().__post_init__(**kwargs)
  90. __all__ = ["SLANeXtConfig"]