Python side TaskNode, connection to the c++ side TaskNode
Python side TaskNode, connection to the c++ side TaskNode
"""
"""
# track the previous init method
previous=None
def__init__(self,
def__init__(self,
cur_rank,
rank,
max_run_times,
max_run_times,
max_slot_times,
max_slot_times,
role=None,
role=None,
node_type='Compute',
node_type=None,
task_id=None,
task_id=0,
ops=None,
ops=None,
program=None):
program=None,
lazy_initialize=False):
"""
"""
:param cur_rank (int): Current rank of the task node.
:param rank (int): Current rank of the task node.
:param max_run_times (int): The max run times of the task node.
:param max_run_times (int): The max run times of the task node.
:param max_slot_times (int): The mas slot times of the task node.
:param max_slot_times (int): The mas slot times of the task node.
:param role (int): The role of the task node.
:param role (int): The role of the task node. (Will be removed in the future)
:param node_type (str): The type of the task node, default is 'Compute'
:param node_type (str): The type of the task node.
:param task_id (int): The task id of the task node.
:param task_id (int): The id of task node.
:param ops (list): A list of op.desc to init the task node.
:param ops (list): A list of op.desc to init the task node. (Will be removed in the future)
:param program (Program): An instance of Program to init the task node.
:param program (Program): An instance of Program to init the task node.
:param lazy_initialize (bool): In user-defined task, the program may change adding feed/fetch op. As efficient consideration, the task node will have the C++ object later.
"""
"""
# NOTE: ops should be checked by `is not None`, since it may be empty list
assert((opsisnotNone)^(programisnotNone)), \
assert((opsisnotNone)^(programisnotNone)), \
"Should provide only one of ops or program to task node."
"Should provide only one of ops or program to task node."
ifnotself.previous:
assert(not((opsisnotNone)andlazy_initialize)), \
self.previous='program'ifprogramelse'ops'
"Lazy initialization doesn't support with ops list"
"The task node has been instantiated by program, calling init before passing to fleet executor."
self.max_run_times,self.max_slot_times)
)
ifself.node_type:
self.node.init()
self.node.set_type(self.node_type)
ifself.run_pre_steps:
self.node.set_run_pre_steps(self.run_pre_steps)
ifself.run_at_offset:
self.node.set_run_at_offset(self.run_at_offset)
forupinself.upstreams:
self.node.add_upstream_task(up[0],up[1])
fordowninself.downstreams:
self.node.add_downstream_task(down[0],down[1])
self.lazy_initialize=False
returnself.node
returnself.node
defset_program(self,program):
defset_program(self,program):
assertself.lazy_initialize, \
"Inside program is unchangable for immediate initialized task node. Set the lazy_initialize to be true if the inside program need to be update. Remember to do all your change before eval node.task_node()."
self.program=program
self.program=program
self.node.set_program(program.desc)
defget_program(self):
defget_program(self):
asserthasattr(self,'program'),'There is no program to get'
assertself.programisnotNone,"The task node is not initialized using program"