Skip to content

Commit c1f320c

Browse files
Aapo Kyrolafacebook-github-bot
authored andcommitted
fix traversal order
Summary: Memonger did not properly track the number of times a blob output has to be produced before an operator can be visited. Actually I remember fixing this before, but well. This bug was manifested in Priya's model, so thanks prigoyal, and benz's model verifier nicely caught the wrong output. Reviewed By: asaadaldien Differential Revision: D5524912 fbshipit-source-id: 10f4d7056b84aba0274a918af508ea043e6026f9
1 parent 18d73eb commit c1f320c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

caffe2/python/memonger.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,22 @@ def _compute_blob_recycling_for_dag(
145145
for op in ops:
146146
optim_op_outputs.update(set(op.output))
147147

148+
blob_seen = collections.defaultdict(lambda: 0)
148149
for i, op in enumerate(ops):
149150
for inp in op.input:
150151
if is_shareable(inp) or inp in heads:
151152
if inp in optim_op_outputs:
152153
blobs_to_ops[inp].append(i)
153-
op_inputs[i] += 1
154+
assert blob_seen[inp] > 0, \
155+
"Input {} was not output by an op before".format(inp)
156+
op_inputs[i] += blob_seen[inp]
154157
else:
155158
# For external blobs, we don't increase the op_inputs
156159
# count.
157160
blobs_to_ops[inp].append(i)
158161
share_counts[inp] = 1
162+
for outp in op.output:
163+
blob_seen[outp] += 1
159164

160165
output_blobs = set()
161166
mapping = {}

0 commit comments

Comments
 (0)