configuration_uvdoc.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  2. # This file was automatically generated from src/transformers/models/uvdoc/modular_uvdoc.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_uvdoc.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 collections.abc import Sequence
  21. from huggingface_hub.dataclasses import strict
  22. from ...backbone_utils import BackboneConfigMixin, consolidate_backbone_kwargs_to_config
  23. from ...configuration_utils import PreTrainedConfig
  24. from ...utils import auto_docstring
  25. from ..auto import AutoConfig
  26. @auto_docstring(checkpoint="PaddlePaddle/UVDoc_safetensors")
  27. @strict
  28. class UVDocBackboneConfig(BackboneConfigMixin, PreTrainedConfig):
  29. r"""
  30. resnet_head (`Sequence[list[int] | tuple[int, ...]]`, *optional*, defaults to `((3, 32), (32, 32))`):
  31. Configuration for the ResNet head layers in format [in_channels, out_channels].
  32. resnet_configs (`Sequence[Sequence[tuple[int, int, int, bool] | list[int | bool]]]`, *optional*, defaults to `(((32, 32, 1, False),
  33. (32, 32, 3, False), (32, 32, 3, False)), ((32, 64, 1, True), (64, 64, 3, False), (64, 64, 3, False), (64, 64, 3, False)), ((64, 128, 1, True),
  34. (128, 128, 3, False), (128, 128, 3, False), (128, 128, 3, False), (128, 128, 3, False), (128, 128, 3, False)))`):
  35. Configuration for the ResNet stages in format [in_channels, out_channels, dilation_value, downsample].
  36. stage_configs (Sequence[Sequence[tuple[int, ...] | list[int]]], *optional*, defaults to `(((128, 1),), ((128, 2),),
  37. ((128, 5),), ((128, 8),(128, 3),(128, 2),), ((128, 12), (128, 7), (128, 4),), ((128, 18), (128, 12), (128, 6),),)`):
  38. Configuration for the bridge module stages in format [in_channels, dilation_value].
  39. Each inner sequence corresponds to a single bridge block, and the outer sequence groups blocks by bridge stage.
  40. """
  41. model_type = "uvdoc_backbone"
  42. _out_features: list[str] | None = None
  43. _out_indices: list[int] | None = None
  44. resnet_head: Sequence[list[int] | tuple[int, ...]] = (
  45. (3, 32),
  46. (32, 32),
  47. )
  48. resnet_configs: Sequence[Sequence[tuple[int, int, int, bool] | list[int | bool]]] = (
  49. (
  50. (32, 32, 1, False),
  51. (32, 32, 3, False),
  52. (32, 32, 3, False),
  53. ),
  54. (
  55. (32, 64, 1, True),
  56. (64, 64, 3, False),
  57. (64, 64, 3, False),
  58. (64, 64, 3, False),
  59. ),
  60. (
  61. (64, 128, 1, True),
  62. (128, 128, 3, False),
  63. (128, 128, 3, False),
  64. (128, 128, 3, False),
  65. (128, 128, 3, False),
  66. (128, 128, 3, False),
  67. ),
  68. )
  69. stage_configs: Sequence[Sequence[tuple[int, ...] | list[int]]] = (
  70. ((128, 1),),
  71. ((128, 2),),
  72. ((128, 5),),
  73. (
  74. (128, 8),
  75. (128, 3),
  76. (128, 2),
  77. ),
  78. (
  79. (128, 12),
  80. (128, 7),
  81. (128, 4),
  82. ),
  83. (
  84. (128, 18),
  85. (128, 12),
  86. (128, 6),
  87. ),
  88. )
  89. kernel_size: int = 5
  90. def __post_init__(self, **kwargs):
  91. self.depths = [len(stages) for stages in self.stage_configs]
  92. self.stage_names = ["stem"] + [f"stage{idx}" for idx in range(1, len(self.stage_configs) + 1)]
  93. self.set_output_features_output_indices(
  94. out_indices=kwargs.pop("out_indices", None), out_features=kwargs.pop("out_features", None)
  95. )
  96. super().__post_init__(**kwargs)
  97. @auto_docstring(checkpoint="PaddlePaddle/UVDoc_safetensors")
  98. @strict
  99. class UVDocConfig(PreTrainedConfig):
  100. r"""
  101. padding_mode (`str`, *optional*, defaults to `"reflect"`):
  102. Padding mode for convolutional layers. Supported modes are `"reflect"`, `"constant"`, and `"replicate"`.
  103. kernel_size (`int`, *optional*, defaults to 5):
  104. Kernel size for convolutional layers in the backbone network.
  105. bridge_connector (`list[int] | tuple[int, ...]`, *optional*, defaults to `(128, 128)`):
  106. Configuration for the bridge connector in format [in_channels, out_channels].
  107. out_point_positions2D (`Sequence[list[int] | tuple[int, ...]]`, *optional*, defaults to `((128, 32), (32, 2))`):
  108. Configuration for the output point positions 2D layer in format [in_channels, out_channels].
  109. """
  110. model_type = "uvdoc"
  111. sub_configs = {"backbone_config": AutoConfig}
  112. backbone_config: dict | PreTrainedConfig | None = None
  113. hidden_act: str = "prelu"
  114. padding_mode: str = "reflect"
  115. kernel_size: int = 5
  116. bridge_connector: list[int] | tuple[int, ...] = (128, 128)
  117. out_point_positions2D: Sequence[list[int] | tuple[int, ...]] = ((128, 32), (32, 2))
  118. def __post_init__(self, **kwargs):
  119. self.backbone_config, kwargs = consolidate_backbone_kwargs_to_config(
  120. backbone_config=self.backbone_config,
  121. default_config_type="uvdoc_backbone",
  122. **kwargs,
  123. )
  124. super().__post_init__(**kwargs)
  125. __all__ = ["UVDocBackboneConfig", "UVDocConfig"]