Skip to content

deepmd: preload the mpich wheel's libfabric before importing deepmd - #226

Merged
OwenPriceSkelly merged 1 commit into
mainfrom
deepmd-libfabric
Sep 4, 2026
Merged

deepmd: preload the mpich wheel's libfabric before importing deepmd#226
OwenPriceSkelly merged 1 commit into
mainfrom
deepmd-libfabric

Conversation

@OwenPriceSkelly

Copy link
Copy Markdown
Member

Problem

First Delta sync of the deepmd env (#225, 2026-09-04): the build succeeded, then every download failed with

error: download failed: OSError: /opt/cray/libfabric/2.3.1/lib64/libfabric.so.1: version `FABRIC_1.9' not found (required by /work/hdd/data/rootstock/envs/deepmd/lib/python3.11/site-packages/../../libmpi.so.12)

Cause

deepmd.pt imports deepmd/pt/cxx_op.py, which on cibuildwheel builds calls load_mpi_library(): a ctypes.CDLL of the mpich wheel's libmpi.so.12 (the custom-op library links MPI for the LAMMPS plugin's border op). That libmpi is built against the libfabric the wheel bundles in lib/mpich/libfabric.so.1, reached via RUNPATH. On Cray systems the module environment puts /opt/cray/libfabric/<ver>/lib64 on LD_LIBRARY_PATH, which the dynamic linker consults before RUNPATH, so the Cray build is picked and it does not export FABRIC_1.9. Rootstock's own LD_LIBRARY_PATH prepend covers <venv>/lib (where libmpi is) but not <venv>/lib/mpich.

Fix

setup() / setup_from_path() now locate the bundled libfabric through importlib.metadata.files("mpich") (same lookup deepmd uses for libmpi, with a sys.prefix/lib/mpich fallback) and ctypes.CDLL(..., RTLD_GLOBAL) it before the first deepmd import. A library already loaded under the soname libfabric.so.1 is reused when libmpi asks for it, so the Cray copy is never opened. No-op when mpich ships no libfabric. Not Delta-specific: Perlmutter, Frontier, Polaris and Aurora all run Cray PE.

Documented in the env docstring as a technical constraint. Two tests added (preload path + RTLD_GLOBAL; skip when absent). uv run pytest tests/sample_configs: 154 passed.

🤖 Generated with Claude Code

deepmd-kit's PyTorch backend preloads libmpi.so.12 from the mpich wheel at
import. That libmpi needs the libfabric bundled under lib/mpich/ (symbol
version FABRIC_1.9). On Cray systems LD_LIBRARY_PATH carries the system
libfabric, which outranks the wheel's RUNPATH and lacks that version, so
every setup() died on Delta with:

    OSError: /opt/cray/libfabric/2.3.1/lib64/libfabric.so.1: version
    `FABRIC_1.9' not found (required by .../libmpi.so.12)

Load the bundled libfabric by absolute path (RTLD_GLOBAL) before the first
deepmd import; the dynamic linker then reuses it when libmpi asks for
libfabric.so.1. No-op when mpich ships none.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@OwenPriceSkelly
OwenPriceSkelly merged commit 627d55b into main Sep 4, 2026
5 checks passed
@OwenPriceSkelly
OwenPriceSkelly deleted the deepmd-libfabric branch September 4, 2026 19:45
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

Successfully merging this pull request may close these issues.

1 participant