Skip to content

Preserve coordinate gradients at integer interpolation points - #126

Open
sylvesterkaczmarek wants to merge 2 commits into
google-deepmind:masterfrom
sylvesterkaczmarek:fix/interpolation-grid-gradients
Open

sylvesterkaczmarek wants to merge 2 commits into
google-deepmind:masterfrom
sylvesterkaczmarek:fix/interpolation-grid-gradients

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor

Summary

Use floor(coordinate) + 1 for the upper interpolation neighbour instead of ceil(coordinate). At integer coordinates, both neighbours currently collapse onto the same sample and the coordinate derivative becomes zero. This is incorrect even for an affine ramp, which is differentiable there: interpolating [0, .25, .5, .75, 1] at coordinate 1 returns derivative 0 instead of .25.

The same defect removes translation gradients from identity-initialized affine_transform calls. The one-line change preserves finite sampled values and existing boundary clipping while retaining the adjacent sample needed by the derivative.

Validation

Python 3.12.11, JAX 0.11.2, NumPy 2.5.3 on macOS arm64, CPU:

  • All 16 new cases pass; 14 fail on unchanged ebaab9b. Coverage includes 1D/2D/3D ramps, flattened inputs, nearest/constant boundaries, eager/JIT reverse-mode gradients, JVPs, identity affine transforms, and gradients with respect to pixel values.
  • Focused interpolation suite: 112 passed, 24 skipped.
  • Full python -m pytest -q -n 2 dm_pix: 1,346 passed, 99 skipped.
  • Built and installed the wheel outside the checkout; all 16 regression cases pass against the installed package.
  • Ruff correctness checks, Pyink on the new test module, Python compilation, and git diff --check pass. Pylint has only the same repository-configuration and existing source line-length findings as the unchanged base, with no new code findings.

GPU/TPU execution and documentation builds were not run.

@sylvesterkaczmarek
sylvesterkaczmarek marked this pull request as ready for review September 22, 2026 20:09
@claudiofantacci claudiofantacci self-assigned this Oct 4, 2026
@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor Author

@claudiofantacci Thanks for the approvals on #126 and #131. #125 also retains an approval, and all three current heads are mergeable with green public checks; #126 and #131 additionally have successful Copybara import and Google internal feedback. I am grouping this here rather than pinging all three PRs separately. Could you take these through the remaining maintainer merge step, or let me know if there is another gate I should address?

@claudiofantacci

Copy link
Copy Markdown
Collaborator

I'm looking why this isn't going through.

@claudiofantacci
claudiofantacci self-requested a review October 12, 2026 21:47
@claudiofantacci

Copy link
Copy Markdown
Collaborator

Ok back on track! I hope this goes trhough quickly :D

@@ -0,0 +1,89 @@
# Copyright 2021 DeepMind Technologies Limited. All Rights Reserved.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though I already left this comment...? Can you please move these tests under https://github.com/google-deepmind/dm_pix/blob/master/dm_pix/_src/interpolation_test.py please?

@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor Author

Moved all the new interpolation-gradient regressions into the existing dm_pix/_src/interpolation_test.py in a2fc9aa, and removed the separate interpolation_gradient_test.py as requested. The production interpolation fix is unchanged.

Validated on macOS arm64, Python 3.12 and JAX 0.11.2 (CPU): python -m pytest -q -o addopts='' dm_pix/_src/interpolation_test.py reports 112 passed, 24 skipped. Scoped Ruff correctness, Python compilation, and diff checks pass. GPU/TPU and the full image-processing suite were not rerun for this test-only move.

@claudiofantacci claudiofantacci left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@claudiofantacci claudiofantacci added the bug Something isn't working label Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants