diff --git a/paddle/fluid/imperative/layout_transformer.h b/paddle/fluid/imperative/layout_transformer.h index 9689fffb673420b07d89831ec3d908e789d7f88c..555ec4170c8a8a5c2e627d04f50e6033b64f70d7 100644 --- a/paddle/fluid/imperative/layout_transformer.h +++ b/paddle/fluid/imperative/layout_transformer.h @@ -25,7 +25,7 @@ namespace imperative { template void SetOutDataLayout(std::shared_ptr var, const paddle::experimental::DataLayout layout) { - if (var != nullptr) { + if (var != nullptr && var->Var().IsInitialized()) { paddle::imperative::SetDataLayout(var, layout); // set out_tensor's layout if (var->MutableVar()->IsInitialized()) {