PaddlePaddle / Paddle

PArallel Distributed Deep LEarning: Machine Learning Framework from Industrial Practice (『飞桨』核心框架,深度学习&机器学习高性能单机、分布式训练和跨平台部署)
http://www.paddlepaddle.org/
Apache License 2.0
22.31k stars 5.63k forks source link

Paddle 3.0 不再支持数组按位赋值 #69391

Closed Liyulingyue closed 1 week ago

Liyulingyue commented 2 weeks ago

请提出你的问题 Please ask your question

问题说明

下述代码在Paddle 2.5 下可以使用,但在 Paddle 3.0 会出现报错。请问这个情况是是升级的特性,还是一个需要被修复的问题?

可复现代码


import paddle
t_not_eq_zero_indices = paddle.to_tensor([[True, True, True, True, True, True, False, True, True, True, True, True, True]])
sinc_filter = paddle.to_tensor([-159.05421448,  159.34126282, -159.57885742,  159.76324463,
        -159.89434814,  159.97329712,  159.97329712, -159.89434814,
         159.76324463, -159.57885742,  159.34126282, -159.05421448])
weights = paddle.to_tensor([[0.00024673, 0.07367989, 0.25912309, 0.50785363, 0.75452065, 0.93431580,
         1.        , 0.93431580, 0.75452065, 0.50785363, 0.25912309, 0.07367989,
         0.00024673]])
weights[t_not_eq_zero_indices] *= sinc_filter

报错信息

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)Cell In[6], line 1 ----> 1 weights[t_not_eq_zero_indices] *= sinc_filter File /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/base/dygraph/tensor_patch_methods.py:1020, in monkey_patch_tensor.<locals>.__setitem__(self, item, value) 1014 def __setitem__( 1015 self, 1016 item: TensorIndex, 1017 value: Tensor | npt.NDArray[Any] | complex | bool, 1018 ) -> None: 1019 item = pre_deal_index(self, item) -> 1020 return self._setitem_dygraph(item, value) 
ValueError: (InvalidArgument) The value (12) of the non-singleton dimension does not match the corresponding value (13) in shape for expand_v2 op. 
[Hint: Expected vec_in_dims[i] == expand_shape[i], but received vec_in_dims[i]:12 != expand_shape[i]:13.] (at /paddle/paddle/phi/kernels/impl/expand_kernel_impl.h:65)
zhwesky2010 commented 2 weeks ago

@Liyulingyue 你好,我咨询下相关同学看是否有不兼容升级

zhwesky2010 commented 2 weeks ago

@Liyulingyue 该问题为确认的Bug,相关同学后续会修复

HydrogenSulfate commented 1 week ago

已在#69480 中修复,

t_not_eq_zero_indices = paddle.to_tensor([[True, True, True, True, True, True, False, True, True, True, True, True, True]])
mask = (t_not_eq_zero_indices.numpy())
sinc_filter = paddle.to_tensor([-159.05421448,  159.34126282, -159.57885742,  159.76324463,
        -159.89434814,  159.97329712,  159.97329712, -159.89434814,
         159.76324463, -159.57885742,  159.34126282, -159.05421448])
v = (sinc_filter.numpy())
weights = paddle.to_tensor([[0.00024673, 0.07367989, 0.25912309, 0.50785363, 0.75452065, 0.93431580,
         1.        , 0.93431580, 0.75452065, 0.50785363, 0.25912309, 0.07367989,
         0.00024673]])
x = (weights.numpy())
weights[t_not_eq_zero_indices] *= sinc_filter

x[mask] *= v

import numpy as np

np.testing.assert_allclose(weights.numpy(), x)