-
Notifications
You must be signed in to change notification settings - Fork 955
Identity recursively uses :set instead of assignment #673
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
Conversation
-- clean up behind if the current input is | ||
-- smaller than the previous one | ||
for k in pairs(out) do | ||
if not input[k] then |
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.
This should be "if input[k] == nil", since we do not want to remove "false" entries from out.
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.
Indeed, I should fix it ! Thanks for pointing this out !
@davidsaxton I've fixed the |
After giving it a second thought, I think we might not want to use I think that what is necessary is to ensure that all leaf modules (non-container modules) to have it's own I think that in this setup, To summarize, I propose to keep all the containers as is, and only change the leaf modules to avoid lua assignment. |
@fmassa Awesome! I've been fighting with that Identity behaviour for a while. It will finally be consistent with other modules. |
@fmassa The only downside of not using |
@apaszke That was my initial thought too. But I'm not sure we need If you look at the network as a computation graph, where each node performs some operation (and owns its output tensor) and an edge corresponds to taking the output of node A and passing it as input to node B, a On the other hand, you can see a |
@fmassa Well, Identity doesn't perform any operation either 😜 You could see a Sequential as a container ending with an Identity, so it might also perform an operation that owns a tensor in a way. But I understand the point of view, that some of the containers only serve computation graph construction, while others perform "true" operations as well. However, in this setting, Identity can be seen as one of the construction modules too - it represents a single graph edge (that might not be connected yet - e.g. nngraph). I'm not sure if it's a good idea to change it then. |
@apaszke after thinking about what you said, I think that we might not want to change the behaviour of What we could possible enforce is that all modules that perform some operation should own its Indeed, Having that in mind, we can easily create nice graphs from nn networks if what I said before is enforced. If you all agree, I can close this PR. |
@fmassa Ok, I'm fine with taking that way. However, it would be worth documenting it somewhere. When I wrote code for sharing/clearing outputs/gradInputs it was a real pain to do that (it was before Wow, that package looks very cool! It's awesome that it shares internal buffers. |
I don't think anymore that this PR is a good idea. Closing it. |
Here is an attempt to avoid using the assignment operator in
Identity
.I tried to handle all previous cases, but maybe I missed something.
Here is a summary:
set
on tensorsIdentity
If we want to go through the path of avoiding lua assignments everywhere in lua (as in several
Containers
for example), then maybe we should factor out theidentity
function to use it everywhere instead of=
. In this case maybe it would be better to rename itassign
or something like that and put it innn.utils
.@jfsantos @soumith as you have worked on that in the past
@dominikgrewe @koraykv to check if I didn't break anything in
nngraph
and in your internal tests.@szagoruyko for the removal of
clearState