OpenVINO™ 2023.2 发布:让生成式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_weights(model.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")
   

 

新的生成式 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_notebooks/blob/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_notebooks/blob/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 的模型。

TorchaVision 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 软件包的更多详细信息,请参阅此处:

https://docs.openvino.ai/2023.1/openvino_docs_install_guides_installing_openvino_conan.html

(复制链接到浏览器打开)

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

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

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

查看我们在 GitHub 上的链接,看看有没有你感兴趣的任务!

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

 

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分