Skip to content

Conversation

jamesr66a
Copy link
Collaborator

@jamesr66a jamesr66a commented Sep 16, 2020

Stack from ghstack:

Differential Revision: D23743850

Copy link
Contributor

@zdevito zdevito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should expose generate forward. It makes more sense that assignment to the .graph property automatically regenerates forward. graph itself should be immutable. This patch should also enforce the immutability of graph after it has had an output declared.

@jamesr66a
Copy link
Collaborator Author

@zdevito how do we enforce immutability of Graph? Subclass list and disable all methods except append and getitem or something?

@jamesr66a jamesr66a changed the title [FX] Make forward regen public and add docstring [FX] Make Graphs immutable after output is set Sep 16, 2020
jamesr66a pushed a commit that referenced this pull request Sep 16, 2020
ghstack-source-id: 21f609a
Pull Request resolved: #44830
@jamesr66a
Copy link
Collaborator Author

@zdevito updated. I don't particularly like how this breaks editing after copy/deepcopy

self.nodes : FinalizableList = FinalizableList()
val_map = {}
for node in from_graph.nodes:
val_map[node] = self.node_copy(node, lambda n: val_map[n])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, should node_copy be delegate-customizable too? I'm thinking of cases when extra metadata is hanging off the node and we want to copy it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delegate is now Tracer and only affects how tracing occurs

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then what is the recommended mechanism fo attaching more stuff to nodes in the graph and preserving them? Should we copy entries in the __dict__ (though it's a bit hacky)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could add extra_info : Dict[str, Any] to Node that gets copied over?

def output(self, result: Argument):
self.result = result
self._mark_uses(result)
self.nodes.finalize()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, have you considered just doing self.nodes = tuple(self.nodes)? :) What is the benefit of FinalizableList over Tuple?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every time you append to the tuple you'd have to create a new data structure? Also that doesn't match with the specification above, of immutable after an output has been specified

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean to change type from list to tuple only when you want to finalize. Afaiu, list and tuple are mostly indistinguishable from the consumption standpoint.

@dr-ci
Copy link

dr-ci bot commented Sep 17, 2020

💊 CI failures summary and remediations

As of commit e38e222 (more details on the Dr. CI page):


None of the CI failures appear to be your fault 💚



🚧 1 fixed upstream failure:

These were probably caused by upstream breakages that were already fixed.

Please rebase on the viable/strict branch (expand for instructions)

If your commit is newer than viable/strict, you can try basing on an older, stable commit:

git fetch https://github.com/pytorch/pytorch viable/strict
git rebase --onto FETCH_HEAD $(git merge-base origin/master HEAD)

If your commit is older than viable/strict:

git fetch https://github.com/pytorch/pytorch viable/strict
git rebase FETCH_HEAD

Check out the recency history of this "viable master" tracking branch.


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 29 times.

else:
return a

class FinalizableList(list):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure all this infrastructure is worth it. We can just change nodes to be a property and then editing nodes doesn't change the graph.

class Graph:
def __init__(self):
self.nodes : List[Node] = []
def __init__(self, from_graph : Optional['Graph'] = None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a big odd to put this in the constructor. A graph could have a function copy_graph similar to copy node that would copy/append the entire graph. Then someone wanting to append to a graph can:

b = Graph()
a.copy_graph(b, input_fn) # same structure as copy node but copies an entire graph

Appending to a graph only is a specific use case, the general one is editing a graph (i.e. doing node-by-node transforms) and then splices graphs into eachother (graph_copy).

jamesr66a pushed a commit that referenced this pull request Sep 17, 2020
ghstack-source-id: bc1a53b
Pull Request resolved: #44830
@jamesr66a jamesr66a changed the title [FX] Make Graphs immutable after output is set [FX] Make Graphs immutable and make GraphModule recompile after assigning graph Sep 17, 2020
jamesr66a pushed a commit that referenced this pull request Sep 18, 2020
ghstack-source-id: 2c2d7dd
Pull Request resolved: #44830
@jamesr66a jamesr66a requested a review from zdevito September 18, 2020 20:45
jamesr66a pushed a commit that referenced this pull request Sep 19, 2020
ghstack-source-id: a0d4a01
Pull Request resolved: #44830
jamesr66a pushed a commit that referenced this pull request Sep 21, 2020
ghstack-source-id: 05a0c84
Pull Request resolved: #44830
@facebook-github-bot
Copy link
Contributor

@jamesr66a merged this pull request in 79fe794.

@facebook-github-bot facebook-github-bot deleted the gh/jamesr66a/285/head branch September 26, 2020 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants