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

相关推荐
七哥的AI日常8 分钟前
个人随想-gpt-o1大模型中推理链的一个落地实现
人工智能
985小水博一枚呀3 小时前
【深度学习|可视化】如何以图形化的方式展示神经网络的结构、训练过程、模型的中间状态或模型决策的结果??
人工智能·python·深度学习·神经网络·机器学习·计算机视觉·cnn
LluckyYH5 小时前
代码随想录Day 46|动态规划完结,leetcode题目:647. 回文子串、516.最长回文子序列
数据结构·人工智能·算法·leetcode·动态规划
古猫先生5 小时前
YMTC Xtacking 4.0(Gen5)技术深度分析
服务器·人工智能·科技·云计算
一水鉴天5 小时前
智能工厂的软件设计 “程序program”表达式,即 接口模型的代理模式表达式
开发语言·人工智能·中间件·代理模式
Hiweir ·6 小时前
机器翻译之创建Seq2Seq的编码器、解码器
人工智能·pytorch·python·rnn·深度学习·算法·lstm
Element_南笙6 小时前
数据结构_1、基本概念
数据结构·人工智能
FutureUniant6 小时前
GitHub每日最火火火项目(9.21)
人工智能·计算机视觉·ai·github·音视频
菜♕卷6 小时前
深度学习-03 Pytorch
人工智能·pytorch·深度学习
明明真系叻6 小时前
第十二周:机器学习笔记
人工智能·机器学习