OpenVINO™ 2023.2发布:让生成式AI在实际场景中更易用

openlab_4276841a 更新于 4月前

作者: Yury Gorbachev — Intel 院士, OpenVINO 产品架构师

翻译:武卓,英特尔AI软件布道师

在过去的一年里,人工智能正以越来越快的速度发展,这得益于生成式 AI模型的引入和从中受益的场景的演变。我们承认这一点,并决定比平时更快地发布新版本的OpenVINO™,以帮助您获得新功能!

与之前的版本一样,在提高性能、增加对新AI模型的支持以及构建基础设施和模型缓存等不同组件方面,我们做了大量工作。对于我们最新的2023.2版本,我们做出了一些重大改进,我们将在下面概述。

边缘文本生成模型的附加性能

在我们的上一个版本2023.1中,我们引入了一些更改,以在英特尔CPU和GPU上运行大语言模型(LLM)。开发者们能够量化权重为int8格式,并将其作为初始步骤在CPU上运行。

在2023.2版本中,我们进一步优化此工作流程,并引入在CPU和集成显卡上运行权重量化为int8和int4精度的LLM的能力。权重量化直接影响内存带宽,并帮助模型更快、更高效地执行推理,因为模型消耗的内存更少了,所需的磁盘空间也更少,因此总体上需要的内存带宽也更少了!

此外,我们的模型转换和优化工具已经更新,可以帮助您处理模型准备流程。要压缩模型权重为int8和int4格式,您可以使用我们的神经网络压缩框架(NNCF)工具,该工具适用于OpenVINO格式或中间表示(IR)文件。此外,为了获得具有int4压缩权重的模型,您可以通过GPTQ(生成预训练transformers量化)算法来优化转换模型。实现这一过程的一种方法是通过Hugging Face AutoGPTQ实现。

如果你将Hugging Face作为模型的来源,你可以使用我们的optimum-Intel,它集成了OpenVINO的优势。此集成允许您自动压缩和转换模型,如我们在下面所示的这样:

要将模型压缩到int8精度:

#make use of optimum-intel
from optimum.intel import OVModelForCausalLM
#load pretrained model, convert to OpenVINO representation
#and compress weights
model = OVModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b", use_cache=True, export=True, load_in_8bit=True)
#store OpenVINO IR in a folder
model.save_pretrained("./Llama-2-7b")

请注意“load_in_8bit”选项,该选项指定应将原始模型压缩到int8精度。对于大于1B的模型,默认情况下会启用此选项。

要将模型压缩到int4精度:

#make use of optimum-intel
from optimum.intel import OVModelForCausalLM
#explicitly use NNCF for compression
from nncf import compress_weights, CompressWeightsMode
#load pretrained model, convert to OpenVINO representation
model = OVModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b", use_cache=True, export=True, load_in_8bit=False)
#perform weights compression using NNCF
model.model = compress_weight***odel.model, mode=CompressWeightsMode.INT4_SYM, group_size=128, ratio=0.8)
#store OpenVINO IR in a folder
model.save_pretrained("./Llama-2-7b")

请注意,这一次我们没有使用HF API功能,而是直接调用NNCF将权重压缩到int4。根据模型的不同,您可以更改压缩参数以获得更准确的结果。在这种情况下,我们使用对称量化,组大小为128个元素,int4与int8的权重之比为0.8。您可以查看我们的权重压缩文档,以获得更多详细信息和压缩提示。

要转换使用AutoGPTQ优化为int4精度的模型,请执行以下操作:

#make use of optimum-intel
from optimum.intel import OVModelForCausalLM
#load pretrained model, convert to OpenVINO representation
#with keeping weights in int4
model = OVModelForCausalLM.from_pretrained("TheBloke/Llama-2-7B-GPTQ", use_cache=True, export=True)
#store OpenVINO IR in a folder
model.save_pretrained("./Llama-2-7B-GPTQ")

优化模型就是这么简单。更详细的信息请查看这里:Optimize and Deploy Generative AI Models — OpenVINO™ documentation

新的生成式AI 以及更多的Notebooks代码示例!

我们知道,亲身体验最新功能和最先进模型是最好的学习方式。因此,我们的OpenVINO团队非常专注于为OpenVINO Notebooks代码示例带来新的及备受关注的模型。我们希望展示并鼓励您立即在您的设备上进行本地实验,以获得您所需的性能。以下是我们最近更新或新发布的一些Notebooks代码示例,以帮助您更快地将想法付诸生产。

一些Jupyter Notebooks已经更新,以演示PyTorch模型在没有ONNX转换的情况下的转换和优化,包括以下内容:

● PyTorch to OpenVINO(https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/102-pytorch-to-openvino ) —转换格式为torch.nn.Module以及torch.jit.ScriptModule 的 PyTorch模型为OpenVINO IR格式

● Post-Training Quantization of PyTorch models with NNCF(https://github.com/openvinotoolkit/openvino_notebook***lob/main/notebooks/112-pytorch-post-training-quantization-nncf/112-pytorch-post-training-quantization-nncf.ipynb ) —将int8 量化应用于PyTorch 模型

● Quantization of Image Classification Models(https://github.com/openvinotoolkit/openvino_notebook***lob/main/notebooks/113-image-classification-quantization/113-image-classification-quantization.ipynb ) — 将int8 量化应用于MobileNet V2 PyTorch模型

● Visual Question Answering and Image Captioning using BLIP and OpenVINO (https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/233-blip-visual-language-processing )— 优化BLIP PyTorch 模型

● Text-to-Image Generation and Infinite Zoom with Stable Diffusion v2 and OpenVINO™ (https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/236-stable-diffusion-v2 )— 在Stable Diffusion 2.0 流水线中优化模型

● Object masks from prompts with SAM and OpenVINO™ (https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/237-segment-anything#object-masks-from-prompts-with-sam--and-openvino )— 优化基于PyTorch的 Segment Anything Model (SAM)模型

● Optimizing PyTorch models with Neural Network Compression Framework of OpenVINO™ by 8-bit quantization(https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/302-pytorch-quantization-aware-training ) —PyTorch 模型量化感知训练(QAT)

我们还加入了一些notebooks代码示例,展示如何转换和优化模型,包括来自TensorFlow Hub, TorchVision, and Hugging Face Hub的模型。

● TorchVision Zoo with OpenVINO™ (https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/125-torchvision-zoo-to-openvino )— 下载和直接优化基于PyTorch的预训练模型

● Hugging Face Model Hub with OpenVINO™ (https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/124-hugging-face-hub )—学习如何下载和优化Hugging Face hub的预训练模型

● TensorFlow Hub models + OpenVINO(https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/126-tensorflow-hub ) — 学习如何下载和优化TensorFlow Hub的预训练模型

● Convert Detectron2 Models to OpenVINO(https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/123-detectron2-to-openvino ) — 优化来自Facebook Research流行的目标检测和分割模型

● Convert TensorFlow Object Detection and Instance Segmentation Models to OpenVINO™(https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/120-tensorflow-object-detection-to-openvino ) — 优化来自于TensorFlow Hub的 使用 Resnet-50 V1的Faster R-CNN

● Visual-language assistant with LLaVA and OpenVINO (https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/257-llava-multimodal-chatbot )— 使用LLaVA (Large Language and Vision Assistant)的端到端多模态演示

● Subject-driven image generation and editing using BLIP Diffusion and OpenVINO (https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/258-blip-diffusion-subject-generation )— 优化用于零样本主题驱动的图像生成的BLIP扩散模型

● SoftVC VITS Singing Voice Conversion and OpenVINO™(https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/262-softvc-voice-conversion#softvc-vits-singing-voice-conversion-and-openvino ) — 优化以音频作为输入的声音转换模型SoftVC 及 VITS

● Object segmentations with FastSAM and OpenVINO™(https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/261-fast-segment-anything ) — 优化用于目标分割的Fast Segment Anything Model (FastSAM) 模型

● Image Generation with DeciDiffusion(https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/259-decidiffusion-image-generation ) — 优化用于文生图的 DeciDiffusion 1.0 模型

● Document Visual Question Answering Using Pix2Struct and OpenVINO (https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/260-pix2struct-docvqa )— 利用OCR和语言模型进行多模态问答的演示



图 1: 文档视觉问答

最后,我们还提供了几个具有开箱即用、优化性能的流行的生成式AI的notebooks代码示例。

● Create an LLM-powered Chatbot using OpenVINO(https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/254-llm-chatbot#create-llm-powered-chatbot-using-openvino ) —在CPU和GPU上运行具有int8权重压缩的Llama2等聊天机器人,令人印象深刻的是,它将在只有24GB RAM的笔记本电脑上运行。

● Image generation with Latent Consistency Model and OpenVINO(https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/263-latent-consistency-models-image-generation ) — 用低得多的计算机资源实现卓越的图像生成

● Generate creative QR codes with ControlNet QR Code Monster and OpenVINO™ (https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/264-qrcode-monster )— 使用ControlNet和Stable Diffusion创建您自己的图形二维码。



图2: 使用 OpenVINO优化基于大语言模型的聊天机器人



图3: ControlNet 二维码Monster以及OpenVINO

新的分发渠道

在这个版本中,我们继续改进您访问和使用OpenVINO进行AI应用程序开发的方式,我们已经开发了一个Conan(https://conan.io)软件包管理器。Conan允许您为大型项目执行包管理,我们很高兴看到已经有开发者对此做出的积极回应。

有关如何使用OpenVINO Conan软件包的更多详细信息,请参阅此处:

Install OpenVINO™ Runtime from Conan Package Manager — OpenVINO™ documentation

OpenVINO是在开源中开发的,一旦在我们的初步测试中验证了这些功能,我们的最新功能就可以在我们的主分支上获得。因此,如果您想尝试新功能,您可以随时从源代码构建我们的包。对于pip用户,我们通过引入openvino-nightly包来简化这一点。你可以使用这个每日构建的包来尝试最新的功能,并在我们的下一个官方版本中预览一下!

开源贡献对我们来说很重要!

OpenVINO已经是一个超过5年的开源项目了。最近,我们准备了一系列贡献任务,通过向OpenVINO贡献,可以更好地帮助社区围绕人工智能生态系统和开源项目构建知识。这包括支持新的编译选项和添加更多需要注意的操作等任务。

查看我们在GitHub上的链接,看看有没有你感兴趣的任务:https://github.com/openvinotoolkit/openvino/issues/17502

如上所述,我们非常感谢迄今为止我们看到的所有被合并进来的开源贡献。我们还要公开感谢我们最近的一些贡献者!他们是Siddhant Chauhan、rsa-10、Santhosh Mamidisetti和Mahimai Raja J.。由于您的帮助,产品变得更好!

其它资源
OpenVINO™ 文档

OpenVINO 2023.2 — OpenVINO™ documentation

OpenVINO™ Notebook***r/>
https://github.com/openvinotoolkit/openvino_notebooks

提供反馈及上报问题

https://github.com/openvinotoolkit/openvino/issues/new/choose

0个评论