sngp¶
- probly.method.sngp(base: Predictor[In, Out], name: str = 'weight', n_power_iterations: int = 1, norm_multiplier: float = 6.0, eps: float = 1e-12, num_random_features: int = 1024, ridge_penalty: float = 1.0, momentum: float = -1.0, random_feature_init_std: float = 1.0) SNGPPredictor[In, Out][source]¶
Wrap a model with SNGP (Spectral-normalized Neural Gaussian Process).
Replaces the last
nn.Linearwith anSNGPLayer(random Fourier features + Laplace-approximated Gaussian process) and registers a spectral-norm parametrization on every precedingnn.Linearandnn.Conv2d. Defaults match the ImageNet ResNet-50 baseline atgoogle/uncertainty-baselines/baselines/imagenet/sngp.py.- Parameters:
base – The model to wrap.
name – The name of the weight parameter to spectrally normalize on non-output layers. Defaults to
"weight".n_power_iterations – Power iterations per training step for the spectral-norm estimate. Defaults to 1. (A 15-iteration warmup runs once at construction time, independent of this value.)
norm_multiplier – Upper bound on each non-output layer’s spectral norm. Defaults to 6.0 (high because ResNet’s BatchNorm already applies its own Lipschitz scaling).
eps – Small constant to stabilize the spectral-norm denominator. Defaults to 1e-12.
num_random_features – Dimensionality of the random Fourier feature map. Defaults to
1024.ridge_penalty – Ridge factor used inside the covariance inversion
inv(ridge * I + precision). Defaults to 1.0.momentum – Discount factor for the precision-matrix update. Default
-1.0triggers accumulate mode (paper Algorithm 1; imagenetgp_cov_discount_factor=-1); the user must callreset_precision_matrix()at the start of each training epoch in this mode. Passmomentum > 0for EMA mode (no reset needed; matches the CLINC reference’sgp_cov_momentum=0.999).random_feature_init_std – Standard deviation of the Gaussian used to initialize the frozen random projection
W_L. Defaults to1.0(paper / imagenet / Edward2; full RFF kernel approximation, expects from-scratch training). Set to0.05(matchinguntangle.wrappers.sngp_wrapper) when fine-tuning from a pretrained backbone: keepsW_L^T hin the near-linear regime ofcosso pretrained-feature signal flows through the RFF, at the cost of a longer effective kernel lengthscale and weaker distance-aware uncertainty.
- Returns:
An
SNGPPredictorwhosepredict(...)returns aGaussianDistributionover logits.