`Executor` should not create variable whose name are `@Empty@`
Created by: JiayiFeng
In backward building process, @Empty@
is used to rename variables to indicate that they are not necessary for backward. If we try accessing a @Empty@
, we shall get a nullptr
. This is required by several places in our code, for example:
class WhileGradOpVarTypeInference : public framework::VarTypeInference {
public:
void operator()(const framework::OpDescBind &op_desc,
framework::BlockDescBind *block) const override {
auto p_names = op_desc.Input(kParameters);
auto pg_names = op_desc.Output(framework::GradVarName(kParameters));
for (size_t i = 0; i < p_names.size(); ++i) {
auto &p_var = detail::Ref(block->FindVarRecursive(p_names[i]));
auto *g_var = block->FindVarRecursive(pg_names[i]);
if (g_var != nullptr) { // Gradient could be @EMPTY@
VLOG(5) << "Setting " << pg_names[i] << " following " << p_names[i]
<< " type: " << p_var.GetType();
g_var->SetType(p_var.GetType());
g_var->SetDataType(p_var.GetDataType());
}
}
}
};
if g_var
is not nullptr
while pg_names[i]
is @Empty@
, we wil go into the if
block and then invoke g_var->SetDataType(p_var.GetDataType());
. However, as a variable which has no gradient value, p_var
maight be some special type which is not supported by GetDataType()
(e.g. lod_rank_table
).
To aviod it, we shall make sure that Executor
does not create variables whose name are @Empty@