random_matrix_hypernet_reconciliation
Bases: fabrication
A reconciliation mechanism using a hypernetwork approach with random matrices.
This class computes a reconciliation matrix W
using a series of random matrices and a hypernetwork-like architecture.
Notes
Formally, based on the parameter vector \(\mathbf{w} \in R^l\), the random_matrix_hypernet_reconciliation function will fabricate it into a parameter matrix \(\mathbf{W} \in R^{n \times D}\) as follow:
\[ \begin{equation} \begin{aligned} \text{Hypernet}(\mathbf{w}) &= \sigma(\mathbf{w} \mathbf{H}_1) \mathbf{H}_2 \\ &= \sigma \left( \mathbf{w} (\mathbf{P} \mathbf{Q}^\top) \right) \left( \mathbf{S} \mathbf{T}^\top \right)\\ &= \left( \sigma \left( (\mathbf{w} \mathbf{P}) \mathbf{Q}^\top \right) \mathbf{S} \right) \mathbf{T}^\top \in R^{n \times D}, \end{aligned} \end{equation} \]
where \(\mathbf{P} \in R^{l \times r}\), \(\mathbf{Q} \in R^{d \times r}\), \(\mathbf{S} \in R^{d \times r}\) and \(\mathbf{T} \in R^{(n \times D) \times r}\) are the low-rank random and frozen sub-matrices that can compose the matrices \(\mathbf{H}_1 \in R^{l \times d}\) and \(\mathbf{H}_2 \in R^{d \times (n \times D)}\) of the hypernet. Moreover, by leveraging the associative law of matrix multiplication, we can avoid explicitly calculating and storing \(\mathbf{H}_1\) and \(\mathbf{H}_2\) as indicated by the above equation. These low-rank random matrix representations reduce the space consumption of this function to \(\mathcal{O}\left(r \cdot (l + 2d + n \cdot D)\right)\).
Attributes:
Name | Type | Description |
---|---|---|
r |
int
|
Rank of the random matrices. |
l |
int
|
Dimension of the hypernetwork input. |
hidden_dim |
int
|
Hidden dimension of the hypernetwork. |
P |
Tensor
|
Random matrix of shape |
Q |
Tensor
|
Random matrix of shape |
S |
Tensor
|
Random matrix of shape |
T |
Tensor
|
Random matrix of shape |
Methods:
Name | Description |
---|---|
calculate_l |
Computes the number of parameters required for the hypernetwork. |
forward |
Computes the reconciliation matrix using the hypernetwork approach. |
Source code in tinybig/reconciliation/random_matrix_reconciliation.py
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 |
|
__init__(name='random_matrix_hypernet_reconciliation', r=2, l=64, hidden_dim=128, *args, **kwargs)
Initializes the random matrix hypernetwork reconciliation mechanism.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the reconciliation instance. Defaults to 'random_matrix_hypernet_reconciliation'. |
'random_matrix_hypernet_reconciliation'
|
r
|
int
|
Rank of the random matrices. Defaults to 2. |
2
|
l
|
int
|
Dimension of the hypernetwork input. Defaults to 64. |
64
|
hidden_dim
|
int
|
Hidden dimension of the hypernetwork. Defaults to 128. |
128
|
*args
|
tuple
|
Additional positional arguments for the parent class. |
()
|
**kwargs
|
dict
|
Additional keyword arguments for the parent class. |
{}
|
Source code in tinybig/reconciliation/random_matrix_reconciliation.py
calculate_l(n=None, D=None)
Computes the number of parameters required for the hypernetwork.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
int
|
Number of rows in the reconciliation matrix (unused here). Defaults to None. |
None
|
D
|
int
|
Number of columns in the reconciliation matrix (unused here). Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
int
|
Total number of parameters required, equal to |
Source code in tinybig/reconciliation/random_matrix_reconciliation.py
forward(n, D, w, device='cpu', *args, **kwargs)
Computes the reconciliation matrix using the hypernetwork approach.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
int
|
Number of rows in the reconciliation matrix. |
required |
D
|
int
|
Number of columns in the reconciliation matrix. |
required |
w
|
Parameter
|
Parameter tensor of shape |
required |
device
|
str
|
Device for computation ('cpu', 'cuda', etc.). Defaults to 'cpu'. |
'cpu'
|
*args
|
tuple
|
Additional positional arguments. |
()
|
**kwargs
|
dict
|
Additional keyword arguments. |
{}
|
Returns:
Type | Description |
---|---|
Tensor
|
Reconciliation matrix of shape |
Raises:
Type | Description |
---|---|
AssertionError
|
If the dimensions of |