【自己更換模型】如何用 Serverless 一鍵部署 Stable Diffusion?
作者 | 寒斜(阿里云智能技術(shù)專(zhuān)家) 上一篇講了 ?如何使用 Serverless Devs 和函數(shù)計(jì)算快速體驗(yàn)部署 Stable Diffusion? , 本篇繼續(xù)聊聊如何解決動(dòng)態(tài)模型加載的問(wèn)題, 從玩起來(lái)到用起來(lái)。
思路
其實(shí)很簡(jiǎn)單, 我們只需要將鏡像里面的動(dòng)態(tài)路徑映射到 NAS [ 1] 文件存儲(chǔ)里面即可,利用 NAS 獨(dú)立存儲(chǔ)文件模型,擴(kuò)展,語(yǔ)言包等,并且我們可以為管理 NAS 單獨(dú)配置一個(gè)可視化的后臺(tái),用簡(jiǎn)單的文件上傳刪除的方式管理我們的文件,為此我們需要展開(kāi)打鏡像的腳本,為了完成全套的流程我們接下來(lái)盤(pán)一下整體的準(zhǔn)備項(xiàng)。
準(zhǔn)備項(xiàng)
1. 開(kāi)通阿里云函數(shù)計(jì)算[2]
2. 文件存儲(chǔ) NAS(可以根據(jù)情況自己創(chuàng)建性能更好的實(shí)例)
3. 開(kāi)通阿里云容器鏡像服務(wù) ACR[3]
4. 安裝 Serverless Devs[4]
$ npm install @serverless-devs/s -g
5. 使用 Serverless Devs 配置阿里云密鑰信息[5]
快速開(kāi)始
初始化應(yīng)用模版
s init fc-stable-diffusion-plus
選擇 region:cn-hangzhou
輸入鏡像:registry.cn-hangzhou.aliyuncs.com/serverlessdevshanxie/sd-auto-nas:v1
部署應(yīng)用模版
cd fc-stable-diffusion-plus && s deploy
部署需要花費(fèi)一些時(shí)間(預(yù)估 5 分鐘),之后你會(huì)收到兩個(gè)域名返回。
:region: cn-hangzhouservice:name: fc-stable-diffusion-plusfunction:name: nas-initruntime: python3.9handler: index.handlermemorySize: 3072timeout: 1200cpu: 2diskSize: 512:region: cn-hangzhouservice:name: fc-stable-diffusion-plusfunction:name: adminruntime: customhandler: index.handlermemorySize: 3072timeout: 7200cpu: 2diskSize: 512url:system_url: https://xxx.cn-hangzhou.fcapp.runsystem_intranet_url: https://xxx.cn-hangzhou-vpc.fcapp.runcustom_domain:domain: http://admin.fc-stable-diffusion-plus.xxxx.cn-hangzhou.fc.devsapp.nettriggers:type: httpname: httpTrigger:region: cn-hangzhouservice:name: fc-stable-diffusion-plusfunction:name: keep-warmruntime: python3handler: index.handlermemorySize: 128timeout: 120cpu: 0.1diskSize: 512triggers:type: timername: timerTrigger:region: cn-hangzhouservice:name: fc-stable-diffusion-plusfunction:name: sdruntime: custom-containerhandler: index.handlermemorySize: 32768timeout: 600cpu: 8diskSize: 10240url:system_url: https://xxx.cn-hangzhou.fcapp.runsystem_intranet_url: https://xxx.cn-hangzhou-vpc.fcapp.runcustom_domain:domain: http://sd.fc-stable-diffusion-plus.xxxxx.cn-hangzhou.fc.devsapp.nettriggers:type: httpname: defaultTrigger
其中:
http://admin.fc-stable-diffusion-plus.xxxx.cn-hangzhou.fc.devsapp.net 是后臺(tái)管理頁(yè)面 http://sd.fc-stable-diffusion-plus.xxxxx.cn-hangzhou.fc.devsapp.net 是 Stable Diffusion 的操作界面上傳模型
因?yàn)樯厦嫒萜麋R像中移除了模型部分,所以你現(xiàn)在還無(wú)法啟動(dòng) Stable Diffusion 的操作界面,需要上傳自己的模型,之后再去啟動(dòng) Stable Diffusion 操作界面,上傳模型有兩個(gè)方法:
方法一
通過(guò)可視化界面上傳,訪問(wèn) http://admin.fc-stable-diffusion-plus.xxxx.cn-hangzhou.fc.devsapp.net,點(diǎn)點(diǎn)點(diǎn),配好登錄密碼之后,進(jìn)來(lái)到這個(gè)界面:文件管理,然后在路徑欄里輸入"/mnt/auto/sd"



你就看到自己熟悉的本地目錄了~

然后再訪問(wèn) models/Stable-diffusion/ 把模型拖進(jìn)來(lái)就行。
不過(guò)值得注意的是,這種方式上傳的模型超過(guò) 2、3 個(gè) G 的時(shí)候會(huì)不穩(wěn)定。所以如果你的模型很大,可以考慮用我們提供的 nas 指令。
方法二
使用 nas 指令上傳,進(jìn)入項(xiàng)目根目錄,執(zhí)行↓
s fc-nas-init nas upload -r <你的模型地址> /mnt/auto/sd/models/Stable-diffusion/
就可以,剩下的就是等待,可能要花費(fèi) 30 分鐘。 注: 其他的如 controlNet,extension 可以按照類(lèi)似的方式,不過(guò)注意對(duì)應(yīng)的 nas 地址變一下。
頁(yè)面瀏覽
準(zhǔn)備就緒后我們開(kāi)始使用頁(yè)面了,打開(kāi)這個(gè)地址↓
http://sd.fc-stable-diffusion-plus.xxxxx.cn-hangzhou.fc.devsapp.net 冷啟動(dòng)會(huì)有一定的加載時(shí)間。
文生圖

圖生圖

其他的自己可以多摸索摸索。
有獎(jiǎng)體驗(yàn)
阿里云將 提供免費(fèi) Serverless 函數(shù)計(jì)算產(chǎn)品資源 ,邀請(qǐng)你,體驗(yàn)一把 AIGC 級(jí)的畢加索、達(dá)芬奇、梵高等大師作畫(huà)的快感。下面請(qǐng)盡情發(fā)揮你的想象空間??!雙重獎(jiǎng)品設(shè)置,完成體驗(yàn)場(chǎng)景可得社區(qū) 1000 積分兌換獎(jiǎng)品,還可參加 AI 生成圖像比賽 贏取 Airpods、500 元貓超卡及社區(qū)定制抱枕!
?? 體驗(yàn)地址: https://developer.aliyun.com/topic/aigc 你也可以輕松做出下方畫(huà)作???? 
相關(guān)鏈接:
[1] NAS
https://www.aliyun.com/product/nas?spm=5176
[2] 函數(shù)計(jì)算 https://www.aliyun.com/product/fc?spm=5176.devs [3] 容器鏡像服務(wù) ACR https://www.aliyun.com/product/acr?spm=5176.28055625.J_3207526240.121.1d22154aWn0gl1&scm=20140722.M_4776670._.V_1 [4] Serverless Devs https://docs.serverless-devs.com/serverless-devs/quick_start [5] 配置阿里云密鑰信息 https://docs.serverless-devs.com/serverless-devs/command/config#config-add-%E5%91%BD%E4%BB%A4
點(diǎn)擊閱讀原文立即部署!
