@@ -48,13 +48,6 @@ std::unordered_set<Symbol> skip_list = {
48
48
// where the constant tensor would be large but cheap to create.
49
49
};
50
50
51
- std::unordered_set<Symbol> tuple_ops = {
52
- prim::TupleSlice,
53
- prim::TupleIndex,
54
- prim::TupleUnpack,
55
- prim::TupleConstruct,
56
- };
57
-
58
51
struct ConstantPropagator {
59
52
// Runs constant propagation with an aliasing db and checks if inputs or
60
53
// outputs might be mutated in the graph
@@ -82,20 +75,11 @@ struct ConstantPropagator {
82
75
}
83
76
}
84
77
85
- void pushIValue (Value* v, Stack& stack) {
86
- if (tuples.count (v)) {
87
- const auto & ival = tuples[v];
88
- stack.push_back (ival);
89
- } else {
90
- stack.push_back (*toIValue (v));
91
- }
92
- }
93
-
94
78
std::vector<IValue> runNode (Node* n) {
95
79
auto op = getOperation (n);
96
80
Stack stack;
97
81
for (auto input : n->inputs ()) {
98
- pushIValue ( input, stack );
82
+ stack. push_back (* toIValue ( input) );
99
83
}
100
84
op (stack);
101
85
auto var_outputs = fmap (stack, [&](IValue v) -> IValue {
@@ -117,34 +101,6 @@ struct ConstantPropagator {
117
101
return var_outputs;
118
102
}
119
103
120
- // Tuples are not representable as constants, however
121
- // we can try to insert each tuple element and then create a TupleConstruct
122
- // from the elements
123
- Value* tryInsertTuple (const IValue& tuple, Value* tuple_to_replace) {
124
- auto type = tuple_to_replace->type ();
125
- TupleTypePtr tup_type;
126
- if (auto opt = type->cast <OptionalType>()) {
127
- tup_type = opt->getElementType ()->expect <TupleType>();
128
- } else {
129
- tup_type = type->expect <TupleType>();
130
- }
131
- auto type_elements = tup_type->elements ();
132
- const auto & tuple_elements = tuple.toTuple ()->elements ();
133
- std::vector<Value*> inputs;
134
- for (size_t i = 0 ; i < type_elements.size (); ++i) {
135
- auto inp = tryInsertConstant (*graph_, tuple_elements[i]);
136
- if (inp) {
137
- inputs.push_back (*inp);
138
- } else {
139
- return nullptr ;
140
- }
141
- }
142
- auto new_tuple = graph_->insertNode (graph_->createTuple (inputs));
143
- tuple_to_replace->replaceAllUsesWith (new_tuple->output ());
144
- new_tuple->output ()->copyMetadata (tuple_to_replace);
145
- return new_tuple->output ();
146
- }
147
-
148
104
void propagateNode (Node* n) {
149
105
std::vector<IValue> outputs;
150
106
try {
@@ -168,19 +124,6 @@ struct ConstantPropagator {
168
124
(*new_output)->setType (n->outputs ()[i]->type ());
169
125
}
170
126
n->outputs ()[i]->replaceAllUsesWith (*new_output);
171
- } else if (outputs[i].isTuple ()) {
172
- // we save the new Tuple ivalue in case it is used in an op that
173
- // forwards tuples later in the graph, such as a Tuple index
174
- auto tuple_val = n->outputs ()[i];
175
- if (auto new_tup = tryInsertTuple (outputs[i], tuple_val)) {
176
- GRAPH_UPDATE (
177
- " Folding tuple %" ,
178
- n->outputs ()[i]->debugName (),
179
- " with " ,
180
- getHeader (new_tup->node ()));
181
- tuple_val = new_tup;
182
- }
183
- tuples[tuple_val] = std::move (outputs[i]);
184
127
}
185
128
// If we cannot insert the IValue as a constant, give up replacing the
186
129
// node and let DCE remove it
@@ -322,12 +265,6 @@ struct ConstantPropagator {
322
265
})) {
323
266
return true ;
324
267
}
325
- if (tuple_ops.count (n->kind ())) {
326
- return (
327
- std::all_of (n->inputs ().begin (), n->inputs ().end (), [&](Value* v) {
328
- return v->node ()->kind () == prim::Constant || tuples.count (v);
329
- }));
330
- }
331
268
return false ;
332
269
};
333
270
@@ -390,8 +327,6 @@ struct ConstantPropagator {
390
327
391
328
std::shared_ptr<Graph> graph_;
392
329
std::unique_ptr<AliasDb> aliasDb_;
393
- // these are tuples which we know the computed IValue for
394
- std::unordered_map<Value*, IValue> tuples;
395
330
};
396
331
} // anonymous namespace
397
332
0 commit comments