Skip to content

OneComp with Llama.cpp conflicts OpenMP execution between PyTorch and Llama.cpp on macOS #50

Description

@y-vectorfield

Summary

When we execute OneComp with Llama.cpp on macOS, it conflicts OpenMP execution between PyTorch and Llama.cpp.

Environment

  • macOS Tahoe 26.6.1
  • CPU: M1 Pro
  • uv 0.11.17
  • Python 3.12.14
  • OneComp 1.13.1
  • torch 2.13.0
  • llama-cpp-python 0.3.34

What Happened

  • If you have installed gcc or clang on macOS using a tool like Homebrew, OpenMP associated with them will conflict with OpenMP within the .venv (generated by uv) directory.
  • OneComp's PyTorch backend is configured to use OpenMP library located within .venv.
  • Depending on the environment, Llama.cpp is configured to use the OpenMP library associated with gcc or clang.
  • Therefore, the above two will result in a conflict at runtime.

If the following warning message is shown, this conflict may be occurring.

**/multiprocessing/resource_tracker.py:279: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '

Suggested Fix

Search for OpenMP associated with PyTorch.

$ find .venv -type f \( -name 'libomp.dylib' -o -name 'libgomp*.dylib' \) -print | grep torch
.venv/lib/python3.<PYVERSION>/site-packages/torch/lib/libomp.dylib

Create an .env

Create a .env file and add the OpenMP path as an environment variable, as shown below.

DYLD_LIBRARY_PATH=".venv/lib/python3.<PYVERSION>/site-packages/torch/lib"

Run uv

Pass the following --env-file options when running uv run.

uv run --env-file /path/to/.env ... python your_script.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions