duplicated_padding_reconciliation
Bases: fabrication
The duplicated padding based parameter reconciliation function.
It performs the duplicated padding 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
Specifically, for the parameter vector \(\mathbf{w} \in {R}^{l}\) of length \(l\), it can be reshaped into a matrix \(\mathbf{W}\) comprising \(s\) rows and \(t\) columns, where \(l = s \times t\). Through the multiplication of \(\mathbf{W}\) with a constant matrix \(\mathbf{C} \in {R}^{p \times q}\) populated with the constant value of ones, the duplicated padding based parameter reconciliation function can be defined as follows: $$ \begin{equation} \psi(\mathbf{w}) = \mathbf{C} \otimes \mathbf{W} = \begin{bmatrix} C_{1,1} \mathbf{W} & C_{1,2} \mathbf{W} & \cdots & C_{1,q} \mathbf{W} \\ C_{2,1} \mathbf{W} & C_{2,2} \mathbf{W} & \cdots & C_{2,q} \mathbf{W} \\ \vdots & \vdots & \ddots & \vdots \\ C_{p,1} \mathbf{W} & C_{p,2} \mathbf{W} & \cdots & C_{p,q} \mathbf{W} \\ \end{bmatrix} \in {R}^{ps \times qt}, \end{equation} $$ where \(\mathbf{W} = \text{reshape}(\mathbf{w})\) and \(\otimes\) denotes the Kronecker product operator. The output dimensions should meet the constraints that \(p \times s = n\) and \(q \times t = D\), where renders \(s = \frac{n}{p}\) and \(t = \frac{D}{q}\).
For the duplicated padding based parameter reconciliation, the number of required parameter \(l\) is defined as $$ \begin{equation} l= s \times t = \frac{n \times D}{pq}, \end{equation} $$ where \(p\) and \(q\) are the duplication numbers in the row and column, respectively.
Attributes:
Name | Type | Description |
---|---|---|
name |
str, default = 'duplicated_padding_reconciliation'
|
Name of the parameter reconciliation function |
p |
int, default = 2
|
Duplication times in the rows. |
q |
int, default = None
|
Duplication times in the columns. If q is not provided with initial values, it will be assigned with value p as well by default. |
Methods:
Name | Description |
---|---|
__init__ |
It initializes the parameter reconciliation function. |
calculate_l |
It calculates the length of required parameters. |
forward |
It implements the abstract forward method declared in the base reconciliation class. |
Source code in tinybig/reconciliation/basic_reconciliation.py
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 |
|
__init__(name='duplicated_padding_reconciliation', p=2, q=None, *args, **kwargs)
The initialization method of the duplicated padding based parameter reconciliation function.
It initializes a duplicated padding 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 parameter reconciliation function |
'duplicated_padding_reconciliation'
|
|
p
|
Duplication times in the rows. |
2
|
|
q
|
Duplication times in the columns. If q is not provided with initial values, it will be assigned with value p by default. |
None
|
Returns:
Type | Description |
---|---|
fabrication
|
The masking parameter reconciliation function object. |
Source code in tinybig/reconciliation/basic_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 duplication parameters \(p\) and \(q\), which can be represented as follows: $$ \begin{equation} l= s \times t = \frac{n \times D}{pq}. \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/basic_reconciliation.py
forward(n, D, w, device='cpu', *args, **kwargs)
The forward method of the parameter reconciliation function.
It applies the duplicated padding based parameter reconciliation operation to the input parameter vector, and returns the reconciled parameter matrix of shape (n, D) subject to duplication parameters \(p\) and \(q\) as follows: $$ \begin{equation} \psi(\mathbf{w}) = \mathbf{C} \otimes \mathbf{W} = \begin{bmatrix} C_{1,1} \mathbf{W} & C_{1,2} \mathbf{W} & \cdots & C_{1,q} \mathbf{W} \\ C_{2,1} \mathbf{W} & C_{2,2} \mathbf{W} & \cdots & C_{2,q} \mathbf{W} \\ \vdots & \vdots & \ddots & \vdots \\ C_{p,1} \mathbf{W} & C_{p,2} \mathbf{W} & \cdots & C_{p,q} \mathbf{W} \\ \end{bmatrix} \in {R}^{n \times D}, \end{equation} $$ where \(\mathbf{W} = \text{reshape}(\mathbf{w}) \in R^{s \times t}\) and \(\otimes\) denotes the Kronecker product operator.
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). |