A C++ and Python library that runs converted Transformer models with a custom runtime tuned for CPU and GPU inference.
Overview
CTranslate2 is a library for efficient inference with Transformer models. It implements a dedicated runtime that applies optimizations such as weight quantization, layer fusion, batch reordering, and related techniques to speed execution and cut memory use on CPU and GPU.
Supported model families include encoder-decoder architectures (including machine translation and speech recognition types), decoder-only language models, encoder-only models, and an experimental text-to-speech type. Models from several training stacks can be converted into an optimized on-disk format before inference.
The library exposes Python and C++ APIs for integration with few dependencies. Capabilities include reduced-precision weights, parallel and asynchronous batching across CPU cores or GPUs, dynamic memory use, configurable decoding, and tensor parallelism across multiple GPUs for very large models.
Installation is via pip for the Python module, which supports model conversion as well as translation and text generation. Documentation covers tasks such as translation, generation, encoding, speech recognition and synthesis, conversion from common frameworks, and hardware backends including ROCm and experimental Apple Metal on Apple Silicon.
Key features
- Custom Transformer inference runtime
- FP16, BF16, INT8, and INT4 quantization
- CPU and GPU execution with backend auto-selection
- Parallel multi-batch and multi-GPU execution
- Converters for OpenNMT, Fairseq, Marian, Transformers
- Python and C++ APIs
- Interactive and configurable decoding
- Tensor parallelism for large models
Use cases
- Machine translation inference
- Text generation with language models
- Speech recognition and synthesis pipelines
- Lower-memory production Transformer deployment