Skip to content

Commit 0f5e0ba

Browse files
【cherry-pick】add more info to tensor.grad warning message (#34264) #34288
Add more information to tensor.grad warning message.
1 parent 4ffd339 commit 0f5e0ba

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

python/paddle/fluid/dygraph/varbase_patch_methods.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,10 @@ def grad(self):
371371
# Tensor(shape=[1], dtype=float32, place=CUDAPlace(0), stop_gradient=False, [500.])
372372
373373
"""
374-
msg = "tensor.grad will return the tensor value of the gradient."
374+
msg = 'tensor.grad will return the tensor value of the gradient.' \
375+
' This is an incompatible upgrade for tensor.grad API. ' \
376+
' It\'s return type changes from numpy.ndarray in version 2.0 to paddle.Tensor in version 2.1.0. ' \
377+
' If you want to get the numpy value of the gradient, you can use :code:`x.grad.numpy()`'
375378
warning_msg = "\033[93m\nWarning:\n%s \033[0m" % (msg)
376379
# ensure ANSI escape sequences print correctly in cmd and powershell
377380
if sys.platform.lower() == 'win32':

0 commit comments

Comments
 (0)