This repository contains examples and tools for running OpenVINO-optimized large language models (LLMs) and vision-language models (VLMs) locally. It includes basic inference scripts, chat interfaces, model compression guides, and an OpenAI-compatible API server.
- Basic Inference: Simple text generation with Mistral-7B
- Interactive Chat: Command-line chat interface for text models
- Vision-Language Server: OpenAI-compatible API server for Qwen2.5-VL-3B-Instruct
- Model Compression: Instructions for optimizing models with INT4 quantization
- Multi-Device Support: CPU, GPU, and NPU execution
- Location:
mistral-7b-ov/ - Optimized for text generation tasks
- Used in
basic_inference.pyandchat.py
- Location:
Qwen2.5-VL-3B-Instruct-ov/ - Supports both text and image inputs
- Powers the OpenAI-compatible server in
openvino_server/
- Python 3.8+
- OpenVINO Runtime
- For GPU/NPU: Appropriate drivers installed
-
Clone the repository
git clone https://github.com/Thisen-Ekanayake/openvino-server.git cd openvino_test -
Create virtual environment
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies
pip install openvino-genai
For the server component:
cd openvino_server pip install -r requirements.txt
Run simple text generation with Mistral-7B:
python basic_inference.pyStart a chat session with Mistral-7B:
python chat.pyType your messages and get responses. Type "exit" or "quit" to end.
For detailed setup and usage of the OpenAI-compatible server, see openvino_server/README.md.
Quick start:
cd openvino_server
python server.py --model-dir ../Qwen2.5-VL-3B-Instruct-ov --device CPU --port 8000The server provides:
/v1/chat/completionsendpoint/v1/modelsendpoint- OpenAI-compatible request/response format
- Support for text and image inputs
See how_to_compress.txt for commands to compress models using Optimum and NNCF.
Example for Mistral-7B:
pip install "optimum[openvino]" nncf
optimum-cli export openvino \
--model mistralai/Mistral-7B-v0.1 \
--task text-generation-with-past \
--weight-format int4 \
./mistral-7b-ovApproximate token generation speeds (may vary by hardware):
| Device | Speed | Notes |
|---|---|---|
| CPU | ~5-10 tok/s | Works on any machine |
| GPU | ~15-25 tok/s | Intel Arc/Iris Xe required |
| NPU | ~20-30 tok/s | Intel Core Ultra only |
First run may be slower due to model compilation and caching.
.
├── basic_inference.py # Simple text generation demo
├── chat.py # Interactive chat interface
├── how_to_compress.txt # Model compression instructions
├── mistral-7b-ov/ # Mistral-7B OpenVINO model files
├── Qwen2.5-VL-3B-Instruct-ov/ # Qwen2.5-VL OpenVINO model files
└── openvino_server/ # OpenAI-compatible API server
├── model.py # Model wrapper class
├── server.py # FastAPI server
├── requirements.txt # Server dependencies
└── README.md # Detailed server documentation
- Import errors: Ensure
openvino-genaiis installed (pip install openvino-genai>=2025.3.0) - Slow first run: Normal - OpenVINO compiles and caches optimized kernels
- Device not found: Check that required drivers are installed for GPU/NPU
- Memory issues: Try CPU mode or reduce
max_new_tokensparameter - Model loading fails: Verify model directory path and ensure all model files are present
Feel free to submit issues, feature requests, or pull requests to improve this collection of OpenVINO examples.