跳到主要内容

Playground

docker run --rm -it \
-v /data/ml:/host \
-v /data/cache/apk:/etc/apk/cache \
-v /data/ml/home:/home/admin \
--entrypoint bash \
--name ml wener/base

apk add shadow sudo doas
adduser -D admin
echo 'admin ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
echo 'permit nopass admin as root' >> /etc/doas.d/admin.conf

apk add \
gcc g++ python3 py3-pip musl-dev cmake make pkgconf build-base \
git openssh-client binutils coreutils util-linux findutils sed grep tar wget curl neofetch \
rust cargo python3-dev openssl-dev linux-headers openblas-dev

su admin

mkdir -p /host/{gits,models}
mkdir -p ~/bin
export PATH="$HOME/bin:$PATH"

cd /host/gits

llama.cpp

  • BLAS performance improvements in prompt processing, doesn't affect the normal generation performance
git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
# OpenBLAS CPU 加速
# macOS LLAMA_METAL=1
make LLAMA_OPENBLAS=1 -j
cp main ~/bin/llama.cppv3

# before https://github.com/ggerganov/llama.cpp/pull/1305
# b9fd7ee^1
git checkout # b9fd7ee^1
make LLAMA_OPENBLAS=1 -j
cp main ~/bin/llama.cppv2


# /host/models/LLaMA-ggml-4bit_2023-03-31/llama-7b-ggml-q4_0/ggml-model-q4_0.bin
llama.cpp -m ./ggml-model-q4_0.bin -p "Building a website can be done in 10 simple steps:" -n 512
# https://huggingface.co/TheBloke/Selfee-13B-GGML
curl -LO https://huggingface.co/TheBloke/Selfee-13B-GGML/resolve/main/selfee-13b.ggmlv3.q2_K.bin

# -p "Building a website can be done in 10 simple steps:"
llama.cpp -m /host/models/selfee-13b.ggmlv3.q2_K.bin -t $(nproc) --repeat_penalty 1.0 --color -i -r "User:" -n 256 -f prompts/chat-with-bob.txt

chinese-alpaca

llama.cpp -m chinese-alpaca-13b-plus-quantized.bin -t $(nproc) -p "你好"

./main -m zh-models/7B/ggml-model-q4_0.bin --color -f prompts/alpaca.txt -ins -c 2048 --temp 0.2 -n 256 --repeat_penalty 1.1

Models

Flags

llama.cppfor
-i, --interactive交互模式
--interactive-first交互模式,立即等待输入
-ins, --instruct指令模式
--multiline-input允许多行输入
-r PROMPT, --reverse-prompt PROMPT遇到 PROMPT 时结束生成,加入交互模式
--color彩色输出
-s SEED, --seed SEED随机数种子,默认 -1 随机
-t N, --threads N线程数,默认 64
-p PROMPT, --prompt PROMPT生成的开始,默认空
-e处理转义字符 \n, \r, \t, \', \", \\
--prompt-cache FNAME保存 prompt 状态,加快启动,默认不保存
--prompt-cache-all保存用户输入和生成的结果
--prompt-cache-ro只读模式,使用 prompt 缓存但不更新
--random-prompt随机 prompt
--in-prefix STRING用户输入前缀,默认空
--in-suffix STRING用户输入后缀,默认空
-f FNAME, --file FNAME生成的文件
-n N, --n-predict N预测的 token 数量,默认 -1 无限
--top-k Ntop-k 采样,默认 40,0=禁用
--top-p Ntop-p 采样,默认 0.9,1.0=禁用
--tfs Ntail free 采样,参数 z,默认 1.0,1.0=禁用
--typical Nlocally typical 采样,参数 p,默认 1.0,1.0=禁用
--repeat-last-n N最后 N 个 token 重复惩罚,默认 64,0=禁用,-1=ctx_size
--repeat-penalty N重复 token 惩罚,默认 1.1,1.0=禁用
--presence-penalty N重复 alpha 出现惩罚,默认 0.0,0.0=禁用
--frequency-penalty N重复 alpha 频率惩罚,默认 0.0,0.0=禁用
--mirostat N使用 Mirostat 采样,默认 0,0=禁用,1=Mirostat,2=Mirostat 2.0
--mirostat-lr NMirostat 学习率,默认 0.1
--mirostat-ent NMirostat target entropy, 参数 eta,默认 5.0
-l,--logit-bias TOKEN_ID(+/-)BIAS
-c N, --ctx-size N上下文大小,默认 512
--ignore-eos忽略 EOS,继续生成
--no-penalize-nl不惩罚换行
--memory-f32使用 f32 代替 f16,不推荐
--temp N温度,默认 0.8
-b N, --batch-size N批处理大小,默认 512
--perplexity计算 perplexity
--keep N保留初始 prompt 的 token 数量,默认 0,-1=全部
--mlock强制系统将模型保留在 RAM 中,而不是交换或压缩
--no-mmap不要内存映射模型
--mtest计算最大内存使用量
--export导出计算图到 llama.ggml
--verbose-prompt生成前打印 prompt
--lora FNAME应用 LoRA 适配器
--lora-base FNAME
-m FNAME, --model FNAME模型文件
modifies the likelihood of token appearing in the completion,
i.e. `--logit-bias 15043+1` to increase likelihood of token ' Hello',
or `--logit-bias 15043-1` to decrease likelihood of token ' Hello'
  • EOS - End of stream

AMD EPYC 7601 (128) @ 2.200GHz

chinese-alpaca-13b-plus-quantized

llama_print_timings:        load time =  1954.73 ms
llama_print_timings: sample time = 57.95 ms / 51 runs ( 1.14 ms per token, 880.08 tokens per second)
llama_print_timings: prompt eval time = 1497.62 ms / 9 tokens ( 166.40 ms per token, 6.01 tokens per second)
llama_print_timings: eval time = 65538.88 ms / 50 runs ( 1310.78 ms per token, 0.76 tokens per second)