[Fixed] RuntimeError: Library libcublas.so.11 is not found or cannot be loaded – Python

by
Ali Hasan
google-colaboratory large-language-model mysql-connector-python openai-whisper pytorch

Quick Fix: To resolve this issue, install the required library using the command !apt install libcublas11. This command should install the necessary library and resolve the error.

The Problem:

A developer is encountering a ‘RuntimeError: Library libcublas.so.11 is not found or cannot be loaded’ error while running a Python program on Google Colab. The code uses the pyannote-audio, transformers, openai, and whisper libraries and performs tasks related to speech recognition and speaker diarization. The error occurs specifically when trying to transcribe audio using the faster_whisper library. The developer has tried updating the libraries, reverting to older versions, and ensuring that the audio file is in WAV format, but the error persists. The code has been working without issues until recently, leading to the suspicion that a recent update to the dependencies might be the cause. The developer seeks assistance in identifying the root cause of the error and resolving it.

The Solutions:

Solution 1: Install libcublas11 Library

The error “RuntimeError: Library libcublas.so.11 is not found or cannot be loaded” typically occurs when the library libcublas is not installed or corrupted on the system. To resolve this issue, you can try the following steps:

  1. Check CUDA Version:

Ensure that you have the correct version of CUDA installed on your system. For Google Colab, you can check the CUDA version by running the following command in a code cell:

!nvcc -V

Make sure that the CUDA version you have installed is compatible with the PyTorch version you are using.

  1. Install libcublas11:

You can install the libcublas11 library using the following command in a code cell:

!apt install libcublas11
  1. Restart Runtime:

After installing libcublas11, restart the Google Colab runtime by clicking the "Runtime" tab and selecting "Restart Runtime." This will ensure that the changes made to the system libraries are applied.

  1. Reinstall PyTorch and TorchAudio:

After restarting the runtime, reinstall PyTorch and TorchAudio using the following commands in a code cell:

!pip install torch==2.1.1
!pip install torchaudio==2.1.1
  1. Retrain or Reload Models:

If you have trained any models using PyTorch or TorchAudio, you might need to retrain them after reinstalling the libraries. Alternatively, you can reload the previously trained models if they are compatible with the new versions of PyTorch and TorchAudio.

  1. Check Your Code:

Once you have completed the above steps, review your code to ensure that you are using the correct library versions and that there are no other compatibility issues.

By following these steps, you should be able to resolve the "RuntimeError: Library libcublas.so.11 is not found or cannot be loaded" error and continue using PyTorch and TorchAudio in your Google Colab notebook.

Solution 2: Investigate CUDA Compatibility Issues

The error message you’re encountering, “RuntimeError: Library libcublas.so.11 is not found or cannot be loaded,” suggests that there’s a compatibility issue between your CUDA version and the required CUDA version for running the faster-whisper library. Here’s how you can resolve this issue:

  1. Check CUDA Version:

    • Verify the CUDA version used by your Google Colab instance. You can run the following command in a Colab cell to check the CUDA version:

      !nvcc --version
      
    • If you find that the CUDA version is 12, then it’s likely incompatible with the faster-whisper library, which requires CUDA 11.

  2. Rebuild CTranslate2 from Source:

    • To make faster-whisper compatible with CUDA 12, you need to rebuild the CTranslate2 library from its source code.
    • Refer to the GitHub issue provided in the Answer (https://github.com/OpenNMT/CTranslate2/issues/1250) for a detailed guide on how to rebuild CTranslate2.
    • Once you successfully rebuild CTranslate2, reinstall the faster-whisper library. This should resolve the compatibility issue and allow you to use the library without the error.
  3. Alternatively, Use a Different Version of Whisper:

    • If you prefer not to rebuild CTranslate2, you can use a different version of Whisper that is compatible with CUDA 12.
    • Check the official Whisper documentation for more information on available versions and their compatibility with different CUDA versions.

Q&A

What is the cause of the error message?

The error is caused by a missing or corrupted Cuda library.

How to fix the error?

Install the missing Cuda library using the command !apt install libcublas11.

What are alternatives for that error?

To resolve the issue, you can also rebuild CTranslate2 from the source.