MCPcopy Create free account
hub / github.com/pytorch/pytorch / _StateMeetsRule

Function _StateMeetsRule

caffe2/python/caffe_translator.py:20–36  ·  view source on GitHub ↗

A function that reproduces Caffe's StateMeetsRule functionality.

(state, rule)

Source from the content-addressed store, hash-verified

18
19
20def _StateMeetsRule(state, rule):
21 """A function that reproduces Caffe's StateMeetsRule functionality."""
22 if rule.HasField('phase') and rule.phase != state.phase:
23 return False
24 if rule.HasField('min_level') and state.level < rule.min_level:
25 return False
26 if rule.HasField('max_level') and state.level > rule.max_level:
27 return False
28 curr_stages = set(list(state.stage))
29 # all stages in rule.stages should be in, otherwise it's not a match.
30 if len(rule.stage) and any([s not in curr_stages for s in rule.stage]):
31 return False
32 # none of the stage in rule.stages should be in, otherwise it's not a match.
33 if len(rule.not_stage) and any([s in curr_stages for s in rule.not_stage]):
34 return False
35 # If none of the nonmatch happens, return True.
36 return True
37
38
39def _ShouldInclude(net_state, layer):

Callers 1

_ShouldIncludeFunction · 0.85

Calls 2

listFunction · 0.85
anyFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…