duplicated_diagonal_padding_reconciliation
Bases: duplicated_padding_reconciliation
A reconciliation mechanism that applies duplicated diagonal padding to the input tensor.
Inherits from duplicated_padding_reconciliation
and extends it to handle diagonal padding with duplication.
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 identity matrix \(\mathbf{I} \in {R}^{p \times q}\) (normally \(p=q\)) populated with the constant value of ones, the duplicated_diagonal_padding_reconciliation function can be defined as follows: $$ \begin{equation} \psi(\mathbf{w}) = \mathbf{I} \otimes \mathbf{W} = \begin{bmatrix} \mathbf{W} & \mathbf{0} & \cdots & \mathbf{0} \\ \mathbf{0} & \mathbf{W} & \cdots & \mathbf{0} \\ \vdots & \vdots & \ddots & \vdots \\ \mathbf{0} & \mathbf{0} & \cdots & \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
|
Name of the reconciliation function. |
Methods:
Name | Description |
---|---|
forward |
Computes the reconciliation matrix using duplicated diagonal padding. |
Source code in tinybig/reconciliation/basic_reconciliation.py
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 |
|
__init__(name='duplicated_diagonal_padding_reconciliation', *args, **kwargs)
Initializes the duplicated diagonal padding reconciliation function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the reconciliation function. Defaults to 'duplicated_diagonal_padding_reconciliation'. |
'duplicated_diagonal_padding_reconciliation'
|
*args
|
tuple
|
Additional positional arguments for the parent class. |
()
|
**kwargs
|
dict
|
Additional keyword arguments for the parent class. |
{}
|
Source code in tinybig/reconciliation/basic_reconciliation.py
forward(n, D, w, device='cpu', *args, **kwargs)
Computes the reconciliation matrix using duplicated diagonal padding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
int
|
Number of instances. |
required |
D
|
int
|
Dimensionality of the output tensor after reconciliation. |
required |
w
|
Parameter
|
Parameter tensor with shape |
required |
device
|
str
|
Device for computation ('cpu', 'cuda', 'mps'). 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 shape of |