The Ray Tracing Sampler: Bayesian Sampling of Neural Networks for Everyone

We derive a Markov Chain Monte Carlo sampler based on following ray paths in a medium where the refractive index $n(x)$ is a function of the desired likelihood $\mathcal{L}(x)$. The sampling method propagates rays at constant speed through parameter space, leading to orders of magnitude higher resilience to heating for stochastic gradients as compared to Hamiltonian Monte Carlo (HMC), as well as the ability to cross any likelihood barrier, including holes in parameter space. Using the ray tracing method, we sample the posterior distributions of neural network outputs for a variety of different architectures, up to the 1.5 billion-parameter GPT-2 (Generative Pre-trained Transformer 2) architecture, all on a single consumer-level GPU. We also show that prior samplers including traditional HMC, microcanonical HMC, Metropolis, Gibbs, and even Monte Carlo integration are special cases within a generalized ray tracing framework, which can sample according to an arbitrary weighting function. Public code and documentation for C, JAX, and PyTorch are available at https://bitbucket.org/pbehroozi/ray-tracing-sampler/src

Paper

References (14)

03https://api.semanticscholar.org/CorpusID:14817657 Speagle J. S.2020 · MNRAS
04in 2016 Progress in Electromagnetic Research Symposium (PIERS). pp 4188–4188, doi:10.1109/PIERS.2016.7735574 Z., et al., 20232016 · Science
05arXiv e-prints, p. arXiv:1402.4102 Choudhary K., et al., 20222014 · npj Computational Materials
062021, arXiv e-prints, p. arXiv:2109.13891 Besag J.1994 · J. Roy. Statist. Soc. Ser. B
07Physics Letters B, 195, 216 Earl D. J., Deem M. W1987 · Phys. Chem. Chem. Phys.
08OpenAI 2023arXiv e-prints
09If necessary
10Adjust the step size, starting with a reasonable guess (e.g., Δ 𝑠 ∼ 0 . 03 𝐷 1 / 2 ), and running until the loss distribution stabilizes
11The angle between the velocity and the refractive index gradient could be computed more transparently as 𝜃 = arccos ( ˆ v · ˆ n )
12Perform burn-in of a single walker at a low temperature (or use an optimizer like Adam) to find a location near the typical set

Scroll for more · 2 remaining

Similar papers

© 2026 NYSGPT2525 LLC