function
Source code in tinybig/module/base_function.py
20 21 22 23 24 25 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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|
func_x(x, functions, device='cpu')
staticmethod
The function execution to the input data.
It applies the list of functions to the input vector and returns the calculation results.
This method will be extensively called for handeling the data processing functions in the expansion functions, RPN head and remainder functions in tinyBIG.
- preprocess_functions in expansion functions
- postprocess_functions in expansion functions
- output_process_functions in rpn heads
- activation_functions in remainder functions
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
The input data vector. |
required | |
functions
|
The functions to be applied to the input vector. The function can be callable functions, string names of the functions, the complete class descriptions of the functions, etc. |
required | |
device
|
str
|
The device to perform the function on the input vector. |
'cpu'
|
Returns:
Type | Description |
---|---|
Tensor
|
The processed input vector by these functions. |
Source code in tinybig/module/base_function.py
str_func_x(x, func, device='cpu', *args, **kwargs)
staticmethod
Function recognition from their string names or string class descriptions.
It recognizes the data processing functions from their names or class description in strings, e.g., "layer_norm" or "torch.nn.functional.layer_norm".
Since these functions can be very diverse, whose definitions are also very different, it makes it very challenging to process them based on their string descriptions. This method can process some basic functions, e.g., activation functions, and normalization functions. For the functions that are not implemented in this method, the users may consider to extend the method to handle more complex input functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
The input data vector. |
required | |
func
|
str | Callable
|
The string description of the functoin name or class. |
required |
device
|
The device to host and apply the recognized functions. |
'cpu'
|
Returns:
Type | Description |
---|---|
Tensor
|
The processed input data vector by the recognized functions. |
Source code in tinybig/module/base_function.py
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 |
|
string_to_function(formula, variable)
staticmethod
Formula recognition from strings.
It recognizes and returns the formula and variables from strings via the sympy package.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
formula
|
The function formula as a string. |
required | |
variable
|
The list of the variables involved in the formula. |
required |
Returns:
Type | Description |
---|---|
FunctionClass
|
The recognized function of the input formula. |