24
2025
02
16:14:36

PVE下ubuntu22.04部署Stable Diffusion教程(使用NVIDIA P100显卡)

PVE下ubuntu22.04部署Stable Diffusion教程(使用NVIDIA P100显卡)


可能有很多人和我有同样的想法,想把Stable Diffusion部署到Ubuntu等Linux服务器上,然后开放端口到外网,这样就可以在任何有网络的地方来进行访问,不必局限于在家的局域网内。下面咱们就用嘴简单的方式进行部署一下。

一、下载Stable Diffusion

B站大佬秋葉aaaki的Stable Diffusion版本,不但可以在Windows11上部署,在Ubuntu22.04上也是超级简单的,我下载的版本是sd-webui-aki-v4.5,有需要可以去大佬主页下载,或者私聊我。本教程参考于阿宁明道大佬的教程。

二、准备Stable Diffusion

把Stable Diffusion下载的压缩包解压到桌面,因为win和Linux的区别,有些字符定义需要转换一下,这里就重新搞一下webui.sh 和 webui-user.sh两个文件。

#切换到root用户sudo su -
#我们的sd路径cd /home/jason/Desktop/sd-webui-aki-v4.5
touch a.shchmod 777 a.shchmod +x a.sh
#然后在图形页面,打开webui.sh,拷贝其内容到a.sh,a.sh中内容就适合于Linux了
rm webui.shmv a.sh webui.sh
touch b.shchmod 777 ba.shchmod +x b.sh
#然后在图形页面,打开webui-user.sh,拷贝期内容到b.sh,b.sh中内容就适合于Linux了
rm webui-user.shmv b.sh webui-user.sh


三、Stable Diffusion运行环境准备

3.1 安装Tesla P100显卡驱动

# installation tipsapt updateapt upgrade -yapt install vim -y
apt install g++ gcc make -y
#查看ubuntu-drivers devicesroot@hep:~# ubuntu-drivers devices== /sys/devices/pci0000:00/0000:00:10.0 ==modalias : pci:v000010DEd000015F8sv000010DEsd0000118Fbc03sc02i00vendor   : NVIDIA Corporationmodel   : GP100GL [Tesla P100 PCIe 16GB]driver   : nvidia-driver-470-server - distro non-freedriver   : nvidia-driver-450-server - distro non-freedriver   : nvidia-driver-535-server - distro non-freedriver   : nvidia-driver-418-server - distro non-freedriver   : nvidia-driver-390 - distro non-freedriver   : nvidia-driver-470 - distro non-freedriver   : nvidia-driver-525 - distro non-freedriver   : nvidia-driver-535 - distro non-free recommendeddriver   : nvidia-driver-525-server - distro non-freedriver   : xserver-xorg-video-nouveau - distro free builtinroot@hep:~#
#选择nvidia-driver-535 - distro non-free recommended这个推荐的驱动安装apt install nvidia-driver-535 -y
#重启reboot
#查看驱动nvidia-smi,显示已经可以识别P100了root@hep:~# nvidia-smiTue Nov 28 14:17:48 2023+---------------------------------------------------------------------------------------+| NVIDIA-SMI 535.129.03             Driver Version: 535.129.03   CUDA Version: 12.2     ||-----------------------------------------+----------------------+----------------------+| GPU Name                 Persistence-M | Bus-Id       Disp.A | Volatile Uncorr. ECC || Fan Temp   Perf         Pwr:Usage/Cap |         Memory-Usage | GPU-Util Compute M. ||                                         |                     |               MIG M. ||=========================================+======================+======================||   0 Tesla P100-PCIE-16GB           Off | 00000000:00:10.0 Off |                    0 || N/A   34C   P0             26W / 250W |     4MiB / 16384MiB |      0%     Default ||                                         |                     |                 N/A |+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+| Processes:                                                                           || GPU   GI   CI       PID   Type   Process name                           GPU Memory ||       ID   ID                                                             Usage     ||=======================================================================================||    0   N/A N/A      1243     G   /usr/lib/xorg/Xorg                           4MiB |+---------------------------------------------------------------------------------------+root@hep:~#



3.2 准备Python环境

#进入sd根目录cd /home/jason/Desktop/sd-webui-aki-v4.5#安装pip && Python虚拟环境apt install git pip -yapt install python3-venv -ypython3 -m venv venvsource ./venv/bin/activate#设置pip源为阿里源pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/#更新pippip install --upgrade pip  -i https://mirrors.aliyun.com/pypi/simple/#增加git目录git config --global --add safe.directory /home/jason/Desktop/sd-webui-aki-v4.5



四、运行Stable Diffusion

#运行命令使用 ./webui.sh -f 或者bash webui.sh -f ,如果不使用root用户,可以去掉f参数bash webui.sh -f#此时会安装各种依赖,慢慢等待就好


报错如下:

OSError: Can't load tokenizer for 'openai/clip-vit-large-patch14'. If you were trying to load it from 'make sure you don't have a local directory with the same name. Otherwise, make sure 'openai/clip-vit-large-patch14' is the correct path to a directory containing all relevant files for a CLIPTokenizer tokenizer.



可以参考这个大佬的解决办法http://www.chen-studio.com/archives/128.html,应该是墙的问题。

五、设置外部访问


#开放7860端口ufw allow 7860ufw enable
#启动参数加上监听./webui.sh --listen


局域网别的机器上,输入Ubuntu的IP和端口号http://192.168.31.29:7860/就可以访问了,如果需要外网访问还可以做内网穿透等操作。

图片




推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

本文链接:https://hqyman.cn/post/9136.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:
打赏





休息一下~~


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

请先 登录 再评论,若不是会员请先 注册

您的IP地址是: