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

Function While

caffe2/python/control.py:372–409  ·  view source on GitHub ↗

Execute nets_or_steps when condition_blob_or_net returns true. Args: condition_blob_or_net: If it is an instance of Net, its last external_output must be a single bool. nets_or_steps: a ExecutionStep or a Net or a list of ExecutionSteps or a list nets.

(name, condition_blob_or_net, nets_or_steps)

Source from the content-addressed store, hash-verified

370
371
372def While(name, condition_blob_or_net, nets_or_steps):
373 """
374 Execute nets_or_steps when condition_blob_or_net returns true.
375
376 Args:
377 condition_blob_or_net: If it is an instance of Net, its last
378 external_output must be a single bool.
379 nets_or_steps: a ExecutionStep or a Net or a list of ExecutionSteps or
380 a list nets.
381
382 Returns:
383 A ExecutionStep instance.
384 """
385 condition_not_net, stop_blob = NotNet(condition_blob_or_net)
386 if isinstance(condition_blob_or_net, core.Net):
387 nets_or_steps = _PrependNets(
388 nets_or_steps, condition_blob_or_net, condition_not_net)
389 else:
390 nets_or_steps = _PrependNets(nets_or_steps, condition_not_net)
391
392 def while_step(control_name):
393 return core.scoped_execution_step(
394 _get_next_step_name(control_name, name),
395 nets_or_steps,
396 should_stop_blob=stop_blob,
397 )
398
399 if _IsNets(nets_or_steps):
400 # In this case, while_step has sub-nets:
401 # [condition_blob_or_net, condition_not_net, nets_or_steps]
402 # If stop_blob is pre-set to True (this may happen when While() is
403 # called twice), the loop will exit after executing
404 # condition_blob_or_net. So we use BootNet to set stop_blob to
405 # False.
406 bool_net = BoolNet((stop_blob, False))
407 return Do(name + '/While', bool_net, while_step('While-inner'))
408 else:
409 return while_step('While')
410
411
412def Until(name, condition_blob_or_net, nets_or_steps):

Callers 1

build_WhileMethod · 0.85

Calls 7

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…