模型下载;从零训练;微调;脚本优化
This commit is contained in:
parent
207b51900e
commit
2c97ce073e
25 changed files with 11441 additions and 16 deletions
9
Makefile
9
Makefile
|
@ -436,15 +436,15 @@ endif # LLAMA_CUBLAS
|
||||||
|
|
||||||
ifdef LLAMA_CLBLAST
|
ifdef LLAMA_CLBLAST
|
||||||
|
|
||||||
MK_CPPFLAGS += -DGGML_USE_CLBLAST $(shell pkg-config --cflags-only-I clblast OpenCL)
|
MK_CPPFLAGS += -DGGML_USE_CLBLAST $(shell pkg-config --cflags-only-I clblast OpenCL) -I/usr/local/include
|
||||||
MK_CFLAGS += $(shell pkg-config --cflags-only-other clblast OpenCL)
|
MK_CFLAGS += $(shell pkg-config --cflags-only-other clblast OpenCL)
|
||||||
MK_CXXFLAGS += $(shell pkg-config --cflags-only-other clblast OpenCL)
|
MK_CXXFLAGS += $(shell pkg-config --cflags-only-other clblast OpenCL)
|
||||||
|
|
||||||
# Mac provides OpenCL as a framework
|
# Mac provides OpenCL as a framework
|
||||||
ifeq ($(UNAME_S),Darwin)
|
ifeq ($(UNAME_S),Darwin)
|
||||||
MK_LDFLAGS += -lclblast -framework OpenCL
|
MK_LDFLAGS += -lclblast -framework OpenCL -L/usr/local/lib
|
||||||
else
|
else
|
||||||
MK_LDFLAGS += $(shell pkg-config --libs clblast OpenCL)
|
MK_LDFLAGS += $(shell pkg-config --libs clblast OpenCL) -L/usr/local/lib
|
||||||
endif
|
endif
|
||||||
OBJS += ggml-opencl.o
|
OBJS += ggml-opencl.o
|
||||||
|
|
||||||
|
@ -629,6 +629,9 @@ beam-search: examples/beam-search/beam-search.cpp build-info.h ggml.o llama.o $(
|
||||||
finetune: examples/finetune/finetune.cpp build-info.h ggml.o llama.o $(COMMON_DEPS) train.o $(OBJS)
|
finetune: examples/finetune/finetune.cpp build-info.h ggml.o llama.o $(COMMON_DEPS) train.o $(OBJS)
|
||||||
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
|
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
|
||||||
|
|
||||||
|
finetune-bc: examples/finetune/finetune-bc.cpp build-info.h ggml.o llama.o $(COMMON_DEPS) train.o $(OBJS)
|
||||||
|
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
|
||||||
|
|
||||||
export-lora: examples/export-lora/export-lora.cpp build-info.h ggml.o llama.o $(COMMON_DEPS) $(OBJS)
|
export-lora: examples/export-lora/export-lora.cpp build-info.h ggml.o llama.o $(COMMON_DEPS) $(OBJS)
|
||||||
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
|
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
|
||||||
|
|
||||||
|
|
184
README_zh.md
Normal file
184
README_zh.md
Normal file
|
@ -0,0 +1,184 @@
|
||||||
|
# llama.cpp
|
||||||
|
|
||||||
|
### 20231030
|
||||||
|
|
||||||
|
|
||||||
|
## VRAM
|
||||||
|
|
||||||
|
1.在消费类硬件上运行 LLaMA 模型有多种不同的方法。 最常见的方法是使用单个 NVIDIA GeForce RTX 3090 GPU。 该 GPU 具有 24 GB 内存,足以运行 LLaMA 模型。 RTX 3090 可以运行 4 位量化的 LLaMA 30B 模型,每秒大约 4 到 10 个令牌。 24GB VRAM 似乎是在消费类台式电脑上使用单个 GPU 的最佳选择。
|
||||||
|
2.但是,如果你想运行更大的模型,则必须使用双 GPU 设置。 这将允许你将模型权重放入 VRAM 中。 你还可以使用高级 GPU,例如 NVIDIA A100。 这个GPU非常昂贵,但有40GB内存,可以更好地运行模型。
|
||||||
|
3.在 CPU 上运行 LLaMA 模型。 必须使用模型的 GGML 版本(LLaMA、Vicuna、Alpaca 和 GPT4All)以及名为 llama.cpp 的软件才能使用CPU。
|
||||||
|
4.训练或微调 LLaMA 模型需要比运行模型更多的 VRAM。 这是因为训练过程需要将模型以及训练数据存储在 VRAM 中。 训练所需的 VRAM 量取决于模型的大小和训练数据量。
|
||||||
|
|
||||||
|
|
||||||
|
## 投机采样 特别适用于代码生成
|
||||||
|
|
||||||
|
不量化,就用FP16精度也让34B的Code LLama跑在苹果电脑上,推理速度超过每秒20个token。草稿7b-q40,大模型32b
|
||||||
|
./speculative -m ggml-model-f16-32b.gguf -md ggml-model-f16-7b-bc2-13b-chat-q2_k.gguf -p "one day" -e -ngl 1 -t 4 -n 512 -c 4096 -s 20 --top_k 1
|
||||||
|
|
||||||
|
### llama.cpp 的目标与初心
|
||||||
|
|
||||||
|
llama.cpp 出现之后,在 GitHub 上狂砍 30k star,比 stable diffusion 还要夸张,堪称 star rocket。这背后是 llama.cpp 切中了 “AI at the edge” 这一方向。
|
||||||
|
“AI at the edge“ 中的 edge 我理解为与 cloud 相对的概念。不管是个人的 laptop,gaming PC,手机,甚至树莓派,都可以称为 edge。
|
||||||
|
|
||||||
|
### 总结一下, llama.cpp 的初心是要把 LLaMA 模型在 MacBook 上跑起来。为此主要做 2 件事儿:
|
||||||
|
|
||||||
|
quantization,目的是减少内存开销,而 llama.cpp 进一步让模型在精度损失与推理性能之间达到了一个微妙的平衡
|
||||||
|
性能方向优化,包括语言的选择,采用向量化,GPU 加速等等手段
|
||||||
|
对这两个方面的极致追求让 llama.cpp 收获了大批没有昂贵硬件,但却想尝试 LLM 的开发者的关注(包括我在内)。
|
||||||
|
|
||||||
|
### 相关结论:
|
||||||
|
|
||||||
|
默认的量化方法为q4_0,虽然速度最快但损失也是最大的,其余方法各有利弊,按实际情况选择
|
||||||
|
需要注意的是F16以及q8_0并不会因为增加线程数而提高太多速度
|
||||||
|
线程数-t与物理核心数一致时速度最快,超过之后速度反而变慢(M1 Max上从8改到10之后耗时变为3倍)
|
||||||
|
如果使用了Metal版本(即启用了苹果GPU解码),速度还会有进一步显著提升,表中标注为-ngl 1
|
||||||
|
综合推荐(仅供参考):7B推荐Q5_1或Q5_K_S,13B推荐Q5_0或Q5_K_S
|
||||||
|
机器资源够用且对速度要求不是那么苛刻的情况下可以使用q8_0或Q6_K,接近F16模型的效果
|
||||||
|
|
||||||
|
|
||||||
|
## 云端环境准备:
|
||||||
|
|
||||||
|
REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||||
|
pytorch/pytorch 2.1.0-cuda12.1-cudnn8-devel 6f873147bf83 3 weeks ago 16.6GB
|
||||||
|
|
||||||
|
docker run -e TZ="Asia/Shanghai" -it --name pytorch2 --gpus all -v /home/ubuntu:/root -v $PWD:/tmp -w /tmp pytorch/pytorch:2.1.0-cuda12.1-cudnn8-devel bash
|
||||||
|
docker exec -it pytorch2 env LANG=C.UTF-8 TZ=Asia/Shanghai bash
|
||||||
|
|
||||||
|
### 开发环境准备
|
||||||
|
|
||||||
|
git clone https://github.com/ggerganov/llama.cpp
|
||||||
|
make LLAMA_CLBLAST=1 LLAMA_NO_METAL=1
|
||||||
|
|
||||||
|
## macos: 边缘计算 端AI
|
||||||
|
|
||||||
|
### 准备开发环境
|
||||||
|
|
||||||
|
xcode-select --install
|
||||||
|
|
||||||
|
### 克隆环境编译
|
||||||
|
|
||||||
|
芯片组型号: Intel HD Graphics 5000
|
||||||
|
类型: GPU
|
||||||
|
总线: 内建
|
||||||
|
VRAM(动态,最大值): 1536 MB
|
||||||
|
供应商: Intel
|
||||||
|
设备ID: 0x0a26
|
||||||
|
修正版ID: 0x0009
|
||||||
|
Metal 系列: 支持,Metal GPUFamily macOS 1
|
||||||
|
|
||||||
|
LBlast是一个可用于生产环境,且高性能的OpenCL开源计算BLAS库,支持平台包括AMD、NVIDIA、Intel的CPU、GPU,也包括移动端领域如Adreno、Mali GPU。系统支持Windows、macOS以及Linux系统。
|
||||||
|
CLBlast有下面几个优点:
|
||||||
|
|
||||||
|
为调优(Tune)而生。
|
||||||
|
可以为特定问题调优。
|
||||||
|
支持FP16精度计算。
|
||||||
|
支持批量操作(Batch),如BachedGEMM等。
|
||||||
|
支持Cuda CLBlast更强调通用性,在率先支持AMD GPU后支持NVIDIA GPU的OpenCL计算,也支持将OpenCL
|
||||||
|
可集成到CUDA支持的项目中,将CUDA buffer直接作为输入;
|
||||||
|
无OpenCL实现的NVIDIA硬件平台,如非X86的Jetson(ARM架构)和Driver PX系列以及IBM Power架构的超算平台等;
|
||||||
|
性能与OpenCL版本的Kernel又有不同
|
||||||
|
|
||||||
|
<!-- 安装clblast -->
|
||||||
|
brew update && brew install clblast
|
||||||
|
<!-- 编译环境 -->
|
||||||
|
MK_CPPFLAGS += -DGGML_USE_CLBLAST $(shell pkg-config --cflags-only-I clblast OpenCL) -I/usr/local/include
|
||||||
|
MK_LDFLAGS += -lclblast -framework OpenCL -L/usr/local/lib
|
||||||
|
<!-- 编译 -->
|
||||||
|
make clean
|
||||||
|
make LLAMA_CLBLAST=1 LLAMA_NO_METAL=1
|
||||||
|
<!-- VRAM(动态,最大值): 1536 MB Intel GMA HD 5000为1.5GB(最大共享系统内存)-->
|
||||||
|
./main --ignore-eos -c 64 -n 128 -t 3 -ngl 10
|
||||||
|
|
||||||
|
### 模型格式转换
|
||||||
|
|
||||||
|
python convert-baichuan-hf-to-gguf.py ../models/baichuan-inc/Baichuan2-7B-Chat/
|
||||||
|
python convert-baichuan-hf-to-gguf.py ../models/baichuan-inc/Baichuan2-13B-Chat/
|
||||||
|
|
||||||
|
|
||||||
|
### 模型量化q4_k
|
||||||
|
|
||||||
|
./quantize ../models/baichuan-inc/Baichuan2-7B-Chat/ggml-model-f16.gguf ../models/ggml-model-f16-bc2-7b-chat-q4_k.gguf q4_k
|
||||||
|
./quantize ../models/baichuan-inc/Baichuan2-7B-Chat/ggml-model-f16.gguf ../models/ggml-model-f16-bc2-7b-chat-q2_k.gguf q2_k
|
||||||
|
./quantize ../models/baichuan-inc/Baichuan2-13B-Chat/ggml-model-f16.gguf ../models/ggml-model-f16-bc2-13b-chat-q8_0.gguf q8_0
|
||||||
|
./quantize ../models/baichuan-inc/Baichuan2-13B-Chat/ggml-model-f16.gguf ../models/ggml-model-f16-bc2-13b-chat-q2_k.gguf q2_k
|
||||||
|
|
||||||
|
### 推理,显卡clblast -ngl 10
|
||||||
|
|
||||||
|
比较重要的参数:
|
||||||
|
|
||||||
|
-ins 启动类ChatGPT的对话交流模式
|
||||||
|
-f 指定prompt模板,alpaca模型请加载prompts/alpaca.txt 指令模板
|
||||||
|
-c 控制上下文的长度,值越大越能参考更长的对话历史(默认:512)
|
||||||
|
-n 控制回复生成的最大长度(默认:128)
|
||||||
|
--repeat_penalty 控制生成回复中对重复文本的惩罚力度
|
||||||
|
--temp 温度系数,值越低回复的随机性越小,反之越大
|
||||||
|
--top_p, top_k 控制解码采样的相关参数
|
||||||
|
-b 控制batch size(默认:512)
|
||||||
|
|
||||||
|
|
||||||
|
<!-- 3G -->
|
||||||
|
./main -m ../models/ggml-model-f16-bc2-7b-chat-q4_k.gguf -t 2 -ngl 8 -n 128 -p '写一首藏头诗五言绝句,每句诗的开头字母分别是"莫""勇"二字:'
|
||||||
|
<!-- 6.5G 勉强能跑-->
|
||||||
|
./main -m ../models/ggml-model-f16-bc2-13b-chat-q2_k.gguf -t 2 -ngl 6 -n 128 -p '写一首藏头诗五言绝句,每句诗的开头字母分别是"莫""勇"二字:'
|
||||||
|
写一首藏头诗五言绝句,每句诗的开头字母分别是"莫""勇"二字:
|
||||||
|
莫 问前程几许远,
|
||||||
|
勇 攀高峰笑傲天。
|
||||||
|
志 在四方谁敢挡,
|
||||||
|
怀 抱梦想永向前。 [end of text]
|
||||||
|
<!-- 12G -->
|
||||||
|
./main -m ../models/ggml-model-f16-bc2-13b-chat-q8_0.gguf -t 2 -ngl 5 -n 128 -p '写一首藏头诗五言绝句,每句诗的开头字母分别是"莫""勇"二字:'
|
||||||
|
|
||||||
|
### 对话模式
|
||||||
|
|
||||||
|
./main -m ../models/ggml-model-f16-bc2-13b-chat-q8_0.gguf -ngl 10 -n 256 --repeat_penalty 1.0 --color -i -r "User:" -f prompts/chat-with-baichuan.txt
|
||||||
|
|
||||||
|
### 投机采样推理 q4_k 草稿;fp16原始模型 TODO 内存不够
|
||||||
|
|
||||||
|
./speculative -m ../models/ggml-model-f16-bc2-13b-chat-q8_0.gguf -md ../models/ggml-model-f16-bc2-7b-chat-q4_k.gguf -p '写一首五言绝句' -e -t 4 -n 512 -c 4096 -s 20 --top_k 1 -ngl 1
|
||||||
|
|
||||||
|
|
||||||
|
### 评估命令
|
||||||
|
|
||||||
|
./perplexity -m ../models/ggml-model-f16-bc2-7b-chat-q4_k.gguf -f prompts/chat-with-baichuan.txt -c 4096 -t 2 -ngl 6
|
||||||
|
|
||||||
|
### 垂直领域小模型边缘计算
|
||||||
|
|
||||||
|
shaowenchen/chinese-llama-2-13b-16k-gguf/chinese-llama-2-13b-16k.Q3_K_S.gguf
|
||||||
|
|
||||||
|
### 目前最强
|
||||||
|
|
||||||
|
zephyr-7b-beta
|
||||||
|
|
||||||
|
### 模型对比
|
||||||
|
|
||||||
|
Mistral7B可能是其中最强的:
|
||||||
|
1. 小型如何非要划一个界限 <= 7B
|
||||||
|
2. 参数量小,不等于训练数据量小
|
||||||
|
3. 小型 LLM 在特定任务上微调,堪比大模型,甚至超过
|
||||||
|
小型模型有其天然的属性,可能更快的落地,在一些边缘端会发挥更大的作用。
|
||||||
|
|
||||||
|
Mistral 7B是由Mistral AI发布的一个拥有70亿参数的语言模型。是一个精心设计的语言模型,旨在提供高效和高性能,以实现真实世界的应用。由于其效率的提升,该模型适用于需要快速响应的实时应用。在发布时,Mistral 7B在所有评估基准中都超过了最佳的开源13B模型(Llama 2)。
|
||||||
|
|
||||||
|
该模型使用了如下的注意力机制:
|
||||||
|
- grouped-query attention (GQA),目的是为了更快的推理和减少解码过程中的内存需求。
|
||||||
|
- sliding window attention (SWA),目的是用较低的推理成本处理任意长度的序列。
|
||||||
|
|
||||||
|
Mistral 7B在各种基准测试中展现出卓越的性能,甚至超过了参数更多的模型。它在数学、代码生成和推理等领域表现出色。以下是在数学推理、世界知识和常识推理等多个任务上的结果:
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
MT-Bench是评估模型处理多轮对话能力的基准测试,问题集涵盖写作、角色扮演、提取等8个类别。
|
||||||
|
|
||||||
|
|
||||||
|
Mistral-7B-Instruct
|
||||||
|
Mistral 7B旨在轻松调整以适应各种任务。Mistral 7B Instruct模型是一个快速演示,基础模型可以轻松进行微调以实现引人注目的性能。该版本的模型经过微调,适用于对话和问题回答。
|
||||||
|
|
||||||
|
### mistral7b 微调
|
||||||
|
|
||||||
|
扩充tokener
|
||||||
|
合并checkpoint
|
17
download-TabbyML-Mistral-7B.py
Normal file
17
download-TabbyML-Mistral-7B.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# https://modelscope.cn/models/TabbyML/Mistral-7B/summary
|
||||||
|
|
||||||
|
# 下载
|
||||||
|
import torch
|
||||||
|
from modelscope import snapshot_download, Model
|
||||||
|
model_dir = snapshot_download("TabbyML/Mistral-7B",cache_dir="../models")
|
||||||
|
|
||||||
|
# 转换
|
||||||
|
# python convert.py ../models/TabbyML/Mistral-7B/
|
||||||
|
|
||||||
|
# 量化
|
||||||
|
# ./quantize ../models/TabbyML/Mistral-7B/ggml-model-f16.gguf ../models/ggml-model-f16-zephyr-7b-beta-q8_0.gguf q8_0
|
||||||
|
# ./quantize ../models/TabbyML/Mistral-7B/ggml-model-f16.gguf ../models/ggml-model-f16-zephyr-7b-beta-q5_0.gguf q5_0
|
||||||
|
|
||||||
|
#推理
|
||||||
|
# ./main -m ../models/ggml-model-f16-zephyr-7b-beta-q5_0.gguf -n 128 -p "How many helicopters can a human eat in one sitting?" -t 2 -ngl 4
|
||||||
|
|
16
download-bc2-13b-int4.py
Normal file
16
download-bc2-13b-int4.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import torch
|
||||||
|
from modelscope import snapshot_download, Model
|
||||||
|
model_dir = snapshot_download("baichuan-inc/Baichuan2-13B-Chat-4bits", revision='v1.0.3')
|
||||||
|
model = Model.from_pretrained(model_dir, device_map="balanced", trust_remote_code=True, torch_dtype=torch.float16)
|
||||||
|
messages = []
|
||||||
|
messages.append({"role": "user", "content": "讲解一下“温故而知新”"})
|
||||||
|
response = model(messages)
|
||||||
|
print(response)
|
||||||
|
messages = response['history'].copy()
|
||||||
|
messages.append({"role": "user", "content": "背诵一下将进酒"})
|
||||||
|
response = model(messages)
|
||||||
|
print(response)
|
||||||
|
|
||||||
|
#python convert.py /root/.cache/modelscope/hub/baichuan-inc/Baichuan2-13B-Chat-4bits/
|
||||||
|
# ./main -m ggml-model-q4_0.gguf -n 128 -p "莫勇开头写一首藏头诗"
|
||||||
|
|
16
download-bc2-13b.py
Normal file
16
download-bc2-13b.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import torch
|
||||||
|
from modelscope import snapshot_download, Model
|
||||||
|
model_dir = snapshot_download("baichuan-inc/Baichuan2-13B-Chat", revision='v1.0.3')
|
||||||
|
model = Model.from_pretrained(model_dir, device_map="balanced", trust_remote_code=True, torch_dtype=torch.float16)
|
||||||
|
messages = []
|
||||||
|
messages.append({"role": "user", "content": "讲解一下“温故而知新”"})
|
||||||
|
response = model(messages)
|
||||||
|
print(response)
|
||||||
|
messages = response['history'].copy()
|
||||||
|
messages.append({"role": "user", "content": "背诵一下将进酒"})
|
||||||
|
response = model(messages)
|
||||||
|
print(response)
|
||||||
|
|
||||||
|
#python convert.py /root/.cache/modelscope/hub/baichuan-inc/Baichuan2-13B-Chat-4bits/
|
||||||
|
# ./main -m ggml-model-q4_0.gguf -n 128 -p "莫勇开头写一首藏头诗"
|
||||||
|
|
17
download-bc2-7b.py
Normal file
17
download-bc2-7b.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import torch
|
||||||
|
from modelscope import snapshot_download, Model
|
||||||
|
# model_dir = snapshot_download("baichuan-inc/Baichuan2-7B-Chat", revision='v1.0.3')
|
||||||
|
model_dir = snapshot_download("baichuan-inc/Baichuan2-7B-Chat", revision='v1.0.4')
|
||||||
|
model = Model.from_pretrained(model_dir, device_map="balanced", trust_remote_code=True, torch_dtype=torch.float16)
|
||||||
|
messages = []
|
||||||
|
messages.append({"role": "user", "content": "讲解一下“温故而知新”"})
|
||||||
|
response = model(messages)
|
||||||
|
print(response)
|
||||||
|
messages = response['history'].copy()
|
||||||
|
messages.append({"role": "user", "content": "背诵一下将进酒"})
|
||||||
|
response = model(messages)
|
||||||
|
print(response)
|
||||||
|
|
||||||
|
#python convert.py /root/.cache/modelscope/hub/baichuan-inc/Baichuan2-13B-Chat-4bits/
|
||||||
|
# ./main -m ggml-model-q4_0.gguf -n 128 -p "莫勇开头写一首藏头诗"
|
||||||
|
|
9
download-chinese-alpaca-13b-16k-q3_k.py
Normal file
9
download-chinese-alpaca-13b-16k-q3_k.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# https://modelscope.cn/models/shaowenchen/chinese-llama-2-13b-16k-gguf/summary
|
||||||
|
|
||||||
|
|
||||||
|
import torch
|
||||||
|
# 下载
|
||||||
|
from modelscope.hub.file_download import model_file_download
|
||||||
|
model_dir = model_file_download(model_id='shaowenchen/chinese-alpaca-2-13b-16k-gguf',file_path='chinese-alpaca-2-13b-16k.Q3_K_S.gguf',cache_dir="../models")
|
||||||
|
# 推理
|
||||||
|
./main -m ../models/shaowenchen/chinese-alpaca-2-13b-16k-gguf/chinese-alpaca-2-13b-16k.Q3_K_S.gguf -n 128 -p "展示上个季度所有销售额超过 10000 美元的订单,写出SQL" -t 2 -ngl 10
|
13
download-chinese-llama2-13b-16k-q3_k.py
Normal file
13
download-chinese-llama2-13b-16k-q3_k.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# https://modelscope.cn/models/shaowenchen/chinese-llama-2-13b-16k-gguf/summary
|
||||||
|
|
||||||
|
|
||||||
|
import torch
|
||||||
|
|
||||||
|
# 下载
|
||||||
|
from modelscope.hub.file_download import model_file_download
|
||||||
|
# model_dir = model_file_download(model_id='shaowenchen/chinese-llama-2-13b-16k-gguf',file_path='chinese-llama-2-13b-16k.Q3_K_S.gguf',cache_dir="../models")
|
||||||
|
model_dir = model_file_download(model_id='shaowenchen/chinese-llama-2-7b-16k-gguf',file_path='chinese-llama-2-7b-16k.Q2_K.gguf',cache_dir="../models")
|
||||||
|
|
||||||
|
# 推理
|
||||||
|
# ./main -m ../models/shaowenchen/chinese-llama-2-13b-16k-gguf/chinese-llama-2-13b-16k.Q3_K_S.gguf -n 128 -p "展示上个季度所有销售额超过 10000 美元的订单,写出SQL" -t 2 -ngl 10
|
||||||
|
# ./main -m ../models/shaowenchen/chinese-llama-2-7b-16k-gguf/chinese-llama-2-7b-16k.Q2_K.gguf -n 128 -p "展示上个季度所有销售额超过 10000 美元的订单,写出SQL" -t 2 -ngl 10
|
29
download-llama2-13b-sql.py
Normal file
29
download-llama2-13b-sql.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# https://modelscope.cn/models/CarbonAgent/llama-2-13b-chat.Q4/summary
|
||||||
|
# 将自然语言转换为 SQL 查询语言
|
||||||
|
|
||||||
|
# 这个模型的主要目标是在垂直行业中进行专业数据代理。通过使用 llama-2-13b-chat,业务人员可以直接使用自然语言来查询数据库,而无需掌握复杂的 SQL 查询语法。这不仅可以提升业务人员的工作效率,也可以减少对 IT 人员的依赖。
|
||||||
|
# 例如,销售人员可以通过输入 "展示上个季度所有销售额超过 10000 美元的订单",llama-2-13b-chat 会将这个查询转换为对应的 SQL 查询,如 "SELECT * FROM orders WHERE sales > 10000 AND quarter = 'Q2';"。
|
||||||
|
|
||||||
|
import torch
|
||||||
|
from modelscope import snapshot_download, Model
|
||||||
|
model_dir = snapshot_download("CarbonAgent/llama-2-13b-chat.Q4",cache_dir="../models")
|
||||||
|
|
||||||
|
#./main -m ../models/CarbonAgent/llama-2-13b-chat.Q4/llama-2-13b-chat.Q4_0.gguf -n 128 -p "展示上个季度所有销售额超过 10000 美元的订单,写出对应的SQL语句" -t 2 -ngl 4
|
||||||
|
|
||||||
|
|
||||||
|
# 9月4日,OpenBuddy发布700亿参数跨语言大模型 OpenBuddy-LLaMA2-70B,并以可商用的形态全面开源!现在已经全面上架魔搭ModelScope社区。
|
||||||
|
# 70B模型在能力表现上,相较于早前发布的较小规模模型,在文本生成、复杂逻辑推理以及自然语言处理等任务有了非常显著的提升。据其内测用户及多项能力测试指标反馈,目前70B模型在语言能力和逻辑推理能力可对标为GPT3.5的开源平替!OpenBuddy社区希望用开源激发中国大模型行业的潜能。
|
||||||
|
# GitHub链接:https://github.com/OpenBuddy/OpenBuddy
|
||||||
|
# from modelscope.hub.snapshot_download import snapshot_download
|
||||||
|
# model_dir = snapshot_download('OpenBuddy/openbuddy-llama2-70b-v10.1-bf16', 'v1.0.0',cache_dir="../models")
|
||||||
|
|
||||||
|
|
||||||
|
python convert.py ../models/OpenBuddy/openbuddy-llama2-70b-v10.1-bf16/
|
||||||
|
|
||||||
|
./quantize ../models/OpenBuddy/openbuddy-llama2-70b-v10.1-bf16/ggml-model-f16.gguf ../models/ggmls/openbuddy-llama2-70b-v10.1-bf16-q3_k_s.gguf q3_k_s
|
||||||
|
./quantize ../models/OpenBuddy/openbuddy-llama2-70b-v10.1-bf16/ggml-model-f16.gguf ../models/ggmls/openbuddy-llama2-70b-v10.1-bf16-q4_k_S.gguf q4_k_s
|
||||||
|
|
||||||
|
./main -m ../models/ggmls/openbuddy-llama2-70b-v10.1-bf16-q2_k.gguf -n 128 -p "展示上个季度所有销售额超过 10000 美元的订单,写出对应的SQL语句" -t 2 -ngl 4
|
||||||
|
./main -t 10 -ngl 40 -gqa 8 -m llama-2-70b-chat.ggmlv3.q4_K_M.bin --color -c 4096 --temp 0.7 --repeat_penalty 1.1 -n -1 -p "[INST] <<SYS>>\nYou are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.\n<</SYS>>\nWrite a story about llamas[/INST]"
|
||||||
|
|
||||||
|
./main -m llama-2-70b.ggmlv3.q4_0.bin -gqa 8 -t 13 -p "Llamas are"
|
25
download-openbuddy-mistral-7b-v13.1.py
Normal file
25
download-openbuddy-mistral-7b-v13.1.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# https://modelscope.cn/models/OpenBuddy/openbuddy-mistral-7b-v13.1/summary
|
||||||
|
|
||||||
|
# 在涵盖数学、历史、法律和其他科目的大规模多任务语言理解测试中,Mistral 的模型准确率达到 60.1%,而 Llama 2 模型 70 亿参数和 130 亿参数两个版本的准确率分别为 44% 和 55%。
|
||||||
|
|
||||||
|
# 在常识推理和阅读理解基准测试中,Mistral 的表现也优于 Llama 2 的模型。
|
||||||
|
|
||||||
|
# 只有在编码方面 Mistral 落后于 Meta 。Mistral 7B 在 "Humaneval " 和 "MBPP " 两项基准测试中的准确率分别为 30.5% 和 47.5%,而 Llama 2 的 70 亿模式的准确率分别为 31.1% 和 52.5%。
|
||||||
|
|
||||||
|
# 下载
|
||||||
|
import torch
|
||||||
|
from modelscope import snapshot_download, Model
|
||||||
|
# model_dir = snapshot_download("OpenBuddy/openbuddy-mistral-7b-v13.1", revision = 'v1.0.0',cache_dir="../models")
|
||||||
|
|
||||||
|
# 转换
|
||||||
|
# python convert.py ../models/OpenBuddy/openbuddy-mistral-7b-v13.1/
|
||||||
|
|
||||||
|
# 量化
|
||||||
|
# ./quantize ../models/OpenBuddy/openbuddy-mistral-7b-v13.1/ggml-model-f16.gguf ../models/ggml-model-f16-openbuddy-mistral-7b-v13.1-q4_0.gguf q4_0
|
||||||
|
# ./quantize ../models/OpenBuddy/openbuddy-mistral-7b-v13.1/ggml-model-f16.gguf ../models/ggml-model-f16-openbuddy-mistral-7b-v13.1-q2_k.gguf q2_k
|
||||||
|
|
||||||
|
#推理
|
||||||
|
# ./main -m ../models/ggml-model-f16-openbuddy-mistral-7b-v13.1-q4_0.gguf -n 128 -p "展示上个季度所有销售额超过 10000 美元的订单,写出SQL" -t 2 -ngl 10
|
||||||
|
# ./main -m ../models/ggml-model-f16-openbuddy-mistral-7b-v13.1-q4_0.gguf -n 256 -p "小丽有3个兄弟, 他们各有2个姐妹, 问小丽有几个姐妹" -t 2 -ngl 10
|
||||||
|
# ./main -m ../models/ggml-model-f16-openbuddy-mistral-7b-v13.1-q4_0.gguf -ngl 10 -n 256 --repeat_penalty 1.0 --color -i -r "User:" -f prompts/chat-with-baichuan.txt
|
||||||
|
|
35
download-zephyr-7b-beta.py
Normal file
35
download-zephyr-7b-beta.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
# https://modelscope.cn/models/modelscope/zephyr-7b-beta/summary
|
||||||
|
# 7b达到gpt3.5 超越 llama2-70b
|
||||||
|
# Zephyr-7B-α是一系列 Zephyr 经过训练的语言模型中的第一个模型,是 Mistral-7B-v0.1 的微调版本,在使用直接偏好优化的混合公开合成数据集上进行训练。
|
||||||
|
|
||||||
|
# 数据也显示,Zephyr高级RAG任务效果可以和GPT-3.5、Claude 2相抗衡。
|
||||||
|
# 他们还继续补充道,Zephyr不仅在RAG上效果突出,而且在路由、查询规划、检索复杂SQL语句、结构化数据提取方面也表现良好。
|
||||||
|
# 但在编码和数学等更复杂的任务上,Zephyr-7B-beta落后于专有模型,需要更多的研究来缩小差距。
|
||||||
|
|
||||||
|
# 开发人员却表示,最有趣的不是各项指标,而是模型的训练方式。
|
||||||
|
# 亮点总结如下:
|
||||||
|
# 微调最好的小型开源预训练模型:Mistral 7B
|
||||||
|
# 大规模偏好数据集的用法:UltraFeedback
|
||||||
|
# 不用强化学习,使用直接偏好优化(DPO)
|
||||||
|
# 意料之外的是,偏好数据集的过拟合会产生更好的效果
|
||||||
|
|
||||||
|
# 用这种方法微调模型,成本只需500美元,也就是在16个A100上跑8小时。
|
||||||
|
|
||||||
|
|
||||||
|
# 下载
|
||||||
|
import torch
|
||||||
|
from modelscope import snapshot_download, Model
|
||||||
|
model_dir = snapshot_download("modelscope/zephyr-7b-beta",cache_dir="../models")
|
||||||
|
|
||||||
|
# 转换
|
||||||
|
python convert.py ../models/modelscope/zephyr-7b-beta/
|
||||||
|
|
||||||
|
# 量化
|
||||||
|
# ./quantize ../models/modelscope/zephyr-7b-beta/ggml-model-f16.gguf ../models/ggml-model-f16-zephyr-7b-beta-q8_0.gguf q8_0
|
||||||
|
./quantize ../models/modelscope/zephyr-7b-beta/ggml-model-f16.gguf ../models/ggml-model-f16-zephyr-7b-beta-q5_0.gguf q5_0
|
||||||
|
|
||||||
|
#推理
|
||||||
|
./main -m ../models/ggml-model-f16-zephyr-7b-beta-q5_0.gguf -n 256 -p "为什么我爸妈结婚的时候没邀请我参加婚礼" -t 2 -ngl 4
|
||||||
|
./main -m ../models/ggml-model-f16-zephyr-7b-beta-q5_0.gguf -n 256 -p "能给我讲讲GPT-4吗?" -t 2 -ngl 4
|
||||||
|
./main -m ../models/ggml-model-f16-zephyr-7b-beta-q5_0.gguf -ngl 10 -n 256 --repeat_penalty 1.0 --color -i -r "User:" -f prompts/chat-with-baichuan.txt
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
# TODO List
|
||||||
|
微调流程已通;
|
||||||
|
选择合适的行业场景;
|
||||||
|
测试微调文本格式与效果;
|
||||||
|
百川模型转换为llama;
|
||||||
|
好的中文llama base model;
|
||||||
|
|
||||||
# finetune
|
# finetune
|
||||||
|
|
||||||
Basic usage instructions:
|
Basic usage instructions:
|
||||||
|
@ -7,18 +14,64 @@ Basic usage instructions:
|
||||||
wget https://raw.githubusercontent.com/brunoklein99/deep-learning-notes/master/shakespeare.txt
|
wget https://raw.githubusercontent.com/brunoklein99/deep-learning-notes/master/shakespeare.txt
|
||||||
|
|
||||||
# finetune LORA adapter
|
# finetune LORA adapter
|
||||||
./bin/finetune \
|
# ./bin/finetune \
|
||||||
--model-base open-llama-3b-v2-q8_0.gguf \
|
# --model-base open-llama-3b-v2-q8_0.gguf \
|
||||||
--checkpoint-in chk-lora-open-llama-3b-v2-q8_0-shakespeare-LATEST.gguf \
|
# --checkpoint-in chk-lora-open-llama-3b-v2-q8_0-shakespeare-LATEST.gguf \
|
||||||
--checkpoint-out chk-lora-open-llama-3b-v2-q8_0-shakespeare-ITERATION.gguf \
|
# --checkpoint-out chk-lora-open-llama-3b-v2-q8_0-shakespeare-ITERATION.gguf \
|
||||||
--lora-out lora-open-llama-3b-v2-q8_0-shakespeare-ITERATION.bin \
|
# --lora-out lora-open-llama-3b-v2-q8_0-shakespeare-ITERATION.bin \
|
||||||
--train-data "shakespeare.txt" \
|
# --train-data "shakespeare.txt" \
|
||||||
--save-every 10 \
|
# --save-every 10 \
|
||||||
--threads 6 --adam-iter 30 --batch 4 --ctx 64 \
|
# --threads 6 --adam-iter 30 --batch 4 --ctx 64 \
|
||||||
--use-checkpointing
|
# --use-checkpointing
|
||||||
|
|
||||||
|
# # predict
|
||||||
|
# ./bin/main -m open-llama-3b-v2-q8_0.gguf --lora lora-open-llama-3b-v2-q8_0-shakespeare-LATEST.bin
|
||||||
|
|
||||||
|
# mac os mistral
|
||||||
|
data_dir="../models/" \
|
||||||
|
model_dir="../models/ggmls/" \
|
||||||
|
model_name="openbuddy-mistral-7b-v13.1-q2_k" \
|
||||||
|
dataset=slqm \
|
||||||
|
sh examples/finetune/finetune.sh >${model_name}.log
|
||||||
|
|
||||||
|
#云电脑 mistral
|
||||||
|
data_dir="../" \
|
||||||
|
model_dir="../" \
|
||||||
|
dataset=slqm \
|
||||||
|
model_name="openbuddy-mistral-7b-v13.1-q2_k" \
|
||||||
|
sh examples/finetune/finetune.sh >${model_name}.log
|
||||||
|
|
||||||
|
# mac os llama2
|
||||||
|
data_dir="../models/" \
|
||||||
|
model_dir="../models/ggmls/" \
|
||||||
|
model_name="chinese-llama-2-7b-16k.Q2_K" \
|
||||||
|
dataset=slqm \
|
||||||
|
sh examples/finetune/finetune.sh >${model_name}.log
|
||||||
|
|
||||||
|
#云电脑 llama2
|
||||||
|
data_dir="../" \
|
||||||
|
model_dir="../" \
|
||||||
|
dataset=slqm \
|
||||||
|
model_name="chinese-llama-2-7b-16k.Q2_K" \
|
||||||
|
sh examples/finetune/finetune.sh >${model_name}.log
|
||||||
|
|
||||||
|
|
||||||
|
#云电脑 finetune-bc
|
||||||
|
data_dir="../" \
|
||||||
|
model_dir="../" \
|
||||||
|
dataset=slqm \
|
||||||
|
model_name="bc2-7b-chat-q2_k" \
|
||||||
|
cmd="finetune-bc" \
|
||||||
|
sh examples/finetune/finetune.sh >${model_name}.log
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
1.微调 CPU核素越多越快 只支持llama架构
|
||||||
|
win cmd 输出编码
|
||||||
|
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
|
||||||
|
修改Windows10 命令终端cmd的编码为UTF-8
|
||||||
|
chcp 65001
|
||||||
|
|
||||||
# predict
|
|
||||||
./bin/main -m open-llama-3b-v2-q8_0.gguf --lora lora-open-llama-3b-v2-q8_0-shakespeare-LATEST.bin
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Finetune output files will be saved every N iterations (config with `--save-every N`).
|
Finetune output files will be saved every N iterations (config with `--save-every N`).
|
||||||
|
|
1940
examples/finetune/finetune-bc.cpp
Normal file
1940
examples/finetune/finetune-bc.cpp
Normal file
File diff suppressed because it is too large
Load diff
35
examples/finetune/finetune.sh
Normal file
35
examples/finetune/finetune.sh
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
# mistral arch = llama
|
||||||
|
|
||||||
|
# data_dir="../" \
|
||||||
|
# model_dir="../" \
|
||||||
|
# model_name="openbuddy-mistral-7b-v13.1-q2_k" \
|
||||||
|
# dataset=slqm
|
||||||
|
# adam-iter 变量名不能带-
|
||||||
|
finetune="finetune"
|
||||||
|
if [ -n "$cmd" ]; then
|
||||||
|
finetune=${cmd}
|
||||||
|
fi
|
||||||
|
./${finetune} \
|
||||||
|
--train-data ${data_dir}/${dataset}.txt \
|
||||||
|
--model-base ${model_dir}/${model_name}.gguf \
|
||||||
|
--checkpoint-in ${model_dir}/chk/chk-${model_name}-LATEST.gguf \
|
||||||
|
--checkpoint-out ${model_dir}/chk/chk-${model_name}-ITERATION.gguf \
|
||||||
|
--lora-out ${model_dir}/lora/lora-${model_name}-ITERATION.bin \
|
||||||
|
--threads 4 --ctx 64 --batch 4 --adam-iter 1 --save-every 5 \
|
||||||
|
--lora-r 8 --lora-alpha 16 \
|
||||||
|
--use-checkpointing
|
||||||
|
|
||||||
|
# # --grad-acc 1 \
|
||||||
|
# # --use-flash \
|
||||||
|
# # --escape \
|
||||||
|
# # --seed 1
|
||||||
|
|
||||||
|
./export-lora \
|
||||||
|
--model-base ${model_dir}/${model_name}.gguf \
|
||||||
|
--model-out ${model_dir}/${dataset}-${model_name}.gguf \
|
||||||
|
--lora-scaled ${model_dir}/lora/lora-${model_name}-LATEST.bin 1.0
|
||||||
|
|
||||||
|
./main \
|
||||||
|
-m ${model_dir}/${dataset}-${model_name}.gguf \
|
||||||
|
-n 512 \
|
||||||
|
-p "雨对风"
|
|
@ -2,12 +2,55 @@
|
||||||
|
|
||||||
Basic usage instructions:
|
Basic usage instructions:
|
||||||
|
|
||||||
|
在解释train from scratch(有说简称为TFS),即从头训练前,先说一下剪枝中的one-shot剪枝(一次剪枝)常见流程:
|
||||||
|
训练一个大模型 -> 在大模型中剪枝 -> 微调/从头训练
|
||||||
|
|
||||||
|
对于剪枝后的模型如何恢复精度目前有好几种方案:
|
||||||
|
|
||||||
|
从头训练(Trrain From Scratch):指只保留剪枝后的模型的结构,而不使用其剪枝后的权重。并随机初始化权重,再进行训练(通常使用和训练大模型时相同的学习率计划)。
|
||||||
|
微调(Finetune):剪枝后的模型使用小学习率继续训练。
|
||||||
|
|
||||||
|
ggml-vocab-aquila 悟道天鹰
|
||||||
|
ggml-vocab-falcon 不如llama2-7b
|
||||||
|
ggml-vocab-gpt-neox EleutherAI 推出 200亿参数的类 GPT 模型:不像 GPT-3,它免费开放 GPT-NeoX-20B
|
||||||
|
ggml-vocab-mpt MPT-7B基于1万亿tokens的文本和代码数据训练得到。是一个decoder-style类型的transformer。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# get training data
|
# get training data
|
||||||
wget https://raw.githubusercontent.com/brunoklein99/deep-learning-notes/master/shakespeare.txt
|
wget https://raw.githubusercontent.com/brunoklein99/deep-learning-notes/master/shakespeare.txt
|
||||||
|
|
||||||
|
# 构建vocab
|
||||||
|
|
||||||
|
```
|
||||||
|
spm_train --model_type=unigram --vocab_size=718 --num_threads=8 --input=slqm.txt --model_prefix=models/vocab-slqm
|
||||||
|
spm_train --model_type=unigram --vocab_size=10000 --num_threads=8 --input=hlm.txt --model_prefix=models/vocab-hlm
|
||||||
|
# --input指定需要训练的文本文件,--model_prefix指定训练好的模型名,本例中生成models/vocab-slqm.model和/models/vocab-slqm.vocab两个文件,vocab是词典信息。
|
||||||
|
# cmd 调用
|
||||||
|
echo "云对雨,雪对风,晚照对晴空。" | spm_encode --model=models/vocab-slqm.model
|
||||||
|
echo "闲言少叙,却说宝玉因近日林黛玉回去,剩得自己孤凄,也不和人顽耍,每到晚间,便索然睡了。" | spm_encode --model=models/vocab-hlm.model
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
# vocab转换为gglm格式 先将model转换为gguf,从ggml中提取vocab ???
|
||||||
|
|
||||||
|
```
|
||||||
|
python convert.py --vocab-only ../models/baichuan-inc/Baichuan2-7B-Chat/ --outfile models/ggml-vocab-bc7.gguf
|
||||||
|
python convert.py --vocab-only ../models/baichuan-inc/Baichuan2-13B-Chat/ --outfile models/ggml-vocab-bc13.gguf
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
# train
|
# train
|
||||||
./bin/train-text-from-scratch \
|
dataset="shakespeare" \
|
||||||
|
vocab_name="ggml-vocab-llama" \
|
||||||
|
vocab_dir="models" \
|
||||||
|
model_dir="../models/ggmls/" \
|
||||||
|
data_dir="../models" \
|
||||||
|
sh examples/train-text-from-scratch/train-scratch.sh
|
||||||
|
|
||||||
|
|
||||||
|
#main: tokenize training data
|
||||||
|
./train-text-from-scratch \
|
||||||
--vocab-model ../models/ggml-vocab-llama.gguf \
|
--vocab-model ../models/ggml-vocab-llama.gguf \
|
||||||
--ctx 64 --embd 256 --head 8 --layer 16 \
|
--ctx 64 --embd 256 --head 8 --layer 16 \
|
||||||
--checkpoint-in chk-shakespeare-256x16-LATEST.gguf \
|
--checkpoint-in chk-shakespeare-256x16-LATEST.gguf \
|
||||||
|
@ -16,9 +59,72 @@ wget https://raw.githubusercontent.com/brunoklein99/deep-learning-notes/master/s
|
||||||
--train-data "shakespeare.txt" \
|
--train-data "shakespeare.txt" \
|
||||||
-t 6 -b 16 --seed 1 --adam-iter 256 \
|
-t 6 -b 16 --seed 1 --adam-iter 256 \
|
||||||
--no-checkpointing
|
--no-checkpointing
|
||||||
|
./main -m ggml-shakespeare-256x16-f32.gguf
|
||||||
|
|
||||||
# predict
|
# predict
|
||||||
./bin/main -m ggml-shakespeare-256x16-f32.gguf
|
./main -m ggml-shakespeare-256x16-f32-LATEST.gguf
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 声律启蒙-baichuan
|
||||||
|
dataset="slqm" \
|
||||||
|
vocab_name="ggml-vocab-baichuan" \
|
||||||
|
vocab_dir="models" \
|
||||||
|
model_dir="../models/ggmls/" \
|
||||||
|
data_dir="../models" \
|
||||||
|
sh examples/train-text-from-scratch/train-scratch.sh
|
||||||
|
|
||||||
|
|
||||||
|
## 训练日志
|
||||||
|
|
||||||
|
train_opt_callback: iter= 1163 sample=1073/1600 sched=0.100000 loss=0.153680 dt=00:00:06 eta=00:00:27 |->
|
||||||
|
train_opt_callback: iter= 1164 sample=1089/1600 sched=0.100000 loss=0.153693 dt=00:00:06 eta=00:00:20 |->
|
||||||
|
train_opt_callback: iter= 1165 sample=1105/1600 sched=0.100000 loss=0.157189 dt=00:00:06 eta=00:00:13 |->
|
||||||
|
train_opt_callback: iter= 1166 sample=1121/1600 sched=0.100000 loss=0.153400 dt=00:00:06 eta=00:00:06 |->
|
||||||
|
train_opt_callback: iter= 1167 sample=1137/1600 sched=0.100000 loss=0.156294 dt=00:00:07 eta=0.0ms |->
|
||||||
|
main: total training time: 00:31:50
|
||||||
|
save_checkpoint_file: saving to chk-slqm-256x16-1167.gguf
|
||||||
|
save_checkpoint_file: saving to chk-slqm-256x16-LATEST.gguf
|
||||||
|
save_llama_model_file: saving to ggml-slqm-256x16-f32-1167.gguf
|
||||||
|
save_llama_model_file: saving to ggml-slqm-256x16-f32-LATEST.gguf
|
||||||
|
|
||||||
|
train_opt_callback: iter= 1929 sample=561/1600 sched=0.100000 loss=0.136846 dt=00:00:06 eta=00:00:40 |->
|
||||||
|
train_opt_callback: iter= 1930 sample=577/1600 sched=0.100000 loss=0.137856 dt=00:00:06 eta=00:00:33 |->
|
||||||
|
train_opt_callback: iter= 1931 sample=593/1600 sched=0.100000 loss=0.138562 dt=00:00:06 eta=00:00:26 |->
|
||||||
|
train_opt_callback: iter= 1932 sample=609/1600 sched=0.100000 loss=0.139201 dt=00:00:06 eta=00:00:19 |->
|
||||||
|
train_opt_callback: iter= 1933 sample=625/1600 sched=0.100000 loss=0.135440 dt=00:00:06 eta=00:00:13 |->
|
||||||
|
train_opt_callback: iter= 1934 sample=641/1600 sched=0.100000 loss=0.141512 dt=00:00:06 eta=00:00:06 |->
|
||||||
|
train_opt_callback: iter= 1935 sample=657/1600 sched=0.100000 loss=0.134973 dt=00:00:06 eta=0.0ms |->
|
||||||
|
main: total training time: 01:03:53
|
||||||
|
save_checkpoint_file: saving to chk-slqm-256x16-1935.gguf
|
||||||
|
save_checkpoint_file: saving to chk-slqm-256x16-LATEST.gguf
|
||||||
|
save_llama_model_file: saving to ggml-slqm-256x16-f32-1935.gguf
|
||||||
|
save_llama_model_file: saving to ggml-slqm-256x16-f32-LATEST.gguf
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 红楼梦-baichuan 貌似macos内存不足
|
||||||
|
dataset="hlm" \
|
||||||
|
vocab_name="ggml-vocab-baichuan" \
|
||||||
|
vocab_dir="models" \
|
||||||
|
model_dir="../models/ggmls/" \
|
||||||
|
data_dir="../models" \
|
||||||
|
sh examples/train-text-from-scratch/train-scratch.sh
|
||||||
|
|
||||||
|
|
||||||
|
## 训练日志
|
||||||
|
|
||||||
|
train_opt_callback: iter= 4534 sample=72561/759953 sched=0.100000 loss=4.727833 dt=00:00:06 eta=00:00:13 |---->
|
||||||
|
train_opt_callback: iter= 4535 sample=72577/759953 sched=0.100000 loss=4.911985 dt=00:00:06 eta=00:00:06 |-->
|
||||||
|
save_checkpoint_file: saving to chk-hlm-256x16-4536.gguf
|
||||||
|
save_checkpoint_file: saving to chk-hlm-256x16-LATEST.gguf
|
||||||
|
save_llama_model_file: saving to ggml-hlm-256x16-f32-4536.gguf
|
||||||
|
save_llama_model_file: saving to ggml-hlm-256x16-f32-LATEST.gguf
|
||||||
|
train_opt_callback: iter= 4536 sample=72593/759953 sched=0.100000 loss=4.705160 dt=00:00:06 eta=0.0ms |---->
|
||||||
|
main: total training time: 05:42:18
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Output files will be saved every N iterations (config with `--save-every N`).
|
Output files will be saved every N iterations (config with `--save-every N`).
|
||||||
|
|
21
examples/train-text-from-scratch/train-scratch.sh
Normal file
21
examples/train-text-from-scratch/train-scratch.sh
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
|
||||||
|
# train
|
||||||
|
#main: tokenize training data
|
||||||
|
# vocab_name="ggml-vocab-llama"
|
||||||
|
# vocab_dir="models"
|
||||||
|
# model_dir="../models/ggmls/"
|
||||||
|
# dataset="shakespeare"
|
||||||
|
# data_dir="../models"
|
||||||
|
|
||||||
|
./train-text-from-scratch \
|
||||||
|
--train-data ${data_dir}/${dataset}.txt \
|
||||||
|
--vocab-model ${vocab_dir}/${vocab_name}.gguf \
|
||||||
|
--ctx 64 --embd 256 --head 8 --layer 16 \
|
||||||
|
--checkpoint-in ${model_dir}/chk/chk-${vocab_name}-LATEST.gguf \
|
||||||
|
--checkpoint-out ${model_dir}/chk/chk-${vocab_name}-ITERATION.gguf \
|
||||||
|
--model-out ${dataset}-${vocab_name}-f32-ITERATION.gguf \
|
||||||
|
-t 6 -b 16 --seed 1 --adam-iter 256 \
|
||||||
|
--no-checkpointing
|
||||||
|
|
||||||
|
./main -m ${dataset}-${vocab_name}-f32-LATEST.gguf
|
BIN
finetune-bc
Executable file
BIN
finetune-bc
Executable file
Binary file not shown.
6301
hlm.txt
Normal file
6301
hlm.txt
Normal file
File diff suppressed because one or more lines are too long
BIN
mistralvsllama2-2-image.png
Normal file
BIN
mistralvsllama2-2-image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 418 KiB |
BIN
mistralvsllama2-image.png
Normal file
BIN
mistralvsllama2-image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 191 KiB |
BIN
mistralvsother.png
Normal file
BIN
mistralvsother.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
BIN
mistralvszephyrvsllama2.png
Normal file
BIN
mistralvszephyrvsllama2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 75 KiB |
2469
shakespeare.txt
Normal file
2469
shakespeare.txt
Normal file
File diff suppressed because it is too large
Load diff
136
slqm.txt
Normal file
136
slqm.txt
Normal file
|
@ -0,0 +1,136 @@
|
||||||
|
《声律启蒙》全文分上下卷,共30个韵,8000多字,现撷取上卷中最朗朗上口的15小段分享给大家,以供学习。
|
||||||
|
|
||||||
|
一 【东】
|
||||||
|
云对雨,雪对风,晚照对晴空。
|
||||||
|
来鸿对去燕,宿鸟对鸣虫。
|
||||||
|
三尺剑,六钧弓,岭北对江东。
|
||||||
|
人间清暑殿,天上广寒宫。
|
||||||
|
两岸晓烟杨柳绿,一园春雨杏花红。
|
||||||
|
两鬓风霜,途次早行之客;
|
||||||
|
一蓑烟雨,溪边晚钓之翁。
|
||||||
|
|
||||||
|
二 【冬】
|
||||||
|
春对夏,秋对冬,暮鼓对晨钟。
|
||||||
|
观山对玩水,绿竹对苍松。
|
||||||
|
冯妇虎,叶公龙,舞蝶对鸣蛩。
|
||||||
|
衔泥双紫燕,课蜜几黄蜂。
|
||||||
|
春日园中莺恰恰,秋天寒外雁雍雍。
|
||||||
|
秦岭云横,迢递八千远路;
|
||||||
|
巫山雨洗,嵯峨十二危峰。
|
||||||
|
|
||||||
|
三 【江】
|
||||||
|
楼对阁,户对窗,巨海对长江。
|
||||||
|
蓉裳对蕙帐,玉斝对银釭。
|
||||||
|
青布幔,碧油幢,宝剑对金缸。
|
||||||
|
忠心安社稷,利口覆家邦。
|
||||||
|
世祖中兴延马武,桀王失道杀龙逄。
|
||||||
|
秋雨潇潇,漫烂黄花都满径;
|
||||||
|
春风袅袅,扶疏绿竹正盈窗。
|
||||||
|
|
||||||
|
四 【支】
|
||||||
|
茶对酒,赋对诗,燕子对莺儿。
|
||||||
|
栽花对种竹,落絮对游丝。
|
||||||
|
四目颉,一足夔,鸲鹆对鹭鸶。
|
||||||
|
半池红菡萏,一架白荼蘼。
|
||||||
|
几阵秋风能应候,一犁春雨甚知时。
|
||||||
|
智伯恩深,国士吞变形之炭;
|
||||||
|
羊公德大,邑人竖堕泪之碑。
|
||||||
|
|
||||||
|
五 【微】
|
||||||
|
来对往,密对稀,燕舞对莺飞。
|
||||||
|
风清对月朗,露重对烟微。
|
||||||
|
霜菊瘦,雨梅肥,客路对渔矶。
|
||||||
|
晚霞舒锦绣,朝露缀珠玑。
|
||||||
|
夏暑客思欹石枕,秋寒妇念寄边衣。
|
||||||
|
春水才深,青草岸边渔父去;
|
||||||
|
夕阳半落,绿莎原上牧童归。
|
||||||
|
|
||||||
|
六 【鱼】
|
||||||
|
无对有,实对虚,作赋对观书。
|
||||||
|
绿窗对朱户,宝马对香车。
|
||||||
|
伯乐马,浩然驴,弋雁对求鱼。
|
||||||
|
分金齐鲍叔,奉璧蔺相如。
|
||||||
|
掷地金声孙绰赋,回文锦字窦滔书。
|
||||||
|
未遇殷宗,胥靡困傅岩之筑;
|
||||||
|
既逢周后,太公舍渭水之渔。
|
||||||
|
|
||||||
|
七 【虞】
|
||||||
|
金对玉,宝对珠,玉兔对金乌。
|
||||||
|
孤舟对短棹,一雁对双凫。
|
||||||
|
横醉眼,捻吟须,李白对杨朱。
|
||||||
|
秋霜多过雁,夜月有啼乌。
|
||||||
|
日暖园林花易赏,雪寒村舍酒难沽。
|
||||||
|
人处岭南,善探巨象口中齿;
|
||||||
|
客居江右,偶夺骊龙颔下珠。
|
||||||
|
|
||||||
|
八 【齐】
|
||||||
|
熊对虎,象对犀,霹雳对虹霓。
|
||||||
|
杜鹃对孔雀,桂岭对梅溪。
|
||||||
|
萧史凤,宋宗鸡,远近对高低。
|
||||||
|
水寒鱼不跃,林茂鸟频栖。
|
||||||
|
杨柳和烟彭泽县,桃花流水武陵溪。
|
||||||
|
公子追欢,闲骤玉骢游绮陌;
|
||||||
|
佳人倦绣,闷欹珊枕掩香闺。
|
||||||
|
|
||||||
|
九 【佳】
|
||||||
|
城对市,巷对街,破屋对空阶。
|
||||||
|
桃枝对桂叶,砌蚓对墙蜗。
|
||||||
|
梅可望,橘堪怀,季路对高柴。
|
||||||
|
花藏沽酒市,竹映读书斋。
|
||||||
|
马首不容孤竹扣,车轮终就洛阳埋。
|
||||||
|
朝宰锦衣,贵束乌犀之带;
|
||||||
|
宫人宝髻,宜簪白燕之钗。
|
||||||
|
|
||||||
|
十 【灰】
|
||||||
|
沙对水,火对灰,雨雪对风雷。
|
||||||
|
书淫对传癖,水浒对岩隈。
|
||||||
|
歌旧曲,酿新醅,舞馆对歌台。
|
||||||
|
春棠经雨放,秋菊傲霜开。
|
||||||
|
作酒固难忘曲蘖,调羹必要用盐梅。
|
||||||
|
月满庾楼,据胡床而可玩;
|
||||||
|
花开唐苑,轰羯鼓以奚催。
|
||||||
|
|
||||||
|
十一 【真】
|
||||||
|
哀对乐,富对贫,好友对嘉宾。
|
||||||
|
弹琴对结绶,白日对青春。
|
||||||
|
金翡翠,玉麒麟,虎爪对龙麟。
|
||||||
|
柳塘生细浪,花径起香尘。
|
||||||
|
闲爱登山穿谢屐,醉思漉酒脱陶巾。
|
||||||
|
雪冷霜严,倚槛松筠同傲岁;
|
||||||
|
日迟风暖,满园花柳各争春。
|
||||||
|
|
||||||
|
十二 【文】
|
||||||
|
尧对舜,夏对殷,蔡惠对刘蕡。
|
||||||
|
山明对水秀,五典对三坟。
|
||||||
|
唐李杜,晋机云,事父对忠君。
|
||||||
|
雨晴鸠唤妇,霜冷雁呼群。
|
||||||
|
酒量洪深周仆射,诗才俊逸鲍参军。
|
||||||
|
鸟翼长随,凤兮洵众禽长;
|
||||||
|
狐威不假,虎也真百兽尊。
|
||||||
|
|
||||||
|
十三 【元】
|
||||||
|
歌对舞,德对恩,犬马对鸡豚。
|
||||||
|
龙池对凤沼,雨骤对云屯。
|
||||||
|
刘向阁,李膺门,唳鹤对啼猿。
|
||||||
|
柳摇春白昼,梅弄月黄昏,
|
||||||
|
岁冷松筠皆有节,春喧桃李本无言。
|
||||||
|
噪晚齐蝉,岁岁秋来泣恨;
|
||||||
|
啼宵蜀鸟,年年春去伤魂。
|
||||||
|
|
||||||
|
十四 【寒】
|
||||||
|
多对少,易对难,虎踞对龙蟠。
|
||||||
|
龙舟对凤辇,白鹤对青鸾。
|
||||||
|
风淅淅,露漙漙,绣毂对雕鞍。
|
||||||
|
鱼游荷叶沼,鹭立蓼花滩。
|
||||||
|
有酒阮貂奚用解,无鱼冯铗必须弹。
|
||||||
|
丁固梦松,柯叶忽然生腹上;
|
||||||
|
文郎画竹,枝梢倏尔长毫端。
|
||||||
|
|
||||||
|
十五 【删】
|
||||||
|
姚对宋,柳对颜,赏善对惩奸。
|
||||||
|
愁中对梦里,巧慧对痴顽。
|
||||||
|
孔北海,谢东山,使越对征蛮,
|
||||||
|
淫声闻濮上,离曲听阳关。
|
||||||
|
骁将袍披仁贵白,小儿衣着老莱斑。
|
||||||
|
茅舍无人,难却尘埃生榻上;
|
||||||
|
竹亭有客,尚留风月在窗间。
|
BIN
zephy-beta-rvsother.png
Normal file
BIN
zephy-beta-rvsother.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 160 KiB |
Loading…
Add table
Add a link
Reference in a new issue