Home > Article > Technology peripherals > A stupid dog robot was trained based on GPT2
First of all, I want to tell you that in the field of programming development, what you need to learn is the way to learn. If you go in the right direction, you can get twice the result with half the effort. And I think the fastest and most effective way to learn technical skills is to practice. Don’t get into too many theories first. You can’t just dismantle the bike you bought. You have to find a way to ride it first.
So this is what Brother Fu is doing, learning things. Driven by the goal, build the smallest unit version that can run tests. Because Conway's Law says; the smaller the problem, the easier it is to understand and deal with. So after coming into contact with ChatGPT, I often thought about how to train and deploy such a chat dialogue model by myself, even with a small amount of training data for me to test. So here comes this silly dog robot that can troll people!
Based on the learning based on the previous article "Build a ChatGPT Algorithm Model" by Brother Fu, OpenAI open source GPT-2 and related GPT2-chitchat The model training code deploys this silly dog robot that can troll people. However, due to problems with training data, this chatbot always feels abnormal when talking to it. ——But it does not affect our learning of algorithm model training.
This page is the WEB version of the chat dialogue window programmed by Brother Fu
OpenAI GPT2 model training and service use require the use of Python, TensorFlow machine learning and other related configurations, and there are some version dependencies between these environments. So for smooth debugging, try to keep the same version as me. If you have difficulty installing the environment, you can also ask Brother Fu to help you buy a cloud server. Then I will mirror my environment to your server and you can use it directly. Below is the basic environment, code, and data required.
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel yum install gcc -y yum -y install libffi-devel make make altinstall
cd ~ # 1.下载Python安装包 wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz # 2.将安装包移动到/usr/local文件夹下 mv Python-3.7.4.tgz /usr/local/ # 3.在local目录下创建Python3目录 mkdir /usr/local/python3 # 4.进入的Python安装包压缩包所在的目录 cd /usr/local/ # 5.解压安装包 tar -xvf Python-3.7.4.tgz # 6.进入解压后的目录 cd /usr/local/Python-3.7.4/ # 7.配置安装目录 ./configure --prefix=/usr/local/python3 # 8.编译源码 make # 9.执行源码安装 make install # 10.创建软连接 ln -s /usr/local/python3/bin/python3/usr/bin/python3 # 11. 测试 python3 -V
cd ~ # 1.下载 wget https://bootstrap.pypa.io/get-pip.py # 2.安装;注意咱们安装了 python3 所以是 pyhton3 get-pip.py python3 get-pip.py # 3.查找pip安装路径 find / -name pip # 4.将pip添加到系统命令 ln -s/usr/local/python/bin/pip /usr/bin/pip # 5.测试 pip -V # 6.更换源,如果不更换那么使用 pip 下载软件会很慢 pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple pip config set install.trusted-host mirrors.aliyun.com pip config list # pip国内镜像源: # 阿里云 http://mirrors.aliyun.com/pypi/simple/ # 中国科技大学https://pypi.mirrors.ustc.edu.cn/simple/ # 豆瓣 http://pypi.douban.com/simple # Python官方 https://pypi.python.org/simple/ # v2ex http://pypi.v2ex.com/simple/ # 中国科学院http://pypi.mirrors.opencas.cn/simple/ # 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
cd ~ # 1.安装前首先得安装依赖环境 yum install -y perl-devel # 2.下载源码包到 CentOS 服务器后进行解压 tar -zxf git-2.9.5.tar.gz cd git-2.9.5 # 3.执行如下命令进行编译安装 ./configure --prefix=/usr/local/git make && make install # 4.添加到系统环境变量 vim ~/.bashrc export PATH="/usr/local/git/bin:$PATH" # 5.使配置生效 source ~/.bashrc # 6.测试 git version
yum install -y wget && wget -O install.sh https://download.bt.cn/install/install_6.0.sh && sh install.sh 12f2c1d72
Model training requires the transformers machine learning service, as well as pytorch, sklearn and other components; the following content needs to be installed separately;
transformers==4.4.2 pytorch==1.7.0 sklearn tqdm numpy scipy==1.2.1
pip install transformers==4.4.2
pip install torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio===0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
For the rest, just follow the pip install instructions. In addition, when running GTP2-chitchat, if you are prompted that some components are missing, use pip directly and follow the instructions. Can.
Here, first put the websocket page code prepared by Brother Fu for you, and then deploy it after creating the site through Pagoda. Code: https://github.com/fuzhengwei/GPT2-chitchat/tree/master/web
After that, open your pagoda address, Create a site and upload web code.
Note: The current configuration for accessing websocket in this code is in index.js, and you need to change it to your server address.
if(!window.WebSocket){ alert("您的浏览器不支持WebSocket协议!推荐使用谷歌浏览器进行测试。"); return; } socket = new WebSocket("ws://120.48.169.252:7397");
cd /home git clone https://github.com/fuzhengwei/GPT2-chitchat.git
You need to modify the interact.py code and change the IP and port configuration of Websocket here;
async def start_server(): try: async with websockets.serve(server, "192.168.0.4", 7397): print("Starting server at ws://localhost:7397") await asyncio.Future()# run forever except OSError as e: print(f"Error starting server: {e}") except Exception as e: print(f"Unexpected error: {e}")
Download model: https://pan.baidu.com/s/1iEu_-Avy-JTRsO4aJNiRiA#list/path=/ - Password: ju6m
Upload model: Here you need to install an SFTP tool on your local machine, or use the tool provided by IntelliJ IDEA to link. After linking, you can upload the decompressed model to /home/GPT2-chitchat/model.
async def start_server(): try: async with websockets.serve(server, "192.168.0.4", 7397): print("Starting server at ws://localhost:7397") await asyncio.Future()# run forever except OSError as e: print(f"Error starting server: {e}") except Exception as e: print(f"Unexpected error: {e}")
修改这部分代码的IP和端口,以及在云服务上开启 7397 的访问权限。另外为了安全起见,可以在云服务的防火墙IP来源中授权,只有你当前的台机器才可以链接到 websocket 上。
这里小傅哥通过 mac nuoshell 连接工具,进行模型启动;模型路径:/home/GPT2-chitchat/model/model_epoch40_50w
python3 interact.py --no_cuda --model_path /home/GPT2-chitchat/model/model_epoch40_50w
以上就是整个 GPT2-chitchat 一个闲聊模型的部署,你也可以尝试使用 Docker 部署。如果在部署过程中实在很难部署成功,也可以找小傅哥买云服务,这样我可以直接把镜像部署到你的云服务上,就可以直接使用了。
The above is the detailed content of A stupid dog robot was trained based on GPT2. For more information, please follow other related articles on the PHP Chinese website!