Skip to content

[FIX] Stabilize autograd graph, sigmoid overflow, and dual contouring vertex solve#71

Merged
Leguark merged 4 commits intomainfrom
grads
Apr 27, 2026
Merged

[FIX] Stabilize autograd graph, sigmoid overflow, and dual contouring vertex solve#71
Leguark merged 4 commits intomainfrom
grads

Conversation

@Leguark
Copy link
Copy Markdown
Member

@Leguark Leguark commented Apr 27, 2026

[BUGFIX] Replace inv with solve for improved numerical stability in vertex computation

  • Updated _gen_vertices.py to use torch.linalg.solve instead of matrix inversion (linalg.inv) for solving ATA @ x = ATb.
  • Added Tikhonov regularization (1e-4 * I) for enhanced numerical stability.

[BUGFIX] Clamp sigmoid input to prevent overflow and NaN gradients

  • Added clamping to _sigmoid in _soft_segment.py to prevent exponential overflow issues that cause NaN gradients in float32 precision.
  • Supports both PyTorch (clamp) and NumPy (clip) backends.

[BUGFIX] Prevent autograd graph corruption during overlap vertex averaging

  • Saved original differentiable vertices as vertices_tensor on each mesh before in-place overlap modifications.
  • Replaced mesh.vertices with a detached clone (PyTorch) or copy (NumPy) to prevent vertex averaging from corrupting the autograd graph of the original solve output.

[ENH] Deduplicate change_backend_gempy definition in BackendTensor

  • Removed the duplicate change_backend_gempy method introduced in backend_tensor.py.

Leguark added 4 commits April 27, 2026 10:29
…in vertex computation

- Updated `_gen_vertices.py` to use `torch.linalg.solve` instead of matrix inversion (`linalg.inv`) for solving ATA @ x = ATb.
- Added regularization for enhanced stability.
- Added clamping to `_sigmoid` to address potential exponential overflow issues causing NaN gradients in float32 precision.
…rlaps

- Detached and cloned mesh vertices to safeguard the autograd graph from in-place modifications during overlap vertex averaging.
- Stored original differentiable vertices as `vertices_tensor`.
Copy link
Copy Markdown
Member Author

Leguark commented Apr 27, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@Leguark Leguark marked this pull request as ready for review April 27, 2026 12:31
@Leguark Leguark changed the title [ENH] Add change_backend_gempy method to streamline backend configuration in BackendTensor [FIX] Stabilize autograd graph, sigmoid overflow, and dual contouring vertex solve Apr 27, 2026
@Leguark Leguark merged commit a38bf03 into main Apr 27, 2026
2 checks passed
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