You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, Developer, Due to the poor support for the 0D tensor in Paddle API. In many case, the output 1D tensor which shoulde be 0D Tensor (such as loss) are used by mistake. Paddle is plan to support 0D tensor fully, which will not cause incompatibility in most cases. However, it is also found that some code will report error.
This code is: loss.numpy()[0] 。 The reason is that the loss was 1D Tensor (wrong) before, it can be used as loss.numpy()[0]. After the loss is modified to 0D Tensor (correct), the operation will result in an error. Therefore, it is needed to modify loss.numpy()[0] to float(loss) , to avoid errors in future paddle version.
Therefore, please modify:
As for shape[1] Tensor: modify Tensor.numpy()[0] to float (Tensor) , It will not affect the current situation, but also adapt to future. Thank you for contributing code.
The text was updated successfully, but these errors were encountered:
Hi,开发者你好,由于飞桨API之前对0维Tensor的支持不完善,通过shape为[1]的1D Tensor来替代shape为[]的0D Tensor,因此在很多本应输出0维tensor的场景中,实际输出的是1维tensor(如:loss)。目前飞桨计划全面支持0维tensor,在大多数情况下不会有不兼容问题,但也发现少量情况可能会报错。
目前发现 会报错 的代码是:
loss.numpy()[0]
。原因是此前loss为1D Tensor(错误的语义),运行loss.numpy()[0]可以将其转化为python float数据。在修改为0D Tensor(正确的语义)后,此操作会报错。需要将所有loss.numpy()[0]
修改为float(loss)
,以避免后续版本的代码错误。因此请麻烦修改:
Tensor.numpy()[0]
修改为float(Tensor)
,对当前不会有影响,亦可适应未来变化。感谢贡献代码。Hi, Developer, Due to the poor support for the 0D tensor in Paddle API. In many case, the output 1D tensor which shoulde be 0D Tensor (such as loss) are used by mistake. Paddle is plan to support 0D tensor fully, which will not cause incompatibility in most cases. However, it is also found that some code will report error.
This code is:
loss.numpy()[0]
。 The reason is that the loss was 1D Tensor (wrong) before, it can be used asloss.numpy()[0]
. After the loss is modified to 0D Tensor (correct), the operation will result in an error. Therefore, it is needed to modifyloss.numpy()[0]
tofloat(loss)
, to avoid errors in future paddle version.Therefore, please modify:
Tensor.numpy()[0]
tofloat (Tensor)
, It will not affect the current situation, but also adapt to future. Thank you for contributing code.The text was updated successfully, but these errors were encountered: