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

Solving infinite recursion #1

Merged
merged 1 commit into from
Jan 20, 2023
Merged

Conversation

vmoens
Copy link

@vmoens vmoens commented Jan 18, 2023

Description

I propose a solution to the infinite recursion problem.
The idea is to keep track of what is being computed with a local function.
If the current tensordict encounters itself down the line, it register what key it is and lets that aside for the moment. Once the computation is "finished" (with all the nested tensordicts let aside) it fills the keys one at a time with what has been retrieved.

Albeit the logic is repetitive i did not find a way of recycling the code across methods (all, clone, to_tensordict, expand etc)
IMO it would be better to have sort of a decorator to handle that, but I can't really think of a way to make it work in the general case.
Any idea @Zooll or @tcbegley ?

@tcbegley
Copy link

Hmm, I you're right it feels like some deduplication ought to be possible, but it's tricky because the duplicated logic is so intertwined with the non-duplicated. I tried doing smth with a general version of the function that you could pass a number of hooks into, but it quickly gets messy and I'm not convinced it's better than just having some redundancy.

@Zooll
Copy link
Owner

Zooll commented Jan 18, 2023

About self nesting, Is it a normal behaviour? I can't imagine a situation when you have to support this feature. It's not hard to detect this self nesting (cycle in graph) and maybe just notify users about it?

@vmoens
Copy link
Author

vmoens commented Jan 18, 2023

I disagree, it's of the uttermost importance to support auto nesting for operations that are not intrinsically incompatible.
Cyclic graphs are common in GNNs and related applications and I'd love to see tensordict support these.

@Zooll
Copy link
Owner

Zooll commented Jan 19, 2023

I disagree, it's of the uttermost importance to support auto nesting for operations that are not intrinsically incompatible. Cyclic graphs are common in GNNs and related applications and I'd love to see tensordict support these.

Yes, it makes sense. I also reviews you PR and you idea should work, but we have to rewrite almost everything to pass all tests. I tried to pass test_equal for auto_nested_td, but I had to write a lot of repetitive code to make it work. If you interested look at ee40162

@vmoens
Copy link
Author

vmoens commented Jan 19, 2023

Cool! We can think of some sort of decorator to make the logic scalable. Might be doable if we can assess what is the unitary operation to do on the contained tensors, but maybe not always obvious.
Can we merge the two branches (yours and mine) together?
Also the PR is made from your main branch, which makes it hard to work cooperatively. If your branch is branched out from mine, can you re-create a PR with it?

@Zooll Zooll merged commit 6be56da into Zooll:main Jan 20, 2023
@Zooll
Copy link
Owner

Zooll commented Jan 21, 2023

@vmoens @tcbegley I was thinking about how to create some decorator to make it easy to support self nesting. Here is some idea about it with sample. Please have a look at https://pym.dev/p/2tc6a/

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.

3 participants