Table of Contents
1. Silly Dog Machine Chat
2. Basic configuration environment
1. Environment dependencies
2. Python 3.7
3. Install pip3
4. Install git
5. Install Pagoda
3. Model running environment
1. transformers
2. pytorch
3. Other installations
4. Chat page configuration
5. Model training deployment
1. Download code
2. Upload model
3. 启动服务
Home Technology peripherals AI A stupid dog robot was trained based on GPT2

A stupid dog robot was trained based on GPT2

Apr 10, 2023 pm 06:11 PM
robot chatgpt 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!

1. Silly Dog Machine Chat

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.

A stupid dog robot was trained based on GPT2

This page is the WEB version of the chat dialogue window programmed by Brother Fu

  • Access address: http:/ /120.48.169.252/ - The server configuration is limited and cannot handle excessive concurrent access.
  • Video demonstration: https://www.bilibili.com/video/BV1LG4y1P7bo - You can also watch the GPT2 model deployment demonstration through the Bilibili video.

2. Basic configuration environment

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.

  • System configuration: Centos 7.9 - 2-core 4GB memory 200G disk 4Mbps bandwidth cloud server
  • Deployment environment: Python3.7, Transformers==4.2.0, pytorch==1.7 .0
  • Model code: https://github.com/fuzhengwei/GPT2-chitchat - This code is open source and contains websocket communication page
  • Model data: https://pan.baidu .com/s/1iEu_-Avy-JTRsO4aJNiRiA - ju6m

1. Environment dependencies

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
Copy after login

2. Python 3.7

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
Copy after login

3. Install pip3

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/
Copy after login

4. Install git

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
Copy after login

5. Install Pagoda

yum install -y wget && wget -O install.sh https://download.bt.cn/install/install_6.0.sh && sh install.sh 12f2c1d72
Copy after login
  1. After installation, log in to the address prompted by Pagoda. By default, it will use port 8888, so you need to be on the server Enable access to port 8888.
  2. The installation of Pagoda is to deploy a web version of the chat interface on the server side, using the Nginx service. It's easier to operate with a pagoda here.

3. Model running environment

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
Copy after login

1. transformers

pip install transformers==4.4.2
Copy after login

2. pytorch

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
Copy after login
  • This torch version cpu and torchvision need to match.

3. Other installations

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.

4. Chat page configuration

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

A stupid dog robot was trained based on GPT2

After that, open your pagoda address, Create a site and upload web code.

A stupid dog robot was trained based on GPT2

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");
Copy after login

5. Model training deployment

1. Download code

cd /home

git clone https://github.com/fuzhengwei/GPT2-chitchat.git
Copy after login

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}")
Copy after login
Copy after login

2. Upload model

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}")
Copy after login
Copy after login

修改这部分代码的IP和端口,以及在云服务上开启 7397 的访问权限。另外为了安全起见,可以在云服务的防火墙IP来源中授权,只有你当前的台机器才可以链接到 websocket 上。

3. 启动服务

这里小傅哥通过 mac nuoshell 连接工具,进行模型启动;模型路径:/home/GPT2-chitchat/model/model_epoch40_50w

python3 interact.py --no_cuda --model_path /home/GPT2-chitchat/model/model_epoch40_50w
Copy after login

A stupid dog robot was trained based on GPT2

  • 启动后就可以把你的 websocket 页面打开了,它会自动的链接到这个 websocket 服务上。
  • 如果你还需要 Socket 或者命令行的服务,也可以修改 interact.py 代码进行处理。

以上就是整个 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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ChatGPT now allows free users to generate images by using DALL-E 3 with a daily limit ChatGPT now allows free users to generate images by using DALL-E 3 with a daily limit Aug 09, 2024 pm 09:37 PM

DALL-E 3 was officially introduced in September of 2023 as a vastly improved model than its predecessor. It is considered one of the best AI image generators to date, capable of creating images with intricate detail. However, at launch, it was exclus

The second generation Ameca is here! He can communicate with the audience fluently, his facial expressions are more realistic, and he can speak dozens of languages. The second generation Ameca is here! He can communicate with the audience fluently, his facial expressions are more realistic, and he can speak dozens of languages. Mar 04, 2024 am 09:10 AM

The humanoid robot Ameca has been upgraded to the second generation! Recently, at the World Mobile Communications Conference MWC2024, the world's most advanced robot Ameca appeared again. Around the venue, Ameca attracted a large number of spectators. With the blessing of GPT-4, Ameca can respond to various problems in real time. "Let's have a dance." When asked if she had emotions, Ameca responded with a series of facial expressions that looked very lifelike. Just a few days ago, EngineeredArts, the British robotics company behind Ameca, just demonstrated the team’s latest development results. In the video, the robot Ameca has visual capabilities and can see and describe the entire room and specific objects. The most amazing thing is that she can also

The first robot to autonomously complete human tasks appears, with five fingers that are flexible and fast, and large models support virtual space training The first robot to autonomously complete human tasks appears, with five fingers that are flexible and fast, and large models support virtual space training Mar 11, 2024 pm 12:10 PM

This week, FigureAI, a robotics company invested by OpenAI, Microsoft, Bezos, and Nvidia, announced that it has received nearly $700 million in financing and plans to develop a humanoid robot that can walk independently within the next year. And Tesla’s Optimus Prime has repeatedly received good news. No one doubts that this year will be the year when humanoid robots explode. SanctuaryAI, a Canadian-based robotics company, recently released a new humanoid robot, Phoenix. Officials claim that it can complete many tasks autonomously at the same speed as humans. Pheonix, the world's first robot that can autonomously complete tasks at human speeds, can gently grab, move and elegantly place each object to its left and right sides. It can autonomously identify objects

How can AI make robots more autonomous and adaptable? How can AI make robots more autonomous and adaptable? Jun 03, 2024 pm 07:18 PM

In the field of industrial automation technology, there are two recent hot spots that are difficult to ignore: artificial intelligence (AI) and Nvidia. Don’t change the meaning of the original content, fine-tune the content, rewrite the content, don’t continue: “Not only that, the two are closely related, because Nvidia is expanding beyond just its original graphics processing units (GPUs). The technology extends to the field of digital twins and is closely connected to emerging AI technologies. "Recently, NVIDIA has reached cooperation with many industrial companies, including leading industrial automation companies such as Aveva, Rockwell Automation, Siemens and Schneider Electric, as well as Teradyne Robotics and its MiR and Universal Robots companies. Recently,Nvidiahascoll

After 2 months, the humanoid robot Walker S can fold clothes After 2 months, the humanoid robot Walker S can fold clothes Apr 03, 2024 am 08:01 AM

Editor of Machine Power Report: Wu Xin The domestic version of the humanoid robot + large model team completed the operation task of complex flexible materials such as folding clothes for the first time. With the unveiling of Figure01, which integrates OpenAI's multi-modal large model, the related progress of domestic peers has been attracting attention. Just yesterday, UBTECH, China's "number one humanoid robot stock", released the first demo of the humanoid robot WalkerS that is deeply integrated with Baidu Wenxin's large model, showing some interesting new features. Now, WalkerS, blessed by Baidu Wenxin’s large model capabilities, looks like this. Like Figure01, WalkerS does not move around, but stands behind a desk to complete a series of tasks. It can follow human commands and fold clothes

Can chatgpt be used in China? Can chatgpt be used in China? Mar 05, 2024 pm 03:05 PM

chatgpt can be used in China, but cannot be registered, nor in Hong Kong and Macao. If users want to register, they can use a foreign mobile phone number to register. Note that during the registration process, the network environment must be switched to a foreign IP.

How to install chatgpt on mobile phone How to install chatgpt on mobile phone Mar 05, 2024 pm 02:31 PM

Installation steps: 1. Download the ChatGTP software from the ChatGTP official website or mobile store; 2. After opening it, in the settings interface, select the language as Chinese; 3. In the game interface, select human-machine game and set the Chinese spectrum; 4 . After starting, enter commands in the chat window to interact with the software.

Ten humanoid robots shaping the future Ten humanoid robots shaping the future Mar 22, 2024 pm 08:51 PM

The following 10 humanoid robots are shaping our future: 1. ASIMO: Developed by Honda, ASIMO is one of the most well-known humanoid robots. Standing 4 feet tall and weighing 119 pounds, ASIMO is equipped with advanced sensors and artificial intelligence capabilities that allow it to navigate complex environments and interact with humans. ASIMO's versatility makes it suitable for a variety of tasks, from assisting people with disabilities to delivering presentations at events. 2. Pepper: Created by Softbank Robotics, Pepper aims to be a social companion for humans. With its expressive face and ability to recognize emotions, Pepper can participate in conversations, help in retail settings, and even provide educational support. Pepper's

See all articles