OpenVINO Tokenizers

2026.1.0.0 · active · verified Thu Apr 16

OpenVINO Tokenizers provides utilities to convert pre-trained tokenizers, primarily from the Hugging Face `transformers` library, into OpenVINO models. These converted tokenizers can then be compiled and run efficiently on various hardware using the OpenVINO runtime, preparing text inputs for OpenVINO-optimized Large Language Models (LLMs). The current version is 2026.1.0.0, and releases typically align with major OpenVINO toolkit releases, often on a quarterly or yearly cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load a standard Hugging Face tokenizer and convert it into an OpenVINO model. The resulting `ov.Model` object can then be compiled and run by the OpenVINO runtime. Note that `transformers` is a common prerequisite for obtaining the initial tokenizer object.

from transformers import AutoTokenizer
from openvino_tokenizers import convert_tokenizer
import openvino as ov

# 1. Load a Hugging Face tokenizer (requires `pip install transformers`)
hf_tokenizer = AutoTokenizer.from_pretrained("gpt2")

# 2. Convert the Hugging Face tokenizer to an OpenVINO model
# The output is an ov.Model object
ov_tokenizer_model = convert_tokenizer(hf_tokenizer, tokenizer_name="gpt2_ov_tokenizer")

# 3. Print information about the converted OpenVINO model
print(f"OpenVINO Tokenizer Model Name: {ov_tokenizer_model.get_friendly_name()}")
print(f"Number of inputs: {len(ov_tokenizer_model.inputs)}")
print(f"Number of outputs: {len(ov_tokenizer_model.outputs)}")

# The `ov_tokenizer_model` can now be compiled and used with `openvino.Core()`

view raw JSON →