Environment variables
Some environment variables can be configured to customize the execution. When using Python, these variables should be set before importing the ctranslate2 module, e.g.:
import os
os.environ["CT2_VERBOSE"] = "1"
import ctranslate2
Note
Boolean environment variables can be enabled with "1" or "true".
CT2_CUDA_ALLOCATOR
Allocating memory on the GPU with cudaMalloc is costly and is best avoided in high-performance code. For this reason CTranslate2 integrates caching allocators which enable a fast reuse of previously allocated buffers. The following allocators are integrated:
cuda_malloc_async(default for NVIDIA CUDA >= 11.2)
Uses the asynchronous allocator with memory pools introduced in CUDA 11.2.cub_caching(default for CUDA < 11.2 and HIP/ROCm)
Uses the caching allocator from the CUB project.
CT2_CUDA_ALLOW_BF16
Allow using BF16 computation on GPU even if the device does not have efficient BF16 support.
CT2_CUDA_ALLOW_FP16
Allow using FP16 computation on GPU even if the device does not have efficient FP16 support.
CT2_CUDA_TRUE_FP16_GEMM
Allow using true FP16 computation in GEMM operations. When disabled, the computation or accumulation may use FP32 instead.
This flag is enabled by default, but some models may automatically disable it when they are known to work better with the increased precision.
CT2_CUDA_CACHING_ALLOCATOR_CONFIG
The cub_caching allocator can be configured to tradeoff memory usage and speed. By default, CTranslate2 uses the following values which have been selected experimentally:
bin_growth = 4min_bin = 3max_bin = 12max_cached_bytes = 209715200(200MB)
You can override these parameters with comma-separated values in the same order as the list above:
export CT2_CUDA_CACHING_ALLOCATOR_CONFIG=8,3,7,6291455
See the description of each parameter in the allocator implementation.
Attention
Apple Metal (experimental). The CT2_MPS_* variables below configure the experimental Apple Metal (MPS) backend. It is included in Apple Silicon Python wheels and can be enabled in source builds with -DWITH_MPS=ON. It remains an explicit runtime opt-in with device="mps"; device="auto" continues to select CPU. The variables and their defaults may change.
CT2_MPS_MAX_COMPUTE_OPS
Set the maximum number of compute operations encoded before the current MPS
command buffer is committed without waiting. The default is 16.
CT2_MPS_MAX_BLIT_OPS
Set the maximum number of copy/blit operations encoded before the current MPS
command buffer is committed without waiting. The default is 64.
CT2_MPS_MAX_INFLIGHT_COMMAND_BUFFERS
Set the maximum number of unfinished MPS command buffers. The default is 8,
which keeps useful CPU/GPU overlap while bounding Metal temporary resources on
unified-memory systems. Increasing this value can help large-memory devices,
but should be validated with cold, end-to-end inference rather than GEMM-only
benchmarks.
CT2_MPS_PROFILE
Print aggregated MPS execution counters at process exit, including command buffers, dispatches, synchronization points, GEMM paths, TopK calls, copies, allocations, and buffer lookups. Profiling is disabled by default.
This is an unstable debugging interface and its output may change without notice.
CT2_MPS_LOG_GEMM
Log each MPS GEMM shape, transpose and stride configuration, and selected execution path. This option is intended for debugging and benchmarking.
This is an unstable debugging interface and its output may change without notice.
CT2_MPS_LOG_SYNC
Log each MPS synchronization together with its reason and host-visible byte count.
This is an unstable debugging interface and its output may change without notice.
CT2_FORCE_CPU_ISA
Force CTranslate2 to select a specific instruction set architecture (ISA). Possible values are:
GENERICAVXAVX2AVX512
Attention
This does not impact backend libraries (such as Intel MKL) which usually have their own environment variables to configure ISA dispatching.
CT2_DRAMA3_CPU_MMAP
Set to 1 to memory-map Drama3’s byte-encoded expert weights from a local
checkpoint on Linux or macOS with device="cpu". Default: 0.
Requires compute_type="default" or "float32". FP8 projections decode on demand;
standard quantized weights may allocate converted copies.
Mapped pages are reclaimable, but other weights and inference state still use RAM. This does not set a memory limit. Performance depends on disk speed and filesystem cache. Keep the checkpoint unchanged while loaded.
CT2_DRAMA3_GPU_EXPERT_CACHE_GB
Limit Drama3’s GPU expert weights and quantization scales in decimal GB
(e.g. CT2_DRAMA3_GPU_EXPERT_CACHE_GB=8). Unset, empty, or 0 means unlimited;
invalid values raise an error. Requires Linux, a local checkpoint, and
device="cuda" (CUDA or ROCm).
The budget is split equally across backbone layers, each with LRU eviction. Each layer must fit its selected routed experts and shared expert; smaller budgets raise an error. Cache size depends on compute type. Byte-encoded CPU experts are memory-mapped; floating-point CPU weights remain resident.
This limits the expert cache, not total VRAM or RAM. Other weights, inference state, temporary allocations, and allocator overhead require additional memory.
CT2_PACKED_GEMM
Enable or disable the packed GEMM API for Intel MKL. Packed GEMM is enabled by default when using the MKL backend and improves decoding performance by pre-packing weight matrices at model load time. Set to 0 to disable it. See Intel’s article to learn more about packed GEMM.
CT2_USE_MKL
Force CTranslate2 to use (or not) Intel MKL. By default, the runtime automatically decides whether to use Intel MKL or not based on the CPU vendor.
CT2_VERBOSE
Configure the default logs verbosity:
-3 = off
-2 = critical
-1 = error
0 = warning (default)
1 = info
2 = debug
3 = trace
Tip
The log level can also be controlled by API. See for example the Python function ctranslate2.set_log_level.