目录
4.3、模型转换(把7B 模型转换成 ggml FP16 )
4.4、对FP16模型进行4-bit 进一步量化。(使用上面编译生成的 ./quantize)
前言
LLM大模型学的时间也有大半年了,相关的模型、工具、技术和知识等也更新比较快。很多东西之前都没有留痕,回头一看,学了个寂寞。
一、llama.cpp是什么?
llama.cpp 的主要目标是在MacBook上使用 4 位整数量化运行 LLaMA 模型。
- Plain C/C++ implementation without dependencies
- Apple silicon first-class citizen - optimized via ARM NEON, Accelerate and Metal frameworks
- AVX, AVX2 and AVX512 support for x86 architectures
- Mixed F16 / F32 precision
- 2-bit, 3-bit, 4-bit, 5-bit, 6-bit and 8-bit integer quantization support
- CUDA, Metal and OpenCL GPU backend support
总之一句话:llama.cpp 一个C++编写的轻量级开源大模型框架,可以支持在消费级普通设备上本地部署运行大模型。基本上大部分开源大模型他都支持。
注:之前老版本转换的模型文件扩展名都是.bin,最新的模型文件都是.gguf。
二、使用步骤
1.下载编译llama.cpp
llama.cpp 编译分为CPU和GPU两种,但编译方式有好几种:普通编译,Metal 编译,MPI编译,BLAS编译。 本文只介绍少普通编译和BLAS编译。其他详见llama.cpp
2. 普通编译
默认编译出来的CPU版本。
-
使用make构建使用下面命令:
cd llama.cpp make
运行如下:
生成了以下:
注:如果失败了,使用make clean 清理一下,重新编译。
-
使用Cmake构建如下:
cd llama.cpp mkdir build cd build cmake .. cmake --build . --config Release
3. BLAS编译
使用 BLAS 可能会提高使用大于 32(默认值为 512)的批处理进行提示处理时的性能。支持纯 CPU BLAS 实现不会影响正常生成性能。我们可能会看到涉及 GPU 的 BLAS 实现(例如 cuBLAS、hipBLAS 和 CLBlast)的生成性能改进。目