grid_interdependence_head
Bases: head
A head for handling grid-based interdependence mechanisms.
This class supports different patch structures (cuboid, cylinder, sphere) and geometric interdependence. It includes parameter reconciliation, data transformation, and output processing.
Attributes:
Name | Type | Description |
---|---|---|
h |
int
|
Height of the grid. |
w |
int
|
Width of the grid. |
in_channel |
int
|
Number of input channels. |
out_channel |
int
|
Number of output channels. |
d |
int, default=1
|
Depth of the grid. |
name |
str
|
Name of the head. |
patch_shape |
str, default='cuboid'
|
Shape of the patch. Options: 'cuboid', 'cylinder', 'sphere'. |
cd_h, cd_w, cd_d |
(int, optional)
|
Parameters for packing and compression. |
packing_strategy |
str, default='densest_packing'
|
Strategy for packing grid patches. |
with_batch_norm |
bool, default=True
|
Whether to apply batch normalization. |
with_relu |
bool, default=True
|
Whether to apply ReLU activation. |
with_residual |
bool, default=False
|
Whether to include a residual connection. |
with_dual_lphm |
bool, default=False
|
Whether to use dual low-rank parameterized hyper-matrix (LPHM) for parameter reconciliation. |
with_lorr |
bool, default=False
|
Whether to use LORR (Low-rank Orthogonal Reconciliation). |
r |
int, default=3
|
Rank for parameter reconciliation. |
enable_bias |
bool, default=False
|
Whether to enable bias. |
parameters_init_method |
str, default='xavier_normal'
|
Initialization method for parameters. |
device |
str, default='cpu'
|
Device to run the computations ('cpu' or 'cuda'). |
Methods:
Name | Description |
---|---|
get_patch_size |
Returns the size of the patch. |
get_input_grid_shape |
Returns the shape of the input grid. |
get_output_grid_shape |
Returns the shape of the output grid after packing. |
calculate_phi_w |
Computes the phi_w parameter using parameter fabrication. |
calculate_inner_product |
Calculates the inner product of the given tensors. |
Source code in tinybig/head/grid_based_heads.py
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 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
|
__init__(h, w, in_channel, out_channel, d=1, name='grid_interdependence_head', patch_shape='cuboid', p_h=None, p_h_prime=None, p_w=None, p_w_prime=None, p_d=0, p_d_prime=None, p_r=None, cd_h=None, cd_w=None, cd_d=1, packing_strategy='densest_packing', with_batch_norm=True, with_relu=True, with_residual=False, with_dual_lphm=False, with_lorr=False, r=3, enable_bias=False, parameters_init_method='xavier_normal', device='cpu', *args, **kwargs)
Initializes the grid_interdependence_head
class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
h
|
int
|
Height of the grid. |
required |
w
|
int
|
Width of the grid. |
required |
in_channel
|
int
|
Number of input channels. |
required |
out_channel
|
int
|
Number of output channels. |
required |
d
|
int
|
Depth of the grid. |
1
|
name
|
str
|
Name of the head. |
'grid_interdependence_head'
|
patch_shape
|
str
|
Shape of the patch. Options: 'cuboid', 'cylinder', 'sphere'. |
'cuboid'
|
p_h
|
int
|
Patch height. |
None
|
p_h_prime
|
int
|
Adjusted patch height for the cuboid. |
None
|
p_w
|
int
|
Patch width. Defaults to |
None
|
p_w_prime
|
int
|
Adjusted patch width for the cuboid. |
None
|
p_d
|
int
|
Patch depth. |
0
|
p_d_prime
|
int
|
Adjusted patch depth for the cuboid. |
None
|
p_r
|
int
|
Patch radius (for spherical or cylindrical patches). |
None
|
cd_h
|
int
|
Compression depth in the height dimension. |
None
|
cd_w
|
int
|
Compression depth in the width dimension. |
None
|
cd_d
|
int
|
Compression depth in the depth dimension. |
1
|
packing_strategy
|
str
|
Strategy for packing patches into the grid. |
'densest_packing'
|
with_batch_norm
|
bool
|
Whether to apply batch normalization to the output. |
True
|
with_relu
|
bool
|
Whether to apply ReLU activation to the output. |
True
|
with_residual
|
bool
|
Whether to include a residual connection. |
False
|
with_dual_lphm
|
bool
|
Whether to use dual low-rank parameterized hyper-matrix (LPHM) reconciliation. |
False
|
with_lorr
|
bool
|
Whether to use low-rank orthogonal reconciliation (LORR). |
False
|
r
|
int
|
Rank used for parameter reconciliation. |
3
|
enable_bias
|
bool
|
Whether to enable bias in the linear transformations. |
False
|
parameters_init_method
|
str
|
Initialization method for model parameters. |
'xavier_normal'
|
device
|
str
|
Device to run the computations ('cpu' or 'cuda'). |
'cpu'
|
Source code in tinybig/head/grid_based_heads.py
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 |
|
calculate_inner_product(kappa_xi_x, phi_w, device='cpu', *args, **kwargs)
Calculates the inner product of the given tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kappa_xi_x
|
Tensor
|
Input tensor for inner product calculation. |
required |
phi_w
|
Tensor
|
Weight tensor for inner product calculation. |
required |
device
|
str
|
Device to perform the computation. |
'cpu'
|
Returns:
Type | Description |
---|---|
Tensor
|
The computed inner product. |
Source code in tinybig/head/grid_based_heads.py
calculate_phi_w(channel_index=0, device='cpu', *args, **kwargs)
Computes the phi_w parameter using parameter fabrication.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
channel_index
|
int
|
Index of the channel. |
0
|
device
|
str
|
Device to perform the computation. |
'cpu'
|
Returns:
Type | Description |
---|---|
Tensor
|
The phi_w tensor after parameter fabrication. |
Source code in tinybig/head/grid_based_heads.py
get_input_grid_shape()
Returns the shape of the input grid.
Returns:
Type | Description |
---|---|
tuple
|
A tuple representing (height, width, depth) of the input grid. |
Source code in tinybig/head/grid_based_heads.py
get_output_grid_shape()
Returns the shape of the output grid after packing.
Returns:
Type | Description |
---|---|
tuple
|
A tuple representing (height, width, depth) of the packed grid. |
Source code in tinybig/head/grid_based_heads.py
get_patch_size()
Returns the size of the patch in the grid.
Returns:
Type | Description |
---|---|
int
|
Patch size. |