Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat.] Support tensor set item in graph #7751

Merged
merged 53 commits into from
May 1, 2022
Merged

Conversation

strint
Copy link
Contributor

@strint strint commented Mar 10, 2022

graph中global tensor支持非var op的tesnor.set_item

mask[:, :len_keep] = 0

还有几个其它场景的支持要再完善下:

  • graph下,variable和activation被set item,处理方式其实不同,要考虑兼容;
    • [Done]activation做的是类似ssa的inplace
    • [Done]兼容eager
  • [Done]eager local tensor调用的flow.slice_update 改成Inplace的;

关联Issue:https://github.com/Oneflow-Inc/OneTeam/issues/1303

@strint strint changed the title Slice assign for graph tensor set item for graph Mar 10, 2022
@hjchen2
Copy link
Contributor

hjchen2 commented Mar 11, 2022

local tensor调用的slice update,现在行为其实不正常,需要处理成Inplace的;

local tensor调用slice update行为有什么问题么?它在调用的时候用的就是inplace的

@jackalcooper
Copy link
Collaborator

@mosout @daquexian 如果 nn graph 本身就支持了这个,是不是constant fold也可以用这些接口

@strint
Copy link
Contributor Author

strint commented Apr 26, 2022

local tensor调用的slice update,现在行为其实不正常,需要处理成Inplace的;

local tensor调用slice update行为有什么问题么?它在调用的时候用的就是inplace的

昨天看了下,只是 flow.slice_update 用的非inplace接口,改成inplace就好了。

@hjchen2
Copy link
Contributor

hjchen2 commented Apr 26, 2022

local tensor调用的slice update,现在行为其实不正常,需要处理成Inplace的;

local tensor调用slice update行为有什么问题么?它在调用的时候用的就是inplace的

昨天看了下,只是 flow.slice_update 用的非inplace接口,改成inplace就好了。

嗯,setitem里调用的是inplace的,这个flow.slice_update接口感觉没有必要导出到python,pytorch也没有这个接口,它完全可以用setitem来取代

@mosout
Copy link
Contributor

mosout commented Apr 26, 2022

@mosout @daquexian 如果 nn graph 本身就支持了这个,是不是constant fold也可以用这些接口

不是的 按照目前的方案 constant folding的执行过程是纯eager的

@strint strint marked this pull request as ready for review April 27, 2022 02:48
@strint strint requested review from hjchen2 and BBuf as code owners April 27, 2022 02:48
@github-actions
Copy link
Contributor

CI failed when running job: Build cu102_xla. PR label automerge has been removed

@github-actions
Copy link
Contributor

View latest API docs preview at: https://staging.oneflow.info/docs/Oneflow-Inc/oneflow/pr/7751/

@github-actions
Copy link
Contributor

View latest API docs preview at: https://staging.oneflow.info/docs/Oneflow-Inc/oneflow/pr/7751/

@github-actions
Copy link
Contributor

View latest API docs preview at: https://staging.oneflow.info/docs/Oneflow-Inc/oneflow/pr/7751/

@github-actions
Copy link
Contributor

Speed stats:

@github-actions
Copy link
Contributor

github-actions bot commented May 1, 2022

View latest API docs preview at: https://staging.oneflow.info/docs/Oneflow-Inc/oneflow/pr/7751/

@github-actions
Copy link
Contributor

github-actions bot commented May 1, 2022

View latest API docs preview at: https://staging.oneflow.info/docs/Oneflow-Inc/oneflow/pr/7751/

@github-actions
Copy link
Contributor

github-actions bot commented May 1, 2022

Speed stats:
GPU Name: GeForce GTX 1080 

✔️ OneFlow resnet50 time: 128.6ms (= 12863.2ms / 100, input_shape=[16, 3, 224, 224])
PyTorch resnet50 time: 142.3ms (= 14229.8ms / 100, input_shape=[16, 3, 224, 224])
✔️ Relative speed: 1.11 (= 142.3ms / 128.6ms)

OneFlow resnet50 time: 78.3ms (= 7829.7ms / 100, input_shape=[8, 3, 224, 224])
PyTorch resnet50 time: 84.7ms (= 8468.4ms / 100, input_shape=[8, 3, 224, 224])
✔️ Relative speed: 1.08 (= 84.7ms / 78.3ms)

OneFlow resnet50 time: 53.4ms (= 10687.7ms / 200, input_shape=[4, 3, 224, 224])
PyTorch resnet50 time: 58.9ms (= 11784.2ms / 200, input_shape=[4, 3, 224, 224])
✔️ Relative speed: 1.10 (= 58.9ms / 53.4ms)

OneFlow resnet50 time: 41.7ms (= 8344.2ms / 200, input_shape=[2, 3, 224, 224])
PyTorch resnet50 time: 40.1ms (= 8012.1ms / 200, input_shape=[2, 3, 224, 224])
❌ Relative speed: 0.96 (= 40.1ms / 41.7ms)

OneFlow resnet50 time: 39.1ms (= 7827.0ms / 200, input_shape=[1, 3, 224, 224])
PyTorch resnet50 time: 41.5ms (= 8300.4ms / 200, input_shape=[1, 3, 224, 224])
✔️ Relative speed: 1.06 (= 41.5ms / 39.1ms)

OneFlow swin dataloader time: 0.258s (= 51.537s / 200, num_workers=1)
PyTorch swin dataloader time: 0.150s (= 30.082s / 200, num_workers=1)
Relative speed: 0.584 (= 0.150s / 0.258s)

OneFlow swin dataloader time: 0.071s (= 14.147s / 200, num_workers=4)
PyTorch swin dataloader time: 0.042s (= 8.464s / 200, num_workers=4)
Relative speed: 0.598 (= 0.042s / 0.071s)

OneFlow swin dataloader time: 0.037s (= 7.333s / 200, num_workers=8)
PyTorch swin dataloader time: 0.022s (= 4.457s / 200, num_workers=8)
Relative speed: 0.608 (= 0.022s / 0.037s)

✔️ OneFlow resnet50 time: 135.6ms (= 13563.4ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 160.5ms (= 16054.6ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.18 (= 160.5ms / 135.6ms)

OneFlow resnet50 time: 89.1ms (= 8909.9ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 100.1ms (= 10005.5ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.12 (= 100.1ms / 89.1ms)

OneFlow resnet50 time: 65.9ms (= 13180.2ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 77.4ms (= 15471.2ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
❌ Relative speed: 1.17 (= 77.4ms / 65.9ms)

OneFlow resnet50 time: 50.9ms (= 10182.6ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 69.2ms (= 13848.8ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.36 (= 69.2ms / 50.9ms)

OneFlow resnet50 time: 52.3ms (= 10454.3ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 74.6ms (= 14913.6ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.43 (= 74.6ms / 52.3ms)

@github-actions
Copy link
Contributor

github-actions bot commented May 1, 2022

Speed stats:

@github-actions
Copy link
Contributor

github-actions bot commented May 1, 2022

Speed stats:

@github-actions
Copy link
Contributor

github-actions bot commented May 1, 2022

View latest API docs preview at: https://staging.oneflow.info/docs/Oneflow-Inc/oneflow/pr/7751/

@github-actions
Copy link
Contributor

github-actions bot commented May 1, 2022

View latest API docs preview at: https://staging.oneflow.info/docs/Oneflow-Inc/oneflow/pr/7751/

@mergify mergify bot merged commit b3f84bb into master May 1, 2022
@mergify mergify bot deleted the slice_assign_non_inplace branch May 1, 2022 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants