ezyang / pytorch-unattached

Tensors and Dynamic neural networks in Python with strong GPU acceleration
http://pytorch.org
Other
20 stars 8 forks source link

Add a method for deleting multi-return nodes #231

Open ezyang opened 7 years ago

ezyang commented 7 years ago

Quote from DCE:

    if (node->hasMultipleOutputs() && allSelectsUnused(node)) {
      auto uses = node->uses(); // A copy so we don't modify it within a range loop
      for (auto & use : uses)
        use.user->destroy();
      it.destroyCurrent();
    } else if (node->uses().size() == 0) {
      it.destroyCurrent();
    } 

This is generally useful functionality and should be put in. Would seriously consider having destroyCurrent() learn this, but I also want to avoid putting too much node specific knowledge in the graph iterator (c.f. #229)