Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac support #64

Open
albertgong1 opened this issue Sep 19, 2023 · 2 comments
Open

Mac support #64

albertgong1 opened this issue Sep 19, 2023 · 2 comments

Comments

@albertgong1
Copy link

I tried installing falkon on a MacBook Pro 14 (M2 Pro) from source. It installs without any error, but during runtime, I run into the following error (see call stack) when running fit(). Is support for Mac planned?

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
[/Users/ag2435/repos/falkon/notebooks/FalkonRegression.ipynb](https://file+.vscode-resource.vscode-cdn.net/Users/ag2435/repos/falkon/notebooks/FalkonRegression.ipynb) Cell 11 line 1
----> [1](vscode-notebook-cell:/Users/ag2435/repos/falkon/notebooks/FalkonRegression.ipynb#X13sZmlsZQ%3D%3D?line=0) model.fit(Xtr, Ytr)

File [~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/models/falkon.py:229](https://file+.vscode-resource.vscode-cdn.net/Users/ag2435/repos/falkon/notebooks/~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/models/falkon.py:229), in Falkon.fit(self, X, Y, Xts, Yts, warm_start)
    227     if self.weight_fn is not None:
    228         ny_weight_vec = self.weight_fn(Y[ny_indices], X[ny_indices], ny_indices)
--> 229     precond.init(ny_points, weight_vec=ny_weight_vec)
    231 if _use_cuda_mmv:
    232     # Cache must be emptied to ensure enough memory is visible to the optimizer
    233     torch.cuda.empty_cache()

File [~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/preconditioner/flk_preconditioner.py:101](https://file+.vscode-resource.vscode-cdn.net/Users/ag2435/repos/falkon/notebooks/~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/preconditioner/flk_preconditioner.py:101), in FalkonPreconditioner.init(self, X, weight_vec)
     99     else:  # If sparse tensor we need fortran for kernel calculation
    100         C = create_fortran((M, M), dtype=dtype, device=dev, pin_memory=self._use_cuda)
--> 101     self.kernel(X, X, out=C, opt=self.params)
    102 if not is_f_contig(C):
    103     C = C.T

File [~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/kernels/kernel.py:173](https://file+.vscode-resource.vscode-cdn.net/Users/ag2435/repos/falkon/notebooks/~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/kernels/kernel.py:173), in Kernel.__call__(self, X1, X2, diag, out, opt)
    171     params = dataclasses.replace(self.params, **dataclasses.asdict(opt))
    172 mm_impl = self._decide_mm_impl(X1, X2, diag, params)
--> 173 return mm_impl(self, params, out, diag, X1, X2)

File [~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/mmv_ops/fmm.py:554](https://file+.vscode-resource.vscode-cdn.net/Users/ag2435/repos/falkon/notebooks/~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/mmv_ops/fmm.py:554), in fmm(kernel, opt, out, diag, X1, X2)
    551 import falkon.kernels
    553 if isinstance(kernel, falkon.kernels.DiffKernel):
--> 554     return KernelMmFnFull.apply(kernel, opt, out, diag, X1, X2, *kernel.diff_params.values())
    555 else:
    556     return KernelMmFnFull.apply(kernel, opt, out, diag, X1, X2)

File [~/anaconda3/envs/falkon/lib/python3.10/site-packages/torch/autograd/function.py:506](https://file+.vscode-resource.vscode-cdn.net/Users/ag2435/repos/falkon/notebooks/~/anaconda3/envs/falkon/lib/python3.10/site-packages/torch/autograd/function.py:506), in Function.apply(cls, *args, **kwargs)
    503 if not torch._C._are_functorch_transforms_active():
    504     # See NOTE: [functorch vjp and autograd interaction]
    505     args = _functorch.utils.unwrap_dead_wrappers(args)
--> 506     return super().apply(*args, **kwargs)  # type: ignore[misc]
    508 if cls.setup_context == _SingleLevelFunction.setup_context:
    509     raise RuntimeError(
    510         'In order to use an autograd.Function with functorch transforms '
    511         '(vmap, grad, jvp, jacrev, ...), it must override the setup_context '
    512         'staticmethod. For more details, please see '
    513         'https://pytorch.org/docs/master/notes/extending.func.html')

File [~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/mmv_ops/fmm.py:480](https://file+.vscode-resource.vscode-cdn.net/Users/ag2435/repos/falkon/notebooks/~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/mmv_ops/fmm.py:480), in KernelMmFnFull.forward(ctx, kernel, opt, out, diag, X1, X2, *kernel_params)
    478     out = KernelMmFnFull.run_diag(X1, X2, out, kernel, False, is_sparse)
    479 elif comp_dev_type == "cpu" and data_dev.type == "cpu":
--> 480     out = KernelMmFnFull.run_cpu_cpu(X1, X2, out, kernel, comp_dtype, opt, False)
    481 elif comp_dev_type == "cuda" and data_dev.type == "cuda":
    482     out = KernelMmFnFull.run_gpu_gpu(X1, X2, out, kernel, comp_dtype, opt, False)

File [~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/mmv_ops/fmm.py:354](https://file+.vscode-resource.vscode-cdn.net/Users/ag2435/repos/falkon/notebooks/~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/mmv_ops/fmm.py:354), in KernelMmFnFull.run_cpu_cpu(X1, X2, out, kernel, dtype, options, diff)
    342 @staticmethod
    343 def run_cpu_cpu(X1, X2, out, kernel, dtype, options, diff):
    344     args = ArgsFmm(
    345         X1=X1,
    346         X2=X2,
   (...)
    352         differentiable=diff,
    353     )
--> 354     out = _call_direct(mm_run_starter, (args, -1))
    355     return out

File [~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/mmv_ops/utils.py:86](https://file+.vscode-resource.vscode-cdn.net/Users/ag2435/repos/falkon/notebooks/~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/mmv_ops/utils.py:86), in _call_direct(target, arg)
     84 args_queue.put(arg[0])
     85 new_args_tuple = (-1, args_queue, arg[1])
---> 86 return target(*new_args_tuple)

File [~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/mmv_ops/fmm.py:131](https://file+.vscode-resource.vscode-cdn.net/Users/ag2435/repos/falkon/notebooks/~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/mmv_ops/fmm.py:131), in mm_run_starter(proc_idx, queue, device_id)
    129     return sparse_mm_run_thread(X1, X2, out, kernel, n, m, computation_dtype, dev, tid=proc_idx)
    130 else:
--> 131     return mm_run_thread(X1, X2, out, kernel, n, m, computation_dtype, dev, tid=proc_idx)

File [~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/mmv_ops/fmm.py:291](https://file+.vscode-resource.vscode-cdn.net/Users/ag2435/repos/falkon/notebooks/~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/mmv_ops/fmm.py:291), in mm_run_thread(m1, m2, out, kernel, n, m, comp_dt, dev, tid)
    288 c_dev_out.fill_(0.0)
    290 # Compute kernel sub-matrix
--> 291 kernel.compute(c_dev_m1, c_dev_m2, c_dev_out, diag=False)
    293 # Copy back to host
    294 if has_gpu_bufs:

File [~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/kernels/diff_kernel.py:91](https://file+.vscode-resource.vscode-cdn.net/Users/ag2435/repos/falkon/notebooks/~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/kernels/diff_kernel.py:91), in DiffKernel.compute(self, X1, X2, out, diag)
     90 def compute(self, X1: torch.Tensor, X2: torch.Tensor, out: torch.Tensor, diag: bool):
---> 91     return self.core_fn(X1, X2, out, **self.diff_params, diag=diag, **self._other_params)

File [~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/kernels/distance_kernel.py:163](https://file+.vscode-resource.vscode-cdn.net/Users/ag2435/repos/falkon/notebooks/~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/kernels/distance_kernel.py:163), in rbf_core(mat1, mat2, out, diag, sigma)
    161 mat1_div_sig = mat1 [/](https://file+.vscode-resource.vscode-cdn.net/) sigma
    162 mat2_div_sig = mat2 [/](https://file+.vscode-resource.vscode-cdn.net/) sigma
--> 163 norm_sq_mat1 = square_norm(mat1_div_sig, -1, True)  # b*n*1 or n*1
    164 norm_sq_mat2 = square_norm(mat2_div_sig, -1, True)  # b*m*1 or m*1
    166 out = _sq_dist(mat1_div_sig, mat2_div_sig, norm_sq_mat1, norm_sq_mat2, out)

File [~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/la_helpers/wrapper.py:129](https://file+.vscode-resource.vscode-cdn.net/Users/ag2435/repos/falkon/notebooks/~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/la_helpers/wrapper.py:129), in square_norm(mat, dim, keepdim)
    128 def square_norm(mat: torch.Tensor, dim: int, keepdim: Optional[bool] = None) -> torch.Tensor:
--> 129     return c_ext.square_norm(mat, dim, keepdim)

File [~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/c_ext/__init__.py:15](https://file+.vscode-resource.vscode-cdn.net/Users/ag2435/repos/falkon/notebooks/~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/c_ext/__init__.py:15), in _make_lazy_cuda_func.<locals>.call_cuda(*args, **kwargs)
     14 def call_cuda(*args, **kwargs):
---> 15     from ._backend import _assert_has_ext
     17     _assert_has_ext()
     18     return getattr(torch.ops.falkon, name)(*args, **kwargs)

File [~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/c_ext/_backend.py:86](https://file+.vscode-resource.vscode-cdn.net/Users/ag2435/repos/falkon/notebooks/~/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/c_ext/_backend.py:86)
     84 lib_path = _get_extension_path("_C")
     85 try:
---> 86     torch.ops.load_library(lib_path)
     87 except OSError as e:
     88     # Hack: usually ld can't find torch_cuda_linalg.so which is in TORCH_LIB_PATH
     89     # if we load it first, then load_library will work.
     90     # TODO: This will only work on linux.
     91     if (missing_lib := lib_from_oserror(e)).startswith("libtorch_cuda_linalg"):

File [~/anaconda3/envs/falkon/lib/python3.10/site-packages/torch/_ops.py:643](https://file+.vscode-resource.vscode-cdn.net/Users/ag2435/repos/falkon/notebooks/~/anaconda3/envs/falkon/lib/python3.10/site-packages/torch/_ops.py:643), in _Ops.load_library(self, path)
    638 path = _utils_internal.resolve_library_path(path)
    639 with dl_open_guard():
    640     # Import the shared library into the process, thus running its
    641     # static (global) initialization code in order to register custom
    642     # operators with the JIT.
--> 643     ctypes.CDLL(path)
    644 self.loaded_libraries.add(path)

File [~/anaconda3/envs/falkon/lib/python3.10/ctypes/__init__.py:374](https://file+.vscode-resource.vscode-cdn.net/Users/ag2435/repos/falkon/notebooks/~/anaconda3/envs/falkon/lib/python3.10/ctypes/__init__.py:374), in CDLL.__init__(self, name, mode, handle, use_errno, use_last_error, winmode)
    371 self._FuncPtr = _FuncPtr
    373 if handle is None:
--> 374     self._handle = _dlopen(self._name, mode)
    375 else:
    376     self._handle = handle

OSError: dlopen(/Users/ag2435/anaconda3/envs/falkon/lib/python3.10/site-packages/falkon/c_ext/_C.so, 0x0006): symbol not found in flat namespace '__ZN2at6native14lapackCholeskyIdEEvciPT_iPi'
@Giodiro
Copy link
Contributor

Giodiro commented Sep 21, 2023

Hi @ag2435
I'm not sure what's up honestly! I'll try to find a mac to test on in the next couple of weeks (sorry for the long timeline).
In the meantime, what version of falkon and of pytorch are you using?

@albertgong1
Copy link
Author

I'm using the following versions:
falkon 0.8.4 pypi_0 pypi
pytorch 2.0.0 py3.10_0 pytorch

Thank you so much for looking into this!

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

No branches or pull requests

2 participants