P小二 P小二
← 返回文章 AIGC 约 4 分钟

在mac上跑下一代文生图模型LCM

你知道下一代文生图模型LCM吗?

LCM模型介绍

Latent Consistency Models(LCM)是受2023年3月份openai的Consistency Models论文启发而来,主要特点是基于Stable Diffusion,但是能比较快的生成图像。LCM只需4到8步,即可获得比较好的图像,SD则需要25到50个步。

LCM的相关信息如下:

  • 论文:

Latent Consistency Models: Synthesizing High-Resolution Images with Few-Step Inference

  • 主页:

https://latent-consistency-models.github.io/

  • 代码:

https://github.com/luosiallen/latent-consistency-model

  • demo:

https://huggingface.co/spaces/SimianLuo/Latent_Consistency_Model

  • 模型:

https://huggingface.co/SimianLuo/LCM_Dreamshaper_v7

目前LCM非常活跃,发布10多天,对常用的库和UI都支持了,爱好者还开发了一些比较好玩的应用。下图为更新消息:

目前LCM非常活跃,发布10多天,对常用的库和UI都支持了,爱好者还开发了一些比

这次,我会跟踪最新的消息,从论文解读,代码解析开始,写一系列的实战教程。今天这篇是mac安装教程,主要是为了熟悉环境。

安装

硬件要求,Mac测试了M1和M2,最好16G内存,8G内存也行,但是速度比较慢。mac系统 最低 macOS 12.3 。

这次我们使用replicate的这个github项目:

步骤:

  • 克隆项目
git clone https://github.com/replicate/latent-consistency-model

2. 创建Python3.10以上的环境

conda create —name lcm python=3.10conda activate lcm


3. 安装项目依赖

- - ```
cd latent-consistency-modelpip3 install -r requirements.txt

4. 运行

export HF_ENDPOINT=https://hf-mirror.compython main.py “a cat like a chengdu panda” —steps 4 —width 512 —height 512


注意环境变量HF_ENDPOINT是为了可以科学的从huggingface下载模型。总共有15个文件,SimianLuo/LCM_Dreamshaper_v7模型有 3.44G,需要等待。

下载如下图:

![下载如下图](https://img.pxiaoer.blog/wechat/559e45241eb19328.png)

下载完后会直接做推理。你运行的时候可以修改传入的参数,包括prompt,steps,width和height等。下图为图片生成过程。

![下载完后会直接做推理。你运行的时候可以修改传入的参数,包括prompt,step](https://img.pxiaoer.blog/wechat/ef24a0bf94a2904f.png)

生成的图片

![生成的图片](https://img.pxiaoer.blog/wechat/b09044d79858db0a.png)

推理速度非常快

好了,你已经成功在mac上运行LCM模型了。难点其实是从huggingface下载模型。

**参考链接:**

- Consistency Models  

https://arxiv.org/abs/2303.01469

- Latent Consistency Models: Synthesizing High-Resolution Images with Few-Step Inference  

https://arxiv.org/abs/2310.04378