lphm_reconciliation
Bases: fabrication
The low-rank parameterized hypercomplex multiplication (LPHM) based parameter reconciliation function.
It performs the LPHM parameter reconciliation, and returns the LPHM reconciled parameter matrix of shape (n, D). This class inherits from the reconciliation class (i.e., the fabrication class in the module directory).
The low-rank parameterized hypercomplex multiplication based parameter reconciliation can be viewed as a combination of the low-rank parameter reconciliation with the hypercomplex multiplication based parameter reconciliation, where the matrix \(\mathbf{B}\) in the hypercomplex multiplication based parameter reconciliation is replaced with the product of two low-rank sub-matrices instead.
...
Notes
Formally, given the parameter vector \(\mathbf{w} \in {R}^{l}\) and a rank hyper-parameter \(r\), together with the parameter sub-matrix dimension parameters \(p\) and \(q\), the LPHM reconciliation function partitions \(\mathbf{w}\) into three sub-vectors and subsequently reshapes them into three matrices \(\mathbf{A} \in {R}^{p \times q}\), \(\mathbf{S} \in {R}^{\frac{n}{p} \times r}\) and \(\mathbf{T} \in {R}^{\frac{D}{q} \times r}\). These sub-matrices \(\mathbf{A}\), \(\mathbf{S}\) and \(\mathbf{T}\) help define the LPHM reconciliation function as follows: $$ \begin{equation} \psi(\mathbf{w}) = \mathbf{A} \otimes \mathbf{B} = \mathbf{A} \otimes ( \mathbf{S} \mathbf{T}^\top) \in {R}^{n \times D}. \end{equation} $$ This necessitates imposing certain limitations on these dimension and rank parameters, and the parameter vector length \(l\) can be calculated as follows: $$ \begin{equation} l = p \times q + r( \frac{n}{p} + \frac{D}{q} ). \end{equation} $$
For the LPHM parameter reconciliation function, it adds strict constraints on the parameters \(p\) and \(q\), which should be the divisors of the target dimensions \(n\) and \(D\), respectively, i.e., $$ \begin{equation} n \% p = 0 \text{, and } D \% q = 0. \end{equation} $$
Attributes:
Name | Type | Description |
---|---|---|
name |
str, default = 'lphm_reconciliation'
|
Name of the LPHM 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. |
r |
int, default = 2
|
Submatrix rank parameter. |
Methods:
Name | Description |
---|---|
__init__ |
It initializes the LPHM 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
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 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
|
__init__(name='lphm_reconciliation', p=None, q=None, r=2, *args, **kwargs)
The initialization method of the LPHM parameter reconciliation function.
It initializes a LPHM 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 LPHM parameter reconciliation function. |
'lphm_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
|
r
|
int
|
Submatrix rank parameter. |
2
|
Returns:
Type | Description |
---|---|
fabrication
|
The LPHM 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 dimension and rank parameters \(p\), \(q\) and \(r\), which can be represented as follows: $$ \begin{equation} l = p \times q + r( \frac{n}{p} + \frac{D}{q} ). \end{equation} $$
Notes
For the LPHM parameter reconciliation function, it adds strict constraints on the parameters \(p\) and \(q\), which should be the divisors of the target dimensions \(n\) and \(D\), respectively, i.e., $$ \begin{equation} n \% p = 0 \text{, and } D \% q = 0. \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 LPHM parameter reconciliation operation to the input parameter vector \(\mathbf{w}\), and returns the reconciled parameter matrix of shape (n, D) subject to the dimension and rank parameters \(p\), \(q\) and \(r\) as follows: $$ \begin{equation} \psi(\mathbf{w}) = \mathbf{A} \otimes \mathbf{B} = \mathbf{A} \otimes ( \mathbf{S} \mathbf{T}^\top) \in {R}^{n \times D}. \end{equation} $$ where \(\mathbf{A} \in {R}^{p \times q}\), \(\mathbf{S} \in {R}^{\frac{n}{p} \times r}\) and \(\mathbf{T} \in {R}^{\frac{D}{q} \times r}\) are all obtained by partitioning \(\mathbf{w}\) into 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). |