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

Function _RunOnceIf

caffe2/python/control.py:295–323  ·  view source on GitHub ↗

Execute nets_or_steps once if condition_blob_or_net evaluates as true. If condition_blob_or_net is Net, the condition is its last external_output that must be a single bool. And this net will be executed before nets_or_steps so as to get the condition.

(name, condition_blob_or_net, nets_or_steps)

Source from the content-addressed store, hash-verified

293
294
295def _RunOnceIf(name, condition_blob_or_net, nets_or_steps):
296 """
297 Execute nets_or_steps once if condition_blob_or_net evaluates as true.
298
299 If condition_blob_or_net is Net, the condition is its last external_output
300 that must be a single bool. And this net will be executed before
301 nets_or_steps so as to get the condition.
302 """
303 condition_not_net, stop_blob = NotNet(condition_blob_or_net)
304 if isinstance(condition_blob_or_net, core.Net):
305 nets_or_steps = _PrependNets(
306 nets_or_steps, condition_blob_or_net, condition_not_net)
307 else:
308 nets_or_steps = _PrependNets(nets_or_steps, condition_not_net)
309
310 def if_step(control_name):
311 return core.scoped_execution_step(
312 _get_next_step_name(control_name, name),
313 nets_or_steps,
314 should_stop_blob=stop_blob,
315 only_once=True,
316 )
317
318 if _IsNets(nets_or_steps):
319 bool_net = BoolNet((stop_blob, False))
320 return Do(name + '/_RunOnceIf',
321 bool_net, if_step('_RunOnceIf-inner'))
322 else:
323 return if_step('_RunOnceIf')
324
325
326def _RunOnceIfNot(name, condition_blob_or_net, nets_or_steps):

Callers 3

SwitchFunction · 0.85
IfFunction · 0.85
IfNotFunction · 0.85

Calls 7

NotNetFunction · 0.85
isinstanceFunction · 0.85
_PrependNetsFunction · 0.85
_IsNetsFunction · 0.85
BoolNetFunction · 0.85
DoFunction · 0.85
if_stepFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…