Prompt48 commited on
Commit
cc10368
·
verified ·
1 Parent(s): a722b59

Upload edit\Qwen3-TTS-test\.venv\Lib\site-packages\transformers\models\hiera\configuration_hiera.py with huggingface_hub

Browse files
edit//Qwen3-TTS-test//.venv//Lib//site-packages//transformers//models//hiera//configuration_hiera.py ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2024 The HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Hiera model configuration"""
16
+
17
+ from ...configuration_utils import PretrainedConfig
18
+ from ...utils import logging
19
+ from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices
20
+
21
+
22
+ logger = logging.get_logger(__name__)
23
+
24
+
25
+ class HieraConfig(BackboneConfigMixin, PretrainedConfig):
26
+ r"""
27
+ This is the configuration class to store the configuration of a [`HieraModel`]. It is used to instantiate a Hiera
28
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
29
+ defaults will yield a similar configuration to that of the Hiera
30
+ [facebook/hiera-base-224](https://huggingface.co/facebook/hiera-base-224) architecture.
31
+
32
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
33
+ documentation from [`PretrainedConfig`] for more information.
34
+
35
+ Args:
36
+ embed_dim (`int`, *optional*, defaults to 96):
37
+ Dimensionality of patch embedding.
38
+ image_size (`list(int)`, *optional*, defaults to `[224, 224]`):
39
+ The size (resolution) of input in the format (height, width) for images
40
+ and (frames, height, width) for videos.
41
+ patch_size (`list(int)`, *optional*, defaults to `[7, 7]`):
42
+ The size (resolution) of each patch.
43
+ patch_stride (`list(int)`, *optional*, defaults to `[4, 4]`):
44
+ The stride of the patch.
45
+ patch_padding (`list(int)`, *optional*, defaults to `[3, 3]`):
46
+ The padding of the patch.
47
+ mlp_ratio (`float`, *optional*, defaults to 4.0):
48
+ The ratio of mlp hidden dim to embedding dim.
49
+ depths (`list(int)`, *optional*, defaults to `[2, 3, 16, 3]`):
50
+ Depth of each layer in the Transformer encoder.
51
+ num_heads (`list(int)`, *optional*, defaults to `[1, 2, 4, 8]`):
52
+ Number of attention heads in each layer of the Transformer encoder.
53
+ embed_dim_multiplier (`float`, *optional*, defaults to 2.0):
54
+ The multiplier to the dimensionality of patch embedding in each layer of the Transformer encoder.
55
+ num_query_pool (`int`, *optional*, defaults to 3):
56
+ The number of query pool stages.
57
+ query_stride (`list(int)`, *optional*, defaults to `[2, 2]`):
58
+ The stride of the query pool.
59
+ masked_unit_size (`list(int)`, *optional*, defaults to `[8, 8]`):
60
+ The size of the masked unit.
61
+ masked_unit_attention (`list(bool)`, *optional*, defaults to `[True, True, False, False]`):
62
+ Whether to use masked unit attention in each layer of the Transformer encoder.
63
+ drop_path_rate (`float`, *optional*, defaults to 0.0):
64
+ The drop path rate.
65
+ num_channels (`int`, *optional*, defaults to 3):
66
+ The number of input channels.
67
+ hidden_act (`str`, *optional*, defaults to `"gelu"`):
68
+ The non-linear activation function (function or string) in the encoder. If string, `"gelu"`, `"relu"`,
69
+ `"selu"` and `"gelu_new"` are supported.
70
+ initializer_range (`float`, *optional*, defaults to 0.02):
71
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices and
72
+ the zero_initializer for initializing all bias vectors.
73
+ layer_norm_init (`float`, *optional*, defaults to 1.0):
74
+ The initial weight value for layer normalization layers.
75
+ layer_norm_eps (`float`, *optional*, defaults to 1e-06):
76
+ The epsilon used by the layer normalization layers.
77
+ decoder_hidden_size (`int`, *optional*):
78
+ Dimensionality of decoder embeddings for MAE pretraining.
79
+ decoder_depth (`int`, *optional*):
80
+ Depth of the decoder for MAE pretraining.
81
+ decoder_num_heads (`int`, *optional*):
82
+ Number of attention heads in each layer of the decoder for MAE pretraining.
83
+ normalize_pixel_loss (`bool`, *optional*, defaults to `True`):
84
+ Whether to normalize the pixel loss by the number of pixels.
85
+ mask_ratio (`float`, *optional*, defaults to 0.6):
86
+ The ratio of masked tokens in the input.
87
+ out_features (`list[str]`, *optional*):
88
+ If used as backbone, list of features to output. Can be any of `"stem"`, `"stage1"`, `"stage2"`, etc.
89
+ (depending on how many stages the model has). If unset and `out_indices` is set, will default to the
90
+ corresponding stages. If unset and `out_indices` is unset, will default to the last stage. Must be in the
91
+ same order as defined in the `stage_names` attribute.
92
+ out_indices (`list[int]`, *optional*):
93
+ If used as backbone, list of indices of features to output. Can be any of 0, 1, 2, etc. (depending on how
94
+ many stages the model has). If unset and `out_features` is set, will default to the corresponding stages.
95
+ If unset and `out_features` is unset, will default to the last stage. Must be in the
96
+ same order as defined in the `stage_names` attribute.
97
+
98
+
99
+ Example:
100
+
101
+ ```python
102
+ >>> from transformers import HieraConfig, HieraModel
103
+
104
+ >>> # Initializing a Hiera hiera-base-patch16-224 style configuration
105
+ >>> configuration = HieraConfig()
106
+
107
+ >>> # Initializing a model (with random weights) from the hiera-base-patch16-224 style configuration
108
+ >>> model = HieraModel(configuration)
109
+
110
+ >>> # Accessing the model configuration
111
+ >>> configuration = model.config
112
+ ```"""
113
+
114
+ model_type = "hiera"
115
+
116
+ attribute_map = {"num_hidden_layers": "num_layers"}
117
+
118
+ def __init__(
119
+ self,
120
+ embed_dim=96,
121
+ image_size=[224, 224],
122
+ patch_size=[7, 7],
123
+ patch_stride=[4, 4],
124
+ patch_padding=[3, 3],
125
+ mlp_ratio=4.0,
126
+ depths=[2, 3, 16, 3],
127
+ num_heads=[1, 2, 4, 8],
128
+ embed_dim_multiplier=2.0,
129
+ num_query_pool=3,
130
+ query_stride=[2, 2],
131
+ masked_unit_size=[8, 8],
132
+ masked_unit_attention=[True, True, False, False],
133
+ drop_path_rate=0.0,
134
+ num_channels=3,
135
+ hidden_act="gelu",
136
+ initializer_range=0.02,
137
+ layer_norm_init=1.0,
138
+ layer_norm_eps=1e-6,
139
+ decoder_hidden_size=None,
140
+ decoder_depth=None,
141
+ decoder_num_heads=None,
142
+ normalize_pixel_loss=True,
143
+ mask_ratio=0.6,
144
+ out_features=None,
145
+ out_indices=None,
146
+ **kwargs,
147
+ ):
148
+ super().__init__(**kwargs)
149
+ if masked_unit_size[0] % query_stride[0] ** (len(depths) - 1) != 0:
150
+ raise ValueError(
151
+ f"masked_unit_size[0] ({masked_unit_size[0]}) must be divisible by query_stride[0] ({query_stride[0]}) "
152
+ f"raised to the power of the number of layers ({len(depths) - 1})"
153
+ )
154
+
155
+ if num_query_pool >= len(depths):
156
+ raise ValueError(
157
+ f"num_query_pool ({num_query_pool}) must be less than the number of layers ({len(depths)})"
158
+ )
159
+
160
+ self.embed_dim = embed_dim
161
+ self.image_size = image_size
162
+ self.patch_size = patch_size
163
+ self.patch_stride = patch_stride
164
+ self.patch_padding = patch_padding
165
+ self.mlp_ratio = mlp_ratio
166
+ self.depths = depths
167
+ self.num_heads = num_heads
168
+ self.num_layers = len(depths)
169
+ self.embed_dim_multiplier = embed_dim_multiplier
170
+ self.num_query_pool = num_query_pool
171
+ self.query_stride = query_stride
172
+ self.masked_unit_size = masked_unit_size
173
+ self.masked_unit_attention = masked_unit_attention
174
+ self.drop_path_rate = drop_path_rate
175
+ self.num_channels = num_channels
176
+ self.hidden_act = hidden_act
177
+ self.initializer_range = initializer_range
178
+ self.layer_norm_init = layer_norm_init
179
+ self.layer_norm_eps = layer_norm_eps
180
+ self.decoder_hidden_size = decoder_hidden_size
181
+ self.decoder_depth = decoder_depth
182
+ self.decoder_num_heads = decoder_num_heads
183
+ self.normalize_pixel_loss = normalize_pixel_loss
184
+ self.mask_ratio = mask_ratio
185
+ # we set the hidden_size attribute in order to make Hiera work with VisionEncoderDecoderModel
186
+ # this indicates the channel dimension after the last stage of the model
187
+ self.hidden_size = int(embed_dim * embed_dim_multiplier ** (len(depths) - 1))
188
+ self.stage_names = ["stem"] + [f"stage{idx}" for idx in range(1, len(depths) + 1)]
189
+ self._out_features, self._out_indices = get_aligned_output_features_output_indices(
190
+ out_features=out_features, out_indices=out_indices, stage_names=self.stage_names
191
+ )
192
+
193
+
194
+ __all__ = ["HieraConfig"]