hm_reconciliation
Bases: fabrication
The hypercomplex multiplication based parameter reconciliation function.
It performs the hypercomplex multiplication based parameter reconciliation, and returns the reconciled parameter matrix of shape (n, D). This class inherits from the reconciliation class (i.e., the fabrication class in the module directory).
...
Notes
Formally, given the parameter vector \(\mathbf{w}\) of length \(l\) through partitioning and subsequent reshaping, we can create two parameter sub-matrices \(\mathbf{A} \in R^{p \times q}\) and \(\mathbf{B} \in R^{s \times t}\). The hypercomplex multiplication-based reconciliation computes the Kronecker product of these two parameter matrices to define the reconcilied parameter matrix of shape (n, D) as follows: $$ \begin{equation} \psi(\mathbf{w}) = \mathbf{A} \otimes \mathbf{B} \in {R}^{n \times D}, \end{equation} $$ where the parameter dimension parameters should meeting the constraints that \(l = pq + st\) and \(n = ps\) and \(D = qt\).
In implementation, to reduce the number of hyper-parameters and accommodate the parameter dimensions, we can maintain the size of matrix \(\mathbf{A}\) as fixed by two hyper-parameters \(p\) and \(q\), i.e., \(\mathbf{A} \in {R}^{p \times q}\). Subsequently, the desired size of matrix \(\mathbf{B}\) can be directly calculated as \(s \times t\), where \(s =\frac{n}{p}\) and \(t = \frac{D}{q}\). The hyper-parameters \(p\) and \(q\) need to be divisors of \(n\) and \(D\), respectively. Since both \(\mathbf{A}\) and \(\mathbf{B}\) originate from \(\mathbf{w}\), the desired parameter length defining \(\mathbf{w}\) can be obtained as $$ \begin{equation} l = p \times q + \frac{n}{p} \times \frac{D}{q}. \end{equation} $$
Attributes:
Name | Type | Description |
---|---|---|
name |
str, default = 'hypercomplex_multiplication_reconciliation'
|
Name of the hypercomplex multiplication based parameter reconciliation function |
p |
int, default = 2
|
Parameter sub-matrix row dimension. |
q |
int, default = None
|
Parameter sub-matrix column dimension. If q is not provided with initial values, it will be assigned with value p by default. |
Methods:
Name | Description |
---|---|
__init__ |
It initializes the hypercomplex multiplication based parameter reconciliation function. |
calculate_l |
It calculates the length of required parameters for the reconciliation function. |
forward |
It implements the abstract forward method declared in the base reconciliation class. |
Source code in tinybig/reconciliation/lowrank_reconciliation.py
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 |
|
__init__(name='hypercomplex_multiplication_reconciliation', p=None, q=None, *args, **kwargs)
The initialization method of the hypercomplex multiplication based parameter reconciliation function.
It initializes a hypercomplex multiplication based parameter reconciliation function object. This method will also call the initialization method of the base class as well.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
Name of the hypercomplex multiplication based parameter reconciliation function |
'hypercomplex_multiplication_reconciliation'
|
|
p
|
int
|
Parameter sub-matrix row dimension. |
None
|
q
|
int
|
Parameter sub-matrix column dimension. If q is not provided with initial values, it will be assigned with value p by default. |
None
|
Returns:
Type | Description |
---|---|
fabrication
|
The hypercomplex multiplication based parameter reconciliation function object. |
Source code in tinybig/reconciliation/lowrank_reconciliation.py
calculate_l(n, D)
The required parameter number calculation method.
It calculates the number of required learnable parameters, i.e., \(l\), of the parameter reconciliation function based on the intermediate and output space dimensions, \(n\) and \(D\), and the parameters \(p\) and \(q\), which can be represented as follows: $$ \begin{equation} l = p \times q + \frac{n}{p} \times \frac{D}{q}. \end{equation} $$
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
int
|
The dimension of the output space. |
required |
D
|
int
|
The dimension of the intermediate expansion space. |
required |
Returns:
Type | Description |
---|---|
int
|
The number of required learnable parameters. |
Source code in tinybig/reconciliation/lowrank_reconciliation.py
forward(n, D, w, device='cpu', *args, **kwargs)
The forward method of the parameter reconciliation function.
It applies the hypercomplex multiplication based parameter reconciliation operation to the input parameter vector \(\mathbf{w}\), and returns the reconciled parameter matrix of shape (n, D) subject to the parameters \(p\) and \(q\) as follows: $$ \begin{equation} \psi(\mathbf{w}) = \mathbf{A} \otimes \mathbf{B} \in {R}^{n \times D}, \end{equation} $$ where \(\mathbf{A} \in {R}^{p \times q}\) and \(\mathbf{B} \in {R}^{s \times t}\) are two sub-matrices of obtained by partitioning \(\mathbf{w}\) into two sub-vectors and subsequently reshaping them into matrices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
int
|
The dimension of the output space. |
required |
D
|
int
|
The dimension of the intermediate expansion space. |
required |
w
|
Parameter
|
The learnable parameters of the model. |
required |
device
|
Device to perform the parameter reconciliation. |
'cpu'
|
Returns:
Type | Description |
---|---|
Tensor
|
The reconciled parameter matrix of shape (n, D). |