StableDiffusion模型发展历史

  参考资料:

  相应的github和huggingface

  LDM [github]

  StableDiffusion v1.1 ~ v1.4 [github] [huggingface]

  StableDiffusion v1.5 [huggingface] [github]

  StableDiffusion v2 v2.1 [github] [huggingface]  

  首先说一下,这篇文章的目的是让你清晰地了解StableDffusion这个模型的发展脉络,由于目前开源AIGC模型基本上都是基于SD的,因此了解它的发展历史是非常有必要的,毕竟它是进行再创作的根基,不了解这个base而盲目地搞一些finetune,虽然可能也会出效果,但有事倍功半的危险。

  1. LDM

   LDM指latent-diffusion model。纵观Diffusion model的发展历史,使用一个基于Unet的noise predictor进行diffusion reverse process是主线,这个思路在DDPM这篇文章中就已经阐述的很清楚了,但是受限于大量的hidden features,训练速度堪忧,并且分辨率没办法提的很高。classifier-guided[Diffusion Models Beat GANs on Image Synthesis]和classifier-free[CLASSIFIER-FREE DIFFUSION GUIDANCE]这两篇文章给出了设计“条件Diffusion Model”的方法,但是仍然没有解决训练速度和显存占用的问题。直到LDM的提出,通过引入一个预训练的VAE做图片降维,然后在latent-space做diffusion,才为Diffusion Model的大规模训练打开了大门。与此同时,它提出可以使用一个业务相关的conditioning模块,并借助CrossAttension机制一把实现多个任务比如inpainting,SR,depth-guided等等。总之,LDM是学术界的产物,由Compvis独立提出,为后续的Stablediffusion打下了技术基础。但同时由于它(LDM)学术产物的本质,得到的关注远远不如SD。
   2. StableDiffusion v1.1 ~ v1.4
  发出了LDM那篇CVPR文章后,Compvis团队得到了工业界的关注,得以和Runway和Stability AI合作。有了他们的支持,Compvis开始做一些昂贵的尝试,即在LAION数据集上进行大规模的训练。本质上,SDv1.1 ~ 1.4使用的算法框架和LDM完全一致。特别地,SD使用了固定的(frozen)CLIP text encoder作为上一节提到的conditioning模块,也就是说不做杂七杂八的conditioning了,依赖于LAION数据集的驱动,就一门心思好好把T2I这个任务给做好。下面我摘抄两段github上的话,很好地总结了这个阶段的模型的发展:Stable Diffusion v1 refers to a specific configuration of the model architecture that uses a downsampling-factor 8 autoencoder with an 860M UNet and CLIP ViT-L/14 text encoder for the diffusion model. The model was pretrained on 256x256 images and then finetuned on 512x512 images.

  3. StableDiffusion v1.5

  上面提到Compvis团队不仅了Stablility-AI团队合作,还和Runway团队有合作。而SD1.5这个火遍大江南北的模型就是由RunwayML团队发布在hugging face上的。值得注意的是这次模型的发布就不再是Compvis了(可能是利益相关的问题吧),看看它是怎么做的:

The Stable-Diffusion-v1-5 checkpoint was initialized with the weights of the Stable-Diffusion-v1-2 checkpoint and subsequently fine-tuned on 595k steps at resolution 512x512 on "laion-aesthetics v2 5+" and 10% dropping of the text-conditioning to improve classifier-free guidance sampling.

  似乎没有什么fancy的... 仅仅就是在一个美学打分较高的LAION子集上猛猛训...步数超过了v1-4而已。但是这里有两个需要注意的地方,先看一下runway在hugging face上发布的模型:

  一个是pruned,这个pruned是什么意思?reddit上有一段很好的解释: https://www.reddit.com/r/StableDiffusion/comments/xymibu/what_does_it_mean_to_prune_a_model/

A neural network is just a bunch of math operations. The "neurons" are connected by various "weights," which is to say, the output of a neuron is multipled by a weight (just a number) and gets added into another neuron, along with lots of other connections to that other neuron.

When the neural network learns, these weights get modified. Often, many of them become zero (or real close to it). And since anything time zero is zero, we can skip this part of the math when using the network to predict something. Also, when a set of data has a lot of zeros, it can be compressed to be much smaller.

Pruning finds the nearly zero connections, makes them exactly zero, and then let's you save a smaller, compressed network. Moreover, when you use the network to predict/create something, an optimized neural network solution (i.e. the code that does all of the math specified by the network) can do so faster by intelligently skipping the unneeded calculations involving zero.

  这下就知道了,模型的pruning就是剪掉不需要的部分。pruned知道了,ema又是什么意思呢?这个其实我可以解释一下:EMA stands for Exponential Moving Average, and it refers to a technique used to smooth out noise in the training data. 即EMA是一种训练策略,在训练的时候模型会有一个主模型例如Unet,同时也会保存一个copy即EMA_Unet,这个EMA_Unet可以简单地看作是Unet的一个权值平均化的版本,可以使得训练更加稳定。一般认为EMA_Unet能够降噪,因此load ema版本的权重就可以了,但是如果你想接着finetune,那么不妨同时load EMA_Unet和真实的Unet,继续用ema的策略训练下去。hugging face上有一段话:

   可知v1-5-pruned.ckpt包含的信息是比v1-5-pruned-emaonly.ckpt的信息“绝对”多的,然后就按自己需求有选择地下载就好了。

  4. StableDiffusion v2 v2.1

  上面说到之前的模型发布都是Compvis和Runway完成的,现在老大Stability-AI也坐不住了。我猜它应该是想挣钱的,因此发布Stalediffusion v2的一个重要举措是删除NSFW的东西。这个也可以理解,因为做产品就要考虑风控啊。SD v2同样有一个一句话定义:Stable Diffusion v2 refers to a specific configuration of the model architecture that uses a downsampling-factor 8 autoencoder with an 865M UNet and OpenCLIP ViT-H/14 text encoder for the diffusion model. The SD 2-v model produces 768x768 px outputs. 有三个变化,一个是text-encoder变了,变这个东西意味着什么?意味着和StableDiffusion v1割席,必须重新从零去训练了。一个是分辨率加大了,这个东西似乎没有什么技术壁垒,因为卷积这个操作好像天生就能够兼容不同分辨率的方图。

  然后,StableDiffusion v2引入了一个叫v-prediction的概念,这导致模型出现了v2, v2-base, v2.1, v2.1-base,v2和v2.1是SD主推的产品(我的理解),而v2-base和v2.1-base则是原始的noise-prediction的模型。逻辑是这样的,v2-base是从零开始训的,并且屏蔽了NSFW,v2基于v2-base继续finetune。v2.1-base是基于v2-base finetune的,v2.1基于v2.1-base继续finetune。下面只展示v2-base的训练介绍,其他的模型训练信息可以到hugging face上自己去看:

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值