惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks
B
Blog
腾讯CDC
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - Franky
罗磊的独立博客
月光博客
月光博客
Jina AI
Jina AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
D
Docker
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
G
Google Developers Blog
V
Visual Studio Blog
I
InfoQ
有赞技术团队
有赞技术团队
D
DataBreaches.Net
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志
宝玉的分享
宝玉的分享
Blog — PlanetScale
Blog — PlanetScale

StudyingLover's Blog

Diffusion Policy笔记 rwkv笔记 act笔记 nanovllm-block_manager opencode多智能体 nanobot-pre-train nanobot-rl nanobot-sft nanobot-checkpoint_manager nanobot-gpt nanobot-mid-train Vision Mamba (Vim)笔记 BPE演示 最后一遍学习Transformer YOLOv5 目标检测笔记 下载根服务器解析记录 Dynaseal A Backend-Controlled LLM API Key Distribution Scheme with Constrained Invocation Parameters 判断链表有环 王道25数据结构勘误 关于perplexity的open-sourcing-r1-1776 AI为什么不像人类一样进行多轮对话 新博客改造日记和功能测试 linuxqq只显示登陆背景图 数字设计和计算机体系结构(机械工业出版社)勘误(自制) Dynaseal:面向未来端侧llm agent的llm api key分发机制 A Definitive Guide to Markdown Style This post is using MDX, Where you can embed JSX and Astro components RT-Patch学习 pydantic实现的LLM ReAct fastapi 和 uvicorn 设置监听 ipv6
快速上手llama2.c
About the Author StudyingLover · 2023-07-26 · via StudyingLover's Blog

快速上手llama2.c

llama2.c一个完整的解决方案,可以使用PyTorch从头开始训练的Llama 2 LLM(Lightweight Language Model)模型,并将权重导出为二进制文件,然后加载到一个简单的500行C文件(run.c)中进行推理。另外,你也可以加载、微调和推理Meta的Llama 2模型(但这部分仍在积极开发中)。因此,这个仓库提供了一个”全栈”的训练和推理方案,专注于极简和简洁性。你可能会认为只有拥有数十亿参数的LLM才能实现有用的功能,但事实上,如果领域足够狭窄,非常小的LLM也可以表现出惊人的性能。建议参考TinyStories论文以获得灵感。

需要注意的是,这个项目最初只是一个有趣的周末项目:作者在之前的nanoGPT基础上进行了调整,实现了Llama-2架构而不是GPT-2,并且主要的工作是编写了C推理引擎(run.c)。因此,这个项目还比较年轻,并且在快速发展中。特别感谢llama.cpp项目为此项目提供了灵感。作者希望保持超级简洁,所以选择了硬编码Llama 2架构,采用fp32精度,并仅使用纯C编写一个没有依赖项的推理文件。

首先clone整个仓库并编译

git clone https://github.com/karpathy/llama2.c.git
cd llama.c
gcc -O3 -o run run.c -lm

接下来下载模型

wget https://karpathy.ai/llama2c/model.bin -P out

或者下载更大的一个模型

wget https://karpathy.ai/llama2c/model44m.bin -P out44m

接下来进行推理

./run out/model.bin

我们将会看到这样一段输出就代表运行成功

<s>
 One day, a little otter named Ollie went to play in the river. Ollie was very compassionate. He loved to help his friends in the town.
While playing, Ollie saw a big fish. The fish was stuck in the mud. "Help me, please!" said the fish. Ollie wanted to help the fish. He swam away, looking for something to break the mud.
Ollie found a small stick. He used the stick to break the mud. The fish was free! "Thank you, Ollie!" the fish said. The fish was happy and swam away.
Ollie felt good for helping the fish. He went back to play in the river. Ollie knew that helping others made him feel good. And from that day, Ollie was always compassionate to everyone.
<s>
 Tom was a big boy who liked to help his mom. He saw his mom doing laundry and asked if he could join. His mom said yes, but he had to be careful with the iron. The iron was hot and had a button on it.
Tom took the iron and ran to the house. He wanted to iron his shirt
achieved tok/s: 178.148921