- 
                Notifications
    You must be signed in to change notification settings 
- Fork 103
          [Feature] Support for mixed TensorDictBase types in torch.autograd.grad
          #1434
        
          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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a mil! Not sure the changes really fix the issue -- see my comment
| What about now? Not sure we can do better. Feel free to close the PR in case of a wontfix. | 
| @vmoens bump | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah not sure that's exactly what I had in mind.
I think we should avoid things like
tup_outputs = tuple(outputs[k] for k in outputs.keys(True, True))
which are inefficient (we could just use values(...))
But more in general, the idea I had was to check if the various inputs all shared the same type (possibly recursively because you can have a Lazy stack within a regular TD) and if not, specialize the ones that don't have the right type.
It's a bit convoluted though:
- you would need to call td0.apply(check, td1, td2, is_leaf=_is_tensor_collection)wherecheckreturnsTrueif all types match
- if check returns False, then you need to cast one of these guys
- then we should implement the logic to do that. I guess something like
# td: a TD with a LazyStack within # plain_td: a TD without lazy stack new_td = td.copy().update(plain_td)
With that kind of thing we can keep the rest of the function exactly as it it
| Ok I see, thanks for the heads-up. | 
Description
Support:
Motivation and Context
torch.autograd.grad#1417Types of changes
What types of changes does your code introduce? Remove all that do not apply:
Checklist
Go over all the following points, and put an
xin all the boxes that apply.If you are unsure about any of these, don't hesitate to ask. We are here to help!