Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ jobs:
include:
- os: ubuntu-22.04-arm
arch: aarch64
- os: windows-11-arm
arch: ARM64
build: "cp31[2-4]-*"
- os: macos-15
arch: arm64
- os: macos-15-intel
Expand All @@ -200,7 +203,7 @@ jobs:
submodules: recursive

- name: Cache MKL and oneDNN (Windows)
if: runner.os == 'Windows'
if: runner.os == 'Windows' && matrix.arch != 'ARM64'
uses: actions/cache@v4
with:
path: |
Expand All @@ -224,6 +227,7 @@ jobs:
CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux_2_28
CIBW_ARCHS: ${{ matrix.arch }}
CIBW_BUILD: ${{ matrix.build || '*' }}
CIBW_SKIP: "*-musllinux_*"

- name: Upload Python wheels
Expand Down Expand Up @@ -295,6 +299,11 @@ jobs:
artifact_pattern: python-wheels-Windows-auto64
wheel_pattern: "*cp312*win*amd64.whl"

- os: windows-11-arm
artifact_pattern: python-wheels-Windows-ARM64
wheel_pattern: "*cp312*win*arm64.whl"
python_arch: arm64

- os: macos-15
artifact_pattern: python-wheels-macOS-arm64
wheel_pattern: "*cp312*macosx*arm64.whl"
Expand All @@ -304,6 +313,7 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.12"
architecture: ${{ matrix.python_arch }}

- uses: actions/checkout@v4

Expand All @@ -328,6 +338,36 @@ jobs:
run: |
pytest -v python/tests/ --ignore=python/tests/test_fairseq.py --ignore=python/tests/test_opennmt_py.py --ignore=python/tests/test_opennmt_tf.py

- name: Test multithreaded INT8 inference (Windows ARM64)
if: runner.os == 'Windows' && runner.arch == 'ARM64'
shell: pwsh
run: |
python -c "import ctranslate2; model = 'tests/data/models/v2/aren-transliteration-i8'; translator = ctranslate2.Translator(model, device='cpu', compute_type='int8', inter_threads=1, intra_threads=4); result = translator.translate_batch([['آ', 'ت', 'ز', 'م', 'و', 'ن']], beam_size=1); assert result[0].hypotheses[0] == ['a', 't', 'z', 'm', 'o', 'n']; del result, translator"

- name: Test multithreaded Ruy context shutdown (Windows ARM64)
if: runner.os == 'Windows' && runner.arch == 'ARM64'
timeout-minutes: 2
shell: pwsh
run: |
@'
import ctranslate2

model = "tests/data/models/v2/aren-transliteration"
for _ in range(3):
translator = ctranslate2.Translator(
model,
device="cpu",
compute_type="float32",
inter_threads=1,
intra_threads=4,
)
result = translator.translate_batch(
[["آ", "ت", "ز", "م", "و", "ن"]], beam_size=1
)
assert result[0].hypotheses[0] == ["a", "t", "z", "m", "o", "n"]
del result, translator
'@ | python -


test-legacy-converters:
needs: [build-python-wheels]
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ macro(ct2_compile_kernels_for_isa isa flag)
list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/kernels_${isa}.cc)
endmacro()

if(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm64)|(aarch64)"
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm64)|(aarch64)|(ARM64)"
OR (APPLE AND CMAKE_OSX_ARCHITECTURES STREQUAL "arm64"))
add_definitions(-DCT2_ARM64_BUILD)
set(CT2_BUILD_ARCH "arm64")
Expand Down
8 changes: 4 additions & 4 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ pip install ctranslate2

The Python wheels have the following requirements:

* OS: Linux (x86-64, AArch64), macOS (x86-64, ARM64), Windows (x86-64)
* Python version: >= 3.9
* OS: Linux (x86-64, AArch64), macOS (x86-64, ARM64), Windows (x86-64, ARM64)
* Python version: >= 3.9 (3.12–3.14 for Windows ARM64)
* pip version: >= 19.3 to support `manylinux2014` wheels

```{admonition} GPU support
The Linux and Windows Python wheels support GPU execution. Install [CUDA](https://developer.nvidia.com/cuda-toolkit) 12.x to use the GPU.
The Linux and Windows x86-64 Python wheels support GPU execution. Windows ARM64 wheels are CPU-only. Install [CUDA](https://developer.nvidia.com/cuda-toolkit) 12.x to use the GPU.

If you plan to run models with convolutional layers (e.g. for speech recognition), you should also install [cuDNN 8](https://developer.nvidia.com/cudnn) for CUDA 12.x.
```

```{note}
On Windows [the Visual C++ runtime](https://www.microsoft.com/en-US/download/details.aspx?id=48145) is required. It is installed in most of the systems, but if is not the case, you have to download it and install it.
On Windows [the latest supported Visual C++ runtime](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist) is required. It is installed in most systems, but if this is not the case, you have to download and install it.
```

## Install with Docker
Expand Down
16 changes: 15 additions & 1 deletion python/tools/prepare_build_environment_windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
set -e
set -x

NPROC=$(nproc)

if [ "$CIBW_ARCHS" = "ARM64" ]; then
mkdir build
cd build
cmake -A ARM64 -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$CTRANSLATE2_ROOT" -DBUILD_CLI=OFF -DWITH_MKL=OFF -DWITH_DNNL=OFF -DWITH_RUY=ON -DWITH_CUDA=OFF -DOPENMP_RUNTIME=COMP ..
cmake --build . --config Release --target install --parallel "$NPROC" --verbose
cd ..
rm -r build

cp README.md python/
cp "$CTRANSLATE2_ROOT/bin/ctranslate2.dll" python/ctranslate2/
exit 0
fi

CUDA_ROOT="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.8"
curl --netrc-optional -L -nv -o cuda.exe https://developer.download.nvidia.com/compute/cuda/12.8.1/local_installers/cuda_12.8.1_572.61_windows.exe
./cuda.exe -s nvcc_12.8 cudart_12.8 cublas_dev_12.8 curand_dev_12.8
Expand Down Expand Up @@ -38,7 +53,6 @@ if [ ! -d "C:/Program Files (x86)/Intel/oneAPI" ]; then
./webimage_extracted/bootstrapper.exe -s --action install --components="intel.oneapi.win.mkl.devel" --eula=accept -p=NEED_VS2017_INTEGRATION=0 -p=NEED_VS2019_INTEGRATION=0 --log-dir=.
fi

NPROC=$(nproc)
ONEDNN_VERSION=3.1.1
if [ ! -d "C:/Program Files (x86)/oneDNN" ]; then
curl --netrc-optional -L -O https://github.com/oneapi-src/oneDNN/archive/refs/tags/v${ONEDNN_VERSION}.tar.gz
Expand Down
19 changes: 17 additions & 2 deletions src/cpu/backend.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "backend.h"

#include <memory>

#include "ctranslate2/utils.h"
#include "cpu_info.h"
#include "env.h"
Expand Down Expand Up @@ -106,9 +108,22 @@ namespace ctranslate2 {
}

#ifdef CT2_WITH_RUY
static std::unique_ptr<ruy::Context>& get_thread_local_ruy_context() {
static thread_local std::unique_ptr<ruy::Context> context;
return context;
}

ruy::Context *get_ruy_context() {
static thread_local ruy::Context context;
return &context;
auto& context = get_thread_local_ruy_context();
if (!context)
context = std::make_unique<ruy::Context>();
return context.get();
}

void destroy_ruy_context() {
// The Ruy context owns worker threads. Destroy it before this thread
// enters TLS cleanup, where joining these workers can deadlock on Windows.
get_thread_local_ruy_context().reset();
}
#endif
}
Expand Down
1 change: 1 addition & 0 deletions src/cpu/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace ctranslate2 {
bool pack_gemm_weights(ComputeType compute_type);
#ifdef CT2_WITH_RUY
ruy::Context *get_ruy_context();
void destroy_ruy_context();
#endif

}
Expand Down
2 changes: 1 addition & 1 deletion src/cpu/vec_neon.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace ctranslate2 {
}

static inline value_type round(value_type v) {
#ifdef __aarch64__
#if defined(__aarch64__) || defined(_M_ARM64)
return vrndiq_f32(v);
#else
float temp[4] = {std::nearbyintf(v[0]), std::nearbyintf(v[1]), std::nearbyintf(v[2]), std::nearbyintf(v[3])};
Expand Down
6 changes: 6 additions & 0 deletions src/devices.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# include <unistd.h>
#endif

#include "cpu/backend.h"
#include "device_dispatch.h"

namespace ctranslate2 {
Expand Down Expand Up @@ -121,6 +122,11 @@ namespace ctranslate2 {
}

void destroy_context(Device device) {
#ifdef CT2_WITH_RUY
if (device == Device::CPU) {
cpu::destroy_ruy_context();
}
#endif
#ifdef CT2_WITH_CUDA
if (device == Device::CUDA) {
cuda::free_curand_states();
Expand Down
2 changes: 1 addition & 1 deletion third_party/ruy
Submodule ruy updated 1 files
+4 −0 ruy/CMakeLists.txt
Loading