MCPcopy Index your code
hub / github.com/pytorch/pytorch / _RunIfNet

Class _RunIfNet

caffe2/python/net_builder.py:612–642  ·  view source on GitHub ↗

Generates a single net that uses If operator

Source from the content-addressed store, hash-verified

610
611
612class _RunIfNet(NetBuilder):
613 """
614 Generates a single net that uses If operator
615 """
616 def __init__(self, cond_blob, name=None):
617 NetBuilder.__init__(self, name=name, _use_control_ops=True)
618 assert cond_blob, 'Conditional blob is not specified for an If net'
619 self._cond_blob = cond_blob
620 self._then_net = None
621 self._else_net = None
622
623 def add(self, child):
624 return NetBuilder.add(self, child)
625
626 def __exit__(self, type, *args):
627 if type is None:
628 _then_nets = self._children
629 self._reset_children()
630
631 self._then_net = NetBuilder.merge_nets(
632 _then_nets, self._lexical_scope)
633 if not self._then_net:
634 self._then_net = core.Net('empty_then_net')
635
636 if_net = core.Net(self.name + '/if_net')
637 add_if_op(if_net, self._cond_blob, self._lexical_scope,
638 self._then_net, self._else_net)
639
640 self._current_net = if_net
641 self._children = [if_net]
642 NetBuilder.__exit__(self, type, *args)
643
644
645class _RunElseNet(NetBuilder):

Callers 1

IfNetMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…