CTranslate2 is a C++ and Python library for efficient inference with Transformer models.
The tool addresses the challenge of running Transformer models quickly and with low memory overhead in production environments. It implements a custom inference runtime that applies performance optimization techniques including weights quantization, layer fusion, and batch reordering to accelerate execution on both CPU and GPU hardware. Models must first be converted into CTranslate2's optimized format using provided converters that support frameworks such as OpenNMT-py, OpenNMT-tf, Fairseq, Marian, OPUS-MT, and Transformers. The library supports a wide range of model architectures spanning encoder-decoder models like Transformer, NLLB, BART, T5, and Whisper; decoder-only models including GPT-2, Llama, Mistral, and Gemma; and encoder-only models such as BERT and XLM-RoBERTa.
Adoption suits teams deploying Transformer models where inference speed and memory efficiency are critical constraints. The tool is production-oriented with backward compatibility guarantees, making it appropriate for stable deployments. It also includes experimental features for model compression and inference acceleration for those willing to explore newer optimization techniques. The conversion requirement means models must be explicitly prepared for CTranslate2 rather than run directly from their original framework format.
The project maintains active development with regular updates to support new model architectures and optimization techniques. Work spans multiple hardware acceleration paths including CUDA for GPUs, AVX and AVX2 for CPU SIMD operations, and NEON for ARM processors, alongside integration with libraries like OneDNN and MKL for optimized linear algebra. The codebase shows sustained attention to both breadth of model support and depth of performance tuning across diverse hardware targets.