getkeops / keops

KErnel OPerationS, on CPUs and GPUs, with autodiff and without memory overflows
https://www.kernel-operations.io
MIT License
1.03k stars 65 forks source link

cant import test_torch_bindings #295

Closed hududed closed 1 year ago

hududed commented 1 year ago

I am trying to run a notebook on a hpc cluster from a conda environment with a fresh install of pytorch and pykeops library. Torch found my GPU find but get the error when importing:

import torch
torch.cuda.get_device_name()
'Tesla P100-PCIE-16GB'

from pykeops import test_torch_bindings
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[22], line 1
----> 1 from pykeops import test_torch_bindings

ImportError: cannot import name 'test_torch_bindings' from 'pykeops' (/home/hwahab/.conda/envs/synth/lib/python3.10/site-packages/pykeops/__init__.py)

I am guessing somehow it's not detecting the cuda device. How to troubleshoot?

bcharlier commented 1 year ago

Hi @hududed ,

Your import are wrong: should be

import pykeops pykeops.test_torch_bindings()

Hope it will work.

hududed commented 1 year ago

@bcharlier

hm I am getting the following error:

import pykeops
pykeops.test_torch_bindings()
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[11], line 2
      1 import pykeops
----> 2 pykeops.test_torch_bindings()

File ~/.pyenv/versions/3.10.0/lib/python3.10/site-packages/pykeops/torch/test_install.py:21, in test_torch_bindings()
     17 import pykeops.torch as pktorch
     19 my_conv = pktorch.Genred(formula, var)
     20 if torch.allclose(
---> 21     my_conv(x, y).view(-1), torch.tensor(expected_res).type(torch.float32)
     22 ):
     23     pyKeOps_Message("pyKeOps with torch bindings is working!", use_tag=False)
     24 else:

File ~/.pyenv/versions/3.10.0/lib/python3.10/site-packages/pykeops/torch/generic/generic_red.py:627, in Genred.__call__(self, backend, device_id, ranges, out, *args)
    622     elif nred > 2048 and dtype in ("float16", "half"):
    623         raise ValueError(
    624             "size of input array is too large for Arg type reduction with float16 dtype.."
    625         )
--> 627 out = GenredAutograd.apply(
    628     self.formula,
    629     self.aliases,
    630     backend,
    631     dtype,
    632     device_id,
    633     ranges,
    634     self.optional_flags,
    635     self.rec_multVar_highdim,
    636     nx,
    637     ny,
    638     out,
    639     *args
    640 )
    642 return postprocess(out, "torch", self.reduction_op, nout, self.opt_arg, dtype)

File ~/.pyenv/versions/3.10.0/lib/python3.10/site-packages/pykeops/torch/generic/generic_red.py:78, in GenredAutograd.forward(ctx, formula, aliases, backend, dtype, device_id_request, ranges, optional_flags, rec_multVar_highdim, nx, ny, out, *args)
     72             raise ValueError(
     73                 "[KeOps] Gpu device id of arrays is different from device id requested for computation."
     74             )
     76 from pykeops.common.keops_io import keops_binder
---> 78 myconv = keops_binder["nvrtc" if tagCPUGPU else "cpp"](
     79     tagCPUGPU,
     80     tag1D2D,
     81     tagHostDevice,
...
     90 ).import_module()
     92 # Context variables: save everything to compute the gradient:
     93 ctx.formula = formula

KeyError: 'nvrtc'
bcharlier commented 1 year ago

you need to install nvrtc which is usually shipped with cuda in your distro package system...