Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make compatible with torch.vmap #20

Open
adam-coogan opened this issue Apr 21, 2023 · 1 comment
Open

Make compatible with torch.vmap #20

adam-coogan opened this issue Apr 21, 2023 · 1 comment

Comments

@adam-coogan
Copy link

Since torchinterp1d uses torch.autograd.Function, it is not compatible by default with vmap. Here's an example of code that will not run:

import torch
from torchinterp1d import interp1d

def interpolate(xp):
    x = torch.linspace(-5, 5, 100)
    y = x**3
    return interp1d(x, y, torch.atleast_1d(xp))

xp = torch.rand(20) * 10 - 5
print(f"{xp=}, {torch.vmap(interpolate)(xp)=}")

The relevant part of the stack trace is:

RuntimeError: In order to use an autograd.Function with functorch transforms
(vmap, grad, jvp, jacrev, ...), it must override the setup_context staticmethod.
For more details, please see https://pytorch.org/docs/master/notes/extending.func.html

Based on the PyTorch docs, the fix may be as easy as setting generate_vmap_rule=True in torchinterp1d, but I haven't looked into this yet.

It'd be great to get a fix for this since vmap is incredible useful.

@aliutkus
Copy link
Owner

hi, I'm a bit away from this right now, but I'd gladly accept a PR

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

No branches or pull requests

2 participants