diff --git a/python/paddle/fluid/eager/eager_tensor_patch_methods.py b/python/paddle/fluid/eager/eager_tensor_patch_methods.py index b61bf78116aeb3960d32dded684d015ed0991962..547a948da402b0a3e8209ee8d0a2dd8b426c0476 100644 --- a/python/paddle/fluid/eager/eager_tensor_patch_methods.py +++ b/python/paddle/fluid/eager/eager_tensor_patch_methods.py @@ -20,4 +20,5 @@ def monkey_patch_eagertensor(): from paddle.tensor.to_string import eager_tensor_to_string return eager_tensor_to_string(self) - setattr(core.eager.EagerTensor, "__str__", __str__) + if hasattr(core, "eager"): + setattr(core.eager.EagerTensor, "__str__", __str__)