Skip to content

Preserve Gauss-von-Mises single-point autograd - #5255

Open
FlorianPfaff wants to merge 2 commits into
mainfrom
agent/preserve-gauss-von-mises-single-point-autograd
Open

Preserve Gauss-von-Mises single-point autograd#5255
FlorianPfaff wants to merge 2 commits into
mainfrom
agent/preserve-gauss-von-mises-single-point-autograd

Conversation

@FlorianPfaff

Copy link
Copy Markdown
Owner

Bug

GaussVonMisesDistribution.pdf(...) kept backend-native values for batched evaluation, but the single-point path returned float(p[0]).

On the PyTorch backend, a query tensor with requires_grad=True therefore produced a Python float. The conversion silently detached the density from the computation graph, so callers could not differentiate a single-point likelihood even though the equivalent batched path remained differentiable.

Fix

Return the backend scalar p[0] directly for single-point evaluation instead of converting it to Python float.

This preserves the existing numerical value while keeping the active backend's dtype, device, and autograd history.

Regression coverage

Add a PyTorch-backend regression that evaluates a single Gauss-von-Mises point with requires_grad=True and verifies:

  • the result is a scalar PyTorch tensor;
  • dtype and device match the query;
  • the density is finite and positive;
  • backpropagation reaches both query coordinates with finite, nonzero gradients.

Validation

  • independently confirmed that converting a differentiable PyTorch scalar with float(...) returns a plain Python float and loses autograd;
  • final production diff is one line;
  • branch is based directly on current main (f196ec41d1d8681e279936db9f1a0a3abfa276e7) and is 2 commits ahead / 0 behind;
  • GitHub Actions is authoritative for the full backend, lint, packaging, documentation, and integration matrix.

@FlorianPfaff
FlorianPfaff marked this pull request as ready for review August 6, 2026 19:42
@FlorianPfaff
FlorianPfaff enabled auto-merge (squash) August 7, 2026 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant