rpn_layer
Bases: Module
, function
The RPN layer class for implementing the multi-head module.
It will be used to compose the RPN model with deep architectures.
...
Notes
Similar to the Transformers, for each layer of RPN model, it allows a multi-head architecture, where each head will disentangle the input data and model parameters using different expansion, reconciliation and remainder functions shown as follows: $$ \begin{equation} g(\mathbf{x} | \mathbf{w}, H) = \sum_{h=0}^{H-1} \left\langle \kappa^{(h)}(\mathbf{x}), \psi^{(h)}(\mathbf{w}^{(h)}) \right\rangle + \pi^{(h)}(\mathbf{x}), \end{equation} $$ where the superscript "\(h\)" indicates the head index and \(H\) denotes the total head number. By default, summation is used to combine the results from all these heads.
Attributes:
Name | Type | Description |
---|---|---|
m |
int
|
The input dimension of the layer. |
n |
int
|
The output dimension of the layer. |
heads |
torch.nn.ModuleList, default = torch.nn.ModuleList()
|
The list of RPN heads involved in the layer. |
head_fusion |
fusion, default = None
|
The fusion function of the outputs learned by multi-heads. |
device |
str, default = 'cpu'
|
The device for hosting the RPN layer. |
Methods:
Name | Description |
---|---|
__init__ |
The initialization method of the RPN-layer module with multiple RPN heads. |
get_widthber |
The head number retrieval method. |
initialize_parameters |
Head parameter initialization method. |
initialize_fusion_parameters |
Fusion component parameter initialization method. |
multi_head_fusion |
The multi-head outputs fusion method. |
forward |
The forward method of this multi-head PRN layer module. |
__call__ |
The re-implementatino of the callable method of this RPN layer module. |
Source code in tinybig/module/base_layer.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
|
__init__(m, n, name='rpn_layer', heads=None, head_configs=None, width=None, width_alloc=None, head_fusion=None, head_fusion_configs=None, parameters_init_method='xavier_uniform', device='cpu', *args, **kwargs)
The initialization method of the RPN-layer module with multiple RPN heads.
It initializes the RPN layer module composed with multiple RPN heads. Specifically, this method initializes the dimension configurations of the layer, the component heads, and defines the device to host the head.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
int
|
The input dimension of the layer. |
required |
n
|
int
|
The output dimension of the layer. |
required |
heads
|
list
|
The list of RPN heads involved in the layer. The heads involved in the layer can be initialized either directly with the heads parameter or via the head_configs parameter. |
None
|
head_configs
|
dict | list
|
The list of RPN head configurations in the layer. |
None
|
width
|
int
|
The total head number of the layer. It is optional, if the "heads" or the "head_configs" can provide sufficient information for the head initialization, this widthber parameter can be set as None. |
None
|
width_alloc
|
int | list
|
RPN allows the heads with different configurations, instead of listing such configurations one by one, it also allows the listing of each configuration types together with the repeating numbers for each of them, which are specified by this optional head number allocation parameter. |
None
|
head_fusion
|
The fusion function of the outputs learned by multi-heads. |
None
|
|
head_fusion_configs
|
The fusion function configurations of the outputs learned by multi-heads. |
None
|
|
device
|
The device for hosting the RPN layer. |
'cpu'
|
Returns:
Type | Description |
---|---|
object
|
This method will return the initialized RPN-layer object. |
Source code in tinybig/module/base_layer.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
forward(x, fusion_strategy='average', device='cpu', *args, **kwargs)
The forward method of this multi-head PRN layer module.
It calculates the outputs with the multi-head RPN layer based on the inputs subject to certain fusion strategy. For each layer of RPN model, RPN allows a multi-head architecture, where each head will disentangle the input data and model parameters using different expansion, reconciliation and remainder functions shown as follows: $$ \begin{equation} g(\mathbf{x} | \mathbf{w}, H) = \sum_{h=0}^{H-1} \left\langle \kappa^{(h)}(\mathbf{x}), \psi^{(h)}(\mathbf{w}^{(h)}) \right\rangle + \pi^{(h)}(\mathbf{x}), \end{equation} $$ where the superscript "\(h\)" indicates the head index and \(H\) denotes the total head number. By default, summation is used to combine the results from all these heads.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input data to the layer. |
required |
fusion_strategy
|
str
|
The optional fusion_strategy of the forward method. If it is set as None, this layer will use the default fusion_strategy at initialization of this layer. |
'average'
|
device
|
str
|
Device used to host this layer for calculation. |
'cpu'
|
Returns:
Type | Description |
---|---|
Tensor
|
It will return the learning results of this RPN layer. |
Source code in tinybig/module/base_layer.py
get_width()
The head number retrieval method.
It returns the head number of the layer.
Returns:
Type | Description |
---|---|
int
|
The number of heads in the layer. |
initialize_fusion_parameters()
Fusion component parameter initialization method.
It initializes the learnable parameters for the fusion component. The RPN head also allows the linear fusion component to combine the outputs of multi-head with learnable parameters.
Returns:
Type | Description |
---|---|
None
|
The initialization method doesn't have any return values. |
Source code in tinybig/module/base_layer.py
initialize_parameters(init_type='xavier_uniform', init_bias=True)
Head parameter initialization method.
It initializes the learnable parameters in each head involved in the layer, which will call the parameter initialization method in each of the heads.
Returns:
Type | Description |
---|---|
None
|
The initialization method doesn't have any return values. |