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

Class _StopGuard

caffe2/python/net_builder.py:525–548  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

523
524
525class _StopGuard(_RunOnce):
526 def __init__(self, has_stopped_blob=None, name=None):
527 _RunOnce.__init__(self, name)
528 self._stopped = has_stopped_blob
529 self._ran = False
530
531 def __enter__(self):
532 r = _RunOnce.__enter__(self)
533 self._stopped = ops.Const(True, blob_out=self._stopped)
534 return r
535
536 def __exit__(self, etype, *args):
537 if etype is None:
538 self._ran = True
539 ops.Const(False, blob_out=self._stopped)
540 _RunOnce.__exit__(self, etype, *args)
541
542 def has_stopped(self):
543 """
544 Return a blob that will be set to scalar bool `True` after
545 this net builder ran, iff it was halted early.
546 """
547 assert self._ran, 'Context not used yet.'
548 return self._stopped
549
550
551class _Loop(NetBuilder):

Callers 1

stop_guardMethod · 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…