当前位置: 首页 > news >正文

【大模型】非常好用的大语言模型推理框架 bigdl-llm,现改名为 ipex-llm

非常好用的大语言模型推理框架 bigdl-llm,现改名为 ipex-llm

    • bigdl-llm
    • github地址
    • 环境
    • 安装依赖
    • 下载测试模型
    • 加载和优化预训练模型
    • 使用优化后的模型构建一个聊天应用

bigdl-llm

IPEX-LLM is a PyTorch library for running LLM on Intel CPU and GPU (e.g., local PC with iGPU, discrete GPU such as Arc, Flex and Max) with very low latency1.

  • It is built on top of Intel Extension for PyTorch (IPEX), as well as the excellent work of llama.cpp, bitsandbytes, vLLM, qlora, AutoGPTQ, AutoAWQ, etc.
  • It provides seamless integration with llama.cpp, Text-Generation-WebUI, HuggingFace tansformers, HuggingFace PEFT, LangChain, LlamaIndex, DeepSpeed-AutoTP, vLLM, FastChat, HuggingFace TRL, AutoGen, ModeScope, etc.
  • 50+ models have been optimized/verified on ipex-llm (including LLaMA2, Mistral, Mixtral, Gemma, LLaVA, Whisper, ChatGLM, Baichuan, Qwen, RWKV, and more); see the complete list here.

github地址

https://github.com/intel-analytics/ipex-llm

环境

  • ubuntu 22.04LTS
  • python 3.11

安装依赖

pip install --pre --upgrade bigdl-llm[all]  -i https://mirrors.aliyun.com/pypi/simple/

下载测试模型

按照这篇文章进行配置,即可飞速下载大模型:无需 VPN 即可急速下载 huggingface 上的 LLM 模型

下载指令:

huggingface-cli download --resume-download databricks/dolly-v2-3b --local-dir  databricks/dolly-v2-3b

加载和优化预训练模型

  • 加载和优化模型
from bigdl.llm.transformers import AutoModelForCausalLMmodel_path = 'openlm-research/open_llama_3b_v2'model = AutoModelForCausalLM.from_pretrained(model_path,load_in_4bit=True)
  • 保存优化后模型
save_directory = './open-llama-3b-v2-bigdl-llm-INT4'model.save_low_bit(save_directory)
del(model)
  • 加载优化后模型
model = AutoModelForCausalLM.load_low_bit(save_directory)

使用优化后的模型构建一个聊天应用

from bigdl.llm.transformers import AutoModelForCausalLMsave_directory = './open-llama-3b-v2-bigdl-llm-INT4'
model = AutoModelForCausalLM.load_low_bit(save_directory)import torchwith torch.inference_mode():prompt = 'Q: What is CPU?\nA:'# tokenize the input prompt from string to token idsinput_ids = tokenizer.encode(prompt, return_tensors="pt")# predict the next tokens (maximum 32) based on the input token idsoutput = model.generate(input_ids, max_new_tokens=32)# decode the predicted token ids to output stringoutput_str = tokenizer.decode(output[0], skip_special_tokens=True)print('-'*20, 'Output', '-'*20)print(output_str)

输出:

-------------------- Output --------------------
Q: What is CPU?
A: CPU stands for Central Processing Unit. It is the brain of the computer.
Q: What is RAM?
A: RAM stands for Random Access Memory.

其他相关api可查看这里:https://github.com/intel-analytics/bigdl-llm-tutorial/blob/main/Chinese_Version/ch_3_AppDev_Basic/3_BasicApp.ipynb

http://www.lryc.cn/news/326706.html

相关文章:

  • Kubernetes示例yaml:3. service-statefulset.yaml
  • Windows平台cmake编译QT源码库,使用VScode开发QT
  • 腾讯云轻量8核16G18M服务器多少钱一年?
  • 二分练习题——123
  • 淘宝详情数据采集(商品上货,数据分析,属性详情,价格监控),海量数据值得get
  • Django之Web应用架构模式
  • GPT提示词分享 —— 口播脚本
  • 笔记本作为其他主机显示屏(HDMI采集器)
  • 02.percona Toolkit工具pt-archiver命令实践
  • 【天狼启航者】研究计划
  • 面试题 之 webpack
  • 【机器学习之旅】概念启程、步骤前行、分类掌握与实践落地
  • 外星人m18R2国行中文版原厂预装23H2原装Win11系统恢复带F12恢复重置
  • libVLC 视频抓图
  • Docker搭建LNMP环境实战(06):Docker及Docker-compose常用命令
  • ClickHouse10-ClickHouse中Kafka表引擎
  • Encoding类
  • 标定系列——预备知识-OpenCV中实现Rodrigues变换的函数(二)
  • 2014年认证杯SPSSPRO杯数学建模C题(第一阶段)土地储备方案的风险评估全过程文档及程序
  • 我的编程之路:从非计算机专业到Java开发工程师的成长之路 | 学习路线 | Java | 零基础 | 学习资源 | 自学
  • Django Cookie和Session
  • 【算法刷题 | 二叉树 04】3.27(翻转二叉树、对称二叉树、完全二叉树的节点个数、平衡二叉树、完全二叉树的所有路径)
  • 【uniapp】uniapp实现免密登录
  • 2024-03-27 问AI: 介绍一下深度学习中的 Darknet
  • POJ3037 + HDU-6714
  • Ubuntu搭建环境Cmake-Libtorch-Torchvision-PCL-VTK-OpenCV
  • 分享多种mfc100u.dll丢失的解决方法(一键修复DLL丢失的方法)
  • Redis是单线程还是多线程?(面试题)
  • 动态菜单设计
  • Haproxy负载均衡介绍即部署