Skip to content

[Bug Report] LinearInterpolation produces NaN gradients during constant extrapolation #9242

Backlog

Description

@sylvesterkaczmarek

Describe the bug

LinearInterpolation.compute() divides by zero when its lower and upper sample indices coincide, then masks the resulting weight. The forward value is correct, but autograd differentiates through the invalid division and produces NaN query gradients. This affects queries outside the sampled range and single-sample curves, both of which should be constant.

Reproduction

import torch
from isaaclab.utils.interpolation import LinearInterpolation

f = LinearInterpolation(torch.tensor([0., 1., 3.]), torch.tensor([1., 3., 11.]), device="cpu")
q = torch.tensor([-2., 0.5, 2., 4.], requires_grad=True)
print(torch.autograd.grad(f.compute(q).sum(), q)[0])

Actual: NaN gradients outside the sampled range. Expected: [0., 2., 4., 0.].

System Info

main at ebf162a, macOS ARM64, Python 3.12, PyTorch 2.12.0. CPU reproduction without Isaac Sim.

Additional context

Mask the numerator and denominator for coincident bounds before division. Both focused regression tests fail on main and pass with this change. No downstream simulation failure is claimed.

Checklist

  • Checked for similar issues and PRs.
  • Reproduced without Isaac Sim.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions