From 0f5e0ba1ba3042dc4ef53ddb372cd162a42e9d4d Mon Sep 17 00:00:00 2001 From: chentianyu03 Date: Wed, 21 Jul 2021 15:06:19 +0800 Subject: [PATCH] =?UTF-8?q?=20=E3=80=90cherry-pick=E3=80=91add=20more=20in?= =?UTF-8?q?fo=20to=20tensor.grad=20warning=20message=20(#34264)=20#34288?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add more information to tensor.grad warning message. --- python/paddle/fluid/dygraph/varbase_patch_methods.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/paddle/fluid/dygraph/varbase_patch_methods.py b/python/paddle/fluid/dygraph/varbase_patch_methods.py index 17cd499bfee..2fda67e891a 100644 --- a/python/paddle/fluid/dygraph/varbase_patch_methods.py +++ b/python/paddle/fluid/dygraph/varbase_patch_methods.py @@ -371,7 +371,10 @@ def monkey_patch_varbase(): # Tensor(shape=[1], dtype=float32, place=CUDAPlace(0), stop_gradient=False, [500.]) """ - msg = "tensor.grad will return the tensor value of the gradient." + msg = 'tensor.grad will return the tensor value of the gradient.' \ + ' This is an incompatible upgrade for tensor.grad API. ' \ + ' It\'s return type changes from numpy.ndarray in version 2.0 to paddle.Tensor in version 2.1.0. ' \ + ' If you want to get the numpy value of the gradient, you can use :code:`x.grad.numpy()`' warning_msg = "\033[93m\nWarning:\n%s \033[0m" % (msg) # ensure ANSI escape sequences print correctly in cmd and powershell if sys.platform.lower() == 'win32': -- GitLab