23 releases (5 breaking)

0.9.5 Nov 22, 2024
0.9.2 Sep 10, 2024
0.9.0 Jul 22, 2024

#170 in Machine learning

Download history 129/week @ 2024-08-17 16/week @ 2024-08-24 7/week @ 2024-08-31 167/week @ 2024-09-07 21/week @ 2024-09-14 10/week @ 2024-09-21 157/week @ 2024-09-28 18/week @ 2024-10-05 191/week @ 2024-10-12 22/week @ 2024-10-19 2/week @ 2024-10-26 26/week @ 2024-11-02 1/week @ 2024-11-09 100/week @ 2024-11-16 98/week @ 2024-11-23 113/week @ 2024-11-30

320 downloads per month

MIT license

11MB
207K SLoC

CUDA 90K SLoC // 0.2% comments C++ 61K SLoC // 0.2% comments Python 33K SLoC // 0.3% comments C 16K SLoC // 0.2% comments Rust 2.5K SLoC // 0.1% comments Bazel 2.5K SLoC // 0.1% comments Shell 1.5K SLoC // 0.2% comments BASH 466 SLoC // 0.3% comments Jupyter Notebooks 378 SLoC // 0.4% comments Batch 69 SLoC // 0.1% comments Forge Config 40 SLoC

ctranslate2-rs

Latest version docs.rs GitHub License Build

This library provides Rust bindings for OpenNMT/CTranslate2. At this time, it has only been tested and confirmed to work on macOS and Linux. Windows support is available experimentally, but it has not been thoroughly tested and may have limitations or require additional configuration.

Supported Models

The ct2rs crate has been tested and confirmed to work with the following models:

  • BART
  • BLOOM
  • FALCON
  • Marian-MT
  • MPT
  • NLLB
  • GPT-2
  • GPT-J
  • OPT
  • T5
  • Whisper

Please see the respective examples for each model.

Stream API

This crate also offers a streaming API that utilizes callback closures. Please refer to the example code for more information.

Compilation

If you plan to use GPU acceleration, CUDA and cuDNN are available. Please enable the cuda or cudnn feature and set the CUDA_TOOLKIT_ROOT_DIR environment variable appropriately.

Several backends are available for use: OpenBLAS, Intel MKL, Ruy, and Apple Accelerate.

  • OpenBLAS: To use OpenBLAS, enable the openblas feature and add the path to the directory containing libopenblas.a to the LIBRARY_PATH environment variable.
  • Intel MKL: To use Intel MKL, enable the mkl feature and set the path to the Intel libraries in the MKLROOT environment variable (default is /opt/intel).
  • Ruy: To use Ruy, enable the ruy feature.
  • Apple Accelerate: Available only on macOS, enable the accelerate feature to use Apple Accelerate.

The installation of CMake is required to compile the library.

Additional notes for Windows: it is necessary to add RUSTFLAGS=-C target-feature=+crt-static to the environment variables for compilation.

Model Conversion for CTranslate2

To use model files with CTranslate2, they must first be converted. Below is an example of how to convert the nllb-200-distilled-600M model:

pip install ctranslate2 huggingface_hub torch transformers
ct2-transformers-converter --model facebook/nllb-200-distilled-600M --output_dir nllb-200-distilled-600M \
    --copy_files tokenizer.json

For more details, please refer to the CTranslate2's docs.

License

This application is released under the MIT License. For details, see the LICENSE file.

Dependencies

~18–33MB
~484K SLoC