Add ProgramDesc as an argument to Operator::Run
Created by: helinwang
Problem
We have OPs (recurrent op, while op, parallel do op, conditional block op, recv op) that needs BlockDesc or ProgramDesc inside Operator::Run. Because currently Operator::Run does not take ProgramDesc as an argument, we serialize them into attributes, and deserialize during run. It has several issues:
-
Hard to debug the ProgramDesc: the attribute is a binary string, we do not understand it when printing it out. Also Python
print(program.to_string(True))
will raise exception when parsing the message, because currently serialized ProgramDesc and BlockDesc is saved asproto::string
, and Pythonproto::string
parsing only support utf8 strings. Related issue: https://github.com/PaddlePaddle/Paddle/issues/7343 https://github.com/PaddlePaddle/Paddle/issues/7419 -
The following code shows up in many places in our codebase:
auto *block = Attr<framework::BlockDesc *>(kStepBlock); auto *program = block->Program();
From my understanding its a workaround to the fact that Operator::Run does not take ProgramDesc as an argument. Otherwise we could use the index of the BlockDesc in the ProgramDesc as an attribute.
Solution
Given some of our OP need ProgramDesc in run, one solution is to pass it as an argument of Operator::Run. I would oppose to this solution if OP does not use executor to run ProgramDesc. Currently OP can run program, I think it's reasonable to let OP know the ProgramDesc that it runs in.