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

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

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 AutoModelForCausalLM

    model_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 AutoModelForCausalLM

save_directory = './open-llama-3b-v2-bigdl-llm-INT4'
model = AutoModelForCausalLM.load_low_bit(save_directory)


import torch

with torch.inference_mode():
    prompt = 'Q: What is CPU?\nA:'
    
    # tokenize the input prompt from string to token ids
    input_ids = tokenizer.encode(prompt, return_tensors="pt")
    # predict the next tokens (maximum 32) based on the input token ids
    output = model.generate(input_ids, max_new_tokens=32)
    # decode the predicted token ids to output string
    output_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

相关推荐
云烟成雨TD4 分钟前
Spring AI 1.x 系列【56】用大模型评判大模型:递归顾问实现自动化评估方案
人工智能·spring·自动化
AI客栈24 分钟前
K8s 自定义控制器中 WorkQueue 队列优化实践:基于 IPVS 转发原理的状态变化处理
人工智能
0xR3lativ1ty29 分钟前
每周AI工具新动态
人工智能
jerryinwuhan31 分钟前
面向产业带与中小企业数字化转型的电商运营人才培养模式
大数据·人工智能
Drgfd39 分钟前
智造赋能品控:汪进进以精益生产,夯实质量制造底座
人工智能·制造
米小虾1 小时前
"Chat is dead":OpenAI 正在杀死的不是聊天,是整个 AI 交互范式
人工智能·openai
冬奇Lab1 小时前
Agent 系列(18):成本与性能优化——省钱且更快
人工智能·llm·agent
Hefei GlobefishAI1 小时前
合肥合豚AI硬件方案:专为智能售货柜厂商定制的无人零售接口套件
人工智能·零售·自动售货机·无人零售硬件·ai硬件方案·智能售货柜·接口套件
冬奇Lab1 小时前
每日一个开源项目(第127篇):PM Skills Marketplace - 把顶级产品方法论塞进 AI Agent
人工智能·开源·资讯
吴佳浩1 小时前
Hermes vs OpenClaw:基于源码的 Agent Loop 全面分析
人工智能·llm·agent