-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IR] Mutable IR implementation (#1344)
Implement mutation methods on Graph and Function and a DoublyLinkedList to support safe mutation during iteration. Nodes in different graphs can be moved to other graphs safely during iteration. ### Methods implemented ``` - __getitem__ - __len__ - __iter__ - __reversed__ - append - extend - remove - insert_after - insert_before - sort (declared, not implemented) ``` The mutation methods are inspired by the pytorch FX graph methods. ### Safe Iterators The behavior of the iterators is: - If new elements are inserted after the current node, the iterator will iterate over them as well. - If new elements are inserted before the current node, they will not be iterated over in this iteration. - If the current node is lifted and inserted in a different location, iteration will start from the "next" node at the _original_ location. A node cannot be added to a graph if it belongs to another graph. It needs to be removed first. The user is responsible for removing nodes from other graphs before adding the same node to a new graph. ### Linked list implementation The doubly linked list implementation is inspired by the pytorch FX graph: They are both doubly linked lists with a dummy root node. Whereas in FX `graph` contains the root node and `Node`s are the links; we create the `DoublyLinkedOrderedSet` class to decouple the list implementation form the graph. Additionally, we created the `LinkedBox` class as a data struct to hold the prev/next pointers for the Nodes to allow nodes to move across graphs. This is in contrast to FX restriction of all nodes must belong to the same graph in their lifecycle. By allowing the nodes to move to different graphs, we are able to flatten/unflatten graphs without copying. DoublyLinkedOrderedSet is unit tested. ### Next steps 1. Naming authority 2. Graph input/output/initializers mutation
- Loading branch information
1 parent
edb68ed
commit b66c6d1
Showing
14 changed files
with
993 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.