再推一波,佬友们轻量使用,预计稳定运行一个月https://sd.hanh.me/?__theme=dark
服务器到期,暂停运,后续恢复会发帖(2024/12/7)
运行一星期已知问题
1.由于机器性能原因,oom炸内存不可避免,难免会有在生图事遇到webui重启的错误,经过测验已有内存能同时保持两个sdxl模型加载,三个sd1.5加载,最高fp16精度模型加载,所以说只要不加载太多lora,或者多人在线使用,生成一张2048x2048的图片也不会炸显存
2.sd模型终归是过去式了,comfyui的确更好用,起码不会出现内存泄漏,之后会部署flux1.1,但也可能会保留sdwebui继续使用sd的一些模型,请佬友们反馈一下,本人也会继续完善
3.关于部署的相关文件,我也会在此公开,各位复制到自己的colab也能自行部署
import os
import time
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
from huggingface_hub import HfApi
# 安装目录
path = "/www"
# 安装网址
url = "https://github.com/AUTOMATIC1111/stable-diffusion-webui"
repo = url.split('/')[-1]
# 是否重装
reinstall = False
# 修改分支
branch = "master"
# SD模型(先换行,再加链接)
model_urls = """
https://share.umua.top/d/local/sd%E7%94%BB%E5%9B%BE/sd1.5/majicmixRealistic_v7.safetensors?sign=V9JPMkppvZLpQaVaqlfrmJbOeH2B-oe_Sb96FkKPtdA=:0
"""
# VAE模型(先换行,再加链接)
VAE_urls = """
"""
# lora模型(先换行,再加链接)
lora_urls = """
https://lxc3069.hanh.me/Gluttony10/1/resolve/main/lcm-lora-sdv1-5.safetensors
https://lxc3069.hanh.me/Gluttony10/1/resolve/main/lcm-lora-sdxl.safetensors
"""
# ControlNet模型(先换行,再加链接)
ControlNet_urls = """
https://share.umua.top/d/local/sd画图/controlnet/controlnet_1.safetensors?sign=NFMWPda9QRLQoOMaFaVxAU0IdBfSC-JLVyNc_vwPGqM=:0
https://share.umua.top/d/local/sd画图/controlnet/controlnet_10.safetensors?sign=CXIXyn-JXs57qCkFr17TqZFmMLTZY-MFjBdKxvvwGqU=:0
https://share.umua.top/d/local/sd画图/controlnet/controlnet_11.safetensors?sign=vo6jqpk4PLsjz1kbe_w23_Q5MQyrR3Z6qBNgg0-Lh8c=:0
https://share.umua.top/d/local/sd画图/controlnet/controlnet_12.safetensors?sign=PJIyootAesjY7hIPj7jJIVH83Hhnsym4uLvGOGmcMpo=:0
https://share.umua.top/d/local/sd画图/controlnet/controlnet_13.safetensors?sign=Tou3PvefuTaqa0fV6RvTQPbGhP7rH2Fw-inBw-rDvvk=:0
https://share.umua.top/d/local/sd画图/controlnet/controlnet_14.safetensors?sign=vRrudAWvFTCNNQ7X6i_KBY-3G3O5mu6y7LIwvxYhP8o=:0
https://share.umua.top/d/local/sd画图/controlnet/controlnet_15.safetensors?sign=vK4nqdAjGlwwQGeK8Fo9GMk9fYH0P18mdQaaiiwy0lE=:0
https://share.umua.top/d/local/sd画图/controlnet/controlnet_16.safetensors?sign=S5fud9CNVuYwUYMuTVlWWHVeEsPFSH1pEtXmFEezfu4=:0
https://share.umua.top/d/local/sd画图/controlnet/controlnet_17.pth?sign=VgOii_d8VlUzRf0vEOI0l3f881ZyvwIDN_gjVGD6njY=:0
https://share.umua.top/d/local/sd画图/controlnet/controlnet_2.yaml?sign=kfJUE3384kbZ_AL2gabVwg01B-m8q3COeIIHs9D_LB8=:0
https://share.umua.top/d/local/sd画图/controlnet/controlnet_3.safetensors?sign=uCuCN1t8679sESp3JIVzTRkrTGtvAB-4QQZ7nIsJL6I=:0
https://share.umua.top/d/local/sd画图/controlnet/controlnet_4.safetensors?sign=MFHun3W598zZP6tY3mj7PmwRy5tRtSGARdJzAGYoSpI=:0
https://share.umua.top/d/local/sd画图/controlnet/controlnet_5.safetensors?sign=kspXfgqIND6j2fecSggPak6J9XGI5svgzL21UKtgnMI=:0
https://share.umua.top/d/local/sd画图/controlnet/controlnet_6.safetensors?sign=HF3xtT7h4s03fUFmy7IIHOMy0Noc4pFsFiaqZjYZwwQ=:0
https://share.umua.top/d/local/sd画图/controlnet/controlnet_7.safetensors?sign=cRk5m91EFwNEQnKpZx7JsCtfgGeT34sasPIp96VdrTA=:0
https://share.umua.top/d/local/sd画图/controlnet/controlnet_8.safetensors?sign=ojfqnzn_DucVzdbTlBq_W2WghXVzbTYTdDOnzvYdZTg=:0
https://share.umua.top/d/local/sd画图/controlnet/controlnet_9.safetensors?sign=ZXY2y_C2y9PvC6u7RoAh0TaJAbi3408Gw54069buvyM=:0
"""
# 扩展插件(先换行,再加链接,不要带.git)
extension_urls = """
https://github.com/sdbds/stable-diffusion-webui-wildcards
https://github.com/lobehub/sd-webui-lobe-theme
https://github.com/Haoming02/sd-webui-memory-release
https://github.com/huchenlei/sd-webui-openpose-editor
https://github.com/Physton/sd-webui-prompt-all-in-one
https://github.com/hanamizuki-ai/stable-diffusion-webui-localization-zh_Hans
https://github.com/zanllp/sd-webui-infinite-image-browsing
https://github.com/butaixianran/Stable-Diffusion-Webui-Civitai-Helper
https://github.com/Tencent/LightDiffusionFlow
https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111
https://github.com/Bing-su/adetailer
https://github.com/Uminosachi/sd-webui-inpaint-anything
https://github.com/DominikDoom/a1111-sd-webui-tagcomplete
"""
# SD安装文件(不要修改)
repositorie_urls = """
https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets
https://github.com/Stability-AI/generative-models
https://github.com/crowsonkb/k-diffusion
https://github.com/salesforce/BLIP
"""
# adetailer模型(先换行,再加链接)
adetailer_urls = """
https://share.umua.top/d/local/sd画图/Adetailer/adetailer_1.pt?sign=UVZDK1GrPhlov_SmXIfrN5U1naI05Cm0i-_vXow1x1Y=:0
https://share.umua.top/d/local/sd画图/Adetailer/adetailer_2.pt?sign=qTjH7gpfWfurgHO-1GzGDTIPwx_1fVmSWYyegtlX7OM=:0
https://share.umua.top/d/local/sd画图/Adetailer/adetailer_3.pt?sign=PdapEq9vXj-FeZ60ywOZu6YsWsJ3kOdQ7ZVU4XcBZYw=:0
https://share.umua.top/d/local/sd画图/Adetailer/adetailer_4.pt?sign=YjnfPGgsikOgqGBj6R0oiK5iDnE2dt7y07CPRnbsaTs=:0
"""
# 额外文件(先换行,再加链接)(下载到安装目录,方便剪切)
extra_urls = """
"""
# 内存优化(不要修改)
def libtcmalloc():
os.system('apt-get update -qq > /dev/null 2>&1')
os.system('apt-get install -qq -y zip ffmpeg gifsicle libimage-exiftool-perl > /dev/null 2>&1')
if os.path.exists(f'{path}/temp'):
os.environ["LD_PRELOAD"] = "libtcmalloc.so"
print('内存优化已安装')
else:
os.chdir(f'{path}')
os.makedirs('temp', exist_ok=True)
os.chdir('temp')
os.system('wget -q http://launchpadlibrarian.net/367274644/libgoogle-perftools-dev_2.5-2.2ubuntu3_amd64.deb')
os.system('wget -q https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/google-perftools_2.5-2.2ubuntu3_all.deb')
os.system('wget -q https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/libtcmalloc-minimal4_2.5-2.2ubuntu3_amd64.deb')
os.system('wget -q https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/libgoogle-perftools4_2.5-2.2ubuntu3_amd64.deb')
os.system('apt-get install -qq libunwind8-dev -y > /dev/null 2>&1')
os.system('dpkg -i *.deb > /dev/null 2>&1')
os.environ["LD_PRELOAD"] = "libtcmalloc.so"
os.system('rm *.deb > /dev/null 2>&1')
print('内存优化安装完毕')
# 安装主体(不要修改)
def install_main():
if os.path.exists(f'{path}/{repo}'):
os.chdir(f'{path}/{repo}')
os.system('pip install -U pip ipywidgets imageio imageio-ffmpeg setuptools opencv-python ultralytics mediapipe > /dev/null 2>&1')
os.system('pip install -r requirements_versions.txt > /dev/null 2>&1')
if not os.path.exists(f'{path}/{repo}/config.json'):
os.system(f'wget -q -O {path}/{repo}/config.json https://git.hanh.me/https://github.com/gluttony-10/1/blob/main/config.json')
if not os.path.exists(f'{path}/{repo}/styles.csv'):
os.system(f'wget -q -O {path}/{repo}/styles.csv https://git.hanh.me/https://github.com/gluttony-10/1/blob/main/styles.csv')
print(f'{repo} 升级完毕')
# 下载文件1(不要修改)
def download_1():
tasks = []
tasks.append(f'git -C {path}/{repo}/repositories clone https://git.hanh.me/https://github.com/Stability-AI/stablediffusion stable-diffusion-stability-ai > /dev/null 2>&1')
tasks.extend(download_git(repositorie_urls, f'{path}/{repo}/repositories'))
tasks.append(f'git -C {path}/{repo}/repositories/stable-diffusion-stability-ai pull > /dev/null 2>&1')
tasks.extend(download_git(extension_urls, f'{path}/{repo}/extensions'))
tasks.append(f'git -C {path}/{repo}/repositories/stable-diffusion-stability-ai fetch > /dev/null 2>&1')
with ThreadPoolExecutor() as executor:
for task in tasks:
executor.submit(os.system, task)
print('插件升级完毕')
# 下载文件2(不要修改)
def download_2():
tasks = []
# 创建必要的目录
os.makedirs(f'{path}/{repo}/models/Stable-diffusion', exist_ok=True)
os.makedirs(f'{path}/{repo}/models/ControlNet', exist_ok=True)
os.makedirs(f'{path}/{repo}/models/Lora', exist_ok=True)
os.makedirs(f'{path}/{repo}/models/VAE', exist_ok=True)
os.makedirs(f'{path}/{repo}/models/adetailer', exist_ok=True)
os.makedirs(f'{path}/{repo}/models/animatediff', exist_ok=True)
os.makedirs('/usr/local/lib/python3.10/dist-packages/gradio', exist_ok=True)
# 下载模型文件
tasks.extend(download_aria(model_urls, f'{path}/{repo}/models/Stable-diffusion'))
tasks.extend(download_aria(ControlNet_urls, f'{path}/{repo}/models/ControlNet'))
tasks.extend(download_aria(lora_urls, f'{path}/{repo}/models/Lora'))
tasks.extend(download_aria(VAE_urls, f'{path}/{repo}/models/VAE'))
tasks.extend(download_aria(adetailer_urls, f'{path}/{repo}/models/adetailer'))
tasks.extend(download_aria(extra_urls, f'{path}'))
# 下载 xformers
xformers_url = 'https://mirror.sjtu.edu.cn/pytorch-wheels/cu118/xformers-0.0.23.post1%2Bcu118-cp310-cp310-manylinux2014_x86_64.whl'
xformers_filename = xformers_url.split('/')[-1]
tasks.extend(download_aria(xformers_url, f'{path}/{repo}'))
# 下载其他依赖
tasks.extend(download_aria('https://mirror.sjtu.edu.cn/pytorch-wheels/cu118/torch-2.1.0%2Bcu118-cp310-cp310-linux_x86_64.whl', f'{path}/{repo}'))
tasks.extend(download_aria('https://mirror.sjtu.edu.cn/pytorch-wheels/cu118/torchvision-0.16.0%2Bcu118-cp310-cp310-linux_x86_64.whl', f'{path}/{repo}'))
tasks.extend(download_aria('https://mirror.sjtu.edu.cn/pytorch-wheels/cu118/torchaudio-2.1.0%2Bcu118-cp310-cp310-linux_x86_64.whl', f'{path}/{repo}'))
# 下载 frpc 文件
tasks.extend(download_aria('https://share.umua.top/d/local/sd%E7%94%BB%E5%9B%BE/frp/frpc_linux_amd64_v0.2?sign=0w4xzGwUuJSa7-_1arSqHg6u9fUzfHrOkCjSrbCeZCE=:0', '/usr/local/lib/python3.10/dist-packages/gradio'))
# 执行下载任务
with ThreadPoolExecutor() as executor:
futures = [executor.submit(os.system, task) for task in tasks]
for future in futures:
future.result()
# 检查 xformers 是否下载成功
xformers_path = os.path.join(f'{path}/{repo}', xformers_filename)
if not os.path.exists(xformers_path):
print(f'错误:未能下载 {xformers_filename},请检查网络连接或下载链接。')
else:
print(f'{xformers_filename} 下载成功。')
print('文件下载完毕')
# 下载 git 库(不要修改)
def download_git(links, folder):
tasks = []
link_list = links.strip().split("\n")
for li in link_list:
tasks.append(f'git -C {folder} clone {li} --recursive > /dev/null 2>&1')
for li in link_list:
name = li.split('/')[-1]
tasks.append(f'git -C {folder}/{name} pull > /dev/null 2>&1')
tasks.append(f'git -C {folder}/{name} submodule update --init --recursive > /dev/null 2>&1')
return tasks
# 下载模块(不要修改)
def download_aria(links, folder):
tasks = []
link_list = links.strip().split("\n")
for li in link_list:
if not li:
continue
filename = os.path.basename(li.split('?')[0])
output_file = os.path.join(folder, filename)
if not os.path.isfile(output_file):
tasks.append(f'aria2c -c -x 16 -s 16 -k 1M -d "{folder}" -o "{filename}" "{li}"')
else:
print(f"文件已存在:{output_file},跳过下载。")
return tasks
# 下载 Hugging Face 库(不要修改)
def download_hf(repo, folder):
hf_api = HfApi(endpoint="https://lxc3069.hanh.me")
tasks = []
max_retries = 3
for retry in range(max_retries):
try:
files = hf_api.list_repo_files(f'{repo}', timeout=60)
files = [f for f in files if f not in ['.gitattributes', 'README.md']]
break
except Exception as e:
if retry == max_retries - 1:
print(f"无法从 HuggingFace 仓库获取文件列表:{e}")
return tasks
time.sleep(10)
for fi in files:
li = os.path.join("https://lxc3069.hanh.me", f'{repo}', "resolve/main/", f'{fi}')
tasks.append(f'aria2c -c -x 16 -s 16 -k 1M -d "{folder}" -o "{fi}" "{li}"')
return tasks
# 主进程(不要修改)
def main():
time_start = time.time()
os.system('git config --global url."https://git.hanh.me/https://github.com".insteadOf "https://github.com"')
os.system('git config --global url."https://git.hanh.me/https://raw.githubusercontent.com".insteadOf "https://raw.githubusercontent.com"')
# 添加 HuggingFace 镜像配置
os.environ["HF_ENDPOINT"] = "https://lxc3069.hanh.me"
os.environ["HF_HOME"] = f"{path}/huggingface"
print("运行开始")
os.system('df -hl')
os.system('nvidia-smi')
os.chdir(f'{path}')
if reinstall:
print('旧文件删除中')
os.system(f'rm -rf {path}/{repo}')
print(f'开始安装 {repo}')
os.system('git config --global http.postBuffer 2000003072')
os.system(f'git -C {path} clone {url} --recursive > /dev/null 2>&1')
if os.path.exists(f'{path}/{repo}'):
os.makedirs(f'{path}/{repo}/repositories', exist_ok=True)
os.makedirs(f'{path}/{repo}/models/Stable-diffusion', exist_ok=True)
os.system(f'git -C {path}/{repo} checkout {branch}')
os.system(f'git -C {path}/{repo} pull')
os.system(f'git -C {path}/{repo} submodule update --init --recursive > /dev/null 2>&1')
print("多进程开始,请耐心等待")
with ProcessPoolExecutor() as executor:
futures = []
futures.append(executor.submit(install_main))
futures.append(executor.submit(libtcmalloc))
for future in futures:
future.result()
futures = []
futures.append(executor.submit(download_2))
futures.append(executor.submit(download_1))
for future in futures:
future.result()
os.chdir(f'{path}/{repo}')
# 安装 PyTorch 和 xformers
os.system('pip install torch-2.1.0%2Bcu118-cp310-cp310-linux_x86_64.whl > /dev/null 2>&1')
os.system('pip install torchvision-0.16.0%2Bcu118-cp310-cp310-linux_x86_64.whl > /dev/null 2>&1')
os.system('pip install torchaudio-2.1.0%2Bcu118-cp310-cp310-linux_x86_64.whl > /dev/null 2>&1')
xformers_filename = 'xformers-0.0.23.post1+cu118-cp310-cp310-manylinux2014_x86_64.whl'
os.system(f'pip install {xformers_filename} > /dev/null 2>&1')
time_end = time.time()
print('\033[32m安装耗时:', int((time_end - time_start)/60), 'min\033[0m')
os.system('chmod 755 /usr/local/lib/python3.10/dist-packages/gradio/frpc_linux_amd64_v0.2')
os.system('HF_ENDPOINT=https://lxc3069.hanh.me python launch.py --api --no-download-sd-model --opt-sdp-attention --share --listen --enable-insecure-extension-access --theme dark')
else:
print('安装失败请重试')
if __name__ == '__main__':
main()