Skip to content

func_x

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/util/util.py
def func_x(x, functions, device: str = 'cpu'):
    """
    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
    ----------
    x: torch.Tensor
        The input data vector.
    functions: list | tuple | callable
        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.
    device: str, default = 'cpu'
        The device to perform the function on the input vector.

    Returns
    -------
    torch.Tensor
        The processed input vector by these functions.
    """
    if functions is None or ((isinstance(functions, list) or isinstance(functions, tuple)) and len(functions) == 0):
        return x
    elif isinstance(functions, list) or isinstance(functions, tuple):
        for f in functions:
            if callable(f):
                x = f(x)
            elif type(f) is str:
                x = str_func_x(x=x, func=f, device=device)
        return x
    else:
        if callable(functions):
            return functions(x)
        elif type(functions) is str:
            return str_func_x(x=x, func=functions, device=device)