Stabilizing Equilibrium Models by Jacobian Regularization

Shaojie Bai, Vladlen Koltun, J. Zico Kolter

Introduction

While conventional deep networks like ResNets (He et al. 2016) and Transformers (Vaswani et al. 2017) rely on hierarchical layer stacking, the recently-proposed deep equilibrium networks (DEQs) (Bai et al. 2019) directly model the “infinite-depth” representation of a single layer fθf_{\theta} by solving for its fixed point (i.e., “equilibrium”) z⋆\mathbf{z}^{\star}:

where x\mathbf{x} is the original input. Importantly, to train these models, one could directly differentiate through the final equilibrium z⋆\mathbf{z}^{\star} by the implicit function theorem (Krantz & Parks 2012), irrespective of the method used to solve for this equilibrium in the forward pass. Therefore, like other implicit-depth architectures such as Neural ODEs (Chen et al. 2018), DEQs have the notable advantages that their forward passes can rely on any black-box root solvers (e.g., Newton, quasi-Newton, simplest forward iterations), and that their training only consumes O(1)O(1) memory. With this formulation, prior works have managed to extend the DEQ framework for multiple large-scale applications, such as language modeling (Bai et al. 2019) and large-scale image classification or segmentation (Bai et al. 2020).

However, these models suffer from a few issues. First, despite their memory efficiency, DEQs are also slower than conventional deep networks that achieve the same level of accuracy. Second, the number of iterations required to solve for the equilibrium quickly grows over the course of training, indicating a trend for approaching instability. Third, the DEQ model is sensitive to architectural choices, and sometimes even small modifications could break the model’s stability of convergence. Some recent works have tackled this third issue by exploiting provably convergent layers via monotone operator splitting theories (Winston & Kolter 2020) and Lipschitz boundedness (Revay et al. 2020). However, these structural solutions rely extensively on specific layer parameterizations, rendering DEQ models unscalable and even more inflexible.

In this paper, we first summarize and provide empirical evidence on all of these downsides of the equilibrium networks that have so far thwarted many from extending DEQs to both broader applications and more architectural variants. To address these issues, we further propose a regularization solution to improve on DEQ models’ stability, efficiency and flexibility. Importantly, while prior DEQs adopted regularization methods direcly borrowed from explicit deep networks (e.g., recurrent dropout (Gal & Ghahramani 2016)), we introduce a simple and theoretically-motivated Jacobian regularization pursuant to DEQ models’ implicitness. We will discuss in detail how this Jacobian regularization relates to the contractivity of DEQ’s forward non-linear system and backward linear system, and is thus able to effectively stabilize not only forward but also backward dynamics of DEQ networks. There are two immediate benefits of the resulting stability in the dynamics. First, solving a DEQ requires far fewer iterations than before, which makes regularized DEQs significantly faster than their unregularized counterparts. Second, this model class becomes much less brittle to architectural variants that would otherwise break the DEQ.

We validate the proposed regularization by experiments on both toy-scale synthetic tasks and large-scale real datasets across domains: word-level language modeling on WikiText-103 (Merity et al. 2017) and high-resolutional image classification on the full ImageNet dataset (Deng et al. 2009). Empirically, our regularized DEQs are generally 2x to 3x faster than prior DEQs, and can be accelerated to be as fast as explicit deep networks (e.g., ResNets and DenseNets). This is the first time that implicit models are accelerated to this level without sacrificing scalability, accuracy, or structural flexibility. With their O(1)O(1) memory footprint, this further establishes implicit models as a strong competitor to explicit deep architectures.

Background & Related Work

While explicit deep networks hierarchically stack layers to build a computation graph for their forward and backward propagations, implicit models (Amos & Kolter 2017; Chen et al. 2018; El Ghaoui et al. 2019; Gould et al. 2019; Bai et al. 2019) do not have a prescribed computation graph. Instead these models solve for a non-linear system. One example is the Neural ODE (Chen et al. 2018), which solves an initial-value ODE problem that involves a residual layer. Another example, which is the primary focus of our work, is the deep equilibrium network (DEQ) (Bai et al. 2019), which reduces the forward pass to a root-solving problem. In this section, we introduce the basics of DEQ models and the relevant threads of work, followed by a discussion of prior approaches to regularizing implicit models.

Given a layer/block fθf_{\theta} (which may contain a few shallow sublayers) and an input x\mathbf{x}, a deep equilibrium model aims to approximate an “infinite-level” layer stacking of the form z[i+1]=fθ(z[i];x)\mathbf{z}^{[i+1]}=f_{\theta}(\mathbf{z}^{[i]};\mathbf{x}) (where i=1,…,Li=1,\dots,L, with L→∞L\rightarrow\infty) by directly solving for its fixed-point representation:

where Jfθ(z⋆)J_{f_{\theta}}(\mathbf{z}^{\star}) is the Jacobian matrix at equilibrium z⋆\mathbf{z}^{\star}.

To solve for the equilibrium, Bai et al. 2019 proposed to use Broyden’s method (Broyden 1965) to find the root of fθ(z⋆;x)−z⋆=0f_{\theta}(\mathbf{z}^{\star};\mathbf{x})-\mathbf{z}^{\star}=0; later works (Winston & Kolter 2020; Revay et al. 2020) and a recent tutorial (Duvenaud et al. 2020) have applied other algorithms, such as Peaceman-Rachford splitting (Peaceman & Rachford 1955) and Anderson acceleration (Anderson 1965).

Compared to Neural ODEs, deep equilibrium networks have been demonstrated to scale well to large and high-dimensional tasks, such as language modeling, ImageNet classification, and semantic segmentation (Bai et al. 2019; Bai et al. 2020), and are thus more applicable to domains where deep learning has been traditionally successful. However, unlike ODE flows, DEQ networks do not have a unique trajectory, and are not guaranteed to converge. Thus recent works have also begun to examine the stability and other theoretical properties of DEQs. Winston & Kolter 2020 propose a monotone DEQ that has a unique fixed point. Pabbaraju et al. 2021; Revay et al. 2020 further study the Lipschitz boundedness of monotone DEQs. Kawaguchi 2021 analyze the gradient dynamics of a linearized version of DEQs. Lu et al. 2021 apply an invertible equilibrium model to generative modeling via normalizing flows.

2 Regularizing Implicit Models

Just like explicit deep networks, implicit networks can overfit to the dataset; but additionally, they can also become unstable. For instance, Neural ODEs are essentially modeling infintesimal steps of a residual block (He et al. 2016; Chang et al. 2018), and Grathwohl et al. 2019 found that weight decay & spectral normalization (Miyato et al. 2018) are useful (though expensive) in reducing the rapidly growing number of functional evaluations (NFEs) needed to solve for the ODE endpoint. On the other hand, large-scale DEQ networks (Bai et al. 2019; Bai et al. 2020) have adopted weight normalization (Salimans & Kingma 2016), recurrent dropout (Gal & Ghahramani 2016), and group normalization (Wu & He 2018) for preventing overfitting and divergence. Nonetheless, all these methods are borrowed from explicit deep networks, where they have long been known to work well. They do not exploit the implicitness of implicit models.

More recently, a few different regularization methods have been introduced to specifically fix the numerous issues of the vanilla Neural ODE and continuous normalizing flow models, such as augmenting the hidden state (Dupont et al. 2019), using hyper ODE solvers (Poli et al. 2020), and regularizing higher-order time derivatives (Kelly et al. 2020). These methods directly leverage the dynamical system view of Neural ODEs. However, due to the inherent challenge of solving high-dimensional ODEs, these accelerated Neural ODE models can still easily take >100>100 forward iterations even on MNIST classification (Kelly et al. 2020), and even more for their backward pass. In comparison, DEQs scale better to high-dimensional tasks (e.g., 25-30 iterations on ImageNet) (Bai et al. 2020) and complex fθf_{\theta} (e.g., a Transformer layer). But such extra complexities also make DEQ models harder to regularize; e.g., simply resorting to weight decay doesn’t fix the instability of DEQs (see Section 5.5). To the best of our knowledge, there has been almost no exploration of directly regularizing DEQ stability and convergence.

Our method is closely connected to the many prior works that study Jacobian/gradient regularization (Drucker & Le Cun 1992; Novak et al. 2018; Hoffman et al. 2019; Finlay et al. 2020; Linsley et al. 2020), though these were also motivated differently. Specifically, Sokolić et al. 2017; Hoffman et al. 2019 regularized the input-output Jacobians of the entire (very deep) explicit classification networks to increase the prediction margin in a robust learning setting (and are thus expensive). Finlay et al. 2020 was inspired by a kinetic energy view and possible overfitting of a training-time dynamical system. The method of Linsley et al. 2020 targeted (for a Jacobian JJ) a Lipschitzness level λ\lambda, used max⁡i(1⊤J)i\max_{i}(\mathbf{1}^{\top}J)_{i} to approximate the matrix 1-norm, and proposed loss L=∥(1⊤J−λ)+∥2L=\|(\mathbf{1}^{\top}J-\lambda)^{+}\|_{2}. Yet this approximation is in fact problematic, as it does not provably bound the spectral radius (i.e., stability) at all. For example, matrix

has L=0L=0 and yet an eigenvalue of 4 (we also empirically verify that this method does not help DEQ models, exactly due to this issue).

In contrast to these works, the key contributions of our paper are that (1) we provide a thorough discussion & summary of various issues with DEQ models, and how ill-conditioned Jacobians are related to the forward/backward instabilities, via the new lens of fixed-point convergence; and (2) we demonstrate how regularizing the Jacobian of DEQs at the equilibrium point (i.e., the final output z⋆\mathbf{z}^{\star}) can provably bound the stability of the forward and backward convergences, thereby addressing these various problems. For example, our experiments show that we can significantly stabilize DEQs with new (and more unstable) architectural variants and accelerate DEQs to be nearly as fast as certain explicit architectures (e.g., we only need ≤6\leq 6 NFEs on CIFAR-10) on tasks across different scales and with comparable accuracy.

DEQ Models and Their Discontents

Despite the DEQ models’ success in some very challenging tasks, such as Cityscapes semantic segmentation (Cordts et al. 2016; Bai et al. 2020), these models suffer from multiple serious downsides. In this section, we provide a summary of some of these problems. While these issues directly lead to our subsequent discussion on the need for regularization (see Section 4), we also believe such systematic discussion provides a useful overview for potential future research on further addressing these issues.

Although a DEQ network has no “depth”, a relevant measure of computational efficiency is the number of function evaluations (NFEs) of the layer fθ(z;x)f_{\theta}(\mathbf{z};\mathbf{x}) used by the iterative root solver (e.g., Broyden’s method (Broyden 1965)).

However, one common phenomenon to all prior works on DEQs is that the fixed points are increasingly harder to solve for over the course of model training. In other words, as a DEQ’s performance gradually improves during training, the NFE required to converge to the same threshold ε\varepsilon (e.g., 10−310^{-3}) rapidly grows. This observation has been made on different instantiations of equilibrium networks, and regardless of whether the model is provably convergent or not (e.g., (Bai et al. 2019; Winston & Kolter 2020), where a DEQ at the end of training can take >3×>3\times more iterations). Intuitively, such tendency to approach “critical stability” implicitly characterizes an inclination of the model to learn “deeper” networks; so it is unsurprising that unregularized training will keep driving it in this direction. But as a result, the dynamical system only becomes more and more brittle. The existing way of “addressing” this is to circumvent it by setting a maximum NFE limit besides the ε\varepsilon-threshold; i.e., the solver stops either when 1) the residual is smaller than ε\varepsilon, or 2) it has run for a max number of steps TT. This could be risky because as the convergence gets more unstable/critical, such a hard stop for the solver cannot guarantee that we are close enough to the fixed point. In the backward pass, for instance, we may consequently be training DEQs with very noisy gradients. A similar issue exists for Neural ODEs, though these cannot easily be hard-stopped like DEQs due to the need to accurately trace the flow to the endpoint.

We illustrate this issue on CIFAR-10 classification in Fig. 1(a). One can easily see that both forward and backward estimates of the fixed points gets increasingly worse with the training steps (and eventually plateaus in an unstable region where the model keeps yielding bad gradients). Such growing instability is also reflected empirically in the growth of Jacobian norm at equilibrium; i.e., ∥∂fθ(z⋆;x)∂z⋆∥F\left\|\frac{\partial f_{\theta}(\mathbf{z}^{\star};\mathbf{x})}{\partial\mathbf{z}^{\star}}\right\|_{F}(see Figure 1(b)), which we discuss in Section 4. Moreover, interestingly, while these plots might suggest simple regularizations like weight decay, we show later that weight decay often makes this stability issue worse for equilibrium networks, and even leads to divergence.

2 Inefficiency Compared to Explicit Networks

A direct ramification of the increase in iterations required (see Section 3.1) is the significant increase in both training and inference time for DEQ models.

One advantage of DEQs noted by Bai et al. 2019 is that the forward trajectory need not strictly reach the equilibrium. Therefore in a certain sense, we could trade performance for efficiency by stopping at a “good enough” estimate of the equilibrium. However, due to the growing instability problem, this could still be increasingly costly. This causes the existing DEQs to be significantly slower than their explicit network counterparts of comparable size and performance. E.g., a DEQ-Transformer (Bai et al. 2019) is about 3×3\times slower than a deep Transformer-XL (Dai et al. 2019); a multiscale DEQ (Bai et al. 2020) is over 4×4\times slower than ResNet-101 on ImageNet. Despite their memory efficiency, such slowdown is a roadblock to wider deployment of this class of models in practice. In Figure 1(c), we visualize this slowdown on the validation set of WikiText-103 language modeling (Merity et al. 2017) (with comparable model sizes and number of training steps).

3 Brittleness to Architectural Choices

The need to have a relatively stable DEQ in order to train it via the implicit function theorem also calls for more careful attention in designing the layer fθf_{\theta}. For example, the largest-scale DEQs (Bai et al. 2019; Bai et al. 2020) all had normalizations (Ba et al. 2016; Wu & He 2018) at the end of the layer to constrain the output range. How important are these architectural choices? We demonstrate the brittleness of DEQs by ablative studies on the use of layer normalization (LN) or weight normalization (WN) in the DEQ-Transformer model on the large-scale WikiText-103 language modeling task. Specifically, we compare the use of the two most popular Transformer layer designs in the DEQ framework: pre-LN and post-LN, which simply inserts the LN layers at different parts of the block (see Figure 2). These two settings have been extensively studied, used, and compared in the literature (Liu et al. 2020; Xiong et al. 2020; Vaswani et al. 2017; Baevski & Auli 2019; Dosovitskiy et al. 2020).

The result is shown in Figure 3. Without layer normalization at the end (magenta line), the DEQ quickly diverges after 25K training iterations (reflected in both forward and backward divergences). Similarly, without weight normalization (orange line), the model becomes unstable more quickly, with fixed-point solver collapse at around 18K iterations. The original DEQ-Transformer (Bai et al. 2019) (blue line in Figure 3), although not diverged, still suffers from the same increased instability problem as described in Section 3.1. These plots are strong indicators that while equilibrium networks work on large scales, they are also relatively inflexible, brittle, and reliant on meticulous architectural designs.

4 The Hidden Cost of the Choice of Solver

Although DEQ models enjoy constant memory consumption during training time and can use any black-box fixed point solvers in the forward and backward passes, a commonly neglected cost is that introduced by the choice of solver. For example, in Broyden’s method (Broyden 1965) which Bai et al. 2019; Bai et al. 2020 used, the inverse Jacobian J−1J^{-1} is approximated by low-rank updates of the form J−1≈−I+∑i=1nu[n]v[n]⊤=−I+UV⊤{J^{-1}\approx-I+\sum_{i=1}^{n}\mathbf{u}^{[n]}{\mathbf{v}^{[n]}}^{\top}=-I+UV^{\top}}. As another example, Anderson mixing (Anderson 1965) stores and uses the past mm iterations (z[n−1],…,z[n−m])(\mathbf{z}^{[n-1]},\dots,\mathbf{z}^{[n-m]}). In most such cases, even storing these updates or past steps can be expensive. Moreover, since we depend on the same DEQ solvers also at inference time, we need to spend this same memory cost even when when the trained model is served – which conventional deep networks can avoid. We note that this cost depends strongly on the solver; for example, the simplest iterative “solver” z[i+1]=fθ(z[i];x)\mathbf{z}^{[i+1]}=f_{\theta}(\mathbf{z}^{[i]};\mathbf{x}) wouldn’t have any memory cost, but suffers from bad convergence. This issue also highlights the value of faster and stabler convergence, which entails less memory storage overall (e.g., fewer Broyden steps).

Regularizing the Jacobian of DEQs

We hypothesize that one of the fundamental factors contributing to some of the problems discussed in Section 3 is that DEQ models’ conditioning is not properly regularized during training. Such trend for DEQ models to go unstable is reflected in Figures 1(a) and 1(b), where increasing training steps leads to monotonically growing residual difference and the Jacobian norm at the equilibrium. We now describe how the Jacobian is related to the stability of equilibrium networks’ forward and backward passes, and then harness this relationship to stabilize and accelerate DEQs.

We first recall that the forward pass of a DEQ network aims to solve for the fixed-point representation z⋆\mathbf{z}^{\star} of a layer fθ(⋅;x)f_{\theta}(\cdot;\mathbf{x}); i.e., z⋆=fθ(z⋆)\mathbf{z}^{\star}=f_{\theta}(\mathbf{z}^{\star}). Then in the backward pass, one can differentiate directly through the equilibrium z⋆\mathbf{z}^{\star} by

However, because the scale of JfθJ_{f_{\theta}} can be prohibitively large and the inverse is costly to compute, we usually compute the u⊤\mathbf{u}^{\top} term in Eq. 1 by solving the following linear fixed-point system that depends on the final Jacobian:

2 Jacobian Regularization

These connections between Jfθ(z⋆)J_{f_{\theta}}(\mathbf{z}^{\star}) (which characterizes the shape of the transformation fθf_{\theta} around z⋆\mathbf{z}^{\star}) and the forward/backward pass dynamics of DEQs motivate us to append a soft and auxiliary Jacobian term ρ(Jfθ(z⋆))\rho(J_{f_{\theta}}(\mathbf{z}^{\star})) to the training objective in order to regularize the model’s conditioning. One way of doing this is by spectral normalization, essentially constraining σ(Jfθ)=max⁡∥v∥≤1∥Jfθv∥2\sigma(J_{f_{\theta}})=\max_{\|\mathbf{v}\|\leq 1}\|J_{f_{\theta}}\mathbf{v}\|_{2}. However, explicitly writing out the huge Jacobian and then decomposing it (e.g., by SVD) can be computationally prohibitive, and Miyato et al. 2018 proposes to use the power method (von Mises & Pollaczek-Geiringer 1929) to speed up this estimation on GANs. But in the context of DEQs, even power iterations are too expensive due to the successive vector-Jacobian product computations needed. Instead, we propose to regularize the Jacobian through its Frobenius norm since

Indeed, empirically, we find that M=1M=1 already works well since we use relatively large batch sizes. Since our backward iterations already involved computing multiple vector-Jacobian products u⊤Jfθ\mathbf{u}^{\top}J_{f_{\theta}} (see Eq. (2)), computing Eq. (3) only adds a cost equivalent to that of M=1M=1 backward steps. The eventual training objective is thus

As we observed in Figure 1(a), without regularization, a DEQ model that stops after a fixed number TT of solver iterations exhibits increasingly poor convergence, accompanied by a growing ∥Jfθ∥F\|J_{f_{\theta}}\|_{F} at these fixed points that empirically signals the growing instability. Therefore, by constraining the Jacobian’s Frobenius norm, we encourage DEQs to optimize for stabler and simpler dynamics whose fixed points are easier to solve for.

3 Memory Considerations

Although the loss objective (4) only adds minimal computation cost, the need to backpropate through ∥ϵ⊤Jfθ∥22\|\epsilon^{\top}J_{f_{\theta}}\|_{2}^{2} means we also spend more memory during training to store the computation graph of this vector-Jacobian product. But at the same time, our hidden memory cost due to the solver choice is smaller (e.g., Broyden’s method; see Section 3.4) as we can lower the number of iterations. As a result, empirically we notice a roughly 30% net growth in memory consumption compared to the unregularized DEQs at training (and thus saving about 50% memory compared to explicit deep networks). The regularized DEQ still consumes O(1)O(1) memory relative to the “depth” of the model, as the backpropagation depends only on z⋆\mathbf{z}^{\star}.

Experiments

We validate the proposed regularization of DEQ models on multiple fronts. First, we visualize the effect of the proposed Jacobian regularization on a tiny DEQ trained on a synthetic 1D dataset. Second, importantly, we focus on how our method alleviates some of the core problems with DEQs outlined in Section 3. Then we show that our method scales to challenging high-dimensional tasks: word-level language modeling with the WikiText-103 dataset (Merity et al. 2017) and image classification with CIFAR-10 and ImageNet (Deng et al. 2009). We specifically compare our model with both prior DEQ networks and competitive explicit models (e.g., ResNet-101, Transformers), in terms of both efficiency (in space and time) and performance. We also explore how Jacobian regularization helps stabilize DEQs over a wider range of architectural choices. Lastly, we perform some ablative studies.

The set of tasks used in our experiment is built directly on top of Bai et al. 2019; Bai et al. 2020. As we found the Jacoabian regularization could sometimes hurt performance (see Sec. 5.3), we only apply the proposed loss stochastically with a probability pp, and gradually increase this pp or the regularization strength γ\gamma (see Eq. (4)) over training steps. We also use cosine learning rate schedule (Loshchilov & Hutter 2017) for all tasks, including the synthetic one. The memory and speeds reported are benchmarked across different models on the same setting (e.g., same batch size, sequence length, number of steps, etc.) with the same GPU. We provide more details regarding the tasks, hyperparameters, datasets, and hardware in Appendix A, and extra experimental results in Appendix B. Our code and pretrained models are provided here.

We start by empirically verifying the validity of the approach and visualizing its effect on a synthetic dataset. We generated 5096 scalar data pairs (x,y)(x,y) using function y=h(x)=32x3+x2−5x+2sin⁡(x)−3+δy=h(x)=\frac{3}{2}x^{3}+x^{2}-5x+2\sin(x)-3+\delta (where δ∈N(0,0.05)\delta\in\mathcal{N}(0,0.05)), and split them into 4096 and 1000 training and validation samples, respectively. We then train a tiny DEQ with 200 parameters with the following structure:

2 WikiText-103 Language Modeling

One of the very first successes of large-scale DEQs was its Transformer instantiation (Bai et al. 2019), which uses a multi-head self-attention (Vaswani et al. 2017) layer as the underlying fθ(z;x)f_{\theta}(\mathbf{z};\mathbf{x}) function. Although a DEQ-Transformer is able to perform competitively with a deep Transformer-XL (Dai et al. 2019) in terms of test perplexity, and consumes 60-70% less memory, it is also much slower (about 3×3\times; see Figure 1(c)) and borders on instability. In Table 1, we demonstrate how the Jacobian regularization alleviates this. Compared to the original DEQ models, there are two major improvements. First, we significantly reduce the NFEs required for DEQ-Transformer models while maintaining competitive accuracy. Using the Transformer-XL as a time benchmark (1×1\times), the speed of a DEQ-Transformer is significantly accelerated: training time goes from 3.1×3.1\times to 1.5×1.5\times. Second, the regularized DEQ model is more flexible with architectural choices. Whereas a Pre-LN DEQ-Transformer (see Figure 2) quickly diverges in training even in the presence of a large NFE threshold, the Jacobian regularization resolves this issue and stabilizes the forward/backward convergences consistently (see Figure 3 and Table 1), eventually reaching 24.5 perplexity. Moreover, while we can early-stop a well-trained unregularized DEQ model at inference time, it hurts generalization performance significantly (e.g., 29.2 ppl with 12 NFEs). Similarly, we find training with NFEs <30<30 leads to increasingly bad generalization performance, and when NFEs drops below 2020, model training frequently diverge as a result of extremely noisy gradients. We provide more comprehensive results in Table 5 in the Appendix.

Like DEQs, the regularized DEQs are memory efficient, consuming about 45% less training memory than Transformer-XL. Moreover, we find the Jacobian-regularized DEQs reduce over 50% memory consumption of the original DEQs at inference time (when both using Broyden’s method) due to faster/stabler convergence, suggesting its effectiveness in addressing the hidden solver cost issue discussed in Sec. 3.4.

3 CIFAR-10 and ImageNet Classification

We additionally conduct experiments on vision tasks using the recent multiscale deep equilibrium networks (MDEQ) (Bai et al. 2020), which drive multiple feature resolutions to their equilibria simultaneously. Because of the need to maintain high- and low-resolutional feature maps at all iterative steps and generally higher channel dimensions in fθf_{\theta}, MDEQs are substantially slower than conventional networks like ResNets (which operate on progressively downsampled feature maps). This makes acceleration vital to broader adoption of multiscale implicit models.

The results of applying Jacobian regularization on multiscale DEQs for image classification are shown in Table 2. On CIFAR-10, whereas the unregularized DEQ models used 17 NFEs to reach the reported competitive level of performance, our DEQ with Jacobian regularization can converge well even within 6 iterations (in fact, we find smaller NFE values still trains, but significantly hurts generalization performance). This improvement is also obvious in Figure 1(a) and 1(b), where we show that early stopping at threshold T=6T=6 still yields good convergence with Jacobian regularization. We also demonstrate a more stable backward pass convergence throughout training in Appendix B. On the much larger-scale ImageNet, where we deal with 224×224224\times 224 images, the factor of reduction in NFE is not as strong (e.g., from 27 to 14 iterations, due to the receptive field issue; we’ll explain this in Section 5.5) but still yields a roughly 2×2\times acceleration. This shows that the Jacobian regularization is effective in large-scale computer vision tasks, and in the presence of multiple equilibrium points. However, we also note that as with DEQ-Transformers on WikiText-103, we notice a small slip in accuracy, which may be a result of constraining model parameterizations.

Figure 6 provides a visual comparison of different models with respect to three metrics: performance, inference speed, and training memory. These are reported on the CIFAR-10 dataset. For the first time, we have an implicit-depth model that runs with a competitive level of speed and accuracy as large explicit networks such as ResNet-101, while consuming much less memory.

4 Effect of Jacobian Regularization on ρ⁡(Jfθ)\rho(J_{f_{\theta}})

In addition to the synthetic study, we also verify that the Jacobian regularization is indeed effectively constraining conditioning of JfθJ_{f_{\theta}}. Note that the underlying Jacobian matrices are large (e.g., [(B⋅B\cdot110K) ×\times (B⋅B\cdot110K)] in WikiText-103, and [(B⋅B\cdot198K) ×\times (B⋅B\cdot198K)] in ImageNet with MDEQ-small) and checking their full spectrum would be infeasible. Therefore, we conduct a study that monitors the average spectral radius ρ(Jfθ(z⋆))\rho(J_{f_{\theta}}(\mathbf{z}^{\star})) (i.e., the largest absolute eigenvalue) on the validation set, over the first 100K steps of DEQ training on WikiText-103 using the power method (von Mises & Pollaczek-Geiringer 1929); see Fig. 7. Importantly, although ∥Jfθ∥F\|J_{f_{\theta}}\|_{F} only upper-bounds the spectral radius (see Sec. 4.2), we verify that our proposed regularization does effectively constrain ρ(Jfθ)\rho(J_{f_{\theta}}) (see / paths in Fig. 7), thereby making DEQs more stable. In contrast, the unregularized DEQ with the same few NFEs explodes in both eigenvalue and shortly after also in perplexity (see / paths), and only works if we increase NFE to 30 (see ×\times/×\times paths). In general, we empirically observe that training an unregularized DEQ with insufficient NFEs generally begets extremely noisy gradients, thus leading to faster destabilization and even divergence.

5 Ablative Analysis and Limitations of the Approach

We continue our discussion with some empirical ablative studies. First, while Grathwohl et al. 2019 found weight decay useful for regularizing ODE-based models’ NFEs, we found weight decay generally not effective in stabilizing DEQs and sometimes even counter-productive. This is illustrated in Figure 8, where after 50K steps the model started to diverge to >500>500 perplexity and stopped improving. In addition, we also conduct an ablative experiment on how the Jacobian regularization strength γ\gamma affects the performance when we constrain NFEs to ≤6\leq 6 at inference time, with results shown in Table 3 (CIFAR-10 dataset). In general, we find that if γ\gamma is too small, the final performance may be good but entails more NFEs. When γ\gamma is too large, the accuracy does quickly converge, but the constraint imposed on the model class is too strong and eventually hurts performance (e.g., since the training loss on CIFAR-10 usually overfits to almost 0 towards the end of training, which makes the Jacobian loss dominant instead).

We also highlight two limitations of this approach. First, the addition of Jacobian regularization term does not fundamentally solve the growing instability problem, but only empirically alleviates it. This means that we have to be careful about balancing the main loss objective and this auxiliary objective (see Table 3). Second, while Jacobian regularization facilitates faster convergence, there are certain “physical laws” that we simply cannot bypass. For example, if we apply a shallow convolutional DEQ whose layer has receptive field 5×55\times 5 on a large image (e.g., 1024×10241024\times 1024), it is hard to be able to reach the fixed point with just 6 iterations simply because the model’s receptive field may not broaden sufficiently to cover valuable context. Although one can possibly still force convergence with a large γ\gamma, it would undoubtedly hurt the performance. This explains why we need more NFEs on ImageNet than on CIFAR-10 (see Table 2); it also indicates that while our approach alleviates the brittleness to architectural choices, its effectiveness can still depend on the architecture. This makes global-context alternatives to ConvNets, such as self-attention-based vision layers (e.g.,ViT (Dosovitskiy et al. 2020)) likely more appealing in the implicit model setting, which we leave for future work.

Conclusion

We summarized the weaknesses of existing DEQ models, including instability & inefficiency, architectural brittleness, and hidden memory costs. We specifically discussed the relationship between the spectral radius of the Jacobian and the stability of forward non-linear and backward linear systems of DEQ models, and provided empirical evidence of the poor conditioning of the Jacobian. This motivates our introduction of Jacobian regularization. Our experiments show that our method significantly alleviates the weaknesses of DEQs, yielding a >2.5×>2.5\times acceleration. This is a major step towards making implicit models more practical and suitable for large-scale real-world applications. We hope that our work will motivate further research that advances our understanding and application of this class of models.

References

Appendix A Dataset Information, Experimental Settings and Hyperparameters

We provide below a detailed description of all tasks and settings for experiments reported in Section 5, as well as some training specifics of the deep equilibrium network (DEQs) we use.

To visualize the effect of the proposed Jacobian regularization on DEQ models (see Section 5), we generated a synthetic dataset with 5096 pairs (x,y)(x,y) from the target function:

where δ∈N(0,0.05)\delta\in\mathcal{N}(0,0.05) are i.i.d. noise variables added to

each sample in the dataset. Specifically, we split the generated data into 4096 training samples and 1000 validation samples.

Figure 9 shows the target function. In the context of deep equilibrium networks, we aim to learn a function z⋆(x)z^{\star}(x) such that z⋆=fθ(z⋆;x)z^{\star}=f_{\theta}(z^{\star};x) and z⋆(x)≈h(x)z^{\star}(x)\approx h(x). At a high level, we should expect the intersection between the zout=fθ(z;x)z_{\text{out}}=f_{\theta}(z;x) surface and the zout=zz_{\text{out}}=z plane to be exactly like the gray curve in Figure 9.

The learned DEQ equilibria z⋆(x)z^{\star}(x) are empirically demonstrated in Figure 5 in red dashed lines for different choices of γ\gamma. As expected, all γ\gamma fit the target function perfectly, but the introduction of the Jacobian regularization makes the surface more flat around the fixed point.

A.2 WikiText-103 Word-level Language Modeling

A commonly used large-scale corpus for this task is the WikiText-103 (Merity et al. 2017) dataset, which contains 103M/217K/246K words at train/validation/test time, respectively. The entire corpus has a vocabulary size of 267K (i.e., the number of rows in the word embedding). Unlike other well-processed, much smaller datasets like Penn Treebank (Marcus et al. 1993), WikiText-103 is much more challenging as it contains many rare words and retains punctuations, numbers, upper- and lower-cases from the source Wikipedia articles; it has been the standard benchmark for many high-capacity language models in recent literature (Merity et al. 2018; Bradbury et al. 2017; Dai et al. 2019). We provide a shell script in our submitted code to download this dataset. Officially, this dataset can be downloaded at this link.

A.3 CIFAR-10 & ImageNet Image Classification

The CIFAR-10 (Krizhevsky & Hinton 2009) dataset contains 60,000 color images of resolution 32×3232\times 32 that fall into 10 object classes (with uniformly 6,000 images per class). We use the standard setting where 50K of these images are used for training and the rest 10K for validation purpose.

The ImageNet (Krizhevsky et al. 2012) dataset, on the other hand, contains over 1.28M training images and 150K test images, distributed over 1,000 classes. All images are re-scaled to 224×244224\times 244 resolution before they are fed into the models (as the original images are of variable resolutions and scales). This is a frequently used dataset for evaluating large-scale vision networks, and has been used for also pretraining many image feature extractor for use on downstream tasks.

For both CIFAR-10 and ImageNet, each training image goes through a canonical data augmentation process before they are fed into the model, where we perform random cropping and random horizontal flipping.

A.4 Training Setting and Hardware

Our experimental protocols are intentionally set to be maximally consistent with prior work (Bai et al. 2019; Bai et al. 2020). This includes hyperparameters (see the subsection below), other regularization methods (e.g., recurrent dropout (Gal & Ghahramani 2016) & group normalization (Wu & He 2018)), and initialization schemes (where all parameters are initialized at the start of training by sampling from N(0,0.01)\mathcal{N}(0,0.01)). For the multiscale DEQs that were used in the image classification task, we used 4 resolutions, where each subsequent resolution is of exactly half the height and width of the previous resolution. Although Bai et al. 2020 highlighted the need to train a ReLU-based network with softplus for stability purposes, we found it not necessary in our experiments with regularized DEQs, most likely because of the role Jacobian regularization plays in stabilizing the network convergence.

One thing to note is that empirically, rather than applying the proposed Jacobian regularization on all training iterations, we only randomly and partially apply this auxiliary loss. For example, when we set the auxiliary loss frequency pp to 0.5, only half of the training iterations (randomly selected) are trained with the Jacobian regularization term (see Table 4). This is motivated by the empirical observation that Jacobian-related regularizations usually hurt performance, e.g., as in its application in robust learning (Hoffman et al. 2019). Therefore, such partial/random supervision with the Jacobian regularization brings two benefits: 1) the rest (1−p)(1-p)-portion of the training iterations can pick up a further speedup as we don’t need to compute the Hutchinson estimator and backpropagate through it; and 2) it helps reduce the likelihood of the model overfitting on this auxiliary loss term (since, as we noted in Section 5.5, the model could be sensitive to γ\gamma, and MM is small), which we generally observe to benefit the performance, though only slightly. Therefore, during training, the model would still proceed in the actual stochastic gradient direction, and only use the regularized direction occasionally.

Formally, the training objective we highlighted in Section 4.2 should be:

where τ=Bernoulli(p)\tau=\text{Bernoulli}(p) is a random variable and MM is the number of samples used for Hutchinson estimator.

All experiments in this paper, including the speed and memory benchmarks we provide, were conducted on RTX 2080 Ti GPUs. WikiText-103 language modeling and ImageNet classification models (MDEQ-small) were trained with 4 GPUs in a data-parallel setting.

A.5 Hyperparameters

We report the hyperparameters used at training time in Table 4. Except for those used in the synthetic data and for Jacobian regularization, most of the other hyperparameters were essentially taken from the original DEQ-Transformer (Bai et al. 2019) and MDEQ (Bai et al. 2020) without major modifications. For both Anderson and Broyden fixed-point solvers, we use the relative residual ∥fθ(z;x)−z∥∥fθ(z;x)∥\frac{\|f_{\theta}(\mathbf{z};\mathbf{x})-\mathbf{z}\|}{\|f_{\theta}(\mathbf{z};\mathbf{x})\|} as a measure of convergence quality in forward and backward passes. At inference time, we generally reduce the number of NFEs (e.g., cf. Table 4 and Table 1), while the other hyperparameters (e.g., GroupNorm group sizes) are kept the same.

Appendix B Additional Experimental Results

As we noted in Sections 4 and 5, using Jacobian regularization and thus the vector-Jacobian-product-based Hutchinson estimator introduces some extra memory cost at training time due to the need to differentiate w.r.t. the ∥Jfθ∥F\|J_{f_{\theta}}\|_{F} term. Overall, with the same batch size and sequence length, we observe a roughly 25%25\% increase in training memory required (from about 3.9GB to 4.8GB, excluding embeddings). This is less than the memory consumption of a layer, because the reduction in NFEs needed on the other side saves the memory used by the solver (see Section 3.4). However, this memory footprint is still much better than the conventional explicit Transformer-XL model, which consumes about 2×2\times as much GPU memory. With the Jacobian regularization, as we can see, the DEQ models are much more efficient in time complexity than before, while still staying competitive on the space complexity and the performance fronts.

B.2 DEQ’s Backward Convergence with Jacobian Regularization (CIFAR-10)

As we discussed in Section 4, the backward dynamics of a DEQ model is a linear fixed point system that depends directly on the Jacobian at equilibrium (i.e., Jfθ(z⋆)J_{f_{\theta}}(\mathbf{z}^{\star})). Therefore, the backward pass stability is directly influenced by the conditioning of the Jacobian that we regularize. The stabilizing effect of the proposed Jacobian regularization on the backward pass convergence was already shown for WikiText-103 language modeling in Figure 3(b), where we empirically observe that the Jacobian-regularized DEQ-Transformer’s backward pass stays at a consistent level, which indicates a relatively more accurate gradient produced by the implicit function theorem.

We further corroborate this finding via empirical evidence on the CIFAR-10 dataset with a multiscale DEQ (MDEQ) instance, shown in Figure 10(a). Compared to the original MDEQ (blue line), the Jacobian-regularized version of the backward pass experiences much fewer fluctuations (and thus less stochastic gradients). We also compared to an alternative solution that uses the simple weight decay. Although it also alleviates the fluctuation problem, our empirical observations suggest that weight decay alone almost always adds more difficulty to the fixed point solving. This agrees with what we have observed in the forward pass in Section 5.5. Such comparison can be seen in Figure 10(a) in the purple line, which converged even more poorly than the original baseline after 14 backward solver iterations (with relative residual >0.05>0.05 and increasing slowly over training). In contrast, the regularized backward pass is more smooth and stable (red line) throughout training (we used γ=0.5\gamma=0.5).

B.3 Failure of Weight Decay to Fix the Problem

This overall inability of weight decay alone to fix the DEQ stability issue (e.g., see Figures 8 and 10(a)), we believe, exactly suggests that there is a deeper implicitness property of the model that should be regularized than just the value of individual weights. As DEQ networks typically rely on a single fθf_{\theta} block, their complex non-linear structure makes their stability depend as much on the linear parts of fθf_{\theta} (which weight decay does regularize) as the non-linear parts (which weight decay does not directly regularize; e.g., self-attention in fθf_{\theta} if we use a Transformer layer). On the other hand, Jacobian regularization takes into account both parts as it tries to constrain the overall spectral radius of the matrix.

We also provide some additional analysis on how ∥Jfθ∥F\|J_{f_{\theta}}\|_{F} evolves during training in Figure 10(b) and 10(c). Specifically, even with weight decay, the convergence of DEQ-Transformer models can be quite bad (see purple dots in Figure 10(b)), with a clear correlation between the larger relative residual and larger ∥Jfθ∥F2\|J_{f_{\theta}}\|_{F}^{2}. Indeed, with a non-linear structure as complex as the multi-head self-attention, simply constraining the weights to be small is not sufficient to ensure well-conditioned Jacobians. Moreover, while the Jacobian regularization helps significantly stabilize the forward and backward convergence (see Figure 1(a), 10(a) and 3), we note that a regularized DEQ model still in fact gradually tends to “critical stability”. This can be seen in Figure 10(c), where the Jacobian norm grows slowly over training iterations (red line) for a fixed γ\gamma, though at a rate much slower than the unregularized and weight-decayed baselines. Therefore, as we indicated in Section 5.5, the proposed Jacobian regularization does not fundamentally fix the growing instability problem, but only alleviates it. This also calls for adaptive γ\gamma scheduling during training (which we adopt in a simple form in our implementation and leave more advanced schemes for future work).