assert_gpu.ymlยถ

---
- name: "๐ŸŽฎ Probe and assert the GPU LibreTranslate sees on the stack host"
  when: IS_STACK_HOST | bool
  block:
    - name: "๐ŸŽฎ Ask CTranslate2 how many CUDA devices it sees"
      ansible.builtin.shell:
        cmd: >- # nocheck: raw-docker, container-exec-resolver  the probe has to run inside the served container, and only CTranslate2 can tell a working CUDA stack from a healthy CPU fallback
          container exec {{ LIBRETRANSLATE_CONTAINER_ADDRESS }}
          ./venv/bin/python -c "import ctranslate2; print(ctranslate2.get_cuda_device_count())"
      register: libretranslate_cuda_devices
      changed_when: false

    - name: "โœ… Assert the GPU this host offers actually reached LibreTranslate"
      ansible.builtin.assert:
        that:
          - libretranslate_cuda_devices.stdout | trim | int > 0
        fail_msg: >-
          {{ application_id }} runs with gpu enabled and this host carries
          /dev/nvidia0, but CTranslate2 counts
          {{ libretranslate_cuda_devices.stdout | trim }} CUDA devices. The image
          is missing its CUDA libraries or the nvidia runtime did not reach the
          container.