社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

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

Crossin的编程教室 • 7 月前 • 122 次点击  
明敏 发自 凹非寺
量子位 | 公众号 QbitAI
https://mp.weixin.qq.com/s/_tfMPdaIo6LPDcTXqpy4xw

入门教程、案例源码、学习资料、读者群

请访问: python666.cn

大家好,欢迎来到 Crossin的编程教室 !

专为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

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.

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



Crossin的第2本书《码上行动:利用Python与ChatGPT高效搞定Excel数据分析》已经上市了

本书从 Python 和 Excel 结合使用的角度讲解处理分析数据的思路、方法与实战应用。不论是希望从事数据分析岗位的学习者,还是其他职业的办公人员,都可以通过本书的学习掌握 Python 分析数据的技能。书中创新性地将 ChatGPT 引入到教学当中,用 ChatGPT 答疑并提供实训代码,并介绍了使用 ChatGPT 辅助学习的一些实用技巧,给学习者带来全新的学习方式。


公众号的读者朋友们购买后可在后台联系我,加入读者交流群,Crossin会为你开启陪读模式,解答你在阅读本书时的一切疑问。


感谢转发点赞的各位~

_往期文章推荐_

Python登顶年度语言榜首,SQL工作需求最大




如需了解付费精品课程教学答疑服务
请在Crossin的编程教室内回复: 666

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/161899
 
122 次点击