CTranslate2

OpenNMTMIT活跃维护

面向 Transformer 模型的高性能推理引擎,用 C++ 实现并支持 CUDA、AVX、NEON 等硬件加速,让机器翻译等模型在 CPU/GPU 上跑得更快、显存占用更低。

Fast inference engine for Transformer models

v4.8.5发布于 2026-11-02 18:46 UTC4,746star +10 / 7 天556fork同步于 2026-11-10 11:37 UTC

怎么上手

由 README 提炼,执行前请确认
pip install ctranslate2
硬件要求按 README 说明

CPU 支持 x86-64 与 AArch64/ARM64,集成 Intel MKL、oneDNN、OpenBLAS、Ruy、Apple Accelerate;GPU 侧 README 基准使用 NVIDIA A10G(CUDA 11),AMD ROCm 需从 releases 页下载专用 wheel;README 未给出具体显存门槛。

需要 CUDA支持 ROCm / AMD多卡 / 张量并行
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

面向 Transformer 的 C++/Python 推理引擎,用量化和算子优化在 CPU/GPU 上加速并省内存

面向 Transformer 模型的高性能推理引擎,用 C++ 实现并支持 CUDA、AVX、NEON 等硬件加速,让机器翻译等模型在 CPU/GPU 上跑得更快、显存占用更低。

核心能力

  • 自研运行时做层融合、去 padding、批重排与缓存
  • 支持 FP16/BF16/INT16/INT8 及 AWQ INT4 量化
  • 内置 OpenNMT、Fairseq、Marian、Transformers 等模型转换器
  • 单二进制含多后端与指令集,运行时按 CPU 自动派发
  • 支持多 GPU 张量并行与异步并行批处理

容易踩的坑

模型需先用库内转换器转成优化格式才能加载;AMD ROCm 用户要单独从 releases 页取 wheel,pip 默认包不适用;README 未说明默认端口等运行时配置。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v4.8.5
  1. v4.8.5最新正式版2026-11-02 · 2026-11-02 18:46 UTC

    New features

    • Cache Drama 3 prompt prefixes with LRU eviction, cache controls, and hit/miss diagnostics (#2133, #2144) by @jordimas
    • Add native CPU reference-audio encoding for Drama 3 voice cloning (#2141) by @jordimas

    Fixes and improvements

    • Preserve FP32 attention scores through softmax to fix CUDA alignment precision with FP16 and BF16 models (#2143) by @jordimas
    • Improve Drama 3 prefill performance by increasing the default chunk size from 16 to 128, and fuse gated-delta projections during GPU decoding (#2133) by @jordimas
    • Fix caching allocator shutdown crashes when the allocating thread exits (#2136) by @jordimas
    • Fix FP16 overflow in CUDA attention score accumulation (#2131) by @jordimas
    • Fix the eole converter scale for relative position keys (#2138) by @maksimcialehin
    • Add a Windows ROCm/HIP build guide and document AMD GPU support (#2041) by T0nd3 and @jordimas
    • Add CUDA build instructions for NVIDIA Jetson devices (#2019) by @vimalk78
  2. v4.8.42026-10-25 · 2026-10-25 19:04 UTC
    查看更新说明

    New features

    • Build Python 3.15 wheels (#2129) by @shaanmajid

    • Add an experimental implementation of Drama 3 offline text-to-speech, including model conversion and waveform decoding on CPU with optional CUDA and ROCm acceleration by @jordimas

    • Add CPU and GPU implementations of CausalDepthwiseConv1D, ConvTranspose1D, DequantizeFP8, GatedDeltaNet, MoeTopK, and Snake operations for audio models (#2121) by @jordimas

    See: https://opennmt.net/CTranslate2/guides/drama3.html

    Fixes and improvements

    • Guard integer overflow in tensor size computation, reshape, and growth (#2097) by @Kyozzz and @jordimas
    • Fix CPU Conv1D dilation and INT8 quantization scale overflow for tiny weight rows (#2117) by @jordimas
    • Use the caching allocator by default on HIP (#2118) by @jordimas
    • Fix Wav2Vec2 lookups of packed linear weights (#2119) by @arcusbuilds
    • Fix Wav2Vec2-BERT float16 inference (#2126) by @jordimas
    • Rebuild rotary caches when the device or data type changes by @jordimas
    • Restore the Transformer include in the public attention header by @jordimas
    • Improve CI reliability with updated GitHub Actions and retries for ROCm package index updates and macOS OneAPI downloads (#2125) by @jordimas
  3. v4.8.32026-10-13 · 2026-10-13 05:57 UTC
    查看更新说明

    New features

    • Support converting UMT5 models from Hugging Face Transformers (#2103) by @the-cross-art

    Fixes and improvements

    • Support Transformer models where each layer has its own relative attention bias by @the-cross-art
    • Fix Windows ROCm Translator hangs and DLL loading (#2106) by @0xDELUXA
    • Fix crashes when loading model files from Python file-like objects (#2110) by @Purfview
    • Upgrade pybind11 to 2.13.6 for CPython 3.14 allocator safety (#2108) by @cepeter
    • Guard exhausted candidates in CUDA TopK stage 2 (#2104) by @mzggr0914
    • Fix Windows shutdown deadlocks and memory leaks with the Ruy backend (#2076) by @timo9378
    • Add Clang ThreadSanitizer testing (#1986) by @3manifold
    • Improve ROCm wheel testing and release checks; upgrade build actions to Node.js 24 (#2112) by @jordimas
    • Add local CUDA and ROCm release validation with CI wheels and commit status reporting by @jordimas
  4. v4.8.22026-08-31 · 2026-08-31 19:11 UTC
    查看更新说明

    Fixes and improvements

    • Import Python converters and specs lazily to avoid loading torch for inference-only use (#2080) by @Anai-Guo
    • Fix out-of-bounds reads in StorageView index validation (#2073) by @jordimas, reported by Nathan Keys (Halo Forge Labs)
    • Update cxxopts to v3.3.1 for GCC 15 compatibility (#2084) by @bekard
    • Validate model variable sizes before allocation (#2091) by @jordimas, reported by Hyeonbell
    • Check StorageView reserve byte size before allocation (#2094) by @infinityscroll
    • Remove the runtime dependency on setuptools (#2096) by @Ravencentric
  5. v4.8.12026-07-03 · 2026-07-03 12:39 UTC
    查看更新说明

    New features

    • Support for Gemma4 12B dense model (#2060) by @jordimas

    Fixes and improvements

    • Harden legacy converter checkpoint loading (#2036) by @igorsantosgrueiro
    • Fix model load heap overflow (#2068) by @jordimas, reported by Chegne Eu Joe (Project Umbra)
    • Fix process-killing integer division by zero when Whisper align() gets a window with no frames (#2065) by @MAkcanca
    • CI/CD compilation fixes for Windows (#2069) by @jordimas
    • Optimize attention softmax buffer reuse (#2066) by @jordimas

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    CI PyPI version Documentation Gitter Forum

    CTranslate2

    CTranslate2 is a C++ and Python library for efficient inference with Transformer models.

    The project implements a custom runtime that applies many performance optimization techniques such as weights quantization, layers fusion, batch reordering, etc., to accelerate and reduce the memory usage of Transformer models on CPU and GPU.

    The following model types are currently supported:

    • Encoder-decoder models: Transformer base/big, M2M-100, NLLB, BART, mBART, Pegasus, T5, UMT5, Whisper, T5Gemma, T5Gemma2, MADLAD-400
    • Decoder-only models: GPT-2, GPT-J, GPT-NeoX, OPT, BLOOM, MPT, Llama, Mistral, Gemma, CodeGen, GPTBigCode, Falcon, Qwen2
    • Encoder-only models: BERT, DistilBERT, XLM-RoBERTa
    • Text-to-speech (TTS) models: Drama 3 (experimental)

    Compatible models should be first converted into an optimized model format. The library includes converters for multiple frameworks:

    The project is production-oriented and comes with backward compatibility guarantees, but it also includes experimental features related to model compression and inference acceleration.

    Key features

    • Fast and efficient execution on CPU and GPUThe execution is significantly faster and requires less resources than general-purpose deep learning frameworks on supported models and tasks thanks to many advanced optimizations: layer fusion, padding removal, batch reordering, in-place operations, caching mechanism, etc.
    • Quantization and reduced precisionThe model serialization and computation support weights with reduced precision: 16-bit floating points (FP16), 16-bit brain floating points (BF16), 16-bit integers (INT16), 8-bit integers (INT8) and AWQ quantization (INT4).
    • Multiple CPU architectures supportThe project supports x86-64 and AArch64/ARM64 processors and integrates multiple backends that are optimized for these platforms: Intel MKL, oneDNN, OpenBLAS, Ruy, and Apple Accelerate.
    • Automatic CPU detection and code dispatchOne binary can include multiple backends (e.g. Intel MKL and oneDNN) and instruction set architectures (e.g. AVX, AVX2) that are automatically selected at runtime based on the CPU information.
    • Parallel and asynchronous executionMultiple batches can be processed in parallel and asynchronously using multiple GPUs or CPU cores.
    • Dynamic memory usageThe memory usage changes dynamically depending on the request size while still meeting performance requirements thanks to caching allocators on both CPU and GPU.
    • Lightweight on diskQuantization can make the models 4 times smaller on disk with minimal accuracy loss.
    • Simple integrationThe project has few dependencies and exposes simple APIs in Python and C++ to cover most integration needs.
    • Configurable and interactive decodingAdvanced decoding features allow autocompleting a partial sequence and returning alternatives at a specific location in the sequence.
    • Support tensor parallelism for distributed inferenceVery large model can be split into multiple GPUs. Following this documentation to set up the required environment.

    Some of these features are difficult to achieve with standard deep learning frameworks and are the motivation for this project.

    Installation and usage

    CTranslate2 can be installed with pip:

    pip install ctranslate2
    

    The Python module is used to convert models and can translate or generate text with few lines of code:

    translator = ctranslate2.Translator(translation_model_path)
    translator.translate_batch(tokens)
    
    generator = ctranslate2.Generator(generation_model_path)
    generator.generate_batch(start_tokens)
    

    See the documentation for more information and examples.

    If you have an AMD ROCm GPU, we provide specific Python wheels on the releases page.

    Recommended libraries

    • ctranslate2-web-server: a web server exposing an OpenAI-compatible REST API for CTranslate2 models.
    • faster-whisper: fast speech-to-text transcription with Whisper and CTranslate2.
    • faster-tts: text-to-speech with CTranslate2 and experimental Drama 3 support.

    Benchmarks

    We translate the En->De test set newstest2014 with multiple models:

    • OpenNMT-tf WMT14: a base Transformer trained with OpenNMT-tf on the WMT14 dataset (4.5M lines)
    • OpenNMT-py WMT14: a base Transformer trained with OpenNMT-py on the WMT14 dataset (4.5M lines)
    • OPUS-MT: a base Transformer trained with Marian on all OPUS data available on 2020-02-26 (81.9M lines)

    The benchmark reports the number of target tokens generated per second (higher is better). The results are aggregated over multiple runs. See the benchmark scripts for more details and reproduce these numbers.

    Please note that the results presented below are only valid for the configuration used during this benchmark: absolute and relative performance may change with different settings.

    CPU
    Tokens per secondMax. memoryBLEU
    OpenNMT-tf WMT14 model
    OpenNMT-tf 2.31.0 (with TensorFlow 2.11.0)209.22653MB26.93
    OpenNMT-py WMT14 model
    OpenNMT-py 3.0.4 (with PyTorch 1.13.1)275.82012MB26.77
    - int8323.31359MB26.72
    CTranslate2 3.6.0658.8849MB26.77
    - int16733.0672MB26.82
    - int8860.2529MB26.78
    - int8 + vmap1126.2598MB26.64
    OPUS-MT model
    Transformers 4.26.1 (with PyTorch 1.13.1)147.32332MB27.90
    Marian 1.11.0344.57605MB27.93
    - int16330.25901MB27.65
    - int8355.84763MB27.27
    CTranslate2 3.6.0525.0721MB27.92
    - int16596.1660MB27.53
    - int8696.1516MB27.65

    Executed with 4 threads on a c5.2xlarge Amazon EC2 instance equipped with an Intel(R) Xeon(R) Platinum 8275CL CPU.

    GPU
    Tokens per secondMax. GPU memoryMax. CPU memoryBLEU
    OpenNMT-tf WMT14 model
    OpenNMT-tf 2.31.0 (with TensorFlow 2.11.0)1483.53031MB3122MB26.94
    OpenNMT-py WMT14 model
    OpenNMT-py 3.0.4 (with PyTorch 1.13.1)1795.22973MB3099MB26.77
    FasterTransformer 5.36979.02402MB1131MB26.77
    - float168592.51360MB1135MB26.80
    CTranslate2 3.6.06634.71261MB953MB26.77
    - int88567.21005MB807MB26.85
    - float1610990.7941MB807MB26.77
    - int8 + float168725.4813MB800MB26.83
    OPUS-MT model
    Transformers 4.26.1 (with PyTorch 1.13.1)1022.94097MB2109MB27.90
    Marian 1.11.03241.03381MB2156MB27.92
    - float163962.43239MB1976MB27.94
    CTranslate2 3.6.05876.41197MB754MB27.92
    - int87521.91005MB792MB27.79
    - float169296.7909MB814MB27.90
    - int8 + float168362.7813MB766MB27.90

    Executed with CUDA 11 on a g5.xlarge Amazon EC2 instance equipped with a NVIDIA A10G GPU (driver version: 510.47.03).

    Contributing

    CTranslate2 is a community-driven project. We welcome contributions of all kinds:

    • New Model Support: Help us implement more Transformer architectures.
    • Performance: Propose optimizations for CPU or GPU kernels.
    • Bug Reports: Open an issue if you find something not working as expected.
    • Documentation: Improve our guides or add new examples.

    Check out our Contributing Guide to learn how to set up your development environment.

    Additional resources