目的
好奇心かなぁ..
参考(ありがとうございます)
OpenVINOとは
環境
OS:ubuntu24
Intel Xeon E5 2676V3
DDR3 64GiB
conda python3.12
Disk 128GiB
仮想環境作成
conda仮想環境作成
condaインストール
sudo apt update && sudo apt upgrade -y
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
source ~/.bashrc
# 仮想環境作成
conda create -n {環境名} python=3.12
# 仮想環境有効
conda activate {環境名}
# 仮想環境から抜ける
conda deactivate {環境名}
仮想環境作成
conda create -n openvino-llm python=3.12
conda activate openvino-llm
mkdir workspace && cd workspace
OpenVINO GenAIインストール
pip install openvino-genai
sudo apt-get update && sudo apt-get install git -y
nano export-requirements.txt
#---
--extra-index-url https://download.pytorch.org/whl/cpu
--extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly
openvino-tokenizers[transformers]~=2026.5.0.0.dev
https://github.com/huggingface/optimum-intel/archive/dd4ed1a86f9c2abf34d8dce777da5b592765b644.tar.gz#egg=optimum-intel
einops==0.8.2 # For Qwen
transformers_stream_generator==0.0.5 # For Qwen
diffusers==0.39.0 # For image generation pipelines
timm==1.0.28 # For exporting InternVL2
# torchvision for visual language models
torchvision==0.26.0
transformers==5.5.4
hf_transfer==0.1.9 # for faster models download, should used with env var HF_HUB_ENABLE_HF_TRANSFER=1
backoff==2.2.1 # for microsoft/Phi-3.5-vision-instruct
peft==0.20.0 # For microsoft/Phi-4-multimodal-instruct
#---
pip install --requirement export-requirements.txt
こんなエラーがでる
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
openvino-genai 2026.4.0.0 requires openvino_tokenizers~=2026.4.0.0.dev, but you have openvino-tokenizers 2026.5.0.0b1 which is incompatible.
バージョンを変える
pip install "openvino-tokenizers~=2026.4.0.0"
確認
python -c "import openvino_genai; print('Success')"
# Successと返ってこればOK
モデルをGenAI用に変換する
試しに使うモデル
# モデルの重みに INT4 などの低い精度を使うのがいいらしい。
# <model_id_or_path> Hugging Face Hubのモデル ID
# optimum-cli export openvino --model <model_id_or_path> --weight-format [int4/int8/fp16] <output_dir>
mkdir dev
optimum-cli export openvino --model Qwen/Qwen2.5-14B-Instruct --weight-format int4 qwen2.5-14b-instruct-int4
bailing_moe 系のモデルは動かなかった。残念
https://huggingface.co/inclusionAI/Ling-mini-2.0
対応してるモデルはここからみれるみたい
https://openvinotoolkit.github.io/openvino.genai/docs/supported-models/
Stable Diffusionも対応してるのがびっくり
スクリプトから実行
#python export.py
from optimum.exporters.openvino import main_export
main_export(
model_name_or_path="Qwen/Qwen2.5-14B-Instruct",
output="qwen2.5-14b-instruct-int4",
weight_format="int4",
task="text-generation-with-past",
)
#---
python export.py
コマンド
optimum-cli export openvino \
--model meta-llama/Llama-3.1-8B-Instruct \
--task text-generation-with-past \
--weight-format int4 \
./models/llama-3.1-8b-int4-ov
iostream errorとなった場合
メモリ不足かディスク不足だった。
メモリは64GiB,Diskも128GiBあると安心