FalkonML / falkon

Large-scale, multi-GPU capable, kernel solver
https://falkonml.github.io/falkon/
MIT License
181 stars 22 forks source link

FileExistsError: [Errno 17] File exists: '/root/.cache/pykeops-1.5-cpython-37//build-pybind11_template-libKeOps_template_660bc304e8' #39

Closed nickprock closed 2 years ago

nickprock commented 2 years ago

Hi, I tried to install falkon in Colab. The installation was successful but trying the KernelRidgeRegression demo I get an error on flk.fit().

[pyKeOps] Compiling libKeOpstorch0977e258bf in /root/.cache/pykeops-1.5-cpython-37:
       formula: Sum_Reduction(Exp(SqDist(x1 / g, x2 / g) * IntInv(-2)) * v,0)
       aliases: x1 = Vi(0,13); x2 = Vj(1,13); v = Vj(2,1); g = Pm(3,1); 
       dtype  : float64
... 

--------------------- MAKE DEBUG -----------------
Command '['cmake', '--build', '.', '--target', 'KeOps_formula', '--', 'VERBOSE=1']' returned non-zero exit status 2.

--------------------- ----------- -----------------
[pyKeOps] Compiling pybind11 template libKeOps_template_660bc304e8 in /root/.cache/pykeops-1.5-cpython-37 ... 

---------------------------------------------------------------------------

FileExistsError                           Traceback (most recent call last)

<ipython-input-12-be46bad2abb7> in <module>()
----> 1 flk.fit(Xtrain, Ytrain)

/usr/local/lib/python3.7/dist-packages/falkon/models/falkon.py in fit(self, X, Y, Xts, Yts, warm_start)
    261                 beta = optim.solve(
    262                     X, ny_points, Y, self.penalty, initial_solution=warm_start,
--> 263                     max_iter=self.maxiter, callback=validation_cback)
    264 
    265             self.alpha_ = precond.apply(beta)

/usr/local/lib/python3.7/dist-packages/falkon/optim/conjgrad.py in solve(self, X, M, Y, _lambda, initial_solution, max_iter, callback)
    306                 B = incore_fmmv(Knm, y_over_n, None, transpose=True, opt=self.params)
    307             else:
--> 308                 B = self.kernel.mmv(M, X, y_over_n, opt=self.params)
    309             B = self.preconditioner.apply_t(B)
    310 

/usr/local/lib/python3.7/dist-packages/falkon/kernels/kernel.py in mmv(self, X1, X2, v, out, opt)
    267             params = dataclasses.replace(self.params, **dataclasses.asdict(opt))
    268         mmv_impl = self._decide_mmv_impl(X1, X2, v, params)
--> 269         return mmv_impl(X1, X2, v, self, out, params)
    270 
    271     def _decide_mmv_impl(self,

/usr/local/lib/python3.7/dist-packages/falkon/kernels/distance_kernel.py in _keops_mmv_impl(self, X1, X2, v, kernel, out, opt)
    283         other_vars = [self.sigma.to(device=X1.device, dtype=X1.dtype)]
    284 
--> 285         return self.keops_mmv(X1, X2, v, out, formula, aliases, other_vars, opt)
    286 
    287     def extra_mem(self) -> Dict[str, float]:

/usr/local/lib/python3.7/dist-packages/falkon/kernels/keops_helpers.py in keops_mmv(self, X1, X2, v, out, formula, aliases, other_vars, opt)
     70         return run_keops_mmv(X1=X1, X2=X2, v=v, other_vars=other_vars,
     71                              out=out, formula=formula, aliases=aliases, axis=1,
---> 72                              reduction='Sum', opt=opt)
     73 
     74     def keops_dmmv_helper(self, X1, X2, v, w, kernel, out, differentiable, opt, mmv_fn):

/usr/local/lib/python3.7/dist-packages/falkon/mmv_ops/keops.py in run_keops_mmv(X1, X2, v, other_vars, out, formula, aliases, axis, reduction, opt)
    226     if comp_dev_type == 'cpu' and all([ddev.type == 'cpu' for ddev in data_devs]):  # incore CPU
    227         variables = [X1, X2, v] + other_vars
--> 228         out = fn(*variables, out=out, backend=backend)
    229     elif comp_dev_type == 'cuda' and all([ddev.type == 'cuda' for ddev in data_devs]):  # incore CUDA
    230         variables = [X1, X2, v] + other_vars

/usr/local/lib/python3.7/dist-packages/pykeops/torch/generic/generic_red.py in __call__(self, out, backend, device_id, ranges, *args)
    576             ny,
    577             out,
--> 578             *args
    579         )
    580         if self.dtype in ("float16", "half"):

/usr/local/lib/python3.7/dist-packages/pykeops/torch/generic/generic_red.py in forward(ctx, formula, aliases, backend, dtype, device_id, ranges, optional_flags, rec_multVar_highdim, nx, ny, out, *args)
     45             optional_flags += ['-DMULT_VAR_HIGHDIM=1']
     46         myconv = LoadKeOps(
---> 47             formula, aliases, dtype, "torch", optional_flags, include_dirs
     48         ).import_module()
     49 

/usr/local/lib/python3.7/dist-packages/pykeops/common/keops_io.py in __init__(self, formula, aliases, dtype, lang, optional_flags, include_dirs)
     46             pykeops.config.build_type == "Debug"
     47         ):
---> 48             self._safe_compile()
     49 
     50     @create_and_lock_build_folder()

/usr/local/lib/python3.7/dist-packages/pykeops/common/utils.py in wrapper_filelock(*args, **kwargs)
     75             lock = FileLock(os.path.join(bf, "pykeops_build2.lock"))
     76             with lock:
---> 77                 func_res = func(*args, **kwargs)
     78 
     79             # clean

/usr/local/lib/python3.7/dist-packages/pykeops/common/keops_io.py in _safe_compile(self)
     61             self.optional_flags,
     62             self.include_dirs,
---> 63             self.build_folder,
     64         )
     65 

/usr/local/lib/python3.7/dist-packages/pykeops/common/compile_routines.py in compile_generic_routine(formula, aliases, dllname, dtype, lang, optional_flags, include_dirs, build_folder)
    244 
    245     template_name, is_rebuilt = get_or_build_pybind11_template(
--> 246         dtype, lang, include_dirs, use_prebuilt_formula=True
    247     )
    248 

/usr/local/lib/python3.7/dist-packages/pykeops/common/compile_routines.py in get_or_build_pybind11_template(dtype, lang, include_dirs, use_prebuilt_formula)
     65         # print('(with dtype=',dtype,', lang=',lang,', include_dirs=',include_dirs,')', flush=True)
     66 
---> 67         os.mkdir(template_build_folder)
     68 
     69         command_line += ["-Dtemplate_name=" + "'{}'".format(template_name)]

FileExistsError: [Errno 17] File exists: '/root/.cache/pykeops-1.5-cpython-37//build-pybind11_template-libKeOps_template_660bc304e8'
Giodiro commented 2 years ago

Hi @nickprock ,

You should try to install keops using the colab option,

have a look at this web-page: https://www.kernel-operations.io/keops/python/installation.html

In particular you can try

!pip install pykeops[colab] > install.log

Then you should clear the keops cache, and try again:

import pykeops
pykeops.clean_pykeops()          # just in case old build files are still present
pykeops.test_torch_bindings()    # perform the compilation

Let me know if you have further issues!

nickprock commented 2 years ago

Thanks @Giodiro, now it works.

nickprock commented 2 years ago

Hi @Giodiro, I have submitted a PR with an example Colab. Falkon is very interesting, I hope to be able to use it and maybe contribute in the future. Congratulations to the team!