Convert Models to OpenVINO Format
This page explains how to convert various generative AI models from Hugging Face and ModelScope to OpenVINO IR format. Refer to the Supported Models for a list of available models.
For downloading pre-converted models, see Download Pre-Converted OpenVINO Models.
Converting Models from Hugging Face
-
Install
optimum-intelpackage to download, convert and optimize models:NoteSome models may require additional dependencies. To convert models with
optimum-cliand to run the examples, install the dependencies from./samples/export-requirements.txt:pip install --requirement ./samples/export-requirements.txt -
Download and convert a model to the OpenVINO IR format using
optimum-clitool from Hugging Face:optimum-cli export openvino --model <model_id_or_path> <output_dir>tipFor better performance with minimal accuracy impact, convert the model to lower precision by using
--weight-formatargument:- INT4
- INT8
- FP16
optimum-cli export openvino --model <model_id_or_path> --weight-format int4 <output_dir>optimum-cli export openvino --model <model_id_or_path> --weight-format int8 <output_dir>optimum-cli export openvino --model <model_id_or_path> --weight-format fp16 <output_dir>infoThe
--trust-remote-codeflag is required for some models that use custom code.Check a full list of conversion options here.
Converting Models from ModelScope
ModelScope models need to be downloaded first, then converted to OpenVINO IR format.
- Install
modelscopeandoptimum-intelpackages to download, convert and optimize models:pip install modelscope --requirement ./samples/export-requirements.txt - Download the required model (e.g.
Qwen/Qwen2-7b) to a local directory usingmodelscopetool:modelscope download --model 'Qwen/Qwen2-7b' --local_dir <model_path> - Convert the model (and optionally compress weights) using
optimum-clitool:optimum-cli export openvino --model <model_path> --weight-format int4 <output_dir>
Refer to the Use Cases for detailed instructions on using models with OpenVINO GenAI.