{"id":21756,"library":"pykeops","title":"pykeops","description":"PyKeOps is a Python package providing bindings to the KeOps library, which enables efficient computation of kernel operations on CPUs and GPUs with automatic differentiation and without memory overflows. It is widely used in geometry processing, shape analysis, and machine learning for large-scale distance and kernel computations. Current version is 2.3, with active development on GitHub.","status":"active","version":"2.3","language":"python","source_language":"en","source_url":"https://github.com/getkeops/keops","tags":["kernel operations","gpu","autodiff","pairwise distances","geometry processing"],"install":[{"cmd":"pip install pykeops","lang":"bash","label":"PyPI"}],"dependencies":[{"reason":"PyKeOps integrates with PyTorch for tensor operations and autograd.","package":"torch","optional":false}],"imports":[{"note":"LazyTensor is in the torch submodule; importing directly from pykeops fails.","wrong":"from pykeops import LazyTensor","symbol":"LazyTensor","correct":"from pykeops.torch import LazyTensor"},{"note":"Genred is the correct spelling, lowercase genred does not exist.","wrong":"from pykeops import genred","symbol":"genred","correct":"from pykeops.torch import Genred"}],"quickstart":{"code":"import torch\nfrom pykeops.torch import LazyTensor\n\n# Create sample data\nx = torch.randn(1000, 3).cuda()\ny = torch.randn(2000, 3).cuda()\n\n# Define LazyTensors\nX = LazyTensor(x[:, None, :])  # (1000, 1, 3)\nY = LazyTensor(y[None, :, :])  # (1, 2000, 3)\n\n# Compute pairwise distances squared\nD = ((X - Y) ** 2).sum(2)  # Symbolic reduction\n\n# Compute softmin (log-sum-exp) with Gaussian kernel\nK = (-D).exp()\nresult = K.sum(1)  # (1000,) actually returns a LazyTensor, evaluate with .detach()\nprint(result.detach())","lang":"python","description":"Compute pairwise Gaussian kernel sum using LazyTensors for memory-efficient reduction."},"warnings":[{"fix":"Migrate to LazyTensor-based API: replace generic reductions with symbolic expressions.","message":"PyKeOps 2.0 introduced a completely reworked compilation engine. Old code using from pykeops.torch import generic_logsumexp or similar may not work. Update to LazyTensor API.","severity":"breaking","affected_versions":"<2.0"},{"fix":"Call .eval() on the final LazyTensor or use reduction operations that return tensors (some like .sum() still return LazyTensor).","message":"LazyTensor operations must be explicitly evaluated (e.g., .eval(), .detach(), or .sum() returns a LazyTensor, not a torch.Tensor). Forgetting evaluation leads to symbolic objects in the result.","severity":"gotcha","affected_versions":"all"},{"fix":"Use LazyTensor or Genred for custom formulas.","message":"The old API using pykeops.torch.generic_sum, generic_logsumexp, etc. is deprecated in 2.x and may be removed. Use LazyTensor or Genred instead.","severity":"deprecated","affected_versions":">=2.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Reinstall pykeops with environment variable KEOPS_GPU_ARCH set to your GPU architecture, e.g., KEOPS_GPU_ARCH=sm_86 pip install pykeops --no-cache-dir","cause":"The precompiled CUDA binaries do not support your GPU architecture (e.g., too old or too new).","error":"RuntimeError: KeOps CUDA error: no kernel image is available for execution on the device"},{"fix":"Use: from pykeops.torch import LazyTensor","cause":"Importing from wrong module; LazyTensor is in pykeops.torch, not pykeops.","error":"ImportError: cannot import name 'LazyTensor' from 'pykeops'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}