使用 BigDL-LLM 加速 Intel 数据中心 GPU 上的 LLM 推理

使用 BigDL-LLM 加速 Intel 数据中心 GPU 上的 LLM 推理
2024年03月21日 13:27 InfoQ

作者 | Wesley Du, Yang Y Wang

策划 | Tina

导读:本文探讨了在 Intel® 数据中心 GPU 上采用 BigDL-LLM INT4 和 FP16 (使用 Self-Speculative Decoding) 进行大型语言模型推理的性能评估。文章介绍了 BigDL LLM 的 Self-Speculative Decoding,通过测量下一个 Token 延迟,分析了不同配置下的推理性能,并提供了性能测试所采用的工具包和硬件环境。结果显示,在 Intel® 数据中心 GPU Max 1100C 上利用 BigDL LLM 进行 FP16 (Self-Speculative Decoding)的大语言模型推理,可以显著改善推理的延迟。这篇文章将为对大型语言模型推理性能感兴趣的读者提供有益的参考和启示。

在生成式人工智能领域,针对大型语言模型(LLM)的推理加速,已经开发出多种性能改进技术。例如,低比特(例如 INT4)优化和 Speculative Decoding 等技术为加速 LLM 推理提供了有效的选择。我们已经在 BigDL-LLM 中实现了低比特和 Self-Speculative Decoding 优化,以提高 Intel®数据中心 GPU 上的 LLM 推理速度。

本文将介绍这两个内容:

  • BigDL-LLM 中的 Self-Speculative Decoding

  • Intel® 数据中心 GPU 上的性能数据

BigDL-LLM 中的 Self-Speculative Decoding

在 Speculative Decoding 中,一个小(草稿)模型快速生成多个草稿 Token,然后由大(目标)模型并行验证这些 Token。虽然 Speculative Decoding 可以有效加速目标模型,但在实践中很难维护或甚至获取到一个合适的草稿模型,特别是当目标模型使用定制数据进行微调时。

基于 Self-Speculative Decoding 的概念,BigDL-LLM 现在可以加速原始的 FP16(或 BF16)模型,无需单独的草稿模型或模型微调;BigDL-LLM 会自动将原始模型转换为 INT4,并在幕后使用 INT4 模型作为草稿模型。

在实践中,用户可以通过在加载模型时指定一个额外参数 speculative=True 来使用 BigDL-LLM 中的 Self-Speculative Decoding 功能。以下是示例代码片段:

from bigdl.llm.transformers import AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained(model_path,

optimize_model=True,

torch_dtype=torch.float16, #use bfloat16 on cpu

load_in_low_bit="fp16", #use bf16 on cpu

speculative=True, #set speculative to true

trust_remote_code=True,

use_cache=True)

output = model.generate(input_ids,

max_new_tokens=args.n_predict,

do_sample=False)

在底层,BigDL-LLM 利用 INT4 草稿模型生成一系列输出标记(步骤 A),然后将生成的 Token 馈送到目标 FP16 模型进行一次推理迭代(步骤 B)。通过比较草稿模型和目标模型的输出序列,确定最终的输出 Token。

图 1. BigDL-LLM 中的 Self-Speculative Decoding

理论上,使用 Self-Speculative Decoding 的 FP16 推理预期与原 FP16 模型推理具有相同的准确性。在实际测试中,BigDL-LLM 中的 Self-Speculative Decoding 可以将 FP16 推理的延迟性能提高 35% 到 40%。

Intel® 数据中心 GPU 的性能数据

我们已经使用 BigDL-LLM 在 Intel® GPU 上验证了各种最先进的大型语言模型的推理性能,包括 INT4 和 FP16(带有 Self-Speculative Decoding)。下面的图表展示了在这些模型上观察到的 “Next Token” 的延迟,输入为 1024 个 Token,批处理大小为 1。

实际测试中,使用 Hugging Face 上一些流行的模型在 Intel® 数据中心 GPU Max 1100C 上进行了 INT4 推理,以下图表显示了 Next Token 延迟:

图 2. Intel® 数据中心 GPU Max 1100C 上的 INT4 推理性能

请参考配置和免责声明以获取配置信息。

通过 Self-Speculative Decoding,我们观察到 FP16 推理的显著延迟改善(与没有 Self-Speculative Decoding 相比)。下面的图表比较了在 Intel 数据中心 GPU Max 1100C 上,使用 BigDL-LLM 进行 FP16 推理时的推理延迟。平均而言,Self-Speculative Decoding 可以将 FP16 的下一个 Token 延迟提高约 35%。

图 3. Intel® 数据中心 GPU Max 1100C 上的 FP16 推理性能

请参考配置和免责声明以获取配置信息。

开始使用

请访问该项目的 GitHub 页面,以开始在 Intel® 数据中心 GPU 上使用 BigDL 进行大型语言模型的工作。建议查看我们为 Self-Speculative Decoding 开发的 LLM 推理示例,这些示例适用于 Llama2、Mistral、ChatGLM3、Baichuan2、Qwen 等模型。

摘要

BigDL-LLM INT4 和 FP16 (Self-Speculative Decoding) 是加速大型语言模型推理的有效策略,以克服生成式 AI 模型固有的大量计算和内存挑战。通过对当前流行的大型语言模型的测试和数据分析,我们展示了在 Intel® 数据中心 GPU 上,INT4 和 FP16(Self-Speculative Decoding)可以显著改善推理的延迟性能。

配置和免责声明

The benchmark uses next token latency to measure the inference performance. Batch size 1, greedy search, input tokens 1024, output tokens 128, data type INT4/FP16. The measurements used BigDL-LLM 2.5.0b20240111 for INT4 benchmark and 2.5.0b20240123 for FP16 benchmark, PyTorch 2.1.0a0+cxx11.abi, Intel® Extension for PyTorch* 2.1.10+xpu, Transformers 4.31.0 for llama2 and 4.36.0 for mistral, and Intel oneAPI Base Toolkit 2024.0. Ubuntu 22.04.2 LTS with kernel 5.15.0. Intel GPU Driver 775_20. Tests performed by Intel in January 2024.

Intel® Data Center GPU Flex 170 results were measured on a system with 2S Intel® Xeon® 8480+ and 256 GB DDR5-4800, Intel® Data Center GPU Max 1100 results were measured on a system with 2S Intel® Xeon® 8480+ and 512 GB DDR5-4800.  Intel® Data Center GPU Max 1550 results were measured on a system with 2S Intel® Xeon® 8480+ and 1024 GB DDR5-4800.

Performance varies by use, configuration and other factors. Learn more on the Performance Index site.

Performance results are based on testing as of dates shown in configurations and may not reflect all publicly available updates. No product or component can be absolutely secure. Your costs and results may vary.  Intel technologies may require enabled hardware, software or service activation.  © Intel Corporation.  Intel, the Intel logo, and other Intel marks are trademarks of Intel Corporation or its subsidiaries.  Other names and brands may be claimed as the property of others.

财经自媒体联盟更多自媒体作者

新浪首页 语音播报 相关新闻 返回顶部