【大模型】非常好用的大语言模型推理框架 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

相关推荐
weixin_505154464 小时前
打破传统界限:Bowell Studio引领3D作业指导新纪元
人工智能·3d·制造·数据安全·数字孪生·数据可视化
ModelHub XC信创模盒5 小时前
中国信创AI生态下 “信创模盒”社区战略招募种子用户
人工智能·大模型·开发者·信创·算力
袋鼠云数栈6 小时前
集团数字化统战实战:统一数据门户与全业态监管体系构建
大数据·数据结构·人工智能·多模态
廋到被风吹走6 小时前
【AI】Codex 多语言实测:Python/Java/JS/SQL 效果横评
java·人工智能·python
cskywit6 小时前
【IEEE TNNLS 2025】赋予大模型“跨院行医”的能力:基于全局与局部提示的医学图像泛化框架 (GLP) 解析
人工智能
2501_948114246 小时前
AI API Gateway 选型指南:2026 年生产环境下的聚合平台深度对比
人工智能·gateway
实在智能RPA6 小时前
Agent 在物流行业能实现哪些自动化?——深度拆解 AI Agent 驱动的智慧物流新范式
运维·人工智能·ai·自动化
TechubNews7 小时前
Jack Dorsey:告别传统公司层级,借助 AI 走向智能体架构
大数据·人工智能
伴野星辰7 小时前
如何提高YOLO8目标检测的准确性?
人工智能·目标检测·机器学习
胡耀超8 小时前
Token的八副面孔:为什么“词元“不需要更好的翻译,而需要更多的读者
大数据·人工智能·python·agent·token·代币·词元