Skip to content

Conversation

@liym27
Copy link
Contributor

@liym27 liym27 commented Sep 22, 2020

PR types

New features

PR changes

Others

Describe

Support assignment to a Variable in dynamic mode. note: not deal with backward.


功能支持:动态图 VarBase slice 赋值,inplace操作。

  • key支持:整数、python slice、省略号[...]
  • value支持:int, float, numpy.ndarray, Paddle Tensor
  • 其他:默认支持 expand
paddle.disable_static()
tensor_x = paddle.to_tensor(np.ones((2, 3)).astype(np.float32)) # [[1,1,1], [1,1,1]]
tensor_x[0] = 0    # tensor_x : [[0, 0, 0], [1 ,1, 1]]
tensor_x[0:1] = 0 # tensor_x : [[0, 0, 0], [1 ,1, 1]]
tensor_x[...] = 0   # tensor_x : [[0, 0, 0], [0, 0, 0]]

tensor_x[0] = np.array([3,3,3]) # tensor_x : [[3, 3, 3], [0, 0, 0]]
tensor_x[1] = paddle.ones([3]) # tensor_x : [[3, 3, 3], [1,1,1]]

附说明:本PR方案未使用op,考虑后续inplace操作可能无反向,以及该方案目前性能最优,使用下列方案2。

  1. 若仅在python端开发该功能,虽能支持以上功能,但性能最差
  2. 将方案1迁移到C++端(不调用op),性能最优。较方案1 性能提升了40%-50%
  3. 考虑到反向方案还未完全确定,前向也实现了c++端调用op的方案做对比(代码可见commit),但性能上不如方案2,且功能支持不全:不支持 key是省略号、左值赋值expand的情况。

TODO:

  • 增加前向文档说明
  • 这个只是暂时方案,后面会添加c++ op支持,因此我这里允许这个PR通过,但是后续最好修改,否则转成program后没了这个语句
  • 反向inplace检测

… backward.

Change-Id: Ib58ac537e1a6a0255352bd5b0ff18442d714526e
Change-Id: I612dc6fa735d7e0ba9962d18ea398009a1124cb5
@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot-old
Copy link

paddle-bot-old bot commented Sep 22, 2020

✅ This PR's description meets the template requirements!
Please wait for other CI results.

… op.

Change-Id: If683eb33df476af26ec7eb7fa56a3e6e7dc7dd97
Change-Id: Ib15b301da60bcc8d0240d31c04d1cc7aae713702
@liym27 liym27 changed the title Support setitem forward highperf Support assignment to a Variable in dynamic mode. Sep 24, 2020
@liym27 liym27 requested a review from zhhsplendid September 25, 2020 02:05
@zhiqiu
Copy link
Contributor

zhiqiu commented Sep 25, 2020

这个功能是需要在2.0-rc发布吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants