torch/csrc/jit/interpreter.cpp
// insert Drop nodes to kill references for anything unused:
// this can happen in a few places, e.g. when a node returns
// many values but only one is used
// a, b = foo()
// return a
insert Drop nodes to kill references for anything unused:
this can happen in a few places, e.g. when a node returns
many values but only one is used
a, b = foo()
return a
insert Drop nodes to kill references for anything unused : this can happen in a few places e . g . when a node returns many values but only one is used a b = foo () return a
void dropUnused(Block *b) {
  auto createDropIfUnused = [&](ArrayRef<Value*> values) -> Node* {
    std::vector<Value*> to_drop;
    for(auto v : values) {
      if(v->uses().size() == 0)
        to_drop.push_back(v);
    }
    if(to_drop.size() == 0)
      return nullptr;
    return b->owningGraph()->create(prim::Drop, to_drop, 0);
  };
  if(auto d = createDropIfUnused(b->inputs())) {
    b->prependNode(d);
  }
  for(auto n : b->nodes()) {
    if(auto d = createDropIfUnused(n->outputs())) {
      d->insertAfter(n);
    }
    for(auto b : n->blocks())
      dropUnused(b);
  }
}
void dropUnused ( Block * b ) { auto createDropIfUnused = [ & ] ( ArrayRef < Value * > values ) -> Node * { std :: vector < Value * > to_drop ; for ( auto v : values ) { if ( v -> uses ( ) . size ( ) == 0 ) to_drop . push_back ( v ) ; } if ( to_drop . size ( ) == 0 ) return nullptr ; return b -> owningGraph ( ) -> create ( prim :: Drop , to_drop , 0 ) ; } ; if ( auto d = createDropIfUnused ( b -> inputs ( ) ) ) { b -> prependNode ( d ) ; } for ( auto n : b -> nodes ( ) ) { if ( auto d = createDropIfUnused ( n -> outputs ( ) ) ) { d -> insertAfter ( n ) ; } for ( auto b : n -> blocks ( ) ) dropUnused ( b ) ; } }
insert Drop nodes to kill references for anything unused:
this can happen in a few places, e.g.
insert Drop nodes to kill references for anything unused : this can happen in a few places e . g .