From 402f97df2a706fe36ec6d7afcb8c3169da9e79ec Mon Sep 17 00:00:00 2001 From: Eric Lemesre Date: Thu, 24 Sep 2026 17:11:34 +0200 Subject: [PATCH] Construction de CTranslate2 avec CUDA pour arm64 : roue, paquets Debian, CI Gitea --- .gitea/workflows/build.yml | 53 ++++++++++++++ .gitignore | 6 ++ Dockerfile | 12 ++++ LICENSE | 21 ++++++ README.md | 90 +++++++++++++++++++++++ build.sh | 116 ++++++++++++++++++++++++++++++ debian/changelog | 9 +++ debian/control | 40 +++++++++++ debian/copyright | 43 +++++++++++ debian/libctranslate2-4.install | 1 + debian/libctranslate2-dev.install | 3 + debian/rules | 35 +++++++++ debian/source/format | 1 + debian/source/options | 2 + tools/publish.sh | 29 ++++++++ tools/smoke-gpu.py | 62 ++++++++++++++++ versions.env | 10 +++ 17 files changed, 533 insertions(+) create mode 100644 .gitea/workflows/build.yml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100755 build.sh create mode 100644 debian/changelog create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/libctranslate2-4.install create mode 100644 debian/libctranslate2-dev.install create mode 100755 debian/rules create mode 100644 debian/source/format create mode 100644 debian/source/options create mode 100755 tools/publish.sh create mode 100755 tools/smoke-gpu.py create mode 100644 versions.env diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..b6a85b3 --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,53 @@ +# Construction sur le runner arm64 de mimir (étiquette suffixée -arm64 : +# Gitea aiguille par étiquette, jamais par architecture). Le job tourne +# dans l'image CUDA, sans GPU : la compilation n'en a pas besoin, la +# validation GPU se fait à la main (tools/smoke-gpu.py). +name: build +on: + push: + branches: [main] + tags: ["v*"] + pull_request: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-22.04-arm64 + container: + image: nvidia/cuda:13.0.1-cudnn-devel-ubuntu22.04 + # Le runner borne chaque conteneur à 6 CPU (nproc en voit 20) et 24 Go. + timeout-minutes: 120 + env: + DEBIAN_FRONTEND: noninteractive + JOBS: "6" + steps: + - name: outils de base (git pour le checkout) + run: apt-get update -q && apt-get install -y -q --no-install-recommends git ca-certificates + - uses: actions/checkout@v4 + - name: dépendances + run: ./build.sh deps + - name: sources amont + run: ./build.sh source + - name: paquets Debian + run: ./build.sh deb + - name: roue Python + run: ./build.sh wheel + - name: contrôles (sans GPU) + run: ./build.sh check + - uses: actions/upload-artifact@v3 + with: + name: ctranslate2-cuda-arm64 + path: | + dist/*.whl + dist/*.deb + retention-days: 30 + - name: publication dans les registres Gitea (tags v* seulement) + if: startsWith(gitea.ref, 'refs/tags/v') + env: + GITEA_URL: ${{ gitea.server_url }} + OWNER: ${{ gitea.repository_owner }} + # Jeton personnel à portée write:package, posé dans les secrets du + # dépôt ; le jeton automatique du job ne porte pas cette portée. + PACKAGES_USER: ${{ secrets.PACKAGES_USER }} + PACKAGES_TOKEN: ${{ secrets.PACKAGES_TOKEN }} + run: ./tools/publish.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ca04000 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +work/ +dist/ +*.whl +*.deb +*.changes +*.buildinfo diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..300c605 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +# Environnement de construction reproductible : le même que la CI. +# Usage (sur mimir ou toute machine arm64 avec Docker, GPU inutile) : +# docker build -t ct2-cuda-arm64 . +# docker run --rm -v "$PWD:/src" -e JOBS=20 ct2-cuda-arm64 all +ARG CUDA_IMAGE=nvidia/cuda:13.0.1-cudnn-devel-ubuntu22.04 +FROM ${CUDA_IMAGE} +ENV DEBIAN_FRONTEND=noninteractive +COPY build.sh versions.env /tmp/bootstrap/ +RUN /tmp/bootstrap/build.sh deps && rm -rf /var/lib/apt/lists/* /tmp/bootstrap +WORKDIR /src +ENTRYPOINT ["./build.sh"] +CMD ["all"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3f0dd89 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Eric Lemesre + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ddd6ce1 --- /dev/null +++ b/README.md @@ -0,0 +1,90 @@ +# CTranslate2 avec CUDA pour Linux arm64 + +Roue Python et paquets Debian de [CTranslate2](https://github.com/OpenNMT/CTranslate2) +compilés **avec le backend CUDA** pour Linux aarch64 : NVIDIA DGX Spark (GB10, +sm_121), Grace Hopper (sm_90) et Jetson Orin (sm_87). + +## Pourquoi + +Le projet amont publie sur PyPI des roues `ctranslate2` pour aarch64 **sans CUDA** +(sa chaîne de construction n'installe le toolkit que pour x86_64). Sur un DGX Spark, +`faster-whisper` et `WhisperX` tournent donc en CPU alors que CUDA 13 est bien là. +Ce dépôt reproduit la construction amont en y ajoutant CUDA, et publie le résultat. + +## Installation + +Roue Python (index de paquets Gitea, à côté de PyPI) : + +```bash +pip install ctranslate2 --extra-index-url https://git.lemesre.org/api/packages//pypi/simple +pip install faster-whisper # tire la roue ci-dessus +``` + +Paquets Debian (bibliothèque C++ et en-têtes, pour un programme C++ ou une liaison +FFI comme la crate Rust `ct2rs`) : + +```bash +sudo curl -fsSL https://git.lemesre.org/api/packages//debian/repository.key -o /etc/apt/keyrings/gitea-.asc +echo "deb [signed-by=/etc/apt/keyrings/gitea-.asc] https://git.lemesre.org/api/packages//debian noble main" | sudo tee /etc/apt/sources.list.d/gitea-.list +sudo apt update && sudo apt install libctranslate2-4 libctranslate2-dev +``` + +Les bibliothèques CUDA **ne sont pas embarquées** : CTranslate2 les charge à +l'exécution (`CUDA_DYNAMIC_LOADING`). Il faut cuBLAS 13 et cuDNN 9 trouvables, +soit par le toolkit CUDA de la machine (`/usr/local/cuda`), soit par les paquets +pip `nvidia-cublas` et `nvidia-cudnn-cu13` (ceux que `torch` cu130 installe déjà). +Pilote NVIDIA 580 ou plus récent. Sans GPU, la même roue tourne en CPU. + +Contrat des artefacts : + +| Artefact | Étiquette | Cible | +| --- | --- | --- | +| `ctranslate2-4.6.0-cp3*-manylinux_2_35_aarch64.whl` | glibc ≥ 2.35 | Ubuntu 22.04, DGX OS / Ubuntu 24.04, JetPack 6 | +| `libctranslate2-4_4.6.0-1~cuda13_arm64.deb`, `libctranslate2-dev_…deb` | jammy, noble | idem | + +## Construction + +Tout passe par `build.sh`, dans l'image CUDA (aucun GPU nécessaire) : + +```bash +docker build -t ct2-cuda-arm64 . +docker run --rm -v "$PWD:/src" -e JOBS=20 ct2-cuda-arm64 all # ≈ 20 min sur 20 cœurs +ls dist/ +``` + +Étapes séparées : `deps`, `source` (clone amont avec sous-modules), `deb` +(`dpkg-buildpackage -b`, compile la bibliothèque), `wheel` (roue liée à la +bibliothèque du paquet, réparée par `auditwheel`), `check` (symboles CUDA +présents, `lintian`). Les versions sont épinglées dans `versions.env`. + +Validation sur une machine avec GPU, après installation de la roue : + +```bash +python3 tools/smoke-gpu.py # compte les GPU vus par CTranslate2 +python3 tools/smoke-gpu.py reunion.wav # faster-whisper large-v3, langue forcée fr +``` + +## Intégration continue + +`.gitea/workflows/build.yml` tourne sur un runner Gitea Actions arm64 +(étiquette `ubuntu-22.04-arm64`) dans l'image CUDA, sans GPU. Chaque poussée +construit et dépose les artefacts ; un tag `v*` les publie en plus dans les +registres PyPI et Debian du propriétaire du dépôt. + +Secrets attendus dans le dépôt : `PACKAGES_USER` et `PACKAGES_TOKEN` (jeton +personnel Gitea à portée `write:package`). Le jeton automatique du job n'a pas +cette portée. + +Le runner borne un job à 6 CPU et 24 Go, deux heures au plus. `nproc` y +annonce pourtant tous les cœurs de l'hôte : `JOBS=6` est fixé dans le workflow. + +## Versions et maintenance + +Une reconstruction par version amont de CTranslate2 et par version majeure de +CUDA : modifier `versions.env` et `debian/changelog`, tagger `v-`. +La liste `CUDA_ARCH_LIST` est explicite parce que la valeur amont `Common` +ignore sm_121. + +Ce dépôt ne fait que compiler et empaqueter : aucune modification du code +amont. Licence MIT, comme CTranslate2 ; Ruy et cpu_features (sous-modules) sont +sous Apache-2.0. diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..e0accf3 --- /dev/null +++ b/build.sh @@ -0,0 +1,116 @@ +#!/usr/bin/env bash +# Construction de CTranslate2 avec CUDA pour Linux aarch64 : paquets Debian +# (libctranslate2-4, libctranslate2-dev) puis roue Python liée à la même +# bibliothèque. Tourne dans l'image CUDA (CI, Dockerfile) ou sur un hôte +# qui a nvcc. Étapes : deps | source | deb | wheel | check | all. +set -euo pipefail + +ROOT=$(cd "$(dirname "$0")" && pwd) +# shellcheck source=versions.env +. "$ROOT/versions.env" + +JOBS=${JOBS:-$(nproc)} # en CI, borné à la part de CPU du conteneur +WORK=${WORK:-$ROOT/work} +DIST=${DIST:-$ROOT/dist} +SRC=$WORK/CTranslate2 +STAGE=$WORK/stage # vue « prefix » de l'installation Debian +export DEBIAN_FRONTEND=noninteractive + +log() { printf '\n== %s\n' "$*" >&2; } + +etape_deps() { + log "dépendances de construction" + if [ "$(id -u)" -ne 0 ]; then SUDO=sudo; else SUDO=; fi + $SUDO apt-get update -q + $SUDO apt-get install -y -q --no-install-recommends \ + build-essential cmake ninja-build git ca-certificates pkg-config \ + libopenblas-dev libgomp1 \ + debhelper devscripts fakeroot lintian \ + python3-dev python3-venv python3-pip patchelf + command -v nvcc >/dev/null || export PATH=/usr/local/cuda/bin:$PATH + nvcc --version | tail -1 +} + +etape_source() { + log "sources CTranslate2 v$CT2_VERSION (sous-modules inclus : ruy, cpu_features…)" + mkdir -p "$WORK" + if [ ! -d "$SRC/.git" ]; then + git clone --recursive --depth 1 --branch "v$CT2_VERSION" "$CT2_UPSTREAM" "$SRC" + fi + git -C "$SRC" describe --tags + rm -rf "$SRC/debian" + cp -a "$ROOT/debian" "$SRC/debian" +} + +etape_deb() { + log "paquets Debian (dpkg-buildpackage, $JOBS tâches)" + command -v nvcc >/dev/null || export PATH=/usr/local/cuda/bin:$PATH + cd "$SRC" + export CUDA_ARCH_LIST + # -b : binaires seulement (pas de tarball orig) ; -nc : ne pas nettoyer, + # une relance reprend la compilation là où elle s'est arrêtée. + dpkg-buildpackage -b -us -uc -nc -j"$JOBS" + mkdir -p "$DIST" + mv -f "$WORK"/*.deb "$DIST"/ + mv -f "$WORK"/*.buildinfo "$WORK"/*.changes "$DIST"/ 2>/dev/null || true + ls -la "$DIST" +} + +etape_wheel() { + log "roue Python liée à la bibliothèque du paquet" + # setup.py cherche include/ et lib/ sous CTRANSLATE2_ROOT ; Debian installe + # sous lib/aarch64-linux-gnu, d'où cette vue par liens symboliques. + TMP=$SRC/debian/tmp/usr + [ -e "$TMP/include/ctranslate2" ] || { echo "installation Debian absente : lancer l'étape deb" >&2; exit 1; } + rm -rf "$STAGE" && mkdir -p "$STAGE" + ln -s "$TMP/include" "$STAGE/include" + ln -s "$TMP/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)" "$STAGE/lib" + + python3 -m venv "$WORK/venv" + # shellcheck disable=SC1091 + . "$WORK/venv/bin/activate" + pip install -q -U pip setuptools wheel pybind11 auditwheel + rm -rf "$WORK/wheel-raw" + CTRANSLATE2_ROOT=$STAGE pip wheel -q --no-deps --no-build-isolation "$SRC/python" -w "$WORK/wheel-raw" + + # Étiquette manylinux d'après la glibc de l'image (2.35 → manylinux_2_35). + GLIBC=$(ldd --version | head -1 | grep -oE '[0-9]+\.[0-9]+$' | tr . _) + mkdir -p "$DIST" + # Les bibliothèques CUDA ne sont PAS embarquées : CTranslate2 les charge + # dynamiquement (CUDA_DYNAMIC_LOADING) depuis le toolkit ou les paquets + # pip nvidia-*. Seules libctranslate2 et OpenBLAS entrent dans la roue. + LD_LIBRARY_PATH=$STAGE/lib auditwheel repair \ + --plat "manylinux_${GLIBC}_aarch64" \ + --exclude 'libcuda.so.1' --exclude 'libcublas*' --exclude 'libcublasLt*' \ + --exclude 'libcudnn*' --exclude 'libcudart*' \ + -w "$DIST" "$WORK"/wheel-raw/*.whl + ls -la "$DIST"/*.whl +} + +etape_check() { + log "contrôles sans GPU" + # shellcheck disable=SC1091 + . "$WORK/venv/bin/activate" + pip install -q "$DIST"/ctranslate2-*.whl numpy pyyaml + python3 - <<'PY' +import ctranslate2, subprocess, glob, os +print("ctranslate2", ctranslate2.__version__) +lib = glob.glob(os.path.join(os.path.dirname(ctranslate2.__file__), "..", "ctranslate2.libs", "libctranslate2*"))[0] +syms = subprocess.run(["nm", "-D", lib], capture_output=True, text=True).stdout +assert "cublas" in syms.lower() or "cuda" in syms.lower(), "bibliothèque sans symboles CUDA" +print("symboles CUDA présents dans", os.path.basename(lib)) +print("GPU visibles ici (0 attendu en CI) :", ctranslate2.get_cuda_device_count()) +PY + dpkg-deb -I "$DIST"/libctranslate2-4_*.deb | sed -n '1,25p' + lintian --no-tag-display-limit "$DIST"/*.deb || true +} + +case "${1:-all}" in + deps) etape_deps ;; + source) etape_source ;; + deb) etape_deb ;; + wheel) etape_wheel ;; + check) etape_check ;; + all) etape_deps; etape_source; etape_deb; etape_wheel; etape_check ;; + *) echo "usage : $0 {deps|source|deb|wheel|check|all}" >&2; exit 2 ;; +esac diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..a42067f --- /dev/null +++ b/debian/changelog @@ -0,0 +1,9 @@ +ctranslate2 (4.6.0-1~cuda13) jammy; urgency=medium + + * Build of upstream 4.6.0 with the CUDA 13 backend for Linux arm64 + (Jetson Orin 8.7, Grace Hopper 9.0, DGX Spark GB10 12.1), which the + upstream project does not publish for this architecture. + * CUDA libraries are loaded at run time (CUDA_DYNAMIC_LOADING): the + package works on CPU without them. + + -- Eric Lemesre Wed, 24 Sep 2026 18:00:00 +0200 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..44fea9a --- /dev/null +++ b/debian/control @@ -0,0 +1,40 @@ +Source: ctranslate2 +Section: libs +Priority: optional +Maintainer: Eric Lemesre +Build-Depends: debhelper-compat (= 13), + cmake (>= 3.15), + ninja-build, + libopenblas-dev +Standards-Version: 4.6.2 +Homepage: https://github.com/OpenNMT/CTranslate2 +Rules-Requires-Root: no + +Package: libctranslate2-4 +Architecture: arm64 +Multi-Arch: same +Depends: ${shlibs:Depends}, ${misc:Depends} +Recommends: libcublas-13-0, libcudnn9-cuda-13 +Description: fast inference engine for Transformer models (CUDA 13, arm64) + CTranslate2 is a C++ and Python library for efficient inference with + Transformer models (Whisper, NLLB, T5, Llama, ...), with weight quantization + and CPU/GPU execution. + . + This build enables the CUDA backend for Linux arm64 (Jetson Orin, Grace + Hopper, DGX Spark GB10), which the upstream project does not publish for + this architecture. CUDA libraries are loaded at run time (cuBLAS 13, + cuDNN 9) from the CUDA toolkit or from the nvidia-* pip packages; without + them the library still works on CPU (OpenBLAS + Ruy). + +Package: libctranslate2-dev +Architecture: arm64 +Multi-Arch: same +Section: libdevel +Depends: libctranslate2-4 (= ${binary:Version}), ${misc:Depends} +Description: fast inference engine for Transformer models - development files + CTranslate2 is a C++ and Python library for efficient inference with + Transformer models. + . + This package contains the headers and the unversioned shared library link + needed to build programs against libctranslate2 (C++ or FFI bindings such + as the Rust crate ct2rs). diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..32f87f8 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,43 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: CTranslate2 +Upstream-Contact: OpenNMT +Source: https://github.com/OpenNMT/CTranslate2 + +Files: * +Copyright: 2018-2026 SYSTRAN and the OpenNMT contributors +License: MIT + +Files: third_party/ruy/* +Copyright: Google LLC +License: Apache-2.0 + +Files: third_party/cpu_features/* +Copyright: Google LLC +License: Apache-2.0 + +Files: debian/* +Copyright: 2026 Eric Lemesre +License: MIT + +License: MIT + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + . + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + . + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +License: Apache-2.0 + On Debian systems, the full text of the Apache License version 2.0 can be + found in /usr/share/common-licenses/Apache-2.0. diff --git a/debian/libctranslate2-4.install b/debian/libctranslate2-4.install new file mode 100644 index 0000000..177f041 --- /dev/null +++ b/debian/libctranslate2-4.install @@ -0,0 +1 @@ +usr/lib/*/libctranslate2.so.* diff --git a/debian/libctranslate2-dev.install b/debian/libctranslate2-dev.install new file mode 100644 index 0000000..587a021 --- /dev/null +++ b/debian/libctranslate2-dev.install @@ -0,0 +1,3 @@ +usr/include/ctranslate2 +usr/lib/*/libctranslate2.so +usr/lib/*/cmake/CTranslate2 diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..d5e4d24 --- /dev/null +++ b/debian/rules @@ -0,0 +1,35 @@ +#!/usr/bin/make -f +# Construction Debian de CTranslate2 avec le backend CUDA, arm64. +# CUDA_ARCH_LIST vient de l'environnement (versions.env via build.sh) ; +# repli sur la liste DGX Spark / Grace Hopper / Jetson Orin. +export DEB_BUILD_MAINT_OPTIONS = hardening=+all +# -g sur du code CUDA : compilation lente et binaires énormes, sans usage ici. +export DEB_CFLAGS_MAINT_STRIP = -g +export DEB_CXXFLAGS_MAINT_STRIP = -g +CUDA_ARCH_LIST ?= 8.7;9.0;12.1 + +%: + dh $@ --buildsystem=cmake+ninja + +override_dh_auto_configure: + dh_auto_configure -- \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_CLI=OFF \ + -DBUILD_TESTS=OFF \ + -DWITH_MKL=OFF \ + -DWITH_DNNL=OFF \ + -DWITH_OPENBLAS=ON \ + -DWITH_RUY=ON \ + -DOPENMP_RUNTIME=COMP \ + -DWITH_CUDA=ON \ + -DWITH_CUDNN=ON \ + -DCUDA_DYNAMIC_LOADING=ON \ + -DCUDA_ARCH_LIST="$(CUDA_ARCH_LIST)" + +# Les bibliothèques CUDA sont chargées dynamiquement : aucune information +# shlibs à leur sujet, dpkg-shlibdeps ne doit pas échouer dessus. +override_dh_shlibdeps: + dh_shlibdeps -- --ignore-missing-info + +# dwz sur des fatbins CUDA : long et inutile. +override_dh_dwz: diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/debian/source/options b/debian/source/options new file mode 100644 index 0000000..b48721c --- /dev/null +++ b/debian/source/options @@ -0,0 +1,2 @@ +# Le paquet est construit en binaire seulement (dpkg-buildpackage -b) depuis +# le dépôt git amont avec ses sous-modules ; pas de tarball orig géré ici. diff --git a/tools/publish.sh b/tools/publish.sh new file mode 100755 index 0000000..f3e11b2 --- /dev/null +++ b/tools/publish.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# Publie dist/ dans les registres de paquets Gitea du propriétaire : +# - roue Python → registre PyPI (pip --extra-index-url …/pypi/simple) +# - .deb → registre Debian (apt, distributions jammy et noble) +# Variables : GITEA_URL, OWNER, PACKAGES_USER, PACKAGES_TOKEN (write:package). +set -euo pipefail +ROOT=$(cd "$(dirname "$0")/.." && pwd) +DIST=${DIST:-$ROOT/dist} +: "${GITEA_URL:?}" "${OWNER:?}" "${PACKAGES_USER:?}" "${PACKAGES_TOKEN:?}" + +if [ -x "$ROOT/work/venv/bin/pip" ]; then PIP=$ROOT/work/venv/bin/pip; TWINE=$ROOT/work/venv/bin/twine +else PIP="python3 -m pip"; TWINE=twine; fi +$PIP install -q twine + +echo "== PyPI : $GITEA_URL/api/packages/$OWNER/pypi" +TWINE_USERNAME=$PACKAGES_USER TWINE_PASSWORD=$PACKAGES_TOKEN \ + $TWINE upload --non-interactive --skip-existing \ + --repository-url "$GITEA_URL/api/packages/$OWNER/pypi" "$DIST"/*.whl + +for deb in "$DIST"/*.deb; do + for distribution in jammy noble; do + echo "== Debian : $(basename "$deb") → $distribution/main" + # 409 = déjà présent : on ne casse pas une relance pour cela. + code=$(curl -sS -o /dev/null -w '%{http_code}' --user "$PACKAGES_USER:$PACKAGES_TOKEN" \ + --upload-file "$deb" \ + "$GITEA_URL/api/packages/$OWNER/debian/pool/$distribution/main/upload") + case "$code" in 201|409) echo " $code" ;; *) echo " échec HTTP $code" >&2; exit 1 ;; esac + done +done diff --git a/tools/smoke-gpu.py b/tools/smoke-gpu.py new file mode 100755 index 0000000..eeab08a --- /dev/null +++ b/tools/smoke-gpu.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +"""Validation sur une machine AVEC GPU : la roue voit-elle le GPU, et +faster-whisper transcrit-il en français dessus ? + + pip install faster-whisper --extra-index-url https://git.lemesre.org/api/packages//pypi/simple + python3 tools/smoke-gpu.py [audio.wav] + +Sans argument, seul le comptage des GPU est fait. cuBLAS 13 et cuDNN 9 +doivent être trouvables (toolkit CUDA système, ou paquets pip nvidia-* +dont le script ajoute les dossiers lib à LD_LIBRARY_PATH s'ils existent). +""" +import ctypes +import importlib +import os +import sys +import time + + +def dossiers_nvidia_pip() -> list[str]: + dossiers = [] + for module in ("nvidia.cublas", "nvidia.cudnn", "nvidia.cuda_runtime"): + try: + m = importlib.import_module(module) + except ImportError: + continue + lib = os.path.join(os.path.dirname(m.__file__), "lib") + if os.path.isdir(lib): + dossiers.append(lib) + return dossiers + + +def main() -> int: + for d in dossiers_nvidia_pip(): + for f in sorted(os.listdir(d)): + if f.startswith(("libcublas", "libcudnn")) and ".so" in f: + try: + ctypes.CDLL(os.path.join(d, f)) + except OSError: + pass + import ctranslate2 + n = ctranslate2.get_cuda_device_count() + print(f"ctranslate2 {ctranslate2.__version__} — GPU CUDA visibles : {n}") + if n == 0: + print("aucun GPU : la roue est CPU ou CUDA est introuvable", file=sys.stderr) + return 1 + print("types de calcul GPU :", sorted(ctranslate2.get_supported_compute_types("cuda"))) + if len(sys.argv) < 2: + return 0 + from faster_whisper import WhisperModel + modele = WhisperModel("large-v3", device="cuda", compute_type="float16") + debut = time.perf_counter() + segments, info = modele.transcribe(sys.argv[1], language="fr", beam_size=5, vad_filter=True) + texte = [(s.start, s.end, s.text) for s in segments] + duree = time.perf_counter() - debut + print(f"audio {info.duration:.1f} s transcrit en {duree:.1f} s, langue forcée fr") + for start, end, t in texte[:10]: + print(f"[{start:6.1f}-{end:6.1f}] {t.strip()}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/versions.env b/versions.env new file mode 100644 index 0000000..3114512 --- /dev/null +++ b/versions.env @@ -0,0 +1,10 @@ +# Versions épinglées — une seule source pour build.sh, le Dockerfile et la CI. +CT2_VERSION=4.6.0 +CT2_UPSTREAM=https://github.com/OpenNMT/CTranslate2 +# Image de construction : toolchain CUDA 13 + cuDNN 9, Ubuntu 22.04 (glibc 2.35) +# pour que la roue porte l'étiquette manylinux_2_35 et s'installe sur DGX OS +# (24.04) comme sur Ubuntu 22.04. Le GPU n'est pas nécessaire à la compilation. +CUDA_IMAGE=nvidia/cuda:13.0.1-cudnn-devel-ubuntu22.04 +# Architectures GPU : Jetson Orin (8.7), Grace Hopper (9.0), DGX Spark GB10 (12.1). +# « Common » (défaut amont) ignore 12.1, d'où la liste explicite. +CUDA_ARCH_LIST="8.7;9.0;12.1"