Skip to main content

Optimum Library is an extension of the Hugging Face Transformers library, providing a framework to integrate third-party libraries from Hardware Partners and interface with their specific functionality.

Project description

Optimum Intel

🤗 Optimum Intel is the interface between the 🤗 Transformers, Diffusers, Sentence Transformers and timm libraries and the different tools and libraries provided by OpenVINO 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 model, convert it 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 use pip as follows:

python -m pip install -U "optimum-intel[openvino]"

Optimum Intel is a fast-moving project with regular additions of new model support, so you may want to install from source with the following command:

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

Deprecation Notice: The extras for openvino (e.g., pip install optimum-intel[openvino,nncf]), nncf, neural-compressor, ipex are deprecated and will be removed in a future release.

Export:

To export your model to OpenVINO IR format, use the optimum-cli tool. Below is an example of exporting TinyLlama/TinyLlama_v1.1 model:

optimum-cli export openvino --model TinyLlama/TinyLlama_v1.1 ov_TinyLlama_v1_1

To export a model hosted on the Hub you can use our space. After conversion, a repository will be pushed under your namespace, this repository can be either public or private.

Additional information on exporting models is available in the documentation.

Inference:

To load an exported model and run inference using Optimum Intel, use the corresponding OVModelForXxx class instead of AutoModelForXxx:

from optimum.intel import OVModelForCausalLM
from transformers import AutoTokenizer, pipeline

model_id = "ov_TinyLlama_v1_1"
model = OVModelForCausalLM.from_pretrained(model_id)
tokenizer = AutoTokenizer.from_pretrained(model_id)
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
results = pipe("Hey, how are you doing today?", max_new_tokens=100)

For more details on Optimum Intel inference, refer to the documentation.

Note: Alternatively, an exported model can also be inferred using OpenVINO GenAI framework, that provides optimized execution methods for highly performant Generative AI.

Quantization:

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

from optimum.intel import OVModelForSpeechSeq2Seq, OVQuantizationConfig

model_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 saved
save_dir = "nncf_results"
q_model.save_pretrained(save_dir)

You can find more information in the documentation.

Running the examples

Check out the notebooks 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

optimum_intel-2.0.0.tar.gz (360.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

optimum_intel-2.0.0-py3-none-any.whl (389.9 kB view details)

Uploaded Python 3

File details

Details for the file optimum_intel-2.0.0.tar.gz.

File metadata

  • Download URL: optimum_intel-2.0.0.tar.gz
  • Upload date:
  • Size: 360.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for optimum_intel-2.0.0.tar.gz
Algorithm Hash digest
SHA256 4903fc279579973660216c710a57549a9377d2d95fd4f3620176b6a48e6f6337
MD5 250cd51736afd5dcef0e590caa9f5d43
BLAKE2b-256 ff6e2a72f599b09914b4e4248fd82964f1ad6c4d402d796530e2ff9a0ef79ee9

See more details on using hashes here.

File details

Details for the file optimum_intel-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: optimum_intel-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 389.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for optimum_intel-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc88ce20531a4b868430dc81428cbbf2256bef61d32c7bfa60436263ad7e43b2
MD5 b9510a3734276c8e8d5219649665b2df
BLAKE2b-256 c3c25dd4d694f536cd181c6df25e054aaa5f00e6691bd1d816d05be909c4c105

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page