openvinotoolkit/openvino.genai

GitHub: openvinotoolkit/openvino.genai

OpenVINO GenAI 是一个基于 OpenVINO Runtime 的轻量级生成式 AI 推理库,提供简洁的 C++/Python API,支持在本地高效运行文本、图像、语音等多种生成模型。

Stars: 450 | Forks: 351

![OpenVINO GenAI](/site/static/img/openvino-genai-logo-gradient.svg) [快速入门](#getting-started) • [AI 场景](#ai-scenarios) • [优化方法](#optimization-methods) • [文档](https://openvinotoolkit.github.io/openvino.genai/) [![GitHub Release](https://img.shields.io/github/v/release/openvinotoolkit/openvino.genai?color=green)](https://github.com/openvinotoolkit/openvino.genai/releases) [![PyPI Downloads](https://static.pepy.tech/badge/openvino.genai)](https://pypi.org/project/openvino.genai/) ![Python](https://img.shields.io/badge/python-3.10+-green) ![OS](https://img.shields.io/badge/OS-Linux_|_Windows_|_MacOS-blue) ![](/site/static/img/openvino-genai-workflow.svg)
OpenVINO™ GenAI 是一个包含最流行的生成式 AI 模型流水线、优化执行方法和示例的库,运行在高性能的 [OpenVINO Runtime](https://github.com/openvinotoolkit/openvino) 之上。 该库对 PC 和笔记本电脑执行非常友好,并针对资源消耗进行了优化。它运行生成模型不需要外部依赖,因为它已经包含了所有核心功能(例如通过 [`openvino-tokenizers`](https://github.com/openvinotoolkit/openvino_tokenizers) 进行 tokenization)。 ![在 Intel ARC770 dGPU 上运行 LLaMa 3.2 模型进行文本生成](https://raw.githubusercontent.com/openvinotoolkit/openvino.genai/master/samples/generation.gif) ## 快速入门 * [OpenVINO™ GenAI 简介](https://openvinotoolkit.github.io/openvino.genai/docs/getting-started/introduction) * [安装 OpenVINO™ GenAI](https://openvinotoolkit.github.io/openvino.genai/docs/getting-started/installation) * [构建 OpenVINO™ GenAI](/src/docs/BUILD.md) * [支持的模型](https://openvinotoolkit.github.io/openvino.genai/docs/supported-models/) * [模型准备指南](https://openvinotoolkit.github.io/openvino.genai/docs/category/model-preparation) 浏览博客,利用 OpenVINO GenAI 开启您的首次实践体验: * [如何使用 C++ 构建 OpenVINO™ GenAI 应用](https://medium.com/openvino-toolkit/how-to-build-openvino-genai-app-in-c-32dcbe42fa67) * [如何使用 OpenVINO™ 本地运行 Llama 3.2](https://medium.com/openvino-toolkit/how-to-run-llama-3-2-locally-with-openvino-60a0f3674549) ## 快速开始 1. 从 PyPI 安装 OpenVINO GenAI: pip install openvino-genai 2. 获取模型,例如从 Hugging Face 将模型导出为 OpenVINO IR 格式(有关更多详细信息,请参阅 [模型准备指南](https://openvinotoolkit.github.io/openvino.genai/docs/category/model-preparation)): optimum-cli export openvino --model TinyLlama/TinyLlama-1.1B-Chat-v1.0 --weight-format int4 --trust-remote-code TinyLlama_1_1b_v1_ov 3. 运行推理: import openvino_genai as ov_genai pipe = ov_genai.LLMPipeline("TinyLlama_1_1b_v1_ov", "CPU") # 使用 CPU 或 GPU 作为设备,无需更改任何其他代码 print(pipe.generate("What is OpenVINO?", max_new_tokens=100)) ## 支持的生成式 AI 场景 OpenVINO™ GenAI 库提供非常轻量级的 C++ 和 Python API 来运行以下生成式 AI 场景: - [使用大语言模型 (LLM) 进行文本生成](https://openvinotoolkit.github.io/openvino.genai/docs/use-cases/text-generation/) - 与本地 Llama、Phi、Qwen 和其他模型聊天 - [使用视觉语言模型 (VLM) 进行图像处理](https://openvinotoolkit.github.io/openvino.genai/docs/use-cases/image-processing/) - 使用 LLaVa、MiniCPM-V 和其他模型分析图像/视频 - [使用 Diffusers 进行图像生成](https://openvinotoolkit.github.io/openvino.genai/docs/use-cases/image-generation/) - 使用 Stable Diffusion 和 Flux 模型生成图像 - [使用 Whisper 进行语音识别](https://openvinotoolkit.github.io/openvino.genai/docs/use-cases/speech-recognition/) - 使用 Whisper 模型将语音转换为文本 - [使用 SpeechT5 进行语音生成](https://openvinotoolkit.github.io/openvino.genai/docs/use-cases/speech-generation/) - 使用 SpeechT5 TTS 模型将文本转换为语音 - [使用 Text Embedding 进行语义搜索](https://openvinotoolkit.github.io/openvino.genai/docs/use-cases/text-embedding) - 计算文档和查询的 embedding,以便在 RAG 工作流中实现高效检索 - [用于检索增强生成 (RAG) 的文本重排序](https://openvinotoolkit.github.io/openvino.genai/docs/use-cases/text-rerank) - 分析 RAG 工作流的文档和查询的相关性和准确性 库有效地支持文本和图像生成场景的 LoRA 适配器: - 为每个模型加载多个适配器 - 为每次生成选择活动适配器 - 通过 alpha 混合混合多个适配器 所有场景都运行在支持 CPU、GPU 和 NPU 推理的 OpenVINO Runtime 之上。有关平台支持矩阵,请参见[此处](https://docs.openvino.ai/2025/about-openvino/release-notes-openvino/system-requirements.html)。 ## 支持的生成式 AI 优化方法 OpenVINO™ GenAI 库提供了一种透明的方式来使用最先进的生成优化: - 推测解码,它采用两个不同大小的模型,并使用大模型周期性地校正小模型的结果。更多详细概述请参见[此处](https://pytorch.org/blog/hitchhikers-guide-speculative-decoding/) - KVCache token 驱逐算法,通过修剪影响较小的 token 来减少 KVCache 的大小。 - 稀疏注意力,通过仅关注注意力矩阵中最重要的区域来加速 prefill。OpenVINO GenAI 目前支持两种模式:Tri-shape 和 XAttention。更多详细信息请参见[此处](https://openvinotoolkit.github.io/openvino.genai/docs/concepts/optimization-techniques/sparse-attention-prefill)。 此外,OpenVINO™ GenAI 库实现了一种连续批处理方法,以便在 LLM 服务中使用 OpenVINO。连续批处理库可用于 LLM 服务框架,并支持以下功能: - 前缀缓存,在内部缓存先前生成请求的片段及相应的 KVCache 条目,并在重复查询时使用它们。 连续批处理功能在 OpenVINO Model Server (OVMS) 中用于服务 LLM,更多详细信息请参见[此处](https://docs.openvino.ai/2025/openvino-workflow/model-server/ovms_what_is_openvino_model_server.html)。 ## 更多资源 - [OpenVINO 生成式 AI 工作流](https://docs.openvino.ai/2025/openvino-workflow-generative.html) - [Optimum Intel 和 OpenVINO](https://huggingface.co/docs/optimum/intel/openvino/export) - [包含 GenAI 的 OpenVINO Notebooks](https://openvinotoolkit.github.io/openvino_notebooks/?libraries=OpenVINO+GenAI) ## 许可证 OpenVINO™ GenAI 仓库根据 [Apache License Version 2.0](LICENSE) 授权。 通过为项目做出贡献,您同意其中的许可和版权条款,并根据这些条款发布您的贡献。
标签:AIGC, API, C++, DLL 劫持, GenAI, LLM, OpenVINO, Python, Unmanaged PE, 人工智能, 大语言模型, 开发库, 开源搜索引擎, 推理加速, 数据擦除, 文本生成, 无依赖, 无后门, 本地运行, 模型优化, 模型部署, 深度学习, 生成式AI, 用户模式Hook绕过, 神经网络, 索引, 英特尔, 边缘计算, 逆向工具, 高性能计算