A gradio web UI for running Large Language Models like GPT-J 6B, OPT, GALACTICA, LLaMA, and Pygmalion.

Its goal is to become the AUTOMATIC1111/stable-diffusion-webui of text generation.

语言模型版本的 Stable Diffusion Web UI

环境

  • Debian 11
    • Python 3.9
    • Nginx
  • Tesla P40

步骤

准备运行环境

apt install curl wget git unzip

Text generation Web UI 不能运行在 root 用户下,如果平时使用 root 用户,需要新建普通用户

adduser [username]
# 按提示填写信息
usermod -a -G sudo [username]

切换到普通用户

su - [username]

安装 Text generation Web UI

使用 conda 没有安装成功,这里使用官方提供的安装脚本

下载并解压官方安装包

wget https://github.com/oobabooga/text-generation-webui/releases/download/installers/oobabooga-linux.zip
unzip oobabooga-linux.zip
cd oobabooga

解压后根目录会有三个脚本:download-model.sh、install.sh 和 start-webui.sh

依次运行 install.sh、download-model.sh,并按照提示完成安装/下载

  • install.sh 获取 text-generation-webui 源码并安装 python 运行依赖
    • 安装过程较为漫长
  • download-model.sh 会从 huggingface 下载指定的 LLM
    • pygmalion-6b 模型全部下载完毕后大约占用 15.2 G,分配好磁盘空间(和流量)
    • 当然也可以手动下载后放入 /path/to/oobabooga/text-generation-webui/models
      • 需要对每种模型创建单独的目录

执行完毕后编辑 start-webui.sh 文件,修改最后一行启动服务的指令,按需添加额外参数

下图添加了 --listen-port 参数,修改了默认的监听端口

更多参数可以直接查看源代码根目录下的 modules/shared.py 文件

配置系统服务

在 /etc/systemd/system 下新建配置文件 text-generation-webui.service,写入以下内容

[Unit]
Description=Text generation web ui

[Service]
User=[username]
Group=[user group]
WorkingDirectory=/path/to/oobabooga
ExecStart=/usr/bin/bash /path/to/oobabooga/start-webui.sh

[Install]
WantedBy=multi-user.target

启动服务并设置开机自启

systemctl enable text-generation-webui.service --now

配置 Nginx

在 /etc/nginx/sites-available 下新建配置文件 text-generation-webui.conf,写入以下内容

server {
        listen [port]
        server_name [server name];

        location / {
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_pass http://127.0.0.1:[web ui listen port];
        }

        location /queue/ {
                proxy_pass http://127.0.0.1:[web ui listen port];
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
        }
}

和 tldream 自托管 一样,也需要为 Websocket 设置代理, 路径为 /queue/

新建软链接并载入配置文件

ln -s /etc/nginx/sites-available/text-generation-webui.conf /etc/nginx/sites-enabled/
nginx -t
nginx -s reload

Continue reading "Text generation Web UI 自托管"

A tiny little diffusion drawing app

画图结合 prompts 生成图片

环境

  • Debian 11
    • Python 3.9
    • Nginx
  • Tesla P40

步骤

准备运行环境

apt install libgl1 libglib2.0-0 python3-dev python3-pip nginx

安装 tldream

# 国内网络建议先换源
pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple pip -U
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple
# 安装 tldream
pip install tldream

安装过程中会下载 python 依赖和 Stable Diffusion 模型,模型存储在 ~/.cache/huggingface/hub 下

测试运行

执行指令运行 tldream,添加 --listen 令其监听外部 IP 地址

tldream --listen --port [port]

然后浏览器访问 IP+端口,测试图片可以正常生成

配置系统服务

在 /etc/systemd/system 下新建配置文件 tldream.service,写入以下内容

[Unit]
Description=tldream

[Service]
User=root
ExecStart=/usr/local/bin/tldream --no-listen --port [port] --no-nsfw-filter

[Install]
WantedBy=multi-user.target

添加 --no-nsfw-filter 会允许生成 NSFW 图片

添加 --model [模型] 可以指定其他 Stable Diffusion 模型

启动并设置开机自启

systemctl enable tldream.service --now

配置 Nginx

在 /etc/nginx/sites-available 下新建配置文件 tldream.conf,写入以下内容

server {
        listen [port];
        server_name [server name];

        location / {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass http://127.0.0.1:[tldream listen port];
        }

        location /ws/ {
            proxy_pass http://127.0.0.1:[tldream listen port];
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
}

除了基本的反向代理外,还需要单独为 Websocket 配置代理

新建软链接并重载配置文件

ln -s /etc/nginx/sites-available/tldream.conf /etc/nginx/sites-enabled
nginx -t
nginx -s reload

Continue reading "tldream 自托管"