如何在火山引擎云上部署 Stable Diffusion
作为字节跳动旗下的云服务平台,火山引擎提炼了字节跳动多年云原生机器学习、大模型推理框架、训练/推理软硬件方案等技术实践,推出了一系列高性价的 AI 基础设施。
Stable Diffusion 环境依赖
容器服务 VKE(Kubernetes v1.24)
镜像仓库 CR
弹性容器 VCI
对象存储 TOS
GPU 服务器 ecs.gni2.3xlarge NVIDIA A10
应用负载均衡 ALB
API 网关 APIG
GPU 共享技术 mGPU
Stable Diffusion:huggingface.co/CompVis/stable-diffusion-v1-4
Stable Diffusion WebUI:github.com/AUTOMATIC1111/stable-diffusion-webui
步骤一:准备 VKE 集群环境
2. 开通 TOS 并创建桶,将 CompVis/stable-diffusion-v1-4 相关文件(包括模型)上传到 TOS。
pip install --upgrade diffuserspip install transformers#安装pytorch,根据官网选择对应环境的命令进行安装。https://pytorch.org/get-started/locally/
3. 在自己的命令行上,输入“huggingface-cli login”,出现 successful 即已经成功:
4. 使用 snapshot_download 方法进行下载:
>>> from huggingface_hub import snapshot_download>>> snapshot_download(repo_id="CompVis/stable-diffusion-v1-4",local_dir="/root/")
5. 下载完成后,使用 rclone 工具将文件上传至 TOS,rclone 配置可参考:volcengine.com/docs/6349/81434
rclone copy diffusers/ ${rclone_config_name}:${bucketname}/diffusers --copy-links#需要加上--copy-links参数,保证能通过软链接上传原始文件
部署 Stable Diffusion
apiVersion: apps/v1kind: Deploymentmetadata:name: sd-a10namespace: defaultspec:progressDeadlineSeconds: 600replicas: 0revisionHistoryLimit: 10selector:matchLabels:app: sd-a10strategy:rollingUpdate:maxSurge: 25%maxUnavailable: 25%type: RollingUpdatetemplate:metadata:creationTimestamp: nulllabels:app: sd-a10spec:containers:- image: cr-demo-cn-beijing.cr.volces.com/${namespace}/stable-diffusion:taiyi-0.1# 需要替换为实际的镜像地址imagePullPolicy: IfNotPresentname: sdresources:limits:vke.volcengine.com/mgpu-core: "30"vke.volcengine.com/mgpu-memory: "10240"requests:vke.volcengine.com/mgpu-core: "30"vke.volcengine.com/mgpu-memory: "10240"terminationMessagePath: /dev/termination-logterminationMessagePolicy: FilevolumeMounts:- mountPath: /stable-diffusion-webui/models/Taiyi-Stable-Diffusion-1B-Chinese-v0.1name: datadnsPolicy: ClusterFirstrestartPolicy: AlwaysschedulerName: default-schedulersecurityContext: {}terminationGracePeriodSeconds: 30volumes:- name: datapersistentVolumeClaim:claimName: sd-tos-pvc
步骤三:暴露推理服务
选择一:使用负载均衡 ALB
选择二:使用 API 网关
大模型工程化部署
使用 mGPU 提升 GPU 资源利用率
使用 Serverless GPU 部署 Stable Diffusion
Deployment yaml:
apiVersion: apps/v1kind: Deploymentmetadata:name: sd-vcinamespace: defaultspec:progressDeadlineSeconds: 600replicas: 0revisionHistoryLimit: 10selector:matchLabels:app: sd-vcistrategy:rollingUpdate:maxSurge: 25%maxUnavailable: 25%type: RollingUpdatetemplate:metadata:annotations:vci.vke.volcengine.com/preferred-instance-types: vci.ini2.26c-243gi# 指定使用到GPU规格vci.volcengine.com/tls-enable: "false"vke.volcengine.com/burst-to-vci: enforce# 调度到VCI实例上creationTimestamp: nulllabels:app: sd-vcispec:containers:- image: cr-demo-cn-beijing.cr.volces.com/${namespace}/stable-diffusion:taiyi-0.1# 需要替换为实际的镜像地址imagePullPolicy: IfNotPresentname: sd-vciresources:limits:nvidia.com/gpu: "1"terminationMessagePath: /dev/termination-logterminationMessagePolicy: FilevolumeMounts:- mountPath: /stable-diffusion-webui/models/Taiyi-Stable-Diffusion-1B-Chinese-v0.1name: sddnsPolicy: ClusterFirstrestartPolicy: AlwaysschedulerName: default-schedulersecurityContext: {}terminationGracePeriodSeconds: 30volumes:- name: sdpersistentVolumeClaim:claimName: sd-tos-pvc
结语
[1] 火山引擎: www.volcengine.com
[2] 容器服务: www.volcengine.com/product/vke
[3] 镜像仓库:www.volcengine.com/product/cr
[4] API 网关:www.volcengine.com/product/apig
[5] 托管 Prometheus:www.volcengine.com/product/vmp
点击 阅读原文 申请体验
火山引擎云原生团队主要负责火山引擎公有云及私有化场景中 PaaS 类产品体系的构建,结合字节跳动多年的云原生技术栈经验和最佳实践沉淀,帮助企业加速数字化转型和创新。产品包括容器服务、镜像仓库、分布式云原生平台、函数服务、服务网格、持续交付、可观测服务等。
活动时间:2023 年 6 月 10 日(周六)
活动地点:上海市徐汇区古美路 1520 号漕河泾中心 C 栋·会议室 622(字节工区)/ 线上
预热福利:报名线下参会即可参与抽奖,50% 中奖率,筋膜枪、AI 音箱、掘金周边电脑支架、手机支架等奖品现场兑换,快来与讲师面对面交流吧!