def build(self, var_list):
        """Initialize optimizer variables.

        Adam optimizer has 3 types of variables: momentums, velocities and
        velocity_hat (only set when amsgrad is applied),

        Args:
            var_list: list of model variables to build Adam variables on.
        """
        if self.built:
            return
        super().build(var_list)
        self._r = []
        self._c = []
        self._v = []
        for var in var_list:
            if len(var.shape) < 2:
                # Don't factor if variable is of dimension < 2, but we still
                # need to create dummy variables as placeholder.
                self._r.append(
                    backend.Variable(0, name=var.name, trainable=False)
                )
                self._c.append(
                    backend.Variable(0, name=var.name, trainable=False)
                )
            elif self._overwrite_variable_with_gradient(var):
                self._r.append(None)
                self._c.append(None)
            else:
                # Always factor the last 2 dimensions.
                r_shape = var.shape[:-1]
                c_shape = var.shape[:-2] + (var.shape[-1],)
                self._r.append(
                    self.add_variable(
                        shape=r_shape,
                        dtype=var.dtype,
                        name=var.name,
                    )
                )
                self._c.append(
                    self.add_variable(
                        shape=c_shape,
                        dtype=var.dtype,
                        name=var.name,
                    )
                )

            if self._overwrite_variable_with_gradient(var):
                self._v.append(None)
            else:
                self._v.append(
                    self.add_variable_from_reference(
                        reference_variable=var, name="velocity"
                    )
                )
Initialize optimizer variables.

        Adam optimizer has 3 types of variables: momentums, velocities and
        velocity_hat (only set when amsgrad is applied),

        Args:
            var_list: list of model variables to build Adam variables on.
        
keras/src/optimizers/adafactor.py