C HARACTERIZING SIGNAL PROPAGATION TO CLOSE THE PERFORMANCE GAP IN UNNORMALIZED R ES N ETS
A BSTRACT
Batch Normalization is a key component in almost all state-of-the-art image classiﬁers, but it also introduces practical challenges: it breaks the independence between training examples within a batch, can incur compute and memory overhead, and often results in unexpected bugs.
Building on recent theoretical analyses of deep ResNets at initialization, we propose a simple set of analysis tools to characterize signal propagation on the forward pass, and leverage these tools to design highly performant ResNets without activation normalization layers.
Crucial to our success is an adapted version of the recently proposed Weight Standardization.
Our analysis tools show how this technique preserves the signal in networks with
ReLU or Swish activation functions by ensuring that the per-channel activation means do not grow with depth.
Across a range of FLOP budgets, our networks attain performance competitive with the state-of-the-art EfﬁcientNets on ImageNet.
Our code is available at http://dpmd.ai/nfnets .
I NTRODUCTION
BatchNorm has become a core computational primitive in deep learning (Ioffe & Szegedy, 2015), and it is used in almost all state-of-the-art image classiﬁers (Tan & Le, 2019; Wei et al., 2020).
A number of different beneﬁts of BatchNorm have been identiﬁed.
It smoothens the loss landscape (Santurkar et al., 2018), which allows training with larger learning rates (Bjorck et al., 2018), and the noise arising from the minibatch estimates of the batch statistics introduces implicit regularization (Luo et al., 2019).
Crucially, recent theoretical work (Balduzzi et al., 2017; De & Smith, 2020) has demonstrated that BatchNorm ensures good signal propagation at initialization in deep residual networks with identity skip connections (He et al., 2016b;a), and this beneﬁt has enabled practitioners to train deep ResNets with hundreds or even thousands of layers (Zhang et al., 2019).
However, BatchNorm also has many disadvantages.
Its behavior is strongly dependent on the batch size, performing poorly when the per device batch size is too small or too large (Hoffer et al., 2017), and it introduces a discrepancy between the behaviour of the model during training and at inference time.
BatchNorm also adds memory overhead (Rota Bul`o et al., 2018), and is a common source of implementation errors (Pham et al., 2019). In addition, it is often difﬁcult to replicate batch normalized models trained on different hardware.
A number of alternative normalization layers have been proposed (Ba et al., 2016; Wu & He, 2018), but typically these alternatives generalize poorly or introduce their own drawbacks, such as added compute costs at inference.
Another line of work has sought to eliminate layers which normalize hidden activations entirely.
A common trend is to initialize residual branches to output zeros (Goyal et al., 2017; Zhang et al., 2019;
De & Smith, 2020; Bachlechner et al., 2020), which ensures that the signal is dominated by the skip path early in training.
However while this strategy enables us to train deep ResNets with thousands of layers, it still degrades generalization when compared to well-tuned baselines (De & Smith, 2020).
These simple initialization strategies are also not applicable to more complicated architectures like
EfﬁcientNets (Tan & Le, 2019), the current state of the art on ImageNet (Russakovsky et al., 2015).
This work seeks to establish a general recipe for training deep ResNets without normalization layers, which achieve test accuracy competitive with the state of the art.
Our contributions are as follows:
• We introduce Signal Propagation Plots (SPPs): a simple set of visualizations which help us inspect signal propagation at initialization on the forward pass in deep residual networks.
Leveraging these SPPs, we show how to design unnormalized ResNets which are constrained to have signal propagation properties similar to batch-normalized ResNets.
• We identify a key failure mode in unnormalized ResNets with ReLU or Swish activations and Gaussian weights.
Because the mean output of these non-linearities is positive, the squared mean of the hidden activations on each channel grows rapidly as the network depth increases.
To resolve this, we propose Scaled Weight Standardization, a minor modiﬁcation of the recently proposed Weight Standardization (Qiao et al., 2019; Huang et al., 2017b), which prevents the growth in the mean signal, leading to a substantial boost in performance.
• We apply our normalization-free network structure in conjunction with Scaled Weight Standardization to ResNets on ImageNet, where we for the ﬁrst time attain performance which is comparable or better than batch-normalized ResNets on networks as deep as 288 layers.
Finally, we apply our normalization-free approach to the RegNet architecture (Radosavovic et al., 2020).
By combining this architecture with the compound scaling strategy proposed by Tan & Le (2019), we develop a class of models without normalization layers which are competitive with the current ImageNet state of the art across a range of FLOP budgets.
B ACKGROUND
Deep ResNets at initialization: The combination of BatchNorm (Ioffe & Szegedy, 2015) and skip connections (Srivastava et al., 2015; He et al., 2016a) has allowed practitioners to train deep ResNets with hundreds or thousands of layers.
To understand this effect, a number of papers have analyzed signal propagation in normalized ResNets at initialization (Balduzzi et al., 2017; Yang et al., 2019).
In a recent work, De & Smith (2020) showed that in normalized ResNets with Gaussian initialization, the activations on the (cid:96) th residual branch are suppressed by factor of O ( √ (cid:96) ) , relative to the scale of the activations on the skip path.
This biases the residual blocks in deep ResNets towards the identity function at initialization, ensuring well-behaved gradients.
In unnormalized networks, one can preserve this beneﬁt by introducing a learnable scalar at the end of each residual branch, initialized to zero (Zhang et al., 2019; De & Smith, 2020; Bachlechner et al., 2020).
This simple change is sufﬁcient to train deep ResNets with thousands of layers without normalization.
However, while this method is easy to implement and achieves excellent convergence on the training set, it still achieves lower test accuracies than normalized networks when compared to well-tuned baselines.
These insights from studies of batch-normalized ResNets are also supported by theoretical analyses of unnormalized networks (Taki, 2017; Yang & Schoenholz, 2017; Hanin & Rolnick, 2018; Qi et al., 2020).
These works suggest that, in ResNets with identity skip connections, if the signal does not explode on the forward pass, the gradients will neither explode nor vanish on the backward pass.
Hanin & Rolnick (2018) conclude that multiplying the hidden activations on the residual branch by a factor of O (1 /d ) or less, where d denotes the network depth, is sufﬁcient to ensure trainability at initialization.
Alternate normalizers: To counteract the limitations of BatchNorm in different situations, a range of alternative normalization schemes have been proposed, each operating on different components of the hidden activations.
These include LayerNorm (Ba et al., 2016), InstanceNorm (Ulyanov et al., 2016), GroupNorm (Wu & He, 2018), and many more (Huang et al., 2020).
While these alternatives remove the dependency on the batch size and typically work better than BatchNorm for very small batch sizes, they also introduce limitations of their own, such as introducing additional computational costs during inference time.
Furthermore for image classiﬁcation, these alternatives still tend to achieve lower test accuracies than well-tuned BatchNorm baselines.
As one exception, we note that the combination of GroupNorm with Weight Standardization (Qiao et al., 2019) was recently identiﬁed as a promising alternative to BatchNorm in ResNet-50 (Kolesnikov et al., 2019).
S IGNAL P ROPAGATION P LOTS
Although papers have recently theoretically analyzed signal propagation in ResNets (see Section 2), practitioners rarely empirically evaluate the scales of the hidden activations at different depths in- side a speciﬁc deep network when designing new models or proposing modiﬁcations to existing architectures.
By contrast, we have found that plotting the statistics of the hidden activations at different points inside a network, when conditioned on a batch of either random Gaussian inputs or real training examples, can be extremely beneﬁcial.
This practice both enables us to immediately detect hidden bugs in our implementation before launching an expensive training run destined to fail, and also allows us to identify surprising phenomena which might be challenging to derive from scratch.
We therefore propose to formalize this good practice by introducing Signal Propagation Plots (SPPs), a simple graphical method for visualizing signal propagation on the forward pass in deep ResNets.
We assume identity residual blocks of the form x (cid:96) +
= f (cid:96) ( x (cid:96) )
+ x (cid:96) , where x (cid:96) denotes the input to the (cid:96) th block and f (cid:96) denotes the function computed by the (cid:96) th residual branch.
We consider 4dimensional input and output tensors with dimensions denoted by NHWC , where N denotes the batch dimension, C denotes the channels, and H and W denote the two spatial dimensions.
To generate SPPs, we initialize a single set of weights according to the network initialization scheme, and then provide the network with a batch of input examples sampled from a unit Gaussian distribution.
Then, we plot the following hidden activation statistics at the output of each residual block:
• Average Channel Squared Mean, computed as the square of the mean across the NHW axes, and then averaged across the C axis.
In a network with good signal propagation, we would expect the mean activations on each channel, averaged across a batch of examples, to be close to zero.
Importantly, we note that it is necessary to measure the averaged squared value of the mean, since the means of different channels may have opposite signs.
• Average Channel Variance, computed by taking the channel variance across the NHW axes, and then averaging across the C axis.
We generally ﬁnd this to be the most informative measure of the signal magnitude, and to clearly show signal explosion or attenuation.
• Average Channel Variance on the end of the residual branch, before merging with the skip path.
This helps assess whether the layers on the residual branch are correctly initialized.
We explore several other possible choices of statistics one could measure in Appendix G, but we have found these three to be the most informative.
We also experiment with feeding the network real data samples instead of random noise, but ﬁnd that this step does not meaningfully affect the key trends.
We emphasize that SPPs do not capture every property of signal propagation, and they only consider the statistics of the forward pass.
Despite this simplicity, SPPs are surprisingly useful for analyzing deep ResNets in practice.
We speculate that this may be because in ResNets, as discussed in Section 2 (Taki, 2017; Yang & Schoenholz, 2017; Hanin & Rolnick, 2018), the backward pass will typically neither explode nor vanish so long as the signal on the forward pass is well behaved.
As an example, in Figure 1 we present the SPP for a 600-layer pre-activation ResNet (He et al., 2016a) 1 with BatchNorm, ReLU activations, and He initialization (He et al., 2015). We compare the standard BN-ReLU-Conv ordering to the less common ReLU-BN-Conv ordering.
Immediately, several key patterns emerge.
First, we note that the Average Channel Variance grows linearly with the depth in a given stage, and resets at each transition block to a ﬁxed value close to 1.
The linear growth arises because, at initialization, the variance of the activations satisfy Var( x (cid:96) +1 ) =
Var( x (cid:96) )
+ Var( f (cid:96) ( x (cid:96) )) , while BatchNorm ensures that the variance of the activations at the end of each residual branch is independent of depth (De & Smith, 2020).
The variance is reset at each transition block because in these blocks the skip connection is replaced by a convolution operating on a normalized input, undoing any signal growth on the skip path in the preceding blocks.
With the BN-ReLU-Conv ordering, the Average Squared Channel Means display similar behavior, growing linearly with depth between transition blocks.
This may seem surprising, since we expect
BatchNorm to center the activations.
However with this ordering the ﬁnal convolution on a residual branch receives a rectiﬁed input with positive mean.
As we show in the following section, this causes the outputs of the branch on any single channel to also have non-zero mean, and explains why Var( f (cid:96) ( x (cid:96) ))
≈ 0 .
68 for all depths (cid:96) .
Although this “mean-shift” is explicitly counteracted by the normalization layers in subsequent residual branches, it will have serious consequences when attempting to remove normalization layers, as discussed below.
In contrast, the ReLU-BN-Conv ordering trains equally stably while avoiding this mean-shift issue, with Var( f (cid:96) ( x (cid:96) ))
≈ 1 for all (cid:96) .
N ORMALIZER -F REE R ES N ETS (NF-R ES N ETS )
With SPPs in hand to aid our analysis, we now seek to develop ResNet variants without normalization layers, which have good signal propagation, are stable during training, and reach test accuracies competitive with batch-normalized ResNets.
We begin with two observations from Section 3.
First, for standard initializations, BatchNorm downscales the input to each residual block by a factor proportional to the standard deviation of the input signal (De & Smith, 2020).
Second, each residual block increases the variance of the signal by an approximately constant factor.
We propose to mimic this effect by using residual blocks of the form x (cid:96) +
= x (cid:96) + αf (cid:96) ( x (cid:96) /β
(cid:96) ) , where x (cid:96) denotes the input to the (cid:96) th residual block and f (cid:96) ( · ) denotes the (cid:96) th residual branch.
We design the network such that:
• f ( · ) , the function computed by the residual branch, is parameterized to be variance preserving at initialization, i
e., Var( f (cid:96) ( z )) =
Var( z ) for all (cid:96) .
This constraint enables us to reason about the signal growth in the network, and estimate the variances analytically.
• β (cid:96) is a ﬁxed scalar, chosen as (cid:112) Var( x (cid:96) ) , the expected empirical standard deviation of the activations x (cid:96) at initialization.
This ensures the input to f (cid:96) ( · ) has unit variance.
• α is a scalar hyperparameter which controls the rate of variance growth between blocks.
We compute the expected empirical variance at residual block (cid:96) analytically according to Var( x (cid:96) ) =
Var( x (cid:96) − 1 ) + α 2 , with an initial expected variance of Var( x 0 ) = 1 , and we set β (cid:96) =
(cid:112) Var( x (cid:96) ) .
A similar approach was proposed by Arpit et al.
(2016) for non-residual networks.
As noted in
Section 3, the signal variance in normalized ResNets is reset at each transition layer due to the shortcut convolution receiving a normalized input.
We mimic this reset by having the shortcut convolution in transition layers operate on ( x (cid:96) /β
(cid:96) ) rather than x (cid:96) , ensuring unit signal variance at the start of each stage ( Var( x (cid:96) +1 )
=
1 + α 2 following each transition layer).
For simplicity, we call residual networks employing this simple scaling strategy Normalizer-Free ResNets (NF-ResNets).
4. R E LU A CTIVATIONS I NDUCE M EAN S HIFTS
We plot the SPPs for Normalizer-Free ResNets (NF-ResNets) with α = 1 in Figure 2.
In green, we consider a NF-ResNet, which initializes the convolutions with Gaussian weights using He initialization (He et al., 2015).
Although one might expect this simple recipe to be sufﬁcient to achieve good signal propagation, we observe two unexpected features in practice.
First, the average value of the squared channel mean grows rapidly with depth, achieving large values which exceed the average channel variance.
This indicates a large “mean shift”, whereby the hidden activations for different training inputs (in this case different vectors sampled from the unit normal) are strongly correlated (Jacot et al., 2019; Ruff et al., 2019).
Second, as observed for BN-ReLU-Conv networks in Section 3, the scale of the empirical variances on the residual branch are consistently smaller than one.
To identify the origin of these effects, in Figure 7 (in Appendix F) we provide a similar SPP for a linearized version of ResNetV2-600 without ReLU activation functions.
When the ReLU activations are removed, the averaged squared channel means remain close to zero for all block depths, and the empirical variance on the residual branch ﬂuctuates around one.
This motivates the following question: why might ReLU activations cause the scale of the mean activations on a channel to grow?
To develop an intuition for this phenomenon, consider the transformation z
=
Wg ( x ) , where W is arbitrary and ﬁxed, and g ( · ) is an activation function that acts component-wise on iid inputs x such that g ( x ) is also iid.
Thus, g ( · ) can be any popular activation function like ReLU, tanh, SiLU, etc.
Let E ( g ( x i ))
= µ g and Var( g ( x i ))
=
σ 2 g for all dimensions i .
It is straightforward to show that the expected value and the variance of any single unit i of the output z i =
(cid:80) Nj W i,j g ( x j ) is given by:
[Equation]
where µ W i, · and σ W i, · are the mean and standard deviation of the i th row of W :
[Equation]
Now consider g ( · ) to be the ReLU activation function, i.e., g ( x ) = max( x, 0) .
Then g ( x ) ≥ 0 , which implies that the input to the linear layer has positive mean (ignoring the edge case when all inputs are less than or equal to zero).
In particular, notice that if x i ∼ N (0 , 1) for all i , then µ g = 1 / √ 2 π .
Since we know that µ g > 0 , if µ W i, · is also non-zero, then the output of the transformation, z i , will also exhibit a non-zero mean.
Crucially, even if we sample W from a distribution centred around zero, any speciﬁc weight matrix drawn from this distribution will almost surely have a non-zero empirical mean, and consequently the outputs of the residual branches on any speciﬁc channel will have non-zero mean values.
This simple NF-ResNet model with He-initialized weights is therefore often unstable, and it is increasingly difﬁcult to train as the depth increases.
4. S CALED W EIGHT S TANDARDIZATION
To prevent the emergence of a mean shift, and to ensure that the residual branch f (cid:96) ( · ) is variance preserving, we propose Scaled Weight Standardization, a minor modiﬁcation of the recently proposed Weight Standardization (Qiao et al., 2019) which is also closely related to Centered Weight Normalization (Huang et al., 2017b).
We re-parameterize the convolutional layers, by imposing,
[Equation]
where the mean µ and variance σ are computed across the fan-in extent of the convolutional ﬁlters.
We initialize the underlying parameters W from Gaussian weights, while γ is a ﬁxed constant.
As in Qiao et al.
(2019), we impose this constraint throughout training as a differentiable operation in the forward pass of the network.
Recalling equation 1, we can immediately see that the output of the transformation using Scaled WS, z
= ˆ
Wg ( x ) , has expected value E ( z i )
=
for all i , thus eliminating the mean shift.
Furthermore, the variance Var( z i ) =
γ 2 σ 2 g , meaning that for a correctly chosen γ , which depends on the non-linearity g , the layer will be variance preserving.
Scaled Weight Standardization is cheap during training and free at inference, scales well (with the number of parameters rather than activations), introduces no dependence between batch elements and no discrepancy in training and test behavior, and its implementation does not differ in distributed training.
These desirable properties make it a compelling alternative for replacing BatchNorm.
The SPP of a normalizer-free ResNet-600 employing Scaled WS is shown in Figure 2 in cyan.
As we can see, Scaled Weight Standardization eliminates the growth of the average channel squared mean at initialization.
Indeed, the SPPs are almost identical to the SPPs for a batch-normalized network employing the ReLU-BN-Conv ordering, shown in red.
Note that we select the constant γ to ensure that the channel variance on the residual branch is close to one (discussed further below).
The variance on the residual branch decays slightly near the end of the network due to zero padding.
4. D ETERMINING N ONLINEARITY -S PECIFIC C ONSTANTS γ
The ﬁnal ingredient we need is to determine the value of the gain γ , in order to ensure that the variances of the hidden activations on the residual branch are close to 1 at initialization.
Note that the value of γ will depend on the speciﬁc nonlinearity used in the network.
We derive the value of γ by assuming that the input x to the nonlinearity is sampled iid from N (0 , 1) .
For ReLU networks, this implies that the outputs g ( x ) = max( x, 0) will be sampled from the rectiﬁed Gaussian distribution with variance σ 2 g
= (1 / 2)(1 − (1 /π ))
(Arpit et al., 2016).
Since Var( ˆ Wg ( x ))
=
γ 2 σ 2 g , we set γ = 1 /σ g = √ 2 √ 1 − 1 π to ensure that Var( ˆ Wg ( x )) = 1 .
While the assumption x ∼ N (0 , 1) is not typically true unless the network width is large, we ﬁnd this approximation to work well in practice.
For simple nonlinearities like ReLU or tanh, the analytical variance of the non-linearity g ( x ) when x is drawn from the unit normal may be known or easy to derive.
For other nonlinearities, such as SiLU ((Elfwing et al., 2018; Hendrycks & Gimpel, 2016), recently popularized as Swish (Ramachandran et al., 2018)), analytically determining the variance can involve solving difﬁcult integrals, or may even not have an analytical form.
In practice, we ﬁnd that it is sufﬁcient to numerically approximate this value by the simple procedure of drawing many N dimensional vectors x from the Gaussian distribution, computing the empirical variance Var( g ( x )) for each vector, and taking the square root of the average of this empirical variance.
We provide an example in Appendix D showing how this can be accomplished for any nonlinearity with just a few lines of code and provide reference values.
4. O THER B UILDING B LOCKS AND R ELAXED C ONSTRAINTS
Our method generally requires that any additional operations used in a network maintain good signal propagation, which means many common building blocks must be modiﬁed.
As with selecting γ values, the necessary modiﬁcation can be determined analytically or empirically.
For example, the popular Squeeze-and-Excitation operation (S+E, Hu et al.
, y = sigmoid ( MLP ( pool ( h ))) ∗ h , involves multiplication by an activation in [0 , 1] , and will tend to attenuate the signal and make the model unstable.
This attenuation can clearly be seen in the SPP of a normalizer-free ResNet using these blocks (see Figure 9 in Appendix F).
If we examine this operation in isolation using our simple numerical procedure explained above, we ﬁnd that the expected variance is 0.5 (for unit normal inputs), indicating that we simply need to multiply the output by 2 to recover good signal propagation.
We empirically veriﬁed that this simple change is sufﬁcient to restore training stability.
In practice, we ﬁnd that either a similarly simple modiﬁcation to any given operation is sufﬁcient to maintain good signal propagation, or that the network is sufﬁciently robust to the degradation induced by the operation to train well without modiﬁcation.
We also explore the degree to which we can relax our constraints and still maintain stable training.
As an example of this, to recover some of the expressivity of a normal convolution, we introduce learnable afﬁne gains and biases to the
Scaled WS layer (the gain is applied to the weight, while the bias is added to the activation, as is typical).
While we could constrain these values to enforce good signal propagation by, for example, downscaling the output by a scalar proportional to the values of the gains, we ﬁnd that this is not necessary for stable training, and that stability is not impacted when these parameters vary freely.
Relatedly, we ﬁnd that using a learnable scalar multiplier at the end of the residual branch initialized to 0 (Goyal et al., 2017; De & Smith, 2020) helps when training networks over 150 layers, even if we ignore this modiﬁcation when computing β (cid:96) .
In our ﬁnal models, we employ several such relaxations without loss of training stability.
We provide detailed explanations for each operation and any modiﬁcations we make in Appendix C (also detailed in our model code in Appendix D).
4. S UMMARY
In summary [Table] the core recipe for a Normalizer-Free ResNet (NF-ResNet) is:
Compute and forward propagate the expected signal variance β 2 (cid:96) , which grows by α 2 after each residual block ( β 0 = 1 ).
Downscale the input to each residual branch by β (cid:96) .
Additionally, downscale the input to the convolution on the skip path in transition blocks by β (cid:96) , and reset β (cid:96) +
=
+ α 2 following a transition block.
Employ Scaled Weight Standardization in all convolutional layers, computing γ , the gain speciﬁc to the activation function g ( x ) , as the reciprocal of the expected standard deviation, 1 √ Var( g ( x )) , assuming x ∼ N (0 , 1) .
Code is provided in Appendix D for a reference Normalizer-Free Network.
E XPERIMENTS 5. A N EMPIRICAL EVALUATION ON R ES N ETS FixUp
[Table]
We begin by investigating the performance of Normalizer-Free pre-activation ResNets on the
ILSVRC dataset (Russakovsky et al., 2015), for which we compare our networks to FixUp initialization (Zhang et al., 2019), SkipInit (De & Smith, 2020), and batch-normalized ResNets.
We use a training setup based on Goyal et al.
(2017), and train our models using SGD (Robbins & Monro, 1951) with Nesterov’s Momentum (Nesterov, 1983; Sutskever et al., 2013) for 90 epochs with a batch size of 1024 and a learning rate which warms up from zero to 0.4 over the ﬁrst 5 epochs, then decays to zero using cosine annealing (Loshchilov & Hutter, 2017).
We employ standard baseline preprocessing (sampling and resizing distorted bounding boxes, along with random ﬂips), weight decay of 5e-5, and label smoothing of 0.1 (Szegedy et al., 2016).
For Normalizer-Free ResNets (NF-ResNets), we chose α = 0 .
2 based on a small sweep, and employ SkipInit as discussed above.
For both FixUp and SkipInit we had to reduce the learning rate to 0.2 to enable stable training.
We ﬁnd that without additional regularization, our NF-ResNets achieve higher training accuracies but lower test accuracies than their batch-normalized counterparts. This is likely caused by the known regularization effect of BatchNorm (Hoffer et al., 2017; Luo et al., 2019; De & Smith, 2020).
We therefore introduce stochastic depth (Huang et al., 2016) with a rate of 0.1, and Dropout (Srivastava et al., 2014) before the ﬁnal linear layer with a drop probability of 0.25.
We note that adding this same regularization does not substantially improve the performance of the normalized ResNets in our setup, suggesting that BatchNorm is indeed already providing some regularization beneﬁt.
In Table 1 we compare performance of our networks (NF-ResNets) against the baseline (BNResNets), across a wide range of network depths.
After introducing additional regularization, NFResNets achieve performance better than FixUp/SkipInit and competitive with BN across all network depths, with our regularized NF-ResNet-288 achieving top-1 accuracy of 79 .
However, some of the 288 layer normalizer-free models undergo training collapse at the chosen learning rate, [Table] but only when unregularized.
While we can remove this instability by reducing the learning rate to 0.2, this comes at the cost of test accuracy.
We investigate this failure mode in Appendix A.
One important limitation of BatchNorm is that its performance degrades when the per-device batch size is small (Hoffer et al., 2017; Wu & He, 2018).
To demonstrate that our normalizer-free models overcome this limitation, we train ResNet-50s on ImageNet using very small batch sizes of 8 and 4, and report the results in Table 2.
These models are trained for 15 epochs (4.8M and 2.4M training steps, respectively) with a learning rate of 0.025 for batch size 8 and 0.01 for batch size 4.
For comparison, we also include the accuracy obtained when training for 15 epochs at batch sizeand learning rate 0.4.
The NF-ResNet achieves signiﬁcantly better performance when the batch size is small, and is not affected by the shift from batch size 8 to 4, demonstrating the usefulness of our approach in the microbatch setting.
Note that we do not apply stochastic depth or dropout in these experiments, which may explain superior performance of the BN-ResNet at batch size 1024.
We also study the transferability of our learned representations to the downstream tasks of semantic segmentation and depth estimation, and present the results of these experiments in Appendix H.
5. D ESIGNING P ERFORMANT N ORMALIZER -F REE N ETWORKS
We now turn our attention to developing unnormalized networks which are competitive with the state-of-the-art EfﬁcientNet model family across a range of FLOP budgets (Tan & Le, 2019), We focus primarily on the small budget regime (EfﬁcientNets B0-B4), but also report results for B5 and hope to extend our investigation to larger variants in future work.
First, we apply Scaled WS and our
Normalizer-Free structure directly to the
EfﬁcientNet backbone.
2 While we succeed in training these networks stably without normalization, we ﬁnd that even after extensive tuning our NormalizerFree EfﬁcientNets still substantially underperform their batch-normalized baselines.
For example, our normalization free B0 variant achieves 73.5 % top-1, a 3.2 % absolute degradation relative to the baseline.
We hypothesize that this degradation arises because Weight Standardization imposes a very strong constraint on depth-wise convolutions (which have an input channel count of 1), and this constraint may remove a substantial fraction of the model expressivity.
To support this claim, we note that removing Scaled WS from the depth-wise convolutions improves the test accuracy of Normalizer-Free EfﬁcientNets, although this also reduces the training stability.
Therefore, to overcome the potentially poor interactions between Weight Standardization and depth-wise convolutions, we decided to instead study Normalizer-Free variants of the RegNet model family (Radosavovic et al., 2020).
RegNets are slightly modiﬁed variants of ResNeXts (Xie et al., 2017), developed via manual architecture search.
Crucially, RegNets employ grouped convolutions, which we anticipate are more compatible with Scaled WS than depth-wise convolutions, since the fraction of the degrees of freedom in the model weights remaining after the weight standardization operation is higher.
We develop a new base model by taking the 0.4B
FLOP RegNet variant, and making several minor architectural changes which cumulatively substantially improve the model performance.
We describe our ﬁnal model in full in Appendix C, however we emphasize that most of the architecture changes we introduce simply reﬂect well-known best practices from the literature (Tan & Le, 2019;
He et al., 2019). To assess the performance of our Normalizer-Free RegNets across a range of FLOPS budgets, we apply the EfﬁcientNet compound scaling approach (which increases the width, depth and input resolution in tandem according to a set of three power laws learned using architecture search) to obtain model variants at a range of approximate FLOPS targets.
Denoting these models NF-RegNets, we train variants B0-B5 (analogous to EfﬁcientNet variants) using both baseline preprocessing and combined CutMix (Yun et al., 2019) and MixUp (Zhang et al., 2018) augmentation. Note that we follow the same compound scaling hyper-parameters used by EfﬁcientNets, and do not retune these hyper-parameters on our own architecture.
We compare the test accuracies of EfﬁcientNets and NF-RegNets on ImageNet in Figure 3, and we provide the corresponding numerical values in Table 3 of Appendix A. We present a comparison of training speeds in Table 5 of Appendix A.
For each FLOPS and augmentation setting, NF-RegNets attain comparable but slightly lower test accuracies than EfﬁcientNets, while being substantially faster to train.
In the augmented setting, we report EfﬁcientNet results with AutoAugment (AA) or RandAugment (RA), (Cubuk et al., 2019; 2020), which we ﬁnd performs better than training EfﬁcientNets with CutMix+MixUp.
However, both AA and RA degrade the performance and stability of NF-RegNets, and hence we report results of NF-RegNets with CutMix+Mixup instead.
We hypothesize that this occurs because AA and RA were developed by applying architecture search on batch-normalized models, and that they may therefore change the statistics of the dataset in a way that negatively impacts signal propagation when normalization layers are removed.
To support this claim, we note that inserting a single BatchNorm layer after the ﬁrst convolution in an NF-RegNet removes these instabilities and enables us to train stably with either AA or RA, although this approach does not achieve higher test set accuracies.
These observations highlight that, although our models do beneﬁt from most of the architectural improvements and best practices which researchers have developed from the hundreds of thousands of device hours used while tuning batch-normalized models, there are certain aspects of existing state-of-the-art models, like AA and RA, which may implicitly rely on the presence of activation normalization layers in the network.
Furthermore there may be other components, like depth-wise convolutions, which are incompatible with promising new primitives like Weight Standardization.
It is therefore inevitable that some ﬁne-tuning and model development is necessary to achieve competitive accuracies when removing a component like batch normalization which is crucial to the performance of existing state-of-the-art networks. Our experiments conﬁrm for the ﬁrst time that it is possible to develop deep ResNets which do not require batch normalization or other activation normalization layers, and which not only train stably and achieve low training losses, but also attain test accuracy competitive with the current state of the art on a challenging benchmark like ImageNet.
C ONCLUSION
We introduce Normalizer-Free Networks, a simple approach for designing residual networks which do not require activation normalization layers.
Across a range of FLOP budgets, our models achieve performance competitive with the state-of-the-art EfﬁcientNets on ImageNet.
Meanwhile, our empirical analysis of signal propagation suggests that batch normalization resolves two key failure modes at initialization in deep ResNets.
First, it suppresses the scale of the hidden activations on the residual branch, preventing signal explosion.
Second, it prevents the mean squared scale of the activations on each channel from exceeding the variance of the activations between examples.
Our Normalizer-Free Networks were carefully designed to resolve both of these failure modes.
A CKNOWLEDGMENTS
We would like to thank Karen Simonyan for helpful discussions and guidance, as well as Guillaume
Desjardins, Michael Figurnov, Nikolay Savinov, Omar Rivasplata, Relja Arandjelovi´c and Rishub
Jain.
A PPENDIX A E XPERIMENT D ETAILS
[Table]
A. S TABILITY , L EARNING R ATES , AND B ATCH S IZES
Previous work (Goyal et al., 2017) has established a fairly robust linear relationship between the optimal learning rate (or highest stable learning rate) and batch size for Batch-Normalized ResNets.
As noted in Smith et al.
(2020), we also ﬁnd that this relationship breaks down past batch size 1024 for our unnormalized ResNets, as opposed to 2048 or 4096 for normalized ResNets.
Both the optimal learning rate and the highest stable learning rate decrease for higher batch sizes.
This also appears to correlate with depth: when not regularized, our deepest models are not always stable with a learning rate of 0.4.
While we can mitigate this collapse by reducing the learning rate for deeper nets, this introduces additional tuning expense and is clearly undesirable.
It is not presently clear why regularization aids in stability; we leave investigation of this phenomenon to future work.
Taking a closer look at collapsed networks, we ﬁnd that even though their outputs have exploded (becoming large enough to go NaN), their weight magnitudes are not especially large, even if we remove our relaxed afﬁne transforms and train networks whose layers are purely weight-standardized.
The singular values of the weights, however, end up poorly conditioned, meaning that the Lipschitz constant of the network can become quite large, an effect which Scaled WS does not prevent.
One might consider adopting one of the many techniques from the GAN literature to regularize or constrain this constant (Gulrajani et al., 2017; Miyato et al., 2018), but we have found that this added complexity and expense is not necessary to develop performant unnormalized networks.
This collapse highlights an important limitation of our approach, and of SPPs: as SPPs only show signal prop for a given state of a network (i.e., at initialization), no guarantees are provided far from initialization.
This fact drives us to prefer parameterizations like Scaled WS rather than solely relying on initialization strategies, and highlights that while good signal propagation is generally necessary for stable optimization, it is not always sufﬁcient.
A.
[Table] [Table]
We evaluate the relative training speed of our normalizer-free models against batch-normalized models by comparing training speed (measured as the number of training steps per second).
For comparing NF-RegNets against EfﬁcientNets, we measure using the EfﬁcientNet image sizes for each variant to employ comparable settings, but in practice we employ smaller image sizes so that our actual observed training speed for NF-RegNets is faster.
A PPENDIX B M ODIFIED B UILDING B LOCKS
In order to maintain good signal propagation in our Normalizer-Free models, we must ensure that any architectural modiﬁcations do not compromise our model’s conditioning, as we cannot rely on activation normalizers to automatically correct for such changes.
However, our models are not so fragile as to be unable to handle slight relaxations in this realm.
We leverage this robustness to improve model expressivity and to incorporate known best practices for model design.
B. A FFINE G AINS AND B IASES
First, we add afﬁne gains and biases to our network, similar to those used by activation normalizers.
These are applied as a vector gain, each element of which multiplies a given output unit of a reparameterized convolutional weight, and a vector bias, which is added to the output of each convolution.
We also experimented with using these as a separate afﬁne transform applied before the
ReLU, but moved the parameters next to the weight instead to enable constant-folding for inference.
As is common practice with normalizer parameters, we do not weight decay or otherwise regularize these weights.
Even though these parameters are allowed to vary freely, we do not ﬁnd that they are responsible for training instability, even in networks where we observe collapse.
Indeed, we ﬁnd that for settings which collapse (typically due to learning rates being too high), removing the afﬁne transform has no impact on stability.
As discussed in Appendix A, we observe that model instability arises as a result of the collapse of the spectra of the weights, rather than any consequence of the afﬁne gains and biases.
B. S TOCHASTIC D EPTH
We incorporate Stochastic Depth (Huang et al., 2016), where the output of the residual branch of a block is randomly set to zero during training.
This is often implemented such that if the block is kept, its value is divided by the keep probability.
We remove this rescaling factor to help maintain signal propagation when the signal is kept, but otherwise do not ﬁnd it necessary to modify this block.
While it is possible that we might have an example where many blocks are dropped and signals are attenuated, in practice we ﬁnd that, as with afﬁne gains, removing Stochastic Depth does not improve stability, and adding it does not reduce stability.
One might also consider a slightly more principled variant of Stochastic Depth in this context, where the skip connection is upscaled by 1+ α if the residual branch is dropped, resulting in the variance growing as expected, but we did not ﬁnd this strategy necessary.
B. S QUEEZE AND E XCITE L AYERS
As mentioned in Section 4.4, we incorporate Squeeze and Excitation layers (Hu et al., 2018), which we empirically ﬁnd to reduce signal magnitude by a factor of 0.5, which is simply corrected by multiplying by 2.
This was determined using a similar procedure to that used to ﬁnd γ values for a given nonlinearity, as demonstrated in Appendix D.
We validate this empirically by training NFRegNet models with unmodiﬁed S+E blocks, which do not train stably, and NF-RegNet models with the additional correcting factor of 2, which do train stably.
B. A VERAGE P OOLING
In line with best practices determined by He et al.
(2019), in our NF-RegNet models we replace the strided 1x1 convolutions with average pooling followed by 1x1 convolutions, a common alternative also employed in Zagoruyko & Komodakis (2016).
We found that average pooling with a kernel of size k × k tended to attenuate the signal by a factor of k , but that it was not necessary to apply any correction due to this.
While this will result in mis-estimation of β values at initialization, it does not harm training (and average pooling in fact improved results over strided 1x1 convolutions in every case we tried), so we simply include this operation as-is.
A PPENDIX C M ODEL D ETAILS
We develop the NF-RegNet architecture starting with a RegNetY-400MF architecture (Radosavovic et al.
a low-latency RegNet variant which also uses Squeeze+Excite blocks (Hu et al., 2018)) and uses grouped convolutions with a group width of 8.
Following EfﬁcientNets, we ﬁrst add an additional expansion convolution after the ﬁnal residual block, expanding to 1280 w channels, where w is a model width multiplier hyperparameter.
We ﬁnd this to be very important for performance: if the classiﬁer layer does not have access to a large enough feature basis, it will tend to underﬁt (as measured by higher training losses) and underperform.
We also experimented with adding an additional linear expansion layer after the global average pooling, but found this not to provide the same beneﬁt.
Next, we replace the strided 1x1 convolutions in transition layers with average pooling followed by 1x1 convolutions (following He et al.
(2019)), which we also ﬁnd to improve performance.
We switch from ReLU activations to SiLU activations (Elfwing et al., 2018; Hendrycks & Gimpel, 2016;
Ramachandran et al., 2018).
We ﬁnd that SiLU’s beneﬁts are only realized when used in conjunction with EMA (the model averaging we use, explained below), as in EfﬁcientNets.
The performance of the underlying weights does not seem to be affected by the difference in nonlinearities, so the improvement appears to come from SiLU apparently being more amenable to averaging.
We then tune the choice of width w and bottleneck ratio g by sweeping them on the 0.4B FLOP model.
Contrary to Radosavovic et al.
(2020) which found that inverted bottlenecks (Sandler et al., 2018) were not performant, we ﬁnd that inverted bottlenecks strongly outperformed their compressive bottleneck counterparts, and select w = 0 .
75 and g = 2 . 25 .
Following EfﬁcientNets
(Tan &
Le, 2019), the very ﬁrst residual block in a network uses g = 1 , a FLOP-reducing strategy that does not appear to harmfully impact performance.
We also modify the S+E layers to be wider by making their hidden channel width a function of the block’s expanded width, rather than the block’s input width (which is smaller in an inverted bottleneck).
This results in our models having higher parameter counts than their equivalent FLOP target EfﬁcientNets, but has minimal effect on FLOPS, while improving performance.
While both
FLOPS and parameter count play a part in the latency of a deployed model, (the quantity which is often most relevant in practice) neither are fully predictive of latency (Xiong et al., 2020).
We choose to focus on the FLOPS target instead of parameter count, as one can typically obtain large improvements in accuracy at a given parameter count by, for example, increasing the resolution of the input image, which will dramatically increase the FLOPS.
With our baseline model in hand, we apply the EfﬁcientNet compound scaling (increasing width, depth, and input image resolution) to obtain a family of models at approximately the same FLOP targets as each EfﬁcientNet variant.
We directly use the EfﬁcientNet width and depth multipliers for models B0 through B5, and tune the test image resolution to attain similar FLOP counts (although our models tend to have slightly higher FLOP budgets).
Again contrary to Radosavovic et al.
(2020), which scales models almost entirely by increasing width and group width, we ﬁnd that the EfﬁcientNet compound scaling works effectively as originally reported, particularly with respect to image size.
Improvements might be made by applying further architecture search, such as tuning the w and g values for each variant separately, or by choosing the group width separately for each variant.
Following Touvron et al.
(2019), we train on images of slightly lower resolution than we test on, primarily to reduce the resource costs of training.
We do not employ the ﬁne-tuning procedure of
Touvron et al.
The exact train and test image sizes we use are visible in our model code in
Appendix D.
We train using SGD with Nesterov Momentum, using a batch size of 1024 for 360 epochs, which is chosen to be in line with EfﬁcientNet’s schedule of 360 epoch training at batch size 4096.
We employ a 5 epoch warmup to a learning rate of 0.4 (Goyal et al., 2017), and cosine annealing to 0 over the remaining epochs (Loshchilov & Hutter, 2017).
As with EfﬁcientNets, we also take an exponential moving average of the weights (Polyak, 1964), using a decay of 0.99999 which employs a warmup schedule such that at iteration i , the decay is decay = min ( i, 1+ i 10+ i ) .
We choose a larger decay than the EfﬁcientNets value of 0.9999, as EfﬁcientNets also take an EMA of the running average statistics of the BatchNorm layers, resulting in a longer horizon for the averaged model.
As with EfﬁcientNets, we ﬁnd that some of our models attain their best performance before the end of training, but unlike EfﬁcientNets we do not employ early stopping, instead simply reporting performance at the end of training.
The source of this phenomenon is that as some models (particularly larger models) reach the end of their decay schedule, the rate of change of their weights slows, ultimately resulting in the averaged weights converging back towards the underlying (less performant) weights.
Future work in this area might consider examining the interaction between averaging and learning rate schedules.
Following EfﬁcientNets, we also use stochastic depth (modiﬁed to remove the rescaling by the keep rate, so as to better preserve signal) with a drop rate that scales from 0 to 0.1 with depth (reduced from the EfﬁcientNets value of 0.2).
We swept this value and found the model to not be especially sensitive to it as long as it was not chosen beyond 0.25.
We apply Dropout (Srivastava et al., 2014) to the ﬁnal pooled activations, using the same Dropout rates as EfﬁcientNets for each variant.
We also use label smoothing (Szegedy et al., 2016) of 0.1, and weight decay of 5e-5.
A PPENDIX D M ODEL C ODE
We here provide reference code using Numpy (Harris et al., 2020) and JAX (Bradbury et al., 2018).
Our full training code is publicly available at dpmd.ai/nfnets .
D. N UMERICAL A PPROXIMATIONS OF N ONLINEARITY - SPECIFIC G AINS
It is often faster to determine the nonlinearity-speciﬁc constants γ empirically, especially when the chosen activation functions are complex or difﬁcult to integrate.
One simple way to do this is for the SiLU function is to sample many (say, 1024) random C-dimensional vectors (of say size 256) and compute the average variance, which will allow for computing an estimate of the constant.
Empirically estimating constants to ensure good signal propagation in networks at initialization has previously been proposed in Mishkin & Matas (2016) and Kingma & Dhariwal (2018).
jax.numpy as jnp key =
jax.random.
PRNGKey(2)
# Arbitrary key # Produce a large batch of random noise vectors x = jax.random.normal(key, (1024, 256))
y =
jax.nn.silu(x) # Take the average variance of many random batches gamma = jnp.mean(jnp.var(y, axis=1))
[-[NFBlock(in_channels, block_width, stride=
-]
softmax.""" # Stem out = self.initial_conv(x)-]
A PPENDIX E O VERVIEW OF E XISTING B LOCKS
This appendix contains an overview of several different types of residual blocks
[Figure]
[Figure]
A PPENDIX F A DDITIONAL SPP S
In this appendix we include additional Signal Propagation Plots.
For reference, given an NHWC tensor, we compute the measured properties using the equivalent of the following Numpy (Harris et al., 2020) snippets:
• Average Channel Mean Squared: np.mean(np.mean(y, axis=[0, 1, 2])
** 2) • Average Channel Variance: np.mean(np.var(y, axis=[0, 1, 2]))
• Residual Average Channel Variance: np.mean(
[Figure] [Figure] f
[Figure] ), axis=[ [Figure] [Figure]
A PPENDIX G N EGATIVE R ESULTS G. F ORWARD M ODE VS D ECOUPLED WS
Parameterization methods like Weight Standardization (Qiao et al., 2019), Weight Normalization (Salimans & Kingma, 2016), and Spectral Normalization (Miyato et al., 2018) are typically proposed as “foward mode” modiﬁcations applied to parameters during the forward pass of a network.
This has two consequences: ﬁrst, this means that the gradients with respect to the underlying parameters are inﬂuenced by the parameterization, and that the weights which are optimized may differ substantially from the weights which are actually plugged into the network.
One alternative approach is to implement “decoupled” variants of these parameterizers, by applying them as a projection step in the optimizer.
For example, “Decoupled Weight Standardization” can be implemented atop any gradient based optimizer by replacing W with the normalized ˆ W after the update step.
Most papers proposing parameterizations (including the above) argue that the parameterization’s gradient inﬂuence is helpful for learning, but this is typically argued with respect to simply ignoring the parameterization during the backward pass, rather than with respect to a strategy such as this.
Using a Forward-Mode parameterization may result in interesting interactions with moving averages or weight decay.
For example, with WS, if one takes a moving average of the underlying weights, then applies the WS parameterization to the averaged weights, this will produce different results than if one took the EMA of the Weight-Standardized parameters.
Weight decay will have a similar phenomenon: if one is weight decaying a parameter which is actually a proxy for a weight-standardized parameter, how does this change the behavior of the regularization?
We experimented with Decoupled WS and found that it reduced sensitivity to weight decay (presumably because of the strength of the projection step) and often improved the accuracy of the EMA weights early in training, but ultimately led to worse performance than using the originally proposed “forward-mode” formulation.
We emphasize that our experiments in this regime were only cursory, and suggest that future work might seek to analyze these interactions in more depth.
We also tried applying Scaled WS as a regularizer (“Soft WS”) by penalizing the mean squared error between the parameter W and its Scaled WS parameterization, ˆ W .
We implemented this as a direct addition to the parameters following Loshchilov & Hutter (2019) rather than as a differentiated loss, with a scale hyperparameter controlling the strength of the regularization.
We found that this scale could not be meaningfully decreased from its maximal value without drastic training instability, indicating that relaxing the WS constraint is better done through other means, such as the afﬁne gains and biases we employ.
G. M ISCELLANEOUS
• For SPPs, we initially explored plotting activation mean ( np.mean(h) ) instead of the average squared channel mean, but found that this was less informative.
• We also initially explored plotting the average pixel norm: the Frobenius norm of each pixel (reduced across the C axis) then averaged across the NHW axis, np.mean(np.linalg.norm(h, axis=-1)) ).
We found that this value did not add any information not already contained in the channel or residual variance measures, and was harder to interpret due to it varying with the channel count.
• We explored NF-ResNet variants which maintained constant signal variance, rather than mimicking Batch-Normalized ResNets with signal growth + resets.
The ﬁrst of two key components in this approach was making use of “rescaled sum junctions,” where the sum junction in a residual block was rewritten to downscale the shortcut path as y
= α ∗ f ( x )+ x α which is approximately norm-preserving if f ( x ) is orthogonal to x (which we observed to generally hold in practice).
Instead of Scaled WS, this variant employed SeLU (Klambauer et al., 2017) activations, which we found to work as-advertised in encouraging centering and good scaling.
While these networks could be made to train stably, we found tuning them to be difﬁcult and were not able to easily recover the performance of BN-ResNets as we were with the approach ultimately presented in this paper.
A PPENDIX H E XPERIMENTS WITH A DDITIONAL T ASKS H. S EMANTIC S EGMENTATION ON P ASCAL VOC
[Table]
We present additional results investigating the transferability of our normalizer-free models to downstream tasks, beginning with the Pascal VOC Semantic Segmentation task.
We use the FCN architecture (Long et al., 2015) following He et al.
(2020) and Grill et al.
We take the ResNet backbones of each variant and modify the 3x3 convolutions in the ﬁnal stage to have dilation 2 and stride of 1, then add two extra 3x3 convolutions with dilation of 6, and a ﬁnal 1x1 convolution for classiﬁcation.
We train for 30000 steps at batch size 16 using SGD with Nesterov Momentum of 0.9, a learning rate of 0.003 which is reduced by a factor of 10 at 70% and 90% of training, and weight decay of 5e-5.
Training images are augmented with random scaling in the range [0.5, 2.0]), random horizontal ﬂips, and random crops.
Results in mean Intersection over Union (mIoU) are reported in Table 6 on the val2012 set using a single 513 pixel center crop.
We do not add any additional regularization such as stochastic depth or dropout.
NF-ResNets obtain comparable performance to their BN-ResNet counterparts across all variants.
H. D EPTH E STIMATION ON NYU D EPTH V
[Table]
We next present results for depth estimation on the NYU v2 dataset (Silberman et al., 2012) using the protocol from (Laina et al., 2016).
We downsample the images and center crop them to [304, 228] pixels, then randomly ﬂip and apply several color augmentations: grayscale with probability 30%, brightness with a maximum difference of 0.1255, saturation with a random factor picked from [0.5, 1.5], and Hue with adjustment factor picked in [-0.2, 0.2].
We take the features from the ﬁnal residual stage and feed them into the up-projection blocks from (Silberman et al., 2012), then train with a reverse Huber loss (Laina et al., 2016; Owen, 2007).
We train for 7500 steps at batch size 256 using SGD with Nesterov Momentum of 0.9, a learning rate of 0.16, and cosine annealing.
We report results in Table7 using ﬁve metrics commonly used for this task: the percentage of pixels where the magnitude of the relative error (taken as the ratio of the predicted depth and the ground truth, where the denominator is whichever is smaller) is below a certain threshold, as well as rootmean-squared and relative error (rms and rel).
As with semantic segmentation, we do not apply any additional regularization, and ﬁnd that our normalizer-free ResNets attain comparable performance across all model variants.