比C语言还快20%!Mojo首个大模型开放下载,性能达Python版250倍

开发 前端
带来这个版本的老哥是一位前Meta工程师Aydyn Tairov。他利用Mojo的SIMD(Single Instruction Multiple Data,单指令多数据)和向量化原语,将llama2.py转化为Mojo,性能较Python版本提升了近250倍。

专为AI而来的新语言Mojo,推理LLaMA2性能比Python提升250倍!

比C语言也要快上20%。

上周五才开放下载,Mojo这么快就自证实力了。

要知道,之前官方号称Mojo可以比Python快6.8万倍。

而且作者表示,其实还有进一步提升的空间。

这也展示了通过Mojo进行硬件优化的潜力。

OpenAI创始成员Karpathy已经赶来围观了。

目前,LLaMA.mojo已开放下载~

几行代码即可下载

带来这个版本的老哥是一位前Meta工程师Aydyn Tairov。

他利用Mojo的SIMD(Single Instruction Multiple Data,单指令多数据)和向量化原语,将llama2.py转化为Mojo,性能较Python版本提升了近250倍。

即便在快速运行模式下,Mojo版本也比C语言版本性能提升15-20%。

不过作者尝试了在Mojo中使用并行模式,速度就慢了很多。

作者进行性能比较的系统和硬件情况如下:

如果你也想下载运行这个模型,需要先在环境中安装配置Mojo(文档链接见文末)。

首先将存储库保存到保存项目时的文件夹:

git clone https://github.com/tairov/llama2.mojo.git

然后打开存储文件夹:

cd llama2.mojo

下面就可以下载模型:

wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin

然后即可运行:

mojo llama2.mojo
num hardware threads:  6  SIMD vector width:  8
checkpoint size:  60816028
<s>
Once upon a time, there was a little girl named Lily. She loved to play outside in the sunshine. One day, she saw a big, red ball in the sky. It was the sun! She thought it was so pretty.
Lily wanted to play with the ball, but it was too high up in the sky. She tried to jump and reach it, but she couldn't. Then, she had an idea. She would use a stick to knock the ball down.Lily found a stick and tried to hit the ball. But the stick was too short. She tried again and again, but she couldn't reach it. She felt sad.
Suddenly, a kind man came by and saw Lily. He asked her what was wrong. Lily told him about the ball. The man smiled and said, "I have a useful idea!" He took out a long stick and used it to knock the ball down. Lily was so happy! She thanked the man and they played together in the sunshine.
<s>
Once upon a time, there was a little girl named Lily. She loved to play outside in the sunshine. One day, she saw a big, red
achieved tok/s:  264.24870466321244

为啥Mojo这么快?

不过话说回来,为啥Mojo的速度可以这么快?

这还得从Mojo的来历说起。

它诞生于今年5月,专为AI领域开发,由LLVM之父和Swift之父Chris Lattner带来。

它兼顾了Python和C++的优点,语法简单、运行快,而且可以和任何Python库无缝交互。

自从上线以来,Mojo已经吸引了12万开发者,GitHub星标达9K。

今年8月,Mojo背后公司Modular新获1亿美元融资,总融资金额达1.3亿美元。

Mojo语言这么快的原因,可以归结为4点。

第1步,通过类型注释消除Python动态类型的损失,并做代数简化(algebraic simplifications),避免开方运算以及简化复数平方运算,达到89倍加速。

第2步,通过向量化实现SIMD(单指令多数据)的并行计算,并让向量宽度以匹配CPU的FMA(浮点乘法累加单元)数量,达到874倍。

第3步,把前两步开发好的单线程实现改成多核并行化,对于88核的系统再获得30倍加速,与原始Python相比已经到了26000倍。

第4步,解决并行化中的加载不均衡问题,让线程从池中动态获取任务,得到最终结果68000倍。

几天前,Mojo正式开放下载。目前支持Linux系统,后续将陆续添加Mac和Windows。

同时支持VSCode插件,可以实现语法高亮和代码补全等功能。

以及也能像Python一样在Jupyter里交互式操作。

感兴趣的童鞋,可以去上手体验一下~

GitHub地址:https://github.com/tairov/llama2.mojo

Mojo文档:https://docs.modular.com/mojo/manual/get-started/index.html

责任编辑:武晓燕 来源: 量子位
相关推荐

2023-09-08 15:05:51

Mojo编程语言

2023-09-12 12:14:05

Python程序矢量化

2023-09-09 06:54:02

AI编程语言Mojo

2023-09-08 18:55:50

PythonNumpyAI

2009-03-13 19:30:48

2023-05-10 15:07:00

Mojo开发选项

2010-04-22 11:42:44

Symbian开发

2023-05-15 07:20:24

2023-09-12 13:29:46

AI训练

2013-09-09 15:35:35

Linux

2023-09-11 14:16:28

2009-07-23 10:11:00

Expression

2013-07-31 09:22:14

Windows 8.1ISO镜像

2024-01-16 16:39:33

PythonPyPy

2015-11-11 10:28:53

Windows 10UWP-Beta微博

2023-09-23 15:53:25

Ubuntu

2012-11-05 13:56:50

微软MDOP 2012

2023-07-14 16:45:56

Linux镜像

2013-10-08 09:49:20

OS XOS X GM

2013-09-18 13:55:35

Windows 8.1开发者开放下载
点赞
收藏

51CTO技术栈公众号