constant_interdependence
Bases: interdependence
A class for constant interdependence.
This class defines a constant interdependence matrix (A
) for the relationship between rows or columns
of the input tensor. It does not require input data or additional parameters for computation.
Notes
Formally, based on the (optional) input data batch \(\mathbf{X} \in {R}^{b \times m}\), we define the constant interdependence function as:
\[\begin{equation} \xi(\mathbf{X}) = \mathbf{A} \in {R}^{m \times m'}. \end{equation}\]
This function facilitates the definition of customized constant interdependence matrices, allowing for a manually defined matrix \(\mathbf{A}\) to be provided as a hyper-parameter during function initialization.
Two special cases warrant particular attention: when \(\mathbf{A}_c\) consists entirely of zeros, it is designated as the "zero interdependence matrix", whereas a matrix of all ones is termed the "one interdependence matrix".
Attributes:
Name | Type | Description |
---|---|---|
A |
Tensor
|
The interdependence matrix of shape |
b |
int
|
Number of rows in the input tensor. |
m |
int
|
Number of columns in the input tensor. |
interdependence_type |
str
|
Type of interdependence ('attribute', 'instance', etc.). |
name |
str
|
Name of the interdependence function. |
device |
str
|
Device for computation (e.g., 'cpu' or 'cuda'). |
Methods:
Name | Description |
---|---|
__init__ |
Initializes the constant interdependence function. |
update_A |
Updates the interdependence matrix |
calculate_b_prime |
Computes the number of rows in the output tensor after interdependence. |
calculate_m_prime |
Computes the number of columns in the output tensor after interdependence. |
calculate_A |
Returns the constant interdependence matrix |
Source code in tinybig/interdependence/basic_interdependence.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 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 |
|
__init__(b, m, A, interdependence_type='attribute', name='constant_interdependence', device='cpu', *args, **kwargs)
Initializes the constant interdependence function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b
|
int
|
Number of rows in the input tensor. |
required |
m
|
int
|
Number of columns in the input tensor. |
required |
A
|
Tensor
|
The interdependence matrix of shape |
required |
interdependence_type
|
str
|
Type of interdependence ('attribute', 'instance', etc.). Defaults to 'attribute'. |
'attribute'
|
name
|
str
|
Name of the interdependence function. Defaults to 'constant_interdependence'. |
'constant_interdependence'
|
device
|
str
|
Device for computation (e.g., 'cpu' or 'cuda'). Defaults to 'cpu'. |
'cpu'
|
*args
|
tuple
|
Additional positional arguments for the parent |
()
|
**kwargs
|
dict
|
Additional keyword arguments for the parent |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If |
Source code in tinybig/interdependence/basic_interdependence.py
calculate_A(x=None, w=None, device='cpu', *args, **kwargs)
Returns the constant interdependence matrix A
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Ignored for constant interdependence. Defaults to None. |
None
|
w
|
Parameter
|
Ignored for constant interdependence. Defaults to None. |
None
|
device
|
str
|
Device for computation. Defaults to 'cpu'. |
'cpu'
|
*args
|
tuple
|
Additional positional arguments. |
()
|
**kwargs
|
dict
|
Additional keyword arguments. |
{}
|
Returns:
Type | Description |
---|---|
Tensor
|
The constant interdependence matrix |
Raises:
Type | Description |
---|---|
AssertionError
|
If |
Source code in tinybig/interdependence/basic_interdependence.py
calculate_b_prime(b=None)
Computes the number of rows in the output tensor after applying interdependence function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b
|
int
|
Number of rows in the input tensor. If None, defaults to |
None
|
Returns:
Type | Description |
---|---|
int
|
The number of rows in the output tensor. |
Raises:
Type | Description |
---|---|
AssertionError
|
If |
Source code in tinybig/interdependence/basic_interdependence.py
calculate_m_prime(m=None)
Computes the number of columns in the output tensor after applying interdependence function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
int
|
Number of columns in the input tensor. If None, defaults to |
None
|
Returns:
Type | Description |
---|---|
int
|
The number of columns in the output tensor. |
Raises:
Type | Description |
---|---|
AssertionError
|
If |
Source code in tinybig/interdependence/basic_interdependence.py
update_A(A)
Updates the interdependence matrix A
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A
|
Tensor
|
The new interdependence matrix of shape |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If |