make
This commit is contained in:
parent
e7e2ce551c
commit
e887d6a425
18
Makefile
Normal file
18
Makefile
Normal file
@ -0,0 +1,18 @@
|
||||
MAKEFLAGS += --silent
|
||||
|
||||
all: release run
|
||||
|
||||
install:
|
||||
pip3 install tiktoken
|
||||
|
||||
check:
|
||||
./check.sh
|
||||
|
||||
release:
|
||||
cc gpt.c -lm -O3 -Wno-unused-result -Wno-unused-value -Wno-unused-variable -o gpt
|
||||
|
||||
debug:
|
||||
cc gpt.c -lm -O1 -g -Wno-unused-result -Wno-unused-value -Wno-unused-variable -o gpt
|
||||
|
||||
run:
|
||||
python3 chat.py
|
50
README.md
50
README.md
@ -8,26 +8,64 @@ GPT 很酷,能不能在我自己的电脑上跑一个呢?当然可以!
|
||||
|
||||
![](show.gif)
|
||||
|
||||
现在给你提供 GPT2 的预训练模型:[点击这里](https://alist.yaossg.com/share/model/gpt2_124M.bin),请把该模型放在本仓库代码的同目录下,按照下面的指示即可运行该程序。
|
||||
请按照下面的指示来完成自己的 GPT2 吧!
|
||||
|
||||
## 依赖
|
||||
## 安装依赖
|
||||
|
||||
需要安装 GCC 和 Python3 以及下面的 Python 包
|
||||
完成本题需要 GNU Make、GCC、Python3。请先使用你的 Linux 发行版的包管理器完成安装。
|
||||
|
||||
例如,如果你是 Ubuntu,可以使用下面的命令完成安装。
|
||||
|
||||
```bash
|
||||
pip3 install tiktoken
|
||||
sudo apt install build-essential python3
|
||||
```
|
||||
|
||||
接着你需要安装 `tiktoken` Python 包,可以使用下面的命令完成安装。
|
||||
|
||||
```bash
|
||||
make install
|
||||
```
|
||||
|
||||
## 下载并检查模型
|
||||
|
||||
[这里](https://alist.yaossg.com/share/model/gpt2_124M.bin)有我提供的 GPT2 的预训练模型,请下载后把该模型放在本仓库目录下,并执行下面的命令进行检查。
|
||||
|
||||
|
||||
```bash
|
||||
$ make check
|
||||
Checking your model...
|
||||
Model is OK
|
||||
```
|
||||
|
||||
如果不出意外,会出现上面的结果,表示模型正常。
|
||||
|
||||
|
||||
## 编译
|
||||
|
||||
如果你需要调试你的程序,可以使用下面的命令进行编译。
|
||||
|
||||
```bash
|
||||
bash build.sh
|
||||
make debug
|
||||
```
|
||||
|
||||
调试完毕后用这个编译更快的版本!
|
||||
|
||||
```bash
|
||||
make release
|
||||
```
|
||||
|
||||
## 运行
|
||||
|
||||
完成编译之后,就可以运行你的程序了!
|
||||
|
||||
```bash
|
||||
python3 chat.py
|
||||
make run
|
||||
```
|
||||
|
||||
如果你非常懒,可以用下面这个命令一键编译运行:
|
||||
|
||||
```bash
|
||||
make
|
||||
```
|
||||
|
||||
## 目标
|
||||
|
1
build.sh
1
build.sh
@ -1 +0,0 @@
|
||||
gcc gpt.c -lm -O3 -std=gnu11 -ggdb -Wall -Werror -Wno-unused-result -Wno-unused-value -Wno-unused-variable -o gpt
|
7
check.sh
Normal file
7
check.sh
Normal file
@ -0,0 +1,7 @@
|
||||
echo "Checking your model..."
|
||||
checksum=$(sha1sum gpt2_124M.bin)
|
||||
if [ "$checksum" != "4c7ef26bf866185203350d310e12bb1e6a5b48cb gpt2_124M.bin" ]; then
|
||||
echo "Your model seems broken or missing. Please redownload it or rename it to 'gpt2_124M.bin'"
|
||||
return 1
|
||||
fi
|
||||
echo "Model is OK"
|
Loading…
Reference in New Issue
Block a user