1

AWS EKS上部署Stable Diffusion

 1 month ago
source link: https://blog.51cto.com/jiemei/10230693
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

AWS EKS上部署Stable Diffusion

精选 原创

Stable Diffusion是一款基于深度学习的AI图像生成模型,可以根据文本描述生成逼真的图像。由于模型的庞大体积,在本地运行和部署存在一定困难。幸运的是,AWS提供了一个解决方案,可以在AWS EKS(Elastic Kubernetes Service)上快速部署Stable Diffusion。

![参考](https://aws-samples.github.io/stable-diffusion-on-eks/zh/)

  1. 安装AWS CLI并配置您的AWS凭证
  2. 安装Git和Node.js/npm
yum install -y git npm

注意:npm 9.8.1和Node.js 18.18.2

部署Stable Diffusion

AWS提供了一个开源项目stable-diffusion-on-eks,可以简化部署流程。我们首先克隆该项目:

git clone --recursive https://github.com/aws-samples/stable-diffusion-on-eks
cd stable-diffusion-on-eks

接下来,进入deploy目录并运行deploy.sh脚本。该脚本将自动完成以下工作:

  • 安装必要的运行时和工具
  • 创建S3存储桶,从HuggingFace下载Stable Diffusion 1.5基础模型并存储在桶中
  • 使用提供的示例镜像创建包含Stable Diffusion Web UI的EBS快照
  • 创建并部署包含Stable Diffusion运行时的解决方案

您可以使用多个参数来自定义部署:

./deploy.sh -n dev-sdoneks -R us-east-1 -b dev-bucket-sdoneks -r sdruntime-01
  • -n: 自定义解决方案名称
  • -R: 指定部署区域
  • -b: 指定现有S3桶名称,用于存储模型(提前创建)
  • -r: 指定运行时名称

其他可选参数包括:

  • -d: 只生成配置文件,不执行部署
  • -s: 指定现有EBS快照ID
  • -t: 指定运行时类型(sdwebui或comfyui)

如果需要部署多个运行时或自定义配置,可以先使用--dry-run生成配置文件,再手动修改。

部署完成后,您可以使用以下命令查看部署状态:

kubectl get node
kubectl get deploy
kubectl get pod

添加新模型

如果需要添加新的Stable Diffusion模型,可以按照以下步骤操作:

使用--dry-run生成配置文件:

./deploy.sh -n dev-govee-sdoneks -R us-east-1 -b dev-goveebucket-sdoneks -r sdruntime-01 --dry-run

下载新增一个运行时为sdruntime-02的部分:

stackName: dev-sdoneks
modelBucketArn: arn:aws:s3:::dev-bucket-sdoneks
APIGW:
  stageName: dev
  throttle:
    rateLimit: 30
    burstLimit: 50
modelsRuntime:
- name: sdruntime-01
  namespace: default
  modelFilename: v1-5-pruned-emaonly.safetensors
  dynamicModel: false
  type: sdwebui
  extraValues:
    karpenter:
      nodeTemplate:
        amiFamily: Bottlerocket
        dataVolume:
          volumeSize: 80Gi
          volumeType: gp3
          deleteOnTermination: true
          iops: 4000
          throughput: 1000
          snapshotID: snap-0fc2970a9218047e5
      provisioner:
        instanceType:
        - g4dn.xlarge
        - g4dn.2xlarge
        capacityType:
          onDemand: true
          spot: true
      scaling:
        queueLength: 5 # Target value for queue length. One new instance will be launched when queue launch reaches the value.
        minReplicaCount: 1 # Minimum number of replicas of SD Runtime.
        maxReplicaCount: 20 # Maxinum number of replicas of SD Runtime.
        cooldownPeriod: 60 # The period (in seconds) to wait after the last message before scaling down.
- name: sdruntime-02
  namespace: default
  modelFilename: v1-5-pruned-emaonly-gif.safetensors
  dynamicModel: false
  type: sdwebui
  extraValues:
    karpenter:
      nodeTemplate:
        amiFamily: Bottlerocket
        dataVolume:
          volumeSize: 80Gi
          volumeType: gp3
          deleteOnTermination: true
          iops: 4000
          throughput: 1000
          snapshotID: snap-0fc2970a9218047e5
      provisioner:
        instanceType:
        - g5.xlarge
        - g5.2xlarge
        capacityType:
          onDemand: true
          spot: true
      scaling:
        queueLength: 2 # Target value for queue length. One new instance will be launched when queue launch reaches the value.
        minReplicaCount: 1 # Minimum number of replicas of SD Runtime.
        maxReplicaCount: 10 # Maxinum number of replicas of SD Runtime.
        cooldownPeriod: 60 # The period (in seconds) to wait after the last message before scaling down.

退出deploy目录,使用CDK部署更新:

cd ..
cdk deploy --no-rollback --require-approval never
或
cdk deploy --require-approval never

以下是一些常用的维护命令:

aws eks update-kubeconfig --name dev-govee-sdoneksStack --region us-east-1 # 更新kubeconfig
kubectl get node # 查看节点信息
kubectl get deploy # 查看部署信息
kubectl get karpenter # 查看Karpenter信息(Karpenter是AWS提供的自动节点扩展工具)
kubectl get AWSNodeTemplate # 查看AWS节点模板信息
kubectl get ScaledObject # 查看Scaled Object信息(用于自动扩展资源)
kubectl get pod # 查看Pod信息
kubectl get cm # 查看配置映射信息
kubectl logs <pod name> -c queue-agent # 查看特定 Pod 中名为 queue-agent 的容器的日志
kubectl scale deployment <deployment name> --replicas=0 # 将名为 deployment name 的部署的副本数缩减为 0

通过在AWS EKS上部署Stable Diffusion,您可以轻松获得强大的AI图像生成能力,而无需在本地运行庞大的模型。AWS的解决方案使部署过程变得简单高效。

  • 收藏
  • 评论
  • 分享
  • 举报

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK