Has anyone had this issue with batch GPU ```OSErro...
# ask-metaflow
c
Has anyone had this issue with batch GPU
Copy code
OSError: libcufft.so.11: cannot open shared object file: No such file or directory

and 

ValueError: libcublas.so.[0-9] not found in the system path ['/metaflow', '/metaflow/_escape_trampolines',
Built an environment using the pypi extension. Batch correctly spins up a
g4dn.2xlarge
and things start running. I figure I'm not passing a env variable or something to get cuda installed. Full text in the thread
Copy code
<flow InferenceFlow step slide_point_geometry[0] (input: <s3://mike-test-slide>...)> failed:
    Internal error
Traceback (most recent call last):
  File "/root/micromamba/envs/metaflow_cf9f3ba0982ee4b13002093a7ad13beca8fbc2b6_6898fdd74b61fb799616abbb003f559709fcf2b1/lib/python3.11/site-packages/torch/__init__.py", line 174, in _load_global_deps
    ctypes.CDLL(lib_path, mode=ctypes.RTLD_GLOBAL)
  File "/root/micromamba/envs/metaflow_cf9f3ba0982ee4b13002093a7ad13beca8fbc2b6_6898fdd74b61fb799616abbb003f559709fcf2b1/lib/python3.11/ctypes/__init__.py", line 376, in __init__
    self._handle = _dlopen(self._name, mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: libcufft.so.11: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/metaflow/metaflow/cli.py", line 1177, in main
    start(auto_envvar_prefix="METAFLOW", obj=state)
  File "/metaflow/metaflow/tracing/__init__.py", line 27, in wrapper_func
    return func(args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/metaflow/metaflow/_vendor/click/core.py", line 829, in __call__
    return self.main(args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/metaflow/metaflow/_vendor/click/core.py", line 782, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/metaflow/metaflow/_vendor/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/metaflow/metaflow/_vendor/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/metaflow/metaflow/_vendor/click/core.py", line 610, in invoke
    return callback(args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/metaflow/metaflow/_vendor/click/decorators.py", line 21, in new_func
    return f(get_current_context(), args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/metaflow/metaflow/cli.py", line 572, in step
    task.run_step(
  File "/metaflow/metaflow/task.py", line 619, in run_step
    self._exec_step_function(step_func)
  File "/metaflow/metaflow/task.py", line 70, in _exec_step_function
    step_function()
  File "/metaflow/infer.py", line 100, in slide_point_geometry
    from eru.models import point_geometries
  File "/metaflow/eru/models/__init__.py", line 1, in <module>
    from .model_config import ModelConfig
  File "/metaflow/eru/models/model_config.py", line 1, in <module>
    from .. import constants
  File "/metaflow/eru/constants.py", line 10, in <module>
    from .utils.collate import default_collate, default_collate_fn_map
  File "/metaflow/eru/utils/collate.py", line 13, in <module>
    import torch
  File "/root/micromamba/envs/metaflow_cf9f3ba0982ee4b13002093a7ad13beca8fbc2b6_6898fdd74b61fb799616abbb003f559709fcf2b1/lib/python3.11/site-packages/torch/__init__.py", line 234, in <module>
    _load_global_deps()
  File "/root/micromamba/envs/metaflow_cf9f3ba0982ee4b13002093a7ad13beca8fbc2b6_6898fdd74b61fb799616abbb003f559709fcf2b1/lib/python3.11/site-packages/torch/__init__.py", line 195, in _load_global_deps
    _preload_cuda_deps(lib_folder, lib_name)
  File "/root/micromamba/envs/metaflow_cf9f3ba0982ee4b13002093a7ad13beca8fbc2b6_6898fdd74b61fb799616abbb003f559709fcf2b1/lib/python3.11/site-packages/torch/__init__.py", line 160, in _preload_cuda_deps
    raise ValueError(f"{lib_name} not found in the system path {sys.path}")
ValueError: libcublas.so.[0-9] not found in the system path ['/metaflow', '/metaflow/_escape_trampolines', '/metaflow', '/root/micromamba/envs/metaflow_cf9f3ba0982ee4b13002093a7ad13beca8fbc2b6_6898fdd74b61fb799616abbb003f559709fcf2b1/lib/python311.zip', '/root/micromamba/envs/metaflow_cf9f3ba0982ee4b13002093a7ad13beca8fbc2b6_6898fdd74b61fb799616abbb003f559709fcf2b1/lib/python3.11', '/root/micromamba/envs/metaflow_cf9f3ba0982ee4b13002093a7ad13beca8fbc2b6_6898fdd74b61fb799616abbb003f559709fcf2b1/lib/python3.11/lib-dynload', '/root/micromamba/envs/metaflow_cf9f3ba0982ee4b13002093a7ad13beca8fbc2b6_6898fdd74b61fb799616abbb003f559709fcf2b1/lib/python3.11/site-packages']

    AWS Batch error:
    Essential container in task exited This could be a transient error. Use @retry to retry.

Task failed.
d
that’s interesting. I think the issue is the libcufft first. Can you do
metaflow environment show cf9f3ba0982ee4b13002093a7ad13beca8fbc2b6:6898fdd74b61fb799616abbb003f559709fcf2b1
we do have this:
Copy code
"export PYTHONPATH=$(pwd)/_escape_trampolines:$(printenv PYTHONPATH)",
                # NOTE: Assumes here that remote nodes are Linux
                "if [[ -n $(printenv LD_LIBRARY_PATH) ]]; then "
                "export MF_ORIG_LD_LIBRARY_PATH=$(printenv LD_LIBRARY_PATH); "
                "export LD_LIBRARY_PATH=$(cat _env_path)/lib:$(printenv LD_LIBRARY_PATH); fi",
                "echo 'Environment bootstrapped.'",
you know, looking at this, I wonder if I need to move the
fi
up a line.
To try this out, could you add a
@environment
decorator to pass in
LD_LIBRARY_PATH
(give it any value such as /tmp or whatever, as long as it is not empty)
I don’t think we ran into issues before since we typically have something in LD_LIBRARY_PATH.
c
for the
metaflow environment show
it says this
(arch 'osx-arm64') was not found
I am on a mac is there a way to say linux-arch64?
d
Yes. Add
—arch linux-64
👍 1
c
Copy code
Environment of type pypi-only full hash 415ade6fd757673e25f3e20fafb9da127555b283:207feaeca8b05caa0fcd452d9d86a79c7cb62bfc
Arch linux-64
Available on linux-64

Resolved on 2024-03-26 13:58:59.118495
Resolved by mikebentleymills

User-requested packages sys::__glibc==2.27, pypi::albumentations==1.3.1, pypi::attrs==23.2, pypi::boto3==>=1.14.0, pypi::dask==2023.3.2, pypi::einops==0.7, pypi::geopandas==0.14.3, pypi::git+<https://github.com/Bayer-Group/tiffslide.git@v2.3.1#egg=tiffslide>, pypi::git+<https://github.com/mbr/asciitree.git@0.3.3#egg=asciitree>, pypi::git+<https://github.com/nalepae/pandarallel.git@v1.6.5#egg=pandarallel>, pypi::git+<https://github.com/valarlabs/xarray.git@main#egg=xarray>, pypi::matplotlib==3.8.2, pypi::numpy==1.26.3, pypi::omegaconf, pypi::opencv-python-headless==4.8.0.74, pypi::pandas==2.2, pypi::plotly==5.18, pypi::python-dotenv==1.0.1, conda::python==3.11.7, pypi::rasterio==1.3.9, pypi::requests==>=2.21.0, pypi::rich==13.7, pypi::s3fs==2023.12.2, pypi::timm==0.9.12, pypi::torch==2.1.1, pypi::torchmetrics, pypi::torchvision, pypi::tqdm==4.66.1, pypi::typing_extensions==4.9
User sources conda::conda-forge, pypi::<https://pypi.org/simple>

Conda Packages installed _libgcc_mutex==0.1-conda_forge, _openmp_mutex==4.5-2_gnu, bzip2==1.0.8-hd590300_5, ca-certificates==2024.2.2-hbcca054_0, ld_impl_linux-64==2.40-h41732ed_0, libexpat==2.6.2-h59595ed_0, libffi==3.4.2-h7f98852_5, libgcc-ng==13.2.0-h807b86a_5, libgomp==13.2.0-h807b86a_5, libnsl==2.0.1-hd590300_0, libsqlite==3.45.2-h2797004_0, libuuid==2.38.1-h0b41bf4_0, libxcrypt==4.4.36-hd590300_1, libzlib==1.2.13-hd590300_5, ncurses==6.4.20240210-h59595ed_0, openssl==3.2.1-hd590300_1, pip==24.0-pyhd8ed1ab_0, python==3.11.7-hab00c5b_1_cpython, readline==8.2-h8228510_1, setuptools==69.2.0-pyhd8ed1ab_0, tk==8.6.13-noxft_h4845f30_101, tomli==2.0.1-pyhd8ed1ab_0, tzdata==2024a-h0c530f3_0, wheel==0.42.0-pyhd8ed1ab_0, xz==5.2.6-h166bdaf_0
Pypi Packages installed affine==2.4.0, aiobotocore==2.12.1, aiohttp==3.9.3, aioitertools==0.11.0, aiosignal==1.3.1, albumentations==1.3.1, asciitree==0.3.3.dev2303882+mfbuild, attrs==23.2.0, boto3==1.34.51, botocore==1.34.51, certifi==2024.2.2, charset-normalizer==3.3.2, click==8.1.7, click-plugins==1.1.1, cligj==0.7.2, cloudpickle==3.0.0, contourpy==1.2.0, cycler==0.12.1, dask==2023.3.2, dill==0.3.8, einops==0.7.0, fasteners==0.19, filelock==3.13.3, fiona==1.9.6, fonttools==4.50.0, frozenlist==1.4.1, fsspec==2023.12.2, geopandas==0.14.3, huggingface-hub==0.22.1, idna==3.6, imagecodecs==2024.1.1, imageio==2.34.0, importlib-metadata==7.1.0, jinja2==3.1.3, jmespath==1.0.1, joblib==1.3.2, kiwisolver==1.4.5, lazy-loader==0.3, lightning-utilities==0.11.1, locket==1.0.0, markdown-it-py==3.0.0, markupsafe==2.1.5, matplotlib==3.8.2, mdurl==0.1.2, mpmath==1.3.0, multidict==6.0.5, networkx==3.2.1, numcodecs==0.12.1, numpy==1.26.3, omegaconf==2.0.6, opencv-python-headless==4.8.0.74, packaging==24.0, pandarallel==1.6.5.dev42471059+mfbuild, pandas==2.2.0, partd==1.4.1, pillow==10.2.0, plotly==5.18.0, psutil==5.9.8, pygments==2.17.2, pyparsing==3.1.2, pyproj==3.6.1, python-dateutil==2.9.0.post0, python-dotenv==1.0.1, pytz==2024.1, pyyaml==6.0.1, qudida==0.0.4, rasterio==1.3.9, requests==2.31.0, rich==13.7.0, s3fs==2023.12.2, s3transfer==0.10.1, safetensors==0.4.2, scikit-image==0.22.0, scikit-learn==1.4.1.post1, scipy==1.12.0, setuptools==69.2.0, shapely==2.0.3, six==1.16.0, snuggs==1.4.7, sympy==1.12, tenacity==8.2.3, threadpoolctl==3.4.0, tifffile==2024.2.12, tiffslide==2.3.1.dev1221221+mfbuild, timm==0.9.12, toolz==0.12.1, torch==2.1.1, torchmetrics==1.3.2, torchvision==0.16.1, tqdm==4.66.1, typing-extensions==4.9.0, tzdata==2024.1, urllib3==2.0.7, wrapt==1.16.0, xarray==2023.5.0.dev95331661+mfbuild, yarl==1.9.4, zarr==2.17.1, zipp==3.18.1
I ran the flow with
Copy code
@environment(
        vars={
            "LD_LIBRARY_PATH": "/tmp"
})
I also have the step printing out the environment. See attached output. I've been searching for the /usr/local/cuda directory but it doesn't seem to exist. Even though the AMI running is a GPU one.
d
ok, so it got further (bug on my end — noted). Could you try specifying the pypi index using
extra_indices
and adding https://download.pytorch.org/whl/cu118 ?
else we can try the combo of conda and pypi packages but that uses conda-lock to resolve and may not work as well with the git packages (I have to check that — poetry has issues with some packages that way)
c
Giving it a try now.
Copy code
@pypi(python=PYTHON_VERSION, packages=PACKAGES, extra_indices=["<https://download.pytorch.org/whl/cu118>"])
This is what I added is that correct? It had the same error
I've blown away the cached envs and am rebuilding them. Also should I leave the
"LD_LIBRARY_PATH": "/tmp"
entry or remove it too?
I think that adding the
extra_indices=["<https://download.pytorch.org/whl/cu118>"]
has fixed the issue.
Copy code
@pypi(python=PYTHON_VERSION, packages=PACKAGES, extra_indices=["<https://download.pytorch.org/whl/cu118>"])`
At least the issue I'm seeing now is in my own code 🙂
d
yeah 🙂
and yes, you probably still need the LD_LIBRARY_PATH part
glad I could get you unblocked. I’ll fix that small bug so you don’t have to specify the LD_LIBRARY_PATH.
c
Thank you so much really really appreciate the help.
d
sure np. For my own education, when it didn’t work with the extra_indices was it because you didn’t have the LD_LIBRARY_PATH ? (as in, I would expect it to always work with both those things regardless of blowing away the cache but I would not expect it to work if any of those two settings are not set)
c
I think I needed to delete the cached envs.
Let me run it again to confirm
Ok I'm not sure what happened. This is with the environment
"LD_LIBRARY_PATH": "/tmp",
So I don't get the missing error anymore but pytorch can't see cuda.
Copy code
import torch

if torch.cuda.is_available():
    print("CUDA is available")
else:
    print("CUDA is not available")
Trying it without
"LD_LIBRARY_PATH": "/tmp",
Same result no cuda available.
d
so doesn’t work rn right?
c
Right
Copy code
def run_nvidia_smi(query):
            """
            Run the nvidia-smi command with the specified query and return the output.
            """
            cmd = ["nvidia-smi", "--query-gpu={}".format(query), "--format=csv,noheader,nounits"]
            output = subprocess.check_output(cmd).decode("utf-8")
            return output

        # Get GPU names
        gpu_names = run_nvidia_smi("name")
        print("GPU Names:")
        print(gpu_names)
This code when run in the batch step shows a GPU
Tesla T4
So I asked torch how many cuda devices.
Copy code
print(f"Found {device_count} CUDA devices")
        for i in range(device_count):
            device_name = torch.cuda.get_device_name(i)
            print(f"Device {i}: {device_name}")
And it gave me this error
Copy code
RuntimeError: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from <http://www.nvidia.com/Download/index.aspx>
Ok this now appears to work.
Copy code
@environment(
        vars={
            "LD_LIBRARY_PATH": "/tmp",
            "NVIDIA_DRIVER_CAPABILITIES": "compute,utility",
        }
    )
d
I didn’t know about that last NVIDIA_DRIVER_CAPABILITIES thing
I appreciate our compute team more 🙂
🙏 1