-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Clarify namescopes in the presence of nested subgraphs #1665
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
houseroad
left a comment
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.
The changes look good to me.
docs/IR.md
Outdated
| All names MUST adhere to C identifier syntax rules. | ||
|
|
||
| Names of nodes, inputs, outputs, initializers, and attributes are organized into several namespaces. Within a namespace, each name MUST be unique for each given graph. | ||
| Names of nodes, inputs, outputs, initializers, and attributes are organized into several namespaces. Within a namespace, each name MUST be unique for each given graph. When a graph contains nested subgraphs (as attribute values), each name in a namespace MUST be unique across these graphs. |
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.
Confirm: does this mean all node input/output names across main graph and subgraphs have to be unique? if this is the case, then what's the "namespace" here mean please? With this clarification, I assume there's only ONE namespace in a model now. Every name has to be unique in this ONE namespace. Right?
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.
We have namespaces as described in the table just below (node names are in a different namespace from tensor/value names, for example). We can think of different graphs as a different dimension: let us call them namescopes. So, tensor names must be unique across a graph and a subgraph (one namescope). But a tensor name can be the same as a node name (different namespaces).
zrphercule
left a comment
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.
LGTM
|
Hi, I updated the documentation to be consistent with the checker. However, there are some tricky issues (non-uniform handling of name reuse/clash), so I would like to bring them up. Please clarify if the existing implementation is intentional or whether it needs to be fixed. A name X defined in an outer scope cannot be reused for a different tensor in a subgraph. However, this is permitted for the subgraph inputs. Is this intentional? Why this non-uniform treatment? |
|
I want to follow up on the earlier discussion. Consider what the current checker does with the following example of reuse of names defined in an outer graph in a subgraph (for a different value): graph { This looks a bit odd. Why do we not want to permit the redefinition of X2 above? One possible explanation is that we want to avoid the following scenario: graph () { It seems a reasonable goal to avoid a case where a name Y in a particular scope S is used to both refer to an outer scope variable (that is, defined outside scope S) as well as a variable define in scope S. (A similar situation is when the reference to the outer scope Y occurs in a nested sub-scope within S.) Suggested solution: we forbid redefinitions of names defined in an outer scope only in the above situation. In particular, we allow the redefinition of X2 in the original example above. Does this seem reasonable? This would also explain why we allow the redefinition of X1 in the first example. Note that forbidding the redefinition of X2 has the following consequence: consider a graph G that is completely self-contained (that is, it has no references to an undefined name). Ideally, we should be allowed to use it as a sub-graph anywhere without worrying if it uses a name that conflicts with an outer-scope name. The existing scheme doesn't give us this desirable compositionality property. Fixing it as suggested above will give us this property as well. Please note that this fix will make the checker more complex. I can look into how to update the checker if this proposal looks reasonable. |
houseroad
left a comment
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.
LGTM.
* Clarify namescopes in the presence of nested subgraphs * update checker to handle namescope change * Update explanation to be consistent with the checker * undo accidental commits of other files * undo unintentional changes committed * undo unintentional changes committed
* Clarify namescopes in the presence of nested subgraphs * update checker to handle namescope change * Update explanation to be consistent with the checker * undo accidental commits of other files * undo unintentional changes committed * undo unintentional changes committed
We need to clarify the treatment of names occurring in nested subgraphs, now that we have control-flow ops that use nested subgraphs.
The agreed part is that a nested subgraph can contain references to a name X defined in an outer scope (graph).
The following are less obvious (pros/cons with the different choices):
(1) Should reuse of same name X for different outputs in different graphs be permitted in (a) some cases, (b) all cases, or (c) no cases?
(2) What about node names? Are they required to be unique across a graph and a nested subgraph?
Here is my understanding of what the checker currently does:
X = ADD(…) //
{ // nested subgraph 1
X = MULTIPLY(…) // forbidden by checker
Y = ADD(…) // permitted by checker
Z = ADD(…) // permitted by checker
}
Y = MULTIPLY(…) // permitted by checker
{ // nested subgraph 2
Z = MULTIPLY(…) // permitted by checker
}
Note that forbidding reuse in all above cases is easier to explain/document!
Please indicate if there is any specific requirement or usecase for a particular choice above.