Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🤗 Optimum Intel: Accelerate inference with Intel optimization tools

License

NotificationsYou must be signed in to change notification settings

huggingface/optimum-intel

Repository files navigation

Optimum Intel

🤗Optimum Intel is the interface between the 🤗 Transformers and Diffusers libraries and the different tools and libraries provided by Intel to accelerate end-to-end pipelines on Intel architectures.

OpenVINO is an open-source toolkit that enables high performance inference capabilities for Intel CPUs, GPUs, and special DL inference accelerators (see the full list of supported devices). It is supplied with a set of tools to optimize your models with compression techniques such as quantization, pruning and knowledge distillation. Optimum Intel provides a simple interface to optimize your Transformers and Diffusers models, convert them to the OpenVINO Intermediate Representation (IR) format and run inference using OpenVINO Runtime.

Installation

To install the latest release of 🤗 Optimum Intel with the corresponding required dependencies, you can usepip as follows:

pip install --upgrade --upgrade-strategy eager"optimum[openvino]"

The--upgrade-strategy eager option is needed to ensureoptimum-intel is upgraded to the latest version.

We recommend creating avirtual environment and upgradingpip withpython -m pip install --upgrade pip.

Optimum Intel is a fast-moving project, and you may want to install from source with the following command:

python -m pip install"optimum-intel[openvino]"@git+https://github.com/huggingface/optimum-intel.git

Quick tour

OpenVINO

Below are examples of how to use OpenVINO and itsNNCF framework to accelerate inference.

Export:

It is also possible to export your model to theOpenVINO IR format with the CLI :

optimum-cli export openvino --model meta-llama/Meta-Llama-3-8B ov_llama/

You can also apply 8-bit weight-only quantization when exporting your model : the model linear, embedding and convolution weights will be quantized to INT8, the activations will be kept in floating point precision.

optimum-cli export openvino --model meta-llama/Meta-Llama-3-8B --weight-format int8 ov_llama_int8/

Quantization in hybrid mode can be applied to Stable Diffusion pipeline during model export. This involves applying hybrid post-training quantization to the UNet model and weight-only quantization for the rest of the pipeline components. In the hybrid mode, weights in MatMul and Embedding layers are quantized, as well as activations of other layers.

optimum-cli export openvino --model stabilityai/stable-diffusion-2-1 --dataset conceptual_captions --weight-format int8 ov_model_sd/

To apply quantization on both weights and activations, you can find more information in thedocumentation.

Inference:

To load a model and run inference with OpenVINO Runtime, you can just replace yourAutoModelForXxx class with the correspondingOVModelForXxx class.

- from transformers import AutoModelForSeq2SeqLM+ from optimum.intel import OVModelForSeq2SeqLM  from transformers import AutoTokenizer, pipeline  model_id = "echarlaix/t5-small-openvino"- model = AutoModelForSeq2SeqLM.from_pretrained(model_id)+ model = OVModelForSeq2SeqLM.from_pretrained(model_id)  tokenizer = AutoTokenizer.from_pretrained(model_id)  pipe = pipeline("translation_en_to_fr", model=model, tokenizer=tokenizer)  results = pipe("He never went out without a book under his arm, and he often came back with two.")  [{'translation_text': "Il n'est jamais sorti sans un livre sous son bras, et il est souvent revenu avec deux."}]

Quantization:

Post-training static quantization can also be applied. Here is an example on how to apply static quantization on a Whisper model using theLibriSpeech dataset for the calibration step.

fromoptimum.intelimportOVModelForSpeechSeq2Seq,OVQuantizationConfigmodel_id="openai/whisper-tiny"q_config=OVQuantizationConfig(dtype="int8",dataset="librispeech",num_samples=50)q_model=OVModelForSpeechSeq2Seq.from_pretrained(model_id,quantization_config=q_config)# The directory where the quantized model will be savedsave_dir="nncf_results"q_model.save_pretrained(save_dir)

You can find more information in thedocumentation.

Running the examples

Check out thenotebooks directory to see how 🤗 Optimum Intel can be used to optimize models and accelerate inference.

Do not forget to install requirements for every example:

cd <example-folder>pip install -r requirements.txt

Gaudi

To train your model onIntel Gaudi AI Accelerators (HPU), check outOptimum Habana which provides a set of tools enabling easy model loading, training and inference on single- and multi-HPU settings for different downstream tasks. After training your model, feel free to submit it to the Intelleaderboard which is designed to evaluate, score, and rank open-source LLMs that have been pre-trained or fine-tuned on Intel Hardwares. Models submitted to the leaderboard will be evaluated on the Intel Developer Cloud. The evaluation platform consists of Gaudi Accelerators and Xeon CPUs running benchmarks from the Eleuther AI Language Model Evaluation Harness.


[8]ページ先頭

©2009-2025 Movatter.jp