Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I got the fine-tune web UI to compile and successfully fine-tune a model on my 2018 MacBook Pro #44

Open
TheMechanicX32 opened this issue Aug 6, 2024 · 0 comments

Comments

@TheMechanicX32
Copy link

This is going to be a long write-up. Tldr; I got the finetune UI to compile and complete a training on my 6 year old MacBook Pro.

Initial problem

At first, I was plagued by dependency errors and incomplete installation errors. This got to the point where I had to write my own installation script. The script completely reinstalls every package even if they're already installed. This was an intentional choice on my part because I modify the actual libraries themselves. If something screwed up, I need a fresh start.

Once I resolved the dependency issues, I ran into the super vague "Segmentation fault: 11" error. I discovered that it is caused by this known issue on the faster-whisper git page. In summary, faster-whisper seg-faults when you attempt to transcribe because of a mismatch between multiple versions of the same library.

Fixing the dependency issues

This is my custom install.sh script:

#!/bin/bash

# Create a Python virtual environment
python -m venv venv
# Activate the virtual environment
source venv/bin/activate

# Install other dependencies from requirements.txt
pip install --upgrade pip
pip install -r requirements.txt --force --no-cache-dir # remove these two flags to remove forced reinstall
pip install torch==2.1.1 torchvision==0.16.1 torchaudio==2.1.1
pip install faster-whisper==1.0.2

python xtts_demo.py

It's extremely important (with the current xtts-finetune-webui) that you install torch 2.1.1 and torch-vision 0.16.1. You also need faster-whisper 1.0.2. While running this script, you may get some dependency errors related to torch not being the correct version, but that will resolve itself once torch installs.

Fixing the segmentation fault

  1. Create a new bash script. I called mine "link_symbolically.sh"
  2. Copy the below script into the newly created shell script:
#!/bin/bash

# Paths to delete
file1="./venv/lib/python3.9/site-packages/torch/.dylibs/libiomp5.dylib"
file2="./venv/lib/python3.9/site-packages/torch/lib/libiomp5.dylib"

# Path to link from - This library is the correct version that does not cause crashes.
source_file="./venv/lib/python3.9/site-packages/ctranslate2/.dylibs/libiomp5.dylib"

# Ensure the .dylibs directory exists
mkdir -p ./venv/lib/python3.9/site-packages/torch/.dylibs

# Delete the files
echo "Deleting $file1 and $file2..."
rm -f "$file1"
rm -f "$file2"

# Create symbolic links
echo "Creating symbolic links..."
ln -s "$source_file" "$file1"
ln -s "$source_file" "$file2"

# Verify the symbolic links
echo "Verifying symbolic links..."
ls -l "$file1"
ls -l "$file2"

# Check the target of the symbolic links
echo "Checking the target of the symbolic links..."
readlink "$file1"
readlink "$file2"

# Modify the library paths inside all relevant .dylib files
for lib in ./venv/lib/python3.9/site-packages/torch/lib/*.dylib; do
    echo "Modifying $lib..."
    install_name_tool -change @loader_path/../.dylibs/libiomp5.dylib @loader_path/../../ctranslate2/.dylibs/libiomp5.dylib "$lib"
done

# Additional check for the torch_shm_manager binary
torch_shm_manager="./venv/lib/python3.9/site-packages/torch/bin/torch_shm_manager"
if [ -f "$torch_shm_manager" ]; then
    echo "Modifying $torch_shm_manager..."
    install_name_tool -change @loader_path/../.dylibs/libiomp5.dylib @loader_path/../../ctranslate2/.dylibs/libiomp5.dylib "$torch_shm_manager"
fi

echo "Library paths modified successfully."
  1. Make sure this script is placed into the xtts-finetune-webui folder.
  2. The correct version of libiomp5.dylib is in the ctranslate2 folder. That's the version we want to reference and link our libraries to.

If this script does not complete successfully, try running the command find . -name libiomp5.dylib:

image

You'll notice there are three versions of the problem library, libiomp5.dylib. You can verify that the script worked correctly by going to the first two paths and checking for a symbolic link (created by the script above).

You can see when I navigate to /venv/lib/python3.9/site-packages/torch/.dylibs/libiomp5.dylib:

Screenshot 2024-08-06 at 5 54 23 AM

Note how libiomp5.dylib has that little arrow next to it, indicating it's a symbolic link to the correct version of libiomp5.dylib.

Closing thoughts

After running the link_symbolically.sh script, you'll get an error letting you know that modifying the library will invalidate the code signature from the developers. This is unfortunate, but if you're just using this for personal projects it should be fine. This is also why I reinstall all dependencies.

This was a lot of work. I think I spent about two weeks of free time on this.

Please let me know if anyone is having any trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant