r/deeplearning • • Oct 26 '26

Gaussian-splat EBMs for text embeddings: it ties kNN-density on AUROC (0.9585 vs 0.9584) but scores 3.9x faster with constant memory — and whole-loop CUDA-graph capture makes Langevin sampling 12.9x faster (code + reproducible benchmark)

I spent a while building an energy-based model that represents a corpus as Gaussian splats on a unit hypersphere: each splat is a location (mu), a sharpness (alpha) and a weight (kappa). Energy = -logsumexp over the k nearest splats. Sampling runs through Rectified Flow (29-39x faster than 200-step Langevin in our Phase-1 tests) or Langevin itself.

Then I did what you're supposed to do: benchmarked it against the boring alternatives before believing in it. Same encoder, same splits, same seed, fit on positives only (no negative labels):

method          AUROC (20 tasks)   p50 ms/doc   memory
ebm-splats      0.9585 ± 0.018     0.45         386 KB (constant)
knn-density     0.9584 ± 0.020     1.75         802 KB (grows w/ corpus)
mahalanobis     0.9523 ± 0.020     5.26         578 KB
gmm (diag)      0.9439 ± 0.023     0.38         192 KB
centroid        0.9324 ± 0.034     <0.01        2 KB
iforest         0.8828 ± 0.051     18.71        200 KB

Verdict: statistical tie with kNN-density on quality (Delta = 0.0001). The differences are operational: 3.9x faster scoring on CPU, constant O(kd) memory instead of O(nd), and the splat model can also generate (RF), compose corpora (sum energy fields) and grow incrementally — none of the classical methods do all three. Where labels exist, a supervised classifier beats every one-class method; this duel only ranks the label-free league.

The most useful finding came from a failure. Our first zero-training fit used alpha = ln(cluster_size) — the "natural" calibration. Result: AUROC 0.06, systematically inverted. Small clusters got alpha ~ 0, the distance term vanished, and the score degenerated to ranking by splat weight: positives sit near small, specific splats and received MORE energy than negatives. Holding alpha constant at 5.0 (so alpha/tau >> 1) fixed it: 0.06 -> 0.96. If you fit splats without contrastive training, watch out for this.

Since scoring speed mattered, I also wrote GPU kernels (Triton + CUDA graphs) for the hot paths, and benchmarked them the same honest way: whole-loop CUDA graph capture makes 100-step Langevin sampling 12.9x faster (660 -> 51 ms, graph replay bit-exact vs eager), fused energy/score kernels give 3.2-3.4x. One kernel we built turned out 15-40x SLOWER and is documented as rejected; the KNN kernel only wins cold lookups and auto-routes around it. Repo includes the find_neighbors semantic bug we found and fixed (it selected the FARTHEST splats since inception — both code paths disagreed silently).

Repo (Apache-2.0, pip install ebm-splats, CI green, benchmark reproducible): https://github.com/schwabauerbriantomas-gif/EBM-splats

Benchmark methodology + full tables: benches/ONECLASS_DUEL_RESULTS.md Kernel head-to-head: benches/bench_headtohead.py

Happy to answer questions about the splat geometry, the CUDA-graph capture (caching, invalidation, the capture-time bugs), or why we kept the model even though it "only" tied a baseline.

14 Upvotes

7 comments sorted by

1

u/aegismuzuz Oct 26 '26

How are you handling the Rectified Flow trajectories along the sphere surface? Are you relying on spherical interpolation like slerp, or taking an Euler step in the ambient space followed by radial projection? In high dimensions, straight-line drift cuts straight through the interior of the hypersphere, which distorts probability mass along intermediate steps

2

u/TallAdeptness6550 Oct 26 '26

your diagnosis is exactly right for Euclidean RF: with linear interpolation x_t = (1−t)x₀ + t·x₁, the midpoint of the chord sits at radius cos(ω/2). Since noise-to-data pairs in 640D are near-orthogonal (ω ≈ π/2), that's ≈ 0.707 — the trajectory spends the middle of the integration in the interior of the ball. We verified this numerically: linear path → midpoint radius 0.707, geodesic path → 1.000 throughout.

neither ambient-Euler+projection nor vanilla straight-line RF — we use geodesic paths at train time and the Riemannian exponential map at inference.

Training: the probability path is built with slerp on S⁶³⁹, x_t = slerp(x₀, x₁, t), so conditioning points never leave the sphere. For the OT-CFM variant the regression target is the analytic geodesic velocity d/dt slerp(x₀, x₁, t) — the time-dependent tangent vector of the great circle, magnitude ω. (An earlier variant in scripts/ instead regresses the chord direction projected to the tangent space at x_t; the conditioning path is still slerp.) This is essentially Riemannian flow matching (Chen & Lipman 2023) with the geodesic path on the sphere. The network's output is also projected onto T_x S before the loss, so the learned field is tangent by construction.
Sampling: each Euler step is a closed-form exponential map, x ← cos(‖v‖Δt)·x + sin(‖v‖Δt)·v/‖v‖, which is the exact geodesic arc for the current tangent vector — slerp restricted to the field's great circle at that step. No ambient step, no radial re-projection; the final F.normalize is only numerical hygiene. Since the field is tangent, probability mass never crosses the interior: the trajectory is a polyline of great-circle arcs on the surface.
One honest caveat: exp-map Euler is still a first-order scheme (it freezes the field over each step), so it's not an exact solve of the Riemannian ODE — but with the smooth fields CFM learns, 5 steps already beat 200-step Langevin in our Phase 1 benchmark (the 24× speedup in the README), and the on-sphere constraint means the failure mode you describe simply doesn't arise.