开源轻量级深度学习推理框架
KuiperInfer是一个开源深度学习推理框架,支持Resnet、Yolov5和LLama2等主流模型。基于现代C++设计,该框架提供高效算子实现和优化技术,适用于图像分类、目标检测和自然语言处理任务。KuiperInfer不仅是实用的推理工具,还是学习深度学习框架设计和C++工程实践的优质资源。
我们在本项目的基础上开设了一个全新的课程,《从零自制大模型推理框架》,以下是目录,感兴趣的同学可以扫描二维码或者添加微信 lyrry1997 了解,欢迎大家参加。
<img src="https://yellow-cdn.veclightyear.com/0a4dffa0/fb5e857f-e738-46bb-a525-c17959cc7f4d.jpg" />主体已经更新完毕,完全可以开始自习。支持cuda,int8推理。
收费课程,256元,微信转账。可以,但是我的微信好友快满了,隔一段时间会清理,而且不定期会涨价。
B站要抽成,内容都一样。
飞书网盘,打开浏览器就可以看。
有的,且有答疑群,群友也很热情。
事在人为,我也尽量深入浅出教学。
见下文。
主业就是开发大模型推理框架的,课件已经被人民邮电出版社约稿,同时也是kuiperinfer项目,也就是本项目的发起人,目前全GitHub C++项目排名120位。
《动手自制大模型推理框架》项目运行效果fp32模型1.1b参数。
KuipeInfer目前2.3k star,帮助很多人获得了大 厂岗位。
一、项目整体架构和设计
学习架构思维,防止自己只会优化局部实现
二、支持LLama2模型结构
本节将为大家补齐算法工程师思维,在算法层面讲解大模型和Transformer的原理之后,开始对LLama2进行支持
三、模型的量化
为了减少显存的占用,我们开发了int8模型量化模块
四、Cuda基础和算子实现
带你学Cuda并在实战大模型算子的实现,为大模型推理赋能
五、用推理框架做点有趣的事情
六、学习其他商用推理框架的实现,查漏补缺
带领你亲手打造一个深度学习推理框架。关注我的B站空间,获取最新视频更新。 By following this project to build a deep learning inference framework from scratch, you will gain the following:
Video course link: https://space.bilibili.com/1822828582
We replaced the operators in llama.c with implementations from KuiperInfer
Model download link After downloading, replace it in demos/llama2/main.cpp
The second course is a reset version of the first course, with more comprehensive and improved content. The first course outline is in the section below.
Lesson Number | Progress | Course Link |
---|---|---|
Lecture 1 Project Preview and Environment Setup | Completed | https://www.bilibili.com/video/BV118411f7yM |
Lecture 2 Design and Implementation of Tensor | Completed | https://www.bilibili.com/video/BV1hN411k7q7 |
Lecture 3 Definition of Computational Graph | Completed | https://www.bilibili.com/video/BV1vc411M7Yp |
Lecture 4 Building Computational Graph Relationships and Execution Order | Completed | https://www.bilibili.com/video/BV19s4y1r7az |
Lecture 5 Operators and Registration Factory in KuiperInfer | Completed | https://www.bilibili.com/video/BV1gx4y1o7pj |
Lecture 6 Implementation of Convolution and Pooling Operators | Completed | https://www.bilibili.com/video/BV1hx4y197dS |
Lecture 7 Lexical and Syntactic Analysis in Expression Layer and Operator Implementation | Completed | https://www.bilibili.com/video/BV1j8411o7ao |
Lecture 8 Self-made Inference Framework Supporting ResNet Network Inference | Completed | https://www.bilibili.com/video/BV1o84y1o7ni |
Lecture 9 Self-made Inference Framework Supporting YOLOv5 Network Inference | Completed | https://www.bilibili.com/video/BV1Qk4y1A7XL |
🥰 KuiperInfer currently supports inference of UNet network, using pre-trained weights from Carvana
For inference reproduction, please refer to Running Kuiper's demo at the end of the document.
The demo directly uses YOLOv5-s pre-trained weights (COCO dataset), using KuiperInfer for inference
I have started a teaching course on Bilibili, currently covering the first 13 lessons. The course outline is as follows, and the homepage is: https://space.bilibili.com/1822828582. Welcome everyone to follow and support. The way to join the study group is through the QR code shown in the image above.
课程节数 | 主要内容 | 进度 | 课程链接 |
---|---|---|---|
第一课 | 整体框架解读和开发环境配置 | 完成 | https://www.bilibili.com/video/BV1HV4y1A7H8/ |
第二课 | 张量Tensor类的解析和输入数据的内存排布 | 完成 | https://www.bilibili.com/video/BV1Ed4y1v7Gb/ |
第三课 | 从CSV文件中初始化张量Tensor的一个实例 | 完成 | https://www.bilibili.com/video/BV1Pg411J7V5/ |
第四课 | 手写第一个算子Relu并完成算子注册工厂类 | 完成 | https://www.bilibili.com/video/BV1bG4y1J7sQ/ |
第五课 | Im2col的原理和卷积算子的实现 | 完成 | https://www.bilibili.com/video/BV1F841137Ct |
第六课 | 照葫芦画瓢,完成MaxPooling算子 | 完成 | https://www.bilibili.com/video/BV1m3411S7yy |
第七课 | 图结构(PNNX)讲解和计算图初步 | 完成 | https://www.bilibili.com/video/BV1VW4y1V7vp |
第八课 | 读取PNNX并构建自己的计算图 | 完成 | https://www.bilibili.com/video/BV1HY4y1Z7S3 |
第九课 | 卷积算子的实现和im2col加速计算的原理 | 完成 | https://www.bilibili.com/video/BV1F841137Ct |
第十课 | 再探Tensor类,构建计算图的图关系以及对算子的输入输出预分配 | 完成 | https://www.bilibili.com/video/BV1M54y1K7AG |
第十一课 | 算子的执行流程 | 完成 | https://www.bilibili.com/video/BV1wY411C7Kv |
第十二课 | 用我们自制的推理框架完成ResNet网络的推理和图片的分类 | 完成 | https://www.bilibili.com/video/BV1jD4y1M772 |
第十三课 | 用自制的推理框架支持Yolov5模型的推理 | 完成 | https://www.bilibili.com/video/BV1xs4y1J7t2 |
感谢以下同学对Kuiperinfer的付出
本项目相当于课程的上游或者预研项目
这里的每一个功能都有可能成为视频课程中的知识点,无论是我开发的还是其他同学完善的。
提示:
$DEVELOPMENT
或者指定-DDEVELOPMENT=ON
apt install cmake, libopenblas-dev, liblapack-dev, libarpack-dev, libsuperlu-dev
提示:
编译后请复制 tmp/unet/demo
文件夹下的 test.png 图片的绝对路径或相对路径,
然后在 build/demos
中按以下格式运行推理程序
./unet_test test.png unet_demo.pnnx.param unet_demo.pnnx.bin
pnnx 模型的下载地址:https://cowtransfer.com/s/09c7f337bab443
如果推理成功,你将会在文件夹内看到原图的分割结果 unet_output.jpg 。
请在demos文件夹下的yolo_test.cpp文件中修改以下代码
const std::string& image_path = "imgs/car.jpg"; const std::string& param_path = "tmp/yolo/demo/yolov5s_batch8.pnnx.param"; const std::string& bin_path = "tmp/yolo/demo/yolov5s_batch8.pnnx.bin";
image_path
指定图像目录,param_path
为模型的参数文件,bin_path
为模型的权重文件,请替换为你本地的路径。
模型定义和权重下载地址如下: https://cowtransfer.com/s/9bc43e0905cb40