chain_interdependence_layer
Bases: layer
A chain interdependence layer for capturing sequential dependencies in data.
This layer integrates multiple chain interdependence heads to model sequential interdependencies. It supports features such as multi-hop connections, inverse or exponential approximations, parameter reconciliation, and various output processing functions.
Attributes:
Name | Type | Description |
---|---|---|
m |
int
|
The input dimension of the layer. |
n |
int
|
The output dimension of the layer. |
chain_length |
int
|
The length of the chain for modeling interdependencies. |
channel_num |
int
|
The number of channels in each chain interdependence head. |
width |
int
|
The number of chain interdependence heads in the layer. |
name |
str
|
The name of the layer. |
bi_directional |
bool
|
Whether to include bi-directional dependencies in the chain. |
with_multihop |
bool
|
Whether to enable multi-hop dependencies. |
h |
int
|
The number of hops for multi-hop connections. |
accumulative |
bool
|
Whether to accumulate dependencies across hops. |
with_inverse_approx |
bool
|
Whether to use inverse approximation for interdependence. |
with_exponential_approx |
bool
|
Whether to use exponential approximation for interdependence. |
self_dependence |
bool
|
Whether to include self-dependencies in the chain. |
self_scaling |
float
|
The scaling factor for self-dependencies. |
with_dual_lphm |
bool
|
Whether to use dual LPHM reconciliation for parameters. |
with_lorr |
bool
|
Whether to use LORR reconciliation for parameters. |
r |
int
|
The rank for parameter reconciliation. |
enable_bias |
bool
|
Whether to enable bias in parameter reconciliation. |
with_residual |
bool
|
Whether to include a residual connection in the layer. |
with_batch_norm |
bool
|
Whether to apply batch normalization to the output. |
with_relu |
bool
|
Whether to apply ReLU activation to the output. |
with_dropout |
bool
|
Whether to apply dropout to the output. |
p |
float
|
Dropout probability. |
with_softmax |
bool
|
Whether to apply softmax activation to the output. |
parameters_init_method |
str
|
The initialization method for parameters. |
device |
str
|
The device to run the layer on ('cpu' or 'cuda'). |
Methods:
Name | Description |
---|---|
__init__ |
Initializes the chain interdependence layer with specified parameters. |
forward |
Performs a forward pass through the layer. |
Source code in tinybig/layer/chain_based_layers.py
23 24 25 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 |
|
__init__(m, n, chain_length, channel_num=1, width=1, name='chain_interdependence_layer', bi_directional=False, with_multihop=False, h=1, accumulative=False, with_inverse_approx=False, with_exponential_approx=False, self_dependence=True, self_scaling=1.0, with_dual_lphm=False, with_lorr=False, r=3, enable_bias=False, with_residual=False, with_batch_norm=False, with_relu=True, with_dropout=False, p=0.25, with_softmax=True, parameters_init_method='xavier_normal', device='cpu', *args, **kwargs)
Initializes the chain interdependence layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
int
|
The input dimension of the layer. |
required |
n
|
int
|
The output dimension of the layer. |
required |
chain_length
|
int
|
The length of the chain for modeling interdependencies. |
required |
channel_num
|
int
|
The number of channels in each chain interdependence head. |
1
|
width
|
int
|
The number of chain interdependence heads in the layer. |
1
|
name
|
str
|
The name of the layer. |
'chain_interdependence_layer'
|
bi_directional
|
bool
|
Whether to include bi-directional dependencies in the chain. |
False
|
with_multihop
|
bool
|
Whether to enable multi-hop dependencies. |
False
|
h
|
int
|
The number of hops for multi-hop connections. |
1
|
accumulative
|
bool
|
Whether to accumulate dependencies across hops. |
False
|
with_inverse_approx
|
bool
|
Whether to use inverse approximation for interdependence. |
False
|
with_exponential_approx
|
bool
|
Whether to use exponential approximation for interdependence. |
False
|
self_dependence
|
bool
|
Whether to include self-dependencies in the chain. |
True
|
self_scaling
|
float
|
The scaling factor for self-dependencies. |
1.0
|
with_dual_lphm
|
bool
|
Whether to use dual LPHM reconciliation for parameters. |
False
|
with_lorr
|
bool
|
Whether to use LORR reconciliation for parameters. |
False
|
r
|
int
|
The rank for parameter reconciliation. |
3
|
enable_bias
|
bool
|
Whether to enable bias in parameter reconciliation. |
False
|
with_residual
|
bool
|
Whether to include a residual connection in the layer. |
False
|
with_batch_norm
|
bool
|
Whether to apply batch normalization to the output. |
False
|
with_relu
|
bool
|
Whether to apply ReLU activation to the output. |
True
|
with_dropout
|
bool
|
Whether to apply dropout to the output. |
False
|
p
|
float
|
Dropout probability. |
0.25
|
with_softmax
|
bool
|
Whether to apply softmax activation to the output. |
True
|
parameters_init_method
|
str
|
The initialization method for parameters. |
'xavier_normal'
|
device
|
str
|
The device to run the layer on ('cpu' or 'cuda'). |
'cpu'
|
Returns:
Type | Description |
---|---|
None
|
|
Source code in tinybig/layer/chain_based_layers.py
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 |
|
forward(x, fusion_strategy='average', device='cpu', *args, **kwargs)
Performs a forward pass through the chain interdependence layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input tensor with shape |
required |
fusion_strategy
|
str
|
The strategy for fusing outputs from multiple heads. |
'average'
|
device
|
str
|
The device to run the computation on ('cpu' or 'cuda'). |
'cpu'
|
Returns:
Type | Description |
---|---|
Tensor
|
The output tensor with shape |