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

Class Plan

caffe2/python/core.py:2882–2956  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2880
2881
2882class Plan:
2883
2884 def __init__(self, name_or_step):
2885 self._plan = caffe2_pb2.PlanDef()
2886 self._net_dict = OrderedDict()
2887 self._steps = [] # A list of ExecutionStep
2888 if isinstance(name_or_step, ExecutionStep):
2889 self._plan.name = name_or_step.Name()
2890 self.AddStep(name_or_step)
2891 elif isinstance(name_or_step, basestring):
2892 self._plan.name = name_or_step
2893 else:
2894 raise ValueError('name_or_step must be a string or ExecutionStep')
2895
2896 def __str__(self):
2897 return self._plan.name
2898
2899 def Proto(self):
2900 return self._plan
2901
2902 def AddNets(self, nets):
2903 for net in nets:
2904 if _add_net_to_dict(self._net_dict, net):
2905 assert isinstance(net, Net)
2906 self._plan.network.add().CopyFrom(net.Proto())
2907
2908 def Nets(self):
2909 return list(self._net_dict.values())
2910
2911 def AddStep(self, step):
2912 assert isinstance(step, ExecutionStep)
2913 step._notify_is_used()
2914 if not step.HasNets() and not step.HasSubsteps():
2915 return
2916 self._plan.execution_step.add().CopyFrom(step.Proto())
2917 self._steps.append(step)
2918 # nets need to be added to the plan in order of usage
2919 net_list = []
2920 add_nets_in_order(step, net_list)
2921 self.AddNets([step.get_net(n) for n in net_list])
2922
2923 def Steps(self):
2924 return self._steps
2925
2926 def get_all_attributes(self, name):
2927 """
2928 Return the list of all attributes under the given `name`, present in
2929 all of the nets used in this plan.
2930 """
2931 return [
2932 attr
2933 for net in self._net_dict.values()
2934 for attr in net.get_attributes(name)
2935 ]
2936
2937 @classmethod
2938 def create_from_proto(cls, plan_proto):
2939 assert isinstance(plan_proto, caffe2_pb2.PlanDef)

Callers 5

test_opsMethod · 0.90
test_if_netMethod · 0.90
test_while_netMethod · 0.90
analyze_taskFunction · 0.90
create_from_protoMethod · 0.85

Calls

no outgoing calls

Tested by 3

test_opsMethod · 0.72
test_if_netMethod · 0.72
test_while_netMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…