KuiperLLama

KuiperLLama

校招、秋招、春招、实习好项目,带你从零动手实现支持LLama2/3和Qwen2.5的大模型推理框架。

Stars: 304

Visit
 screenshot

KuiperLLama is a custom large model inference framework that guides users in building a LLama-supported inference framework with Cuda acceleration from scratch. The framework includes modules for architecture design, LLama2 model support, model quantization, Cuda basics, operator implementation, and fun tasks like text generation and storytelling. It also covers learning other commercial inference frameworks for comprehensive understanding. The project provides detailed tutorials and resources for developing and optimizing large models for efficient inference.

README:

KuiperLLama 动手自制大模型推理框架,支持LLama2/3和Qwen2.5

News:新课发布,《动手自制大模型推理框架》,全手写cuda算子,课程框架支持LLama2和3.x以及Qwen2.5模型

Hi,各位朋友们好!我是 KuiperInfer 的作者。KuiperInfer 作为一门开源课程,迄今已经在 GitHub 上已斩获 2.5k star。 如今在原课程的基础上,我们全新推出了《动手自制大模型推理框架》, 新课程支持Llama系列大模型(包括最新的LLama3.2)以及Qwen2.5系列大模型,同时支持 Cuda 加速和 Int8 量化,自推出以来便广受好评。

《动手自制大模型推理框架》课程目录:

https://l0kzvikuq0w.feishu.cn/docx/ZF2hd0xfAoaXqaxcpn2c5oHAnBc

《动手自制大模型推理框架》课程优势

  1. 采用最新的C++ 20标准去写代码,统一、美观的代码风格,良好的错误处理;
  2. 优秀的项目管理形式,我们采用CMake+Git的方式管理项目,接轨大厂;
  3. 授人以渔,教大家怎么设计一个现代C++项目,同时教大家怎么用单元测试和Benchmark去测试验证自己的项目;
  4. CPU算子和CUDA双后端实现,对时新的大模型(LLama3和Qwen系列)有非常好的支持。

如果你对大模型推理感兴趣,想要深入了解并掌握相关技术,想在校招、秋招面试当中脱颖而出,那么这门《动手自制大模型推理框架》课程绝对不容错过。快来加入我们,一起开启学习之旅吧! 感兴趣的同学欢迎扫一扫课程下方二维码或者添加微信 lyrry1997 参加课程

《动手自制大模型推理框架》课程项目运行效果

LLama1.1b fp32模型,视频无加速,运行平台为Nvidia 3060 laptop,速度为60.34 token/s

第三方依赖

借助企业级开发库,更快地搭建出大模型推理框架

  1. google glog https://github.com/google/glog
  2. google gtest https://github.com/google/googletest
  3. sentencepiece https://github.com/google/sentencepiece
  4. armadillo + openblas https://arma.sourceforge.net/download.html
  5. Cuda Toolkit

模型下载地址

  1. LLama2 https://pan.baidu.com/s/1PF5KqvIvNFR8yDIY1HmTYA?pwd=ma8rhttps://huggingface.co/fushenshen/lession_model/tree/main

  2. Tiny LLama

  1. Qwen2.5/LLama

    请参考本项目配套课程,课程参加方式请看本文开头。

模型导出

python export.py llama2_7b.bin --meta-llama path/to/llama/model/7B
# 使用--hf标签从hugging face中加载模型, 指定--version3可以导出量化模型
# 其他使用方法请看export.py中的命令行参数实例

编译方法

  mkdir build 
  cd build
  # 需要安装上述的第三方依赖
  cmake ..
  # 或者开启 USE_CPM 选项,自动下载第三方依赖
  cmake -DUSE_CPM=ON ..
  make -j16

生成文本的方法

./llama_infer llama2_7b.bin tokenizer.model

LLama3.2 推理

  • 以 meta-llama/Llama-3.2-1B 为例,huggingface 上下载模型:
export HF_ENDPOINT=https://hf-mirror.com
pip3 install huggingface-cli
huggingface-cli download --resume-download meta-llama/Llama-3.2-1B --local-dir meta-llama/Llama-3.2-1B --local-dir-use-symlinks False
  • 导出模型:
python3 tools/export.py Llama-3.2-1B.bin --hf=meta-llama/Llama-3.2-1B
  • 编译:
mkdir build 
cd build
# 开启 USE_CPM 选项,自动下载第三方依赖,前提是需要网络畅通
cmake -DUSE_CPM=ON -DLLAMA3_SUPPORT=ON .. 
make -j16
  • 运行:
./build/demo/llama_infer Llama-3.2-1B.bin meta-llama/Llama-3.2-1B/tokenizer.json
# 和 huggingface 推理的结果进行对比
python3 hf_infer/llama3_infer.py

Qwen2.5 推理

  • 以 Qwen2.5-0.5B 为例,huggingface 上下载模型:
export HF_ENDPOINT=https://hf-mirror.com
pip3 install huggingface-cli
huggingface-cli download --resume-download Qwen/Qwen2.5-0.5B --local-dir Qwen/Qwen2.5-0.5B --local-dir-use-symlinks False
  • 导出模型:
python3 tools/export_qwen2.py Qwen2.5-0.5B.bin --hf=Qwen/Qwen2.5-0.5B
  • 编译:
mkdir build 
cd build
# 开启 USE_CPM 选项,自动下载第三方依赖,前提是需要网络畅通
cmake -DUSE_CPM=ON -DQWEN2_SUPPORT=ON .. 
make -j16
  • 运行:
./build/demo/qwen_infer Qwen2.5-0.5B.bin Qwen/Qwen2.5-0.5B/tokenizer.json
# 和 huggingface 推理的结果进行对比
python3 hf_infer/qwen2_infer.py

For Tasks:

Click tags to check more tools for each tasks

For Jobs:

Alternative AI tools for KuiperLLama

Similar Open Source Tools

For similar tasks

For similar jobs