在 AI 领域,模型推理的环境配置和安装过程常常让人头疼。如果你也有这样的困扰,那么 llamafile 将会是你的福音。本文由 deepin(深度)社区用户川顺页创作,让你一文学会如何玩转 llamafile!

 llamafile到底是什么?

llamafile 是一种可在你自己的电脑上运行的可执行大型语言模型(LLM),它包含了给定的开放 LLM 的权重,以及运行该模型所需的一切。让人惊喜的是,你无需进行任何安装或配置。

 llamafile如何实现这一切?

这一切都得益于 llama.cpp 与 Cosmopolitan Libc 的结合,提供了强大的功能:

  • 跨 CPU 微架构运行:llamafiles 可以在多种 CPU 微架构上运行,支持新的 Intel 系统使用现代 CPU 特性,同时兼容旧计算机。
  • 跨 CPU 架构运行:llamafiles 可以在 AMD64 和 ARM64 等多种 CPU 架构上运行,兼容 Win32 和大多数 UNIX shell。
  • 跨操作系统运行:llamafiles 可以在 MacOS、Windows、Linux、FreeBSD、OpenBSD和 NetBSD 六种操作系统上运行。
  • 权重嵌入:LLM 的权重可以嵌入到 llamafile 中,使得未压缩的权重可以直接映射到内存中,类似于自解压缩的存档。

 llamafile支持哪些操作系统和CPU?

llamafile 支持 Linux 2.6.18+、Darwin (MacOS) 23.1.0+、Windows 8+、FreeBSD 13+、NetBSD 9.2+、OpenBSD 7+ 等操作系统。在 CPU 方面,支持 AMD64 和 ARM64 两种微处理器。

llamafile对GPU的支持如何

llamafile 支持 Apple Metal、NVIDIA 和 AMD 三种类型的 GPU。在 MacOS ARM64 上,可以通过编译一个小模块来支持 GPU。NVIDIA 和 AMD 显卡的所有者需要传递特定参数来启用 GPU。

你也可以创建自己的llamafiles!

有了这个项目包含的工具,你可以创建自己的 llamafiles,使用任何你想要的兼容模型权重。然后,你可以将这些 llamafiles 分发给其他人轻松地使用它们,无论他们使用的是什么类型的计算机。

llamafile 无疑是一个强大的工具,它使得模型推理变得更加便捷,无需安装或配置复杂的环境。如果你还在为模型推理的环境配置而烦恼,那么为何不试试 llamafile 呢?具体可以参考这个教程:https://zhuanlan.zhihu.com/p/686886176《利用llamafile构造傻瓜式,支持多平台启动的大模型》

如何在deepin上使用?

打开终端,运行 sh ./xxxx.llamafile

如何在Windows上面使用?

改后缀为.exe,双击打开即可。

如何使用GPU运行而不是CPU?

需要装好 NVIDIA/AMD 驱动,对应 NVIDIA,还应该装了 CUDA,然后在运行时加上 -ngl 99999 即可,这个代表将 99999 层(实际也就几百上千层)网络都搬到 GPU,如果你显存不够,可以适当降低这个数值,比如 99、999 等。

综合来看,对于 deepin: sh ./xxxx.llamafile -ngl 99999

对于 Windows: ./xxx.lamafile.exe -ngl 9999

获取地址

百度网盘链接:

https://pan.baidu.com/s/14cv7McPa1XpXBNKy914HyQ?pwd=msjn       提取码:msjn

123云盘链接:

https://www.123pan.com/s/oEqDVv-IP4o.html        提取码:8MCi

(注:后缀.exe 可以忽略,因为 llamafile 是跨平台的,可以同时在 Linux、Windows、Mac、BSD上运行。)

使用截图

如何接入其他客户端?

推荐这个,一键拥有你自己的跨平台 ChatGPT/Gemini 应用:

https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web

《ChatGPTNextWeb/ChatGPT-Next-Web: A cross-platform ChatGPT/Gemini UI (Web / PWA / Linux / Win / MacOS)》

安装后再设置,模型服务商选择 OpenAI,接口地址换成  http://127.0.0.1:8080

接入UOS-AI(不推荐普通用户尝试)

  • 先启动 llamafile。
  • 再安装 NGINX  sudo apt install nginx
  • 利用 OpenSSL 自签名 SSL 证书,有效期 10 年。

openssl req -newkey rsa:2048 -x509 -nodes -keyout localhost.key -new -out localhost.crt -subj /CN=Hostname -reqexts SAN -extensions SAN -config <(cat /usr/lib/ssl/openssl.cnf \
<(printf ‘[SAN]\nsubjectAltName=DNS:hostname,IP:127.0.0.1’)) -sha256 -days 3650

  • 在 NGINX 配置目录,创建证书目录,将刚刚的证书移过去。

sudo mkdir /etc/nginx/cert/
sudo cp localhost.* /etc/nginx/cert/

  • 编辑NGINX默认网站配置文件,sudo vim /etc/nginx/sites-enabled/default 配置如下:

##
# You should look at the following URL’s in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or WordPress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl_certificate cert/localhost.crt;
ssl_certificate_key cert/localhost.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

# server_name _;
server_name api.openai.com;

location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

}

  • 重启 NGINX。

sudo systemctl restart nginx

  • 修改本机 Host,将本机 IP: 127.0.0.1 映射到刚刚配置的 api.openai.com ,修改方法:sudo vim /etc/hosts 在任意行增加一行 127.0.0.1 api.openai.com
  • 然后按照该内容:https://bbs.deepin.org/zh/post/267049  让 UOS AI 进入英语环境,这样才能添加 ChatGPT 设置。
  • 添加配置:
image.png
  • 添加成功(电脑配置差的可能要多试几次):
image.png
  • 开始使用:
image.png

注意:目前选择 GPT3.5/GPT4 在 UOS AI 里貌似不支持流式传输,也就是没办法一个字一个字吞吐,导致要等待较长时间,等所有字都预测好了才会返回,体验较差,而其他 API 比如讯飞星火是支持流的,所以建议还是用 llamafile 自带的网页聊天窗吧。

原贴地址:https://bbs.deepin.org/zh/post/269443

65 个评论

  1. После того как я купил защитные очки от лазерного излучения, я понял, что это необходимо для обеспечения безопасности при работе с лазерами. Мои глаза теперь защищены, и я могу спокойно выполнять свою работу, не беспокоясь о возможных рисках.

  2. 10 Lotto Online 10line oynamaq təhlükəsizdir?, lotereya oyunlarının təhlükəsizliyi və qaydalara uyğunluğu haqqında məlumat təqdim edir. Bu, istifadəçilərə lotereya oynamanın təhlükəsiz olduğunu və platformanın bütün tədbirləri götürdüyünü göstərir ki, onlar oyun prosesinə güvənə bilərlər.

    Kayla
  3. İstifadəçi Təcrübələri və Rəyləri, istifadəçilərin platforma ilə bağlı fikirlərini və təcrübələrini paylaşmaq üçün bir məkan təmin edir. Bu, yeni istifadəçilərə platformanın pullu loto keyfiyyətini qiymətləndirmək üçün dəyərli məlumatlar təmin edir.

    Amelia
  4. Спасибо за информацию, которую нигде не мог найти. Сделанная с любовью и вниманием к деталям, мебель из сосны деревянная мебель станет не только функциональным элементом интерьера, но и настоящим произведением искусства.

    Леонид

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注