Skip to content

constant_reconciliation

Bases: fabrication

The constant parameter reconciliation function.

It performs the constant parameter reconciliation, and returns the constant reconciled parameter matrix of shape (n, D). This class inherits from the reconciliation class (i.e., the fabrication class in the module directory).

...

Notes

As the simplest parameter reconciliation function, the constant parameter reconciliation projects any input parameters to constants (e.g., zeros or ones) as follows: $$ \begin{equation} \psi(\mathbf{w} | c) = c \cdot \mathbf{1}^{n \times D} = \mathbf{C} \in {R}^{n \times D}, \end{equation} $$ where the output matrix \(\mathbf{C}\) of size \(n \times D\) is filled with the provided constant \(c\).

For constant parameter reconciliation, the input parameter \(\mathbf{w}\) is not required, which together with its dimension hyper-parameter \(l\) can both be set to \textit{none} in implementation.

If the output constant \(\mathbf{C} = \mathbf{0}\) or \(\mathbf{C} = \mathbf{1}\), we can also name the functions as zero reconciliation and one reconciliation, respectively. Constant parameter reconciliation functions can accommodate outputs according to requirements.

Constant reconciliation contributes almost nothing to model learning since it involves no parameters, but it provides RPN with substantial flexibility in representing and designing many models.

Attributes:

Name Type Description
name str, default = 'constant_reconciliation'

Name of the reconciliation function.

c float, default = 1.0

The constant value of the reconciliation function.

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
class constant_reconciliation(fabrication):
    r"""
    The constant parameter reconciliation function.

    It performs the constant parameter reconciliation, and returns the constant reconciled parameter matrix of shape (n, D).
    This class inherits from the reconciliation class (i.e., the fabrication class in the module directory).

    ...

    Notes
    ----------
    As the simplest parameter reconciliation function, the **constant parameter reconciliation** projects
    any input parameters to constants (e.g., zeros or ones) as follows:
    $$
        \begin{equation}
            \psi(\mathbf{w} | c) = c \cdot \mathbf{1}^{n \times D} = \mathbf{C} \in {R}^{n \times D},
        \end{equation}
    $$
    where the output matrix $\mathbf{C}$ of size $n \times D$ is filled with the provided constant $c$.

    For constant parameter reconciliation, the input parameter $\mathbf{w}$ is not required,
    which together with its dimension hyper-parameter $l$ can both be set to \textit{none} in implementation.

    If the output constant $\mathbf{C} = \mathbf{0}$ or $\mathbf{C} = \mathbf{1}$,
    we can also name the functions as **zero reconciliation** and **one reconciliation**, respectively.
    Constant parameter reconciliation functions can accommodate outputs according to requirements.

    Constant reconciliation contributes almost nothing to model learning since it involves no parameters,
    but it provides RPN with substantial flexibility in representing and designing many models.

    Attributes
    ----------
    name: str, default = 'constant_reconciliation'
        Name of the reconciliation function.
    c: float, default = 1.0
        The constant value of the reconciliation function.

    Methods
    ----------
    __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.
    """
    def __init__(self, name: str = 'constant_c_reconciliation', c: float = 1.0, *args, **kwargs):
        """
        The initialization method of the constant parameter reconciliation function.

        It initializes a constant parameter reconciliation function object.
        This method will also call the initialization method of the base class as well.
        Since the constant parameter reconciliation doesn't require parameters, it will
        set the "require_parameters" as False in the initialization.

        Parameters
        ----------
        name: str, default = 'constant_c_reconciliation'
            Name of the constant parameter reconciliation function.
        c: float, default = 1.0
            The constant value of the reconciliation function

        Returns
        ----------
        fabrication
            The constant parameter reconciliation function object.
        """
        super().__init__(name=name, require_parameters=False, *args, **kwargs)
        self.c = c

    def calculate_l(self, n: int, D: int):
        """
        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.
        For constant parameter reconciliation, it doesn't require any learnable parameters, and this function
        will return the parameter number as 0 by default.

        Parameters
        ----------
        n: int
            The dimension of the output space.
        D: int
            The dimension of the intermediate expansion space.

        Returns
        -------
        int
            The number of required learnable parameters.
        """
        return 0

    def forward(self, n: int, D: int, w: torch.nn.Parameter = None, device='cpu', *args, **kwargs):
        r"""
        The forward method of the parameter reconciliation function.

        It applies the constant parameter reconciliation operation to the input parameter of length l,
        and returns the reconciled parameter matrix of shape (n, D) as follows:
        $$
            \begin{equation}
                \psi(\mathbf{w} | c) = c \cdot \mathbf{1}^{n \times D} = \mathbf{C} \in {R}^{n \times D}.
            \end{equation}
        $$

        Parameters
        ----------
        n: int
            The dimension of the output space.
        D: int
            The dimension of the intermediate expansion space.
        w: torch.nn.Parameter, default = None
            The learnable parameters of the model.
            For constant reconciliation, it is assigned with a default value None.
        device: str, default = 'cpu'
            Device to perform the parameter reconciliation.

        Returns
        ----------
        torch.Tensor
            The reconciled parameter matrix of shape (n, D).
        """
        return self.c * torch.ones(n, D, device=device)

__init__(name='constant_c_reconciliation', c=1.0, *args, **kwargs)

The initialization method of the constant parameter reconciliation function.

It initializes a constant parameter reconciliation function object. This method will also call the initialization method of the base class as well. Since the constant parameter reconciliation doesn't require parameters, it will set the "require_parameters" as False in the initialization.

Parameters:

Name Type Description Default
name str

Name of the constant parameter reconciliation function.

'constant_c_reconciliation'
c float

The constant value of the reconciliation function

1.0

Returns:

Type Description
fabrication

The constant parameter reconciliation function object.

Source code in tinybig/reconciliation/basic_reconciliation.py
def __init__(self, name: str = 'constant_c_reconciliation', c: float = 1.0, *args, **kwargs):
    """
    The initialization method of the constant parameter reconciliation function.

    It initializes a constant parameter reconciliation function object.
    This method will also call the initialization method of the base class as well.
    Since the constant parameter reconciliation doesn't require parameters, it will
    set the "require_parameters" as False in the initialization.

    Parameters
    ----------
    name: str, default = 'constant_c_reconciliation'
        Name of the constant parameter reconciliation function.
    c: float, default = 1.0
        The constant value of the reconciliation function

    Returns
    ----------
    fabrication
        The constant parameter reconciliation function object.
    """
    super().__init__(name=name, require_parameters=False, *args, **kwargs)
    self.c = c

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. For constant parameter reconciliation, it doesn't require any learnable parameters, and this function will return the parameter number as 0 by default.

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
def calculate_l(self, n: int, D: int):
    """
    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.
    For constant parameter reconciliation, it doesn't require any learnable parameters, and this function
    will return the parameter number as 0 by default.

    Parameters
    ----------
    n: int
        The dimension of the output space.
    D: int
        The dimension of the intermediate expansion space.

    Returns
    -------
    int
        The number of required learnable parameters.
    """
    return 0

forward(n, D, w=None, device='cpu', *args, **kwargs)

The forward method of the parameter reconciliation function.

It applies the constant parameter reconciliation operation to the input parameter of length l, and returns the reconciled parameter matrix of shape (n, D) as follows: $$ \begin{equation} \psi(\mathbf{w} | c) = c \cdot \mathbf{1}^{n \times D} = \mathbf{C} \in {R}^{n \times D}. \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
w Parameter

The learnable parameters of the model. For constant reconciliation, it is assigned with a default value None.

None
device

Device to perform the parameter reconciliation.

'cpu'

Returns:

Type Description
Tensor

The reconciled parameter matrix of shape (n, D).

Source code in tinybig/reconciliation/basic_reconciliation.py
def forward(self, n: int, D: int, w: torch.nn.Parameter = None, device='cpu', *args, **kwargs):
    r"""
    The forward method of the parameter reconciliation function.

    It applies the constant parameter reconciliation operation to the input parameter of length l,
    and returns the reconciled parameter matrix of shape (n, D) as follows:
    $$
        \begin{equation}
            \psi(\mathbf{w} | c) = c \cdot \mathbf{1}^{n \times D} = \mathbf{C} \in {R}^{n \times D}.
        \end{equation}
    $$

    Parameters
    ----------
    n: int
        The dimension of the output space.
    D: int
        The dimension of the intermediate expansion space.
    w: torch.nn.Parameter, default = None
        The learnable parameters of the model.
        For constant reconciliation, it is assigned with a default value None.
    device: str, default = 'cpu'
        Device to perform the parameter reconciliation.

    Returns
    ----------
    torch.Tensor
        The reconciled parameter matrix of shape (n, D).
    """
    return self.c * torch.ones(n, D, device=device)