def backward_pass(self, y1, y2, d_y1, d_y2):
        """Activation re-compute with the following equation.

        x2 = y2 - g(y1), g = FFN
        x1 = y1 - f(x2), f = MSHA
        """

        # temporarily record intermediate activation for G
        # and use them for gradient calculation of G
        with torch.enable_grad():
            y1.requires_grad = True

            torch.manual_seed(self.seeds['ffn'])
            g_y1 = self.ffn(self.ln2(y1))

            torch.manual_seed(self.seeds['droppath'])
            g_y1 = build_dropout(self.drop_path_cfg)(g_y1)

            g_y1.backward(d_y2, retain_graph=True)

        # activate recomputation is by design and not part of
        # the computation graph in forward pass
        with torch.no_grad():
            x2 = y2 - g_y1
            del g_y1

            d_y1 = d_y1 + y1.grad
            y1.grad = None

        # record F activation and calculate gradients on F
        with torch.enable_grad():
            x2.requires_grad = True

            torch.manual_seed(self.seeds['attn'])
            f_x2 = self.attn(self.ln1(x2))

            torch.manual_seed(self.seeds['droppath'])
            f_x2 = build_dropout(self.drop_path_cfg)(f_x2)

            f_x2.backward(d_y1, retain_graph=True)

        # propagate reverse computed activations at the
        # start of the previous block
        with torch.no_grad():
            x1 = y1 - f_x2
            del f_x2, y1

            d_y2 = d_y2 + x2.grad

            x2.grad = None
            x2 = x2.detach()

        return x1, x2, d_y1, d_y2
Activation re-compute with the following equation.

        x2 = y2 - g(y1), g = FFN
        x1 = y1 - f(x2), f = MSHA
        
mmpretrain/models/backbones/revvit.py