-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Subgraph API creates duplicate inputs and outputs #16108
Comments
Two things to add :
Code :
In src/operator/subgraph/subgraph_property.h : ConnectSubgraphOutputs()
|
We found the same issue when implementing MKLDNN subgraph backend. To address this, we introduced 2 APIs: |
@mxnet-label-bot add [Performance] |
Do we still need the ConnectSubgraphOutputs and ConnectSubgraphInputs now? |
good question. we'll need to go look at the various subgraph properties and see what they are doing in those functions. |
Description
Subgraph API can create duplicated tensors for both inputs to a subgraph and outputs from a subgraph. This happens when there are multiple nodes in a subgraph that consume the same input, or when there are multiple nodes that consume a single subgraph output. This results in tensor duplication, and causes OOM due to excessive memory usage.
Minimum reproducible example
Consider the duplicate input problem first. Lets say we have the following graph:
In this graph node A has a single output, and nodes B and C consume A's output. If nodes B and C are added to a subgraph, the graph is changed to the following:
Heres, nodes B and C are moved into the subgraph, and their dependency on node A (which is not in the subgraph) is broken, and an input node is created for each: A0, A1. The subgraph will have 2 inputs (A0, A1) and will both have dependencies to node A.
Now lets consider the the duplicate output problem. Consider the same graph as above:
But this time lets only node A is added to the subgraph, and nodes B and C are left out. Then the graph is changed to the following:
Here, B and C have dependencies on the output from A inside the subgraph. In this case, the subgraph will have 2 outputs, one for each consumer: B and C. But both outputs will be defined as coming from the same output of node A inside the subgraph.
The text was updated successfully, but these errors were encountered: