Registry / ai-ml / gpytorch

gpytorch

JSON →
library1.15.2pypypi✓ verified 22d ago

GPyTorch is a Gaussian Process (GP) library built on PyTorch, designed for scalable, flexible, and modular GP models. It leverages PyTorch's capabilities for GPU acceleration and automatic differentiation, making it suitable for modern machine learning workflows. GPyTorch frequently releases maintenance updates and new features, with major versions aligning with PyTorch releases.

pip install gpytorch
INSTALL
IMPORT
SIG · GPYTORCH
G
gpytorch
ai-mlpythonv1.15.2
Install
74.2s avg
Import
6345ms
Disk
4992MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.15.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 86.4s
py 3.11
✕ build_error
✓ 77.7s
py 3.12
✕ build_error
✓ 65.6s
py 3.13
✕ build_error
✓ 67s
py 3.9
✕ build_error
✕ timeout
4992MB installed
● package 4992MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

gpytorch
import gpytorch
ExactGP
from gpytorch.models import ExactGP
GaussianLikelihood
from gpytorch.likelihoods import GaussianLikelihood
ConstantMean
from gpytorch.means import ConstantMean
ScaleKernel
from gpytorch.kernels import ScaleKernel
RBFKernel
from gpytorch.kernels import RBFKernel
MultivariateNormal
from gpytorch.distributions import MultivariateNormal
from gpytorch.random_variables import GaussianRandomVariable
gpytorch.random_variables was deprecated and replaced by gpytorch.distributions in early versions.

This quickstart demonstrates a simple exact Gaussian Process regression. It defines a GP model, a Gaussian likelihood, trains the model using the marginal log likelihood, and then makes predictions including confidence intervals.

import math import torch import gpytorch from gpytorch.models import ExactGP from gpytorch.likelihoods import GaussianLikelihood from gpytorch.means import ConstantMean from gpytorch.kernels import ScaleKernel, RBFKernel from gpytorch.distributions import MultivariateNormal from torch.optim import Adam # 1. Set up training data train_x = torch.linspace(0, 1, 100) train_y = torch.sin(train_x * (2 * math.pi)) + torch.randn(train_x.size()) * math.sqrt(0.04) # 2. Define the GP model class ExactGPModel(ExactGP): def __init__(self, train_x, train_y, likelihood): super(ExactGPModel, self).__init__(train_x, train_y, likelihood) self.mean_module = ConstantMean() self.covar_module = ScaleKernel(RBFKernel()) def forward(self, x): mean_x = self.mean_module(x) covar_x = self.covar_module(x) return MultivariateNormal(mean_x, covar_x) # Initialize likelihood and model likelihood = GaussianLikelihood() model = ExactGPModel(train_x, train_y, likelihood) # 3. Train the model # Put model and likelihood in training mode model.train() likelihood.train() # Use the Adam optimizer optimizer = Adam(model.parameters(), lr=0.1) # "Loss" for GPs - the marginal log likelihood mll = gpytorch.mlls.ExactMarginalLogLikelihood(likelihood, model) for i in range(50): # typically 50 training iterations optimizer.zero_grad() output = model(train_x) loss = -mll(output, train_y) loss.backward() optimizer.step() # 4. Make predictions model.eval() likelihood.eval() with torch.no_grad(), gpytorch.settings.fast_pred_var(): test_x = torch.linspace(0, 1, 51) observed_pred = likelihood(model(test_x)) mean = observed_pred.mean lower, upper = observed_pred.confidence_region()
Debug
Known issues
breakingGPyTorch versions 1.14 and later require Python >= 3.10 and PyTorch >= 2.0. Attempting to install or run with older versions will lead to incompatibility issues.
fix
Ensure your Python environment is 3.10+ and PyTorch is 2.0+ before installing GPyTorch >= 1.14. You can check PyTorch compatibility at https://pytorch.org/get-started/locally/
affects: >=1.14
breakingA temporary breaking change was introduced in v1.14.1 related to the `LinearKernel`'s `ard_num_dims` property, which was quickly reverted in v1.14.2.
fix
If you are on v1.14.1, upgrade to v1.14.2 or a newer version to avoid this specific breaking change and benefit from the fix.
affects: 1.14.1
deprecatedThe `gpytorch.random_variables` module and its classes (e.g., `GaussianRandomVariable`, `MultitaskGaussianRandomVariable`) were deprecated and replaced by `gpytorch.distributions`.
fix
Use classes from `gpytorch.distributions`, such as `gpytorch.distributions.MultivariateNormal` or `gpytorch.distributions.MultitaskMultivariateNormal`.
affects: <0.1 (Alpha/Beta versions)
gotchaThe `jaxtyping` dependency was removed in v1.15.2. Users relying on `jaxtyping` for static type checking or runtime validation with GPyTorch might notice changes in type hint behavior or require updates to their type-checking configurations.
fix
Review your type-checking setup if you were explicitly using `jaxtyping` with GPyTorch. `jaxtyping` itself now supports PyTorch without a JAX dependency, so direct usage is still possible if desired.
affects: >=1.15.2
gotchaA potential bug with `gpytorch.settings.debug.on()` was fixed in v1.15.2, meaning its behavior might have been unreliable or incorrect in prior versions.
fix
Upgrade to v1.15.2 or later to ensure that `gpytorch.settings.debug.on()` functions as expected.
affects: <1.15.2
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'gpytorch'
The GPyTorch library is not installed in the Python environment being used, or the environment is not correctly activated.
fix
Install GPyTorch using pip or conda: `pip install gpytorch` or `conda install gpytorch -c gpytorch`
RuntimeError: expected backend CPU and dtype Double but got backend CPU and dtype Float
This error occurs when there is a mismatch in the data types (dtypes) of tensors, typically when GPyTorch expects `torch.float64` (Double) for numerical stability in Gaussian processes but receives `torch.float32` (Float).
fix
Ensure all input tensors (training data, targets, etc.) are of `torch.float64` dtype by calling `.double()` on them, or set the default dtype for PyTorch using `torch.set_default_dtype(torch.float64)`.
RuntimeError: Flattening the training labels failed.
This error usually indicates a mismatch between the expected shape of the prior mean and the actual shape of the training labels (targets).
fix
Verify that your training labels (`train_y`) have the correct shape, often requiring a `torch.Size([num_samples, 1])` or a shape consistent with the output of your GP model's mean function. Reshape `train_y` if necessary (e.g., `train_y.unsqueeze(-1)`).
AttributeError: 'RBFKernel' object has no attribute 'log_lengthscale'
This error arises from trying to access kernel or likelihood hyperparameters (like `lengthscale` or `noise`) directly through `log_` prefixed attributes, which are typically not the public API for parameter access in GPyTorch's more recent versions or when parameters are managed by constraints/priors.
fix
Access the parameter directly without the `log_` prefix (e.g., `model.covar_module.lengthscale`) or through the parameter's `data` attribute if you intend to modify it directly. GPyTorch typically handles transformations (like log-space optimization) internally. For example, `model.covar_module.lengthscale.item()` for reading, or `model.covar_module.lengthscale.data = new_value` for setting.
NotImplementedError: The operator 'aten::_linalg_solve_ex.result' is not currently implemented for the MPS device.
This error occurs on Apple Silicon (M1/M2) Macs when PyTorch's Metal Performance Shaders (MPS) backend is used, and a required linear algebra operation (like solving a system of equations) has not yet been implemented for MPS. GPyTorch relies heavily on these operations.
fix
As a temporary workaround, set the environment variable `PYTORCH_ENABLE_MPS_FALLBACK=1` *before* importing `torch` and `gpytorch` to enable fallback to CPU for unsupported operations. For a permanent solution, monitor PyTorch's development for full MPS support for the required operations, or use a CUDA-enabled GPU.
Upgrade
Version history
1.15.2latest on PyPI · released Feb 28, 2026
Audit
Dependencies
torchrequiredCore deep learning framework dependency, GPyTorch is built on it.
linear_operatorrequiredProvides abstract base classes for linear operators used in GPyTorch's scalable inference methods.
Agent activity
25 hits · last 30 days
node
22
Perplexity
1
OpenAI (training)
1
Resources
gpytorch — pip install gpytorch · libregistry