Back to paper library
Paper notesarXiv 2023CVPR 2023

FasterNet

FLOPs Lie

Original paper

Run, Don't Walk: Chasing Higher FLOPS for Faster Neural Networks

Paper authors

Jierun Chen · Shiu-hong Kao · Hao He …

Show all 7 authors

Jierun Chen · Shiu-hong Kao · Hao He · Weipeng Zhuo · Song Wen · Chul-Ho Lee · S.-H. Gary Chan

Publication
CVPR 2023Conference
First submitted to arXiv
arXiv:2303.03667
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@misc{lightweightfasternet2023,
  title = {{Run, Don't Walk: Chasing Higher FLOPS for Faster Neural Networks}},
  author = {Jierun Chen and Shiu-hong Kao and Hao He and Weipeng Zhuo and Song Wen and Chul-Ho Lee and S.-H. Gary Chan},
  year = {2023},
  eprint = {2303.03667},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2303.03667}
}
On this page

The number people designing lightweight networks look at most is FLOPs. From MobileNet to ShuffleNet to GhostNet, everyone did all they could to push the count of floating-point operations down, and the most common tools were depthwise convolution and grouped convolution.

But with fewer FLOPs, does a network necessarily run faster? Jierun Chen and colleagues at the Hong Kong University of Science and Technology measured a whole range of networks and found the answer is often no. CycleMLP-B1, for example, has only half the FLOPs of ResNet-50, yet it's slower on a CPU, 116.1 ms versus 73.0 ms. The paper's title, “Run, Don't Walk,” means that rather than saving steps, you're better off running faster.

Defining the Problem

Latency Is FLOPs Divided by FLOPS

These two words differ only in the case of one letter. FLOPs is the number of floating-point operations, while FLOPS is how many floating-point operations can be done per second, that is, the speed the hardware actually delivers. Latency is one divided by the other:

Latency=FLOPsFLOPS.\text{Latency}=\frac{\text{FLOPs}}{\text{FLOPS}} .

If you only push FLOPs down and FLOPS falls even further, latency actually gets longer. The authors measured a batch of common networks on an Intel CPU:

Two charts. (a) The horizontal axis is FLOPs (G) and the vertical axis is the actual FLOPS on CPU (G/s). FasterNet's orange stars are at the top, rising from about 37 all the way to 64; ResNet50 is a single point at about 56; PVT, PoolFormer, MobileViT, and EdgeNeXt fall roughly between 13 and 43; MobileNetV2, GhostNet, ShuffleNetV2, MobileFormer, and CycleMLP are mostly below 30, with MobileFormer and GhostNet the lowest, from single digits to the teens. (b) The horizontal axis is FLOPs and the vertical axis is CPU latency (ms), with the full range on the right and a zoom on the part below 1.8 GFLOPs on the left; at the same FLOPs, FasterNet's orange line is always at the bottom, and CycleMLP's two points are at the top, at about 116 and 186 ms
Figure 2 from the paper, excerpted from page 2 of the v3 PDF, CC BY 4.0. (a) FLOPS versus FLOPs on CPU; (b) CPU latency versus FLOPs.

The vertical axis of the left chart is how many operations are actually done per second. Many networks touted as fast have lower FLOPS than ResNet-50, leaving the hardware's compute unused.

ShuffleNet V2 already raised this in 2018, likewise pointing out that FLOPs and speed don't line up. Later lightweight networks kept using depthwise convolution anyway, because no better replacement had come along.

Why Depthwise Convolution Is Slow

Take an input feature map of c×h×wc\times h\times w and a 3×3 kernel with side length k=3k=3. Ordinary convolution has h×w×k2×c2h\times w\times k^2\times c^2 FLOPs. Depthwise convolution uses only each channel's own kernel, bringing FLOPs down to h×w×k2×ch\times w\times k^2\times c, cc times fewer.

The problem is that depthwise convolution only computes along the spatial dimensions, and used on its own it loses a lot of accuracy, so in practice the channel count always gets expanded; MobileNet-V2's inverted residual block expands it 6×. Once the channels go from cc to c′c', the memory access is

h×w×2c′+k2×c′≈h×w×2c′,h\times w\times 2c' + k^2\times c' \approx h\times w\times 2c' ,

one read of the input and one write of the output, nearly all of it spent moving feature maps around. Ordinary convolution's memory access is about h×w×2ch\times w\times 2c, which is actually less.

With little computation, lots of data movement, and only a few operations for every number moved, the hardware spends its time waiting on memory.

Solving the Problem

Partial Convolution (PConv)

The authors observe that the different channels of a feature map are often very similar. They plotted the feature maps of an intermediate layer of a pretrained ResNet-50, and many channels looked very much alike. With that much repetition, the spatial convolution doesn't have to be done on every channel.

Diagram of three kinds of convolution. (a) Ordinary convolution: a cuboid input is convolved with a full row of kernels, producing an output of the same size. (b) Depthwise or grouped convolution: the input is cut by dashed lines into many slices along the channel direction, each slice with its own small kernel. (c) Partial convolution: only a short stretch of channels at the front of the input is outlined with dashed lines and convolved with a few kernels, while the remaining channels are carried unchanged to the output along an arrow
Figure 1 from the paper, excerpted from page 1 of the v3 PDF, CC BY 4.0.

Partial Convolution (PConv) applies an ordinary 3×3 convolution only to the first cpc_p channels and copies the remaining channels straight to the output. Taking a contiguous stretch at the front keeps memory access contiguous. By default cp=c/4c_p = c/4, and the FLOPs are

h×w×k2×cp2,h\times w\times k^2\times c_p^2 ,

only 1/16 of ordinary convolution; the memory access is about h×w×2cph\times w\times 2c_p, 1/4 of ordinary convolution.

Fewer FLOPs do not automatically mean more speed. For a 192×28×28 input, an ordinary 3×3 convolution does 411 multiply-adds for every number it accesses, making the fullest use of the hardware; depthwise convolution does only 4.5 and spends most of its time waiting on memory; PConv convolves only a quarter of the channels and still does 169 multiply-adds per number accessed. In practice, depthwise convolution is usually preceded by widening the channels several times over, sixfold in MobileNet-V2, which adds memory access and pushes latency up.

The paper measured this on a 2080Ti, an i9-9900X and a Cortex-A72. Averaged over four feature-map sizes, PConv has 1/16 the FLOPs of ordinary convolution, and 10.5 times (GPU), 6.2 times (CPU) and 22.8 times (ARM) the FLOPS of depthwise convolution.

Followed by a 1×1 Convolution

PConv looks at only a quarter of the channels, so the rest of the information has to come from the 1×1 convolution that follows. Together, their receptive field looks like a T. The center position sees all the channels, while the eight surrounding positions see only cpc_p channels.

The authors used a pretrained ResNet-18 to check whether this shape makes sense. For each 3×3 kernel, they computed the weight magnitude at each of the nine positions and noted which one was largest. In all four stages, the position that was most often the largest was the center. The center matters more than its surroundings to begin with, so spending a bit more computation on it is reasonable.

Then why not just use a T-shaped convolution? Because splitting it is cheaper. A T-shaped convolution has h×w×(k2cpc+c(c−cp))h\times w\times(k^2 c_p c + c(c-c_p)) FLOPs, while PConv plus a 1×1 convolution has h×w×(k2cp2+c2)h\times w\times(k^2 c_p^2 + c^2). With cp=c/4c_p = c/4, the former is 3c23c^2 and the latter only 1.5625c21.5625c^2.

The authors also checked whether this combination can stand in for ordinary convolution. They took the inputs and outputs of the first 3×3 convolution in each stage of a pretrained ResNet-50 and trained small networks to imitate it. Averaged over the four stages, the test loss is 0.0148 for depthwise convolution plus 1×1, 0.0133 for grouped convolution plus 1×1, and 0.0123 for PConv plus 1×1, which comes closest to the original ordinary convolution.

FasterNet

The top half shows FasterNet's overall architecture: the input passes through an Embedding layer, then four stages, each made of several FasterNet Blocks, with Merging layers between stages; the feature map shrinks from h/4×w/4 to h/32×w/32, followed at the end by global pooling, a 1×1 convolution, and a fully connected layer that produces the output. The bottom left zooms in on partial convolution, where only the first c_p channels of the input are multiplied with c_p k×k kernels and the other channels go straight to the output along an Identity arrow; on the right is the FasterNet Block, made up in order of a PConv 3×3, a 1×1 convolution, BN and ReLU, another 1×1 convolution, and finally an addition with the input
Figure 4 from the paper, excerpted from page 5 of the v3 PDF, CC BY 4.0.

FasterNet's skeleton is very plain. The stem is a 4×4 convolution with stride 4, and between stages a 2×2 convolution with stride 2 does the downsampling. Each block is a PConv followed by two 1×1 convolutions that expand the channels 2× in between, with a residual added at the end.

The block has two more details. First, normalization and activation come only after the middle layer, so the whole block has just one set; the authors believe that too many would reduce feature diversity and also slow things down. Second, the normalization is BatchNorm, which can be merged into the adjacent convolution at inference.

The last two stages have less memory access and higher FLOPS, so the authors put more of the blocks and computation toward the back; T0's four stages, for example, have 1, 2, 8, and 2 blocks. From small to large, the family is T0, T1, T2, S, M, and L, with GELU for the small models and ReLU for the large ones.

Discussion

ImageNet

The authors measured speed on three devices. The GPU is a 2080Ti, measuring throughput at batch size 32; the CPU is an i9-9900X and the ARM chip a Cortex-A72, both single-threaded and measuring latency at batch size 1. Here are a few groups of models with similar accuracy:

Table: Excerpted from Table 3 of the paper. MobileViT's input is 256×256 and the rest 224×224; OOM means out of memory.
ModelFLOPsGPU (images/s)CPU (ms)ARM (ms)Top-1
MobileViT-XXS0.42G2,39330.834869.0%
MobileNetV20.31G4,19812.244272.0%
ShuffleNetV2 ×1.50.30G4,87812.126672.6%
FasterNet-T00.34G6,8079.214371.9%
ResNet-504.11G95973.01,13178.8%
FasterNet-T21.91G1,99133.549778.9%
Swin-T4.51G609122.21,42481.3%
ConvNeXt-T4.47G65786.31,88982.1%
FasterNet-S4.56G1,02971.21,10381.3%
Swin-B15.47G237349.2OOM83.5%
ConvNeXt-B15.38G253257.1OOM83.8%
FasterNet-L15.52G323219.5OOM83.5%

In every group, FasterNet is the fastest on all three devices. The most striking is the last group. FasterNet-L, ConvNeXt-B, and Swin-B have nearly the same FLOPs, all around 15.4G to 15.5G, yet FasterNet-L's GPU throughput is 28% to 36% higher and its CPU time 15% to 37% lower. Same FLOPs, different speeds, and that's exactly what the whole paper sets out to show.

The accuracy needs a closer look. The abstract says T0 is 2.9 percentage points more accurate than MobileViT-XXS, which is true, but MobileNetV2 and ShuffleNetV2 in the same group are both more accurate than T0. FasterNet-S ties Swin-T at 81.3%, 0.8 below ConvNeXt-T. The paper calls FasterNet-L “comparable” to ConvNeXt-B, but it's actually 0.3 lower. What FasterNet buys is speed, with accuracy roughly level and sometimes a little behind.

Detection and Segmentation

On COCO with Mask R-CNN trained for 12 epochs, FasterNet-S reaches 39.9 box AP against ResNet-50's 38.0, with nearly identical GPU latency (54.3 ms versus 54.9 ms). FasterNet-L gets 44.0 against PVT-Large's 42.9, while latency drops from 152.2 ms to 93.8 ms.

Ablation

Table: Excerpted from Table 5 of the paper. T0* is a version with width and depth adjusted to keep the complexity similar; T2 uses ReLU by default, so the comparison here is a switch to GELU.
SettingGPU (images/s)CPU (ms)ARM (ms)Top-1
T0, cp=c/4c_p = c/4 (default)6,8079.214371.9%
T0*, cp=c/2c_p = c/26,6269.614571.7%
T0*, cp=c/8c_p = c/86,2048.914071.3%
T0, LayerNorm instead of BatchNorm5,51510.715971.9%
T0, ReLU instead of GELU6,9298.211471.3%
T2, GELU instead of ReLU1,98535.455778.7%

A cpc_p of 1/4 strikes the best balance. Too large and it degenerates into ordinary convolution; too small and it can't capture spatial features. LayerNorm and BatchNorm give the same accuracy, but LayerNorm can't be merged into the convolution, and GPU throughput drops by a fifth. As for activation functions, GELU is more accurate for small models and ReLU works better for large ones; the authors guess that small models need GELU's nonlinearity more.

In the appendix, the authors also list two limitations. PConv's stride can only be 1, since otherwise the convolved channels and the untouched channels won't line up, so downsampling has to be left to other layers. And FasterNet is built entirely from small convolutions with a limited receptive field; the authors leave enlarging the receptive field to future work.

Conclusion

Latency is FLOPs divided by FLOPS, and the whole paper revolves around that equation. Focus only on shrinking the numerator, and if the denominator falls faster, the network ends up slower. Depthwise convolution is exactly that case, saving on computation but spending the time moving memory around.

PConv is so simple it's almost embarrassing. Convolve a quarter of the channels and stitch them back on, that's all, and a few lines are enough to bring it into your own network.

Finally, always measure speed on your own device. The paper used a 2080Ti, an i9-9900X, and a Cortex-A72; on an i9-13900K we saw the same trend, but quite different numbers. Move to a phone NPU or a different inference framework, and which one is faster could flip entirely, so don't draw conclusions straight from the paper's tables.