Table of Contents
Core Method
Experimental results
Summary and future work
Home Technology peripherals AI The iPhone takes two seconds to produce a picture, and the fastest known mobile Stable Diffusion model is here.

The iPhone takes two seconds to produce a picture, and the fastest known mobile Stable Diffusion model is here.

Jun 12, 2023 am 11:15 AM
Model train

Stable Diffusion (SD) is currently the most popular text to image (text to image) generation diffusion model. Although its powerful image generation capabilities are shocking, an obvious shortcoming is that it requires huge computing resources and the inference speed is very slow: taking SD-v1.5 as an example, even using half-precision storage, its model size is 1.7GB. With 1 billion parameters, the on-device inference time is often close to 2 minutes.

In order to solve the problem of inference speed, academia and industry have begun research on SD acceleration, mainly focusing on two routes: (1) reducing the number of inference steps, this route can Divided into two sub-routes, one is to reduce the number of steps by proposing a better noise scheduler, representative works are DDIM [1], PNDM [2], DPM [3], etc.; the second is to reduce the number of steps through progressive distillation (Progressive Distillation) The number of steps, representative works are Progressive Distillation [4] and w-conditioning [5], etc. (2) Engineering skills optimization. The representative work is that Qualcomm uses int8 quantified full-stack optimization to achieve SD-v1.5 on Android phones in 15 seconds [6], and Google uses on-end GPU optimization to achieve SD-v1.4 on Samsung phones. Accelerate to 12s [7].

While these efforts have come a long way, it’s still not happening fast enough.

Recently, Snap Research Institute launched the latest high-performance Stable Diffusion model. Through comprehensive optimization of the network structure, training process, and loss function, it can produce images in 2 seconds on iPhone 14 Pro. (512x512), and achieves a better CLIP score than SD-v1.5. This is the fastest known end-to-end Stable Diffusion model!

iPhone两秒出图,目前已知的最快移动端Stable Diffusion模型来了

  • Paper address: https://arxiv.org/pdf/2306.00980.pdf
  • Webpage: https://snap-research.github.io/SnapFusion

Core Method

The Stable Diffusion model is divided into three parts: VAE encoder/decoder, text encoder, and UNet. Among them, UNet accounts for the absolute majority in terms of parameter amount and calculation amount, so SnapFusion mainly optimizes UNet. . It is divided into two parts: (1) Optimization of the UNet structure: By analyzing the speed bottleneck of the original UNet, this article proposes a set of automatic evaluation and evolution processes for the UNet structure, and obtains a more efficient UNet structure (called Efficient UNet) . (2) Optimization of the number of inference steps: As we all know, the diffusion model is an iterative denoising process during inference. The more iteration steps, the higher the quality of the generated images, but the time cost also increases linearly with the number of iteration steps. . In order to reduce the number of steps and maintain image quality, we propose a CFG-aware distillation loss function that explicitly considers the role of CFG (Classifier-Free Guidance) during the training process. This loss function is proven to be the key to improving CLIP score!

The following table is an overview comparison between SD-v1.5 and SnapFusion models. It can be seen that the speed improvement comes from the two parts of UNet and VAE decoder, and the UNet part is the big one. There are two aspects to the improvement of the UNet part. One is the reduction of single latency (1700ms -> 230ms, 7.4x acceleration), which is obtained through the proposed Efficient UNet structure; the other is the reduction of Inference steps (50 -> 8, 6.25 x acceleration), which is obtained through the proposed CFG-aware Distillation. VAE decoder is accelerated through structured pruning.

iPhone两秒出图,目前已知的最快移动端Stable Diffusion模型来了

The following focuses on the design of Efficient UNet and the design of CFG-aware Distillation loss function.

(1) Efficient UNet

We locate the speed by analyzing the Cross-Attention and ResNet modules in UNet The bottleneck lies in the Cross-Attention module (especially the Cross-Attention in the first Downsample stage), as shown in the figure below. The root cause of this problem is that the complexity of the attention module has a square relationship with the spatial size of the feature map. In the first Downsample stage, the spatial size of the feature map is still large, resulting in high computational complexity.

iPhone两秒出图,目前已知的最快移动端Stable Diffusion模型来了

In order to optimize the UNet structure, we propose a set of UNet structure automatic evaluation and evolution processes: first conduct robust training (Robust Training) on ​​UNet, and randomly drop some modules during training to test each The real impact of each module on performance is constructed to construct a lookup table of "impact on CLIP score vs. latency"; and then based on the lookup table, priority is given to removing modules that have little impact on CLIP score and are very time-consuming. This set of processes is performed automatically online. After completion, we will get a brand new UNet structure called Efficient UNet. Compared with the original UNet, it achieves 7.4x acceleration without performance degradation.

(2) CFG-aware Step Distillation

CFG (Classifier-Free Guidance) is the SD inference stage Essential skills that can greatly improve picture quality, very crucial! Although there have been works on the diffusion model using step distillation to accelerate [4], they did not include CFG as an optimization goal in distillation training. That is to say, the distillation loss function does not know that CFG will be used later. According to our observation, this will seriously affect the CLIP score when the number of steps is small.

In order to solve this problem, we propose to let both the teacher and student models perform CFG before calculating the distillation loss function, so that the loss function is calculated on the features after CFG, thus The effects of different CFG scales are explicitly considered. In the experiment, we found that although the CLIP score can be improved by completely using CFG-aware Distillation, the FID also becomes significantly worse. We then proposed a random sampling scheme to mix the original Step Distillation loss function and the CFG-aware Distillation loss function, achieving the coexistence of the advantages of the two, which not only significantly improved the CLIP score, but also did not worsen the FID. This step achieves an acceleration of 6.25 times in the further inference stage, achieving a total acceleration of approximately 46 times.

In addition to the above two main contributions, the article also includes the pruning acceleration of VAE decoder and the careful design of the distillation process. Please refer to the paper for specific content.

Experimental results

SnapFusion benchmarks SD-v1.5 text to image function, the goal is to significantly reduce inference time and maintain image quality without degradation, which best illustrates This is shown in the figure below:

iPhone两秒出图,目前已知的最快移动端Stable Diffusion模型来了

This figure randomly selects 30K caption-image pairs on the MS COCO'14 verification set to calculate the CLIP score and FID. CLIP score measures the semantic consistency between pictures and text, the bigger the better; FID measures the distribution distance between generated pictures and real pictures (generally considered a measure of the diversity of generated pictures), the smaller the better. Different points in the graph are obtained using different CFG scales, and each CFG scale corresponds to a data point. As can be seen from the figure, our method (red line) can achieve the same lowest FID as SD-v1.5 (blue line), and at the same time, the CLIP score of our method is better. It is worth noting that SD-v1.5 takes 1.4min to generate an image, while SnapFusion only takes 1.84s. This is also the fastest mobile Stable Diffusion model we know of!

Here are some samples generated by SnapFusion:

iPhone两秒出图,目前已知的最快移动端Stable Diffusion模型来了

More samples Please refer to the article appendix.

In addition to these main results, the article also shows numerous ablation analysis (Ablation Study) experiments, hoping to provide reference experience for the development of efficient SD models:

(1) Previous work on Step Distillation usually used progressive schemes [4, 5], but we found that progressive distillation has no advantages over direct distillation on the SD model, and the process is cumbersome, so we The direct distillation scheme is used in this article.

iPhone两秒出图,目前已知的最快移动端Stable Diffusion模型来了

(2) Although CFG can greatly improve image quality, the cost is doubling the inference cost. This year's CVPR'23 Award Candidate's On Distillation article [5] proposed w-conditioning, which uses CFG parameters as input to UNet for distillation (the resulting model is called w-conditioned UNet), thereby eliminating the CFG step during reasoning and realizing reasoning costs. Halved. However, we found that doing so will actually cause the image quality to decrease and the CLIP score to decrease (as shown in the figure below, the CLIP score of the four w-conditioned lines does not exceed 0.30, which is worse than SD-v1.5). Our method can reduce the number of steps and improve the CLIP score at the same time, thanks to the proposed CFG-aware distillation loss function! What is particularly noteworthy is that the inference cost of the green line (w-conditioned, 16 steps) and the orange line (Ours, 8 steps) in the figure below are the same, but the orange line is obviously better, indicating that our technical route is better than w-conditioned conditioning [5] is more effective on the distilled CFG guided SD model.

iPhone两秒出图,目前已知的最快移动端Stable Diffusion模型来了

(3) The existing work on Step Distillation [4, 5] did not combine the original loss function and distillation The loss functions are added together. Friends who are familiar with image classification knowledge distillation should know that this design is intuitively suboptimal. So we proposed to add the original loss function to the training, as shown in the figure below, which is indeed effective (slightly reducing FID).

iPhone两秒出图,目前已知的最快移动端Stable Diffusion模型来了

Summary and future work

This paper proposes SnapFusion, a high-performance Stable Diffusion model for mobile terminals . SnapFusion has two core contributions: (1) Through layer-by-layer analysis of the existing UNet, it locates the speed bottleneck and proposes a new efficient UNet structure (Efficient UNet), which can effectively replace the UNet in the original Stable Diffusion and achieve 7.4 x acceleration; (2) Optimize the number of iteration steps in the inference phase and propose a new step distillation scheme (CFG-aware Step Distillation), which can significantly improve the CLIP score while reducing the number of steps, achieving 6.25x acceleration. Overall, SnapFusion achieves image output within 2 seconds on iPhone 14 Pro, which is currently the fastest known mobile Stable Diffusion model.

Future work:

1. The SD model can be used in a variety of image generation scenarios. This article is limited to Due to time constraints, we are currently only focusing on the core task of text to image, and other tasks (such as inpainting, ControlNet, etc.) will be followed later.

2. This article mainly focuses on speed improvement and does not optimize model storage. We believe that the proposed Efficient UNet still has room for compression. Combined with other high-performance optimization methods (such as pruning, quantization), it is expected to shrink storage and reduce the time to less than 1 second, making real-time SD on the off-end a step further.

The above is the detailed content of The iPhone takes two seconds to produce a picture, and the fastest known mobile Stable Diffusion model is here.. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation! Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation! Apr 03, 2024 pm 12:04 PM

0.What does this article do? We propose DepthFM: a versatile and fast state-of-the-art generative monocular depth estimation model. In addition to traditional depth estimation tasks, DepthFM also demonstrates state-of-the-art capabilities in downstream tasks such as depth inpainting. DepthFM is efficient and can synthesize depth maps within a few inference steps. Let’s read about this work together ~ 1. Paper information title: DepthFM: FastMonocularDepthEstimationwithFlowMatching Author: MingGui, JohannesS.Fischer, UlrichPrestel, PingchuanMa, Dmytr

The world's most powerful open source MoE model is here, with Chinese capabilities comparable to GPT-4, and the price is only nearly one percent of GPT-4-Turbo The world's most powerful open source MoE model is here, with Chinese capabilities comparable to GPT-4, and the price is only nearly one percent of GPT-4-Turbo May 07, 2024 pm 04:13 PM

Imagine an artificial intelligence model that not only has the ability to surpass traditional computing, but also achieves more efficient performance at a lower cost. This is not science fiction, DeepSeek-V2[1], the world’s most powerful open source MoE model is here. DeepSeek-V2 is a powerful mixture of experts (MoE) language model with the characteristics of economical training and efficient inference. It consists of 236B parameters, 21B of which are used to activate each marker. Compared with DeepSeek67B, DeepSeek-V2 has stronger performance, while saving 42.5% of training costs, reducing KV cache by 93.3%, and increasing the maximum generation throughput to 5.76 times. DeepSeek is a company exploring general artificial intelligence

AI subverts mathematical research! Fields Medal winner and Chinese-American mathematician led 11 top-ranked papers | Liked by Terence Tao AI subverts mathematical research! Fields Medal winner and Chinese-American mathematician led 11 top-ranked papers | Liked by Terence Tao Apr 09, 2024 am 11:52 AM

AI is indeed changing mathematics. Recently, Tao Zhexuan, who has been paying close attention to this issue, forwarded the latest issue of "Bulletin of the American Mathematical Society" (Bulletin of the American Mathematical Society). Focusing on the topic "Will machines change mathematics?", many mathematicians expressed their opinions. The whole process was full of sparks, hardcore and exciting. The author has a strong lineup, including Fields Medal winner Akshay Venkatesh, Chinese mathematician Zheng Lejun, NYU computer scientist Ernest Davis and many other well-known scholars in the industry. The world of AI has changed dramatically. You know, many of these articles were submitted a year ago.

Hello, electric Atlas! Boston Dynamics robot comes back to life, 180-degree weird moves scare Musk Hello, electric Atlas! Boston Dynamics robot comes back to life, 180-degree weird moves scare Musk Apr 18, 2024 pm 07:58 PM

Boston Dynamics Atlas officially enters the era of electric robots! Yesterday, the hydraulic Atlas just "tearfully" withdrew from the stage of history. Today, Boston Dynamics announced that the electric Atlas is on the job. It seems that in the field of commercial humanoid robots, Boston Dynamics is determined to compete with Tesla. After the new video was released, it had already been viewed by more than one million people in just ten hours. The old people leave and new roles appear. This is a historical necessity. There is no doubt that this year is the explosive year of humanoid robots. Netizens commented: The advancement of robots has made this year's opening ceremony look like a human, and the degree of freedom is far greater than that of humans. But is this really not a horror movie? At the beginning of the video, Atlas is lying calmly on the ground, seemingly on his back. What follows is jaw-dropping

KAN, which replaces MLP, has been extended to convolution by open source projects KAN, which replaces MLP, has been extended to convolution by open source projects Jun 01, 2024 pm 10:03 PM

Earlier this month, researchers from MIT and other institutions proposed a very promising alternative to MLP - KAN. KAN outperforms MLP in terms of accuracy and interpretability. And it can outperform MLP running with a larger number of parameters with a very small number of parameters. For example, the authors stated that they used KAN to reproduce DeepMind's results with a smaller network and a higher degree of automation. Specifically, DeepMind's MLP has about 300,000 parameters, while KAN only has about 200 parameters. KAN has a strong mathematical foundation like MLP. MLP is based on the universal approximation theorem, while KAN is based on the Kolmogorov-Arnold representation theorem. As shown in the figure below, KAN has

The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks Apr 29, 2024 pm 06:55 PM

I cry to death. The world is madly building big models. The data on the Internet is not enough. It is not enough at all. The training model looks like "The Hunger Games", and AI researchers around the world are worrying about how to feed these data voracious eaters. This problem is particularly prominent in multi-modal tasks. At a time when nothing could be done, a start-up team from the Department of Renmin University of China used its own new model to become the first in China to make "model-generated data feed itself" a reality. Moreover, it is a two-pronged approach on the understanding side and the generation side. Both sides can generate high-quality, multi-modal new data and provide data feedback to the model itself. What is a model? Awaker 1.0, a large multi-modal model that just appeared on the Zhongguancun Forum. Who is the team? Sophon engine. Founded by Gao Yizhao, a doctoral student at Renmin University’s Hillhouse School of Artificial Intelligence.

Kuaishou version of Sora 'Ke Ling' is open for testing: generates over 120s video, understands physics better, and can accurately model complex movements Kuaishou version of Sora 'Ke Ling' is open for testing: generates over 120s video, understands physics better, and can accurately model complex movements Jun 11, 2024 am 09:51 AM

What? Is Zootopia brought into reality by domestic AI? Exposed together with the video is a new large-scale domestic video generation model called "Keling". Sora uses a similar technical route and combines a number of self-developed technological innovations to produce videos that not only have large and reasonable movements, but also simulate the characteristics of the physical world and have strong conceptual combination capabilities and imagination. According to the data, Keling supports the generation of ultra-long videos of up to 2 minutes at 30fps, with resolutions up to 1080p, and supports multiple aspect ratios. Another important point is that Keling is not a demo or video result demonstration released by the laboratory, but a product-level application launched by Kuaishou, a leading player in the short video field. Moreover, the main focus is to be pragmatic, not to write blank checks, and to go online as soon as it is released. The large model of Ke Ling is already available in Kuaiying.

FisheyeDetNet: the first target detection algorithm based on fisheye camera FisheyeDetNet: the first target detection algorithm based on fisheye camera Apr 26, 2024 am 11:37 AM

Target detection is a relatively mature problem in autonomous driving systems, among which pedestrian detection is one of the earliest algorithms to be deployed. Very comprehensive research has been carried out in most papers. However, distance perception using fisheye cameras for surround view is relatively less studied. Due to large radial distortion, standard bounding box representation is difficult to implement in fisheye cameras. To alleviate the above description, we explore extended bounding box, ellipse, and general polygon designs into polar/angular representations and define an instance segmentation mIOU metric to analyze these representations. The proposed model fisheyeDetNet with polygonal shape outperforms other models and simultaneously achieves 49.5% mAP on the Valeo fisheye camera dataset for autonomous driving

See all articles