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

fix upsample shape infer bug #8105

Merged
merged 66 commits into from
May 21, 2022
Merged

fix upsample shape infer bug #8105

merged 66 commits into from
May 21, 2022

Conversation

BBuf
Copy link
Contributor

@BBuf BBuf commented Apr 27, 2022

fix upsample shape infer bug caused by float precision. linked: Oneflow-Inc/libai#260 (comment)

Copy link
Contributor

@MARD1NO MARD1NO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Attr("output_size")

Copy link
Contributor

@simonJJJ simonJJJ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么设置eps=1e-5呢

@BBuf
Copy link
Contributor Author

BBuf commented Apr 27, 2022

为什么设置eps=1e-5呢

准备基于output_size重构一下op,先忽略这个改动,会去掉。

BBuf and others added 8 commits May 9, 2022 10:31
* fix_upsample_shape_infer_bug

* fix 5 nearest

* add 5 nearest test

* fix 5 nearest test

* fix 1 linear

* fix 4 bilinear

* fix 4 bicubic

* modify bicubic 2d file name

* fix 5 trilinear

* fix exception info

* fix exception info

* fix bug

* modify interpolate

* change float to double

* rm useless SI64ArrayAttr: in OneFlowUserOps

* rm useless import in cpp

* update

* add judge for output_size

* update oneflow/oneflow/core/autograd/gradient_funcs/upsample.cpp

* add grad in td

* test failed

* fix small failed case in upsample

* solve test error

* change float to double

* align to fix_upsample_shape_infer_bug

* align to fix_upsample_shape_infer_bug

Co-authored-by: BBuf <1182563586@qq.com>
Copy link
Contributor

@simonJJJ simonJJJ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interpolate.py 103行这个地方还有必要保留scale吗

@BBuf
Copy link
Contributor Author

BBuf commented May 11, 2022

interpolate.py 103行这个地方还有必要保留scale吗

这个暂时去不掉,因为scale不是Optional的,改起来工作量依然比较大,准备下个pr来做。

@BBuf BBuf added the automerge label May 20, 2022
@github-actions
Copy link
Contributor

Speed stats:

@github-actions
Copy link
Contributor

Speed stats:
GPU Name: NVIDIA GeForce GTX 1080 

❌ OneFlow resnet50 time: 129.9ms (= 12988.5ms / 100, input_shape=[16, 3, 224, 224])
PyTorch resnet50 time: 141.4ms (= 14141.0ms / 100, input_shape=[16, 3, 224, 224])
✔️ Relative speed: 1.09 (= 141.4ms / 129.9ms)

OneFlow resnet50 time: 76.6ms (= 7659.6ms / 100, input_shape=[8, 3, 224, 224])
PyTorch resnet50 time: 82.8ms (= 8278.9ms / 100, input_shape=[8, 3, 224, 224])
✔️ Relative speed: 1.08 (= 82.8ms / 76.6ms)

OneFlow resnet50 time: 49.4ms (= 9887.9ms / 200, input_shape=[4, 3, 224, 224])
PyTorch resnet50 time: 55.1ms (= 11024.6ms / 200, input_shape=[4, 3, 224, 224])
✔️ Relative speed: 1.11 (= 55.1ms / 49.4ms)

OneFlow resnet50 time: 42.1ms (= 8416.8ms / 200, input_shape=[2, 3, 224, 224])
PyTorch resnet50 time: 45.3ms (= 9065.2ms / 200, input_shape=[2, 3, 224, 224])
✔️ Relative speed: 1.08 (= 45.3ms / 42.1ms)

OneFlow resnet50 time: 37.8ms (= 7561.5ms / 200, input_shape=[1, 3, 224, 224])
PyTorch resnet50 time: 38.9ms (= 7781.6ms / 200, input_shape=[1, 3, 224, 224])
✔️ Relative speed: 1.03 (= 38.9ms / 37.8ms)

OneFlow swin dataloader time: 0.247s (= 49.459s / 200, num_workers=1)
PyTorch swin dataloader time: 0.150s (= 29.969s / 200, num_workers=1)
Relative speed: 0.606 (= 0.150s / 0.247s)

OneFlow swin dataloader time: 0.066s (= 13.149s / 200, num_workers=4)
PyTorch swin dataloader time: 0.043s (= 8.568s / 200, num_workers=4)
Relative speed: 0.652 (= 0.043s / 0.066s)

OneFlow swin dataloader time: 0.038s (= 7.631s / 200, num_workers=8)
PyTorch swin dataloader time: 0.022s (= 4.454s / 200, num_workers=8)
Relative speed: 0.584 (= 0.022s / 0.038s)

❌ OneFlow resnet50 time: 145.7ms (= 14566.9ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 170.8ms (= 17077.5ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.17 (= 170.8ms / 145.7ms)

OneFlow resnet50 time: 97.2ms (= 9720.8ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 112.2ms (= 11224.3ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.15 (= 112.2ms / 97.2ms)

OneFlow resnet50 time: 74.3ms (= 14858.0ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 87.1ms (= 17414.1ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
❌ Relative speed: 1.17 (= 87.1ms / 74.3ms)

OneFlow resnet50 time: 61.2ms (= 12235.6ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 73.6ms (= 14723.5ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.20 (= 73.6ms / 61.2ms)

OneFlow resnet50 time: 55.7ms (= 11135.2ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 69.5ms (= 13892.5ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.25 (= 69.5ms / 55.7ms)

@github-actions
Copy link
Contributor

CI failed when running job: cpu-module. PR label automerge has been removed

@BBuf BBuf requested review from oneflow-ci-bot and removed request for oneflow-ci-bot May 21, 2022 01:36
@github-actions
Copy link
Contributor

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

@github-actions
Copy link
Contributor

Speed stats:
GPU Name: NVIDIA GeForce GTX 1080 

❌ OneFlow resnet50 time: 130.3ms (= 13026.4ms / 100, input_shape=[16, 3, 224, 224])
PyTorch resnet50 time: 142.8ms (= 14284.5ms / 100, input_shape=[16, 3, 224, 224])
✔️ Relative speed: 1.10 (= 142.8ms / 130.3ms)

OneFlow resnet50 time: 78.0ms (= 7796.2ms / 100, input_shape=[8, 3, 224, 224])
PyTorch resnet50 time: 84.2ms (= 8419.6ms / 100, input_shape=[8, 3, 224, 224])
✔️ Relative speed: 1.08 (= 84.2ms / 78.0ms)

OneFlow resnet50 time: 54.1ms (= 10821.6ms / 200, input_shape=[4, 3, 224, 224])
PyTorch resnet50 time: 54.8ms (= 10951.3ms / 200, input_shape=[4, 3, 224, 224])
✔️ Relative speed: 1.01 (= 54.8ms / 54.1ms)

OneFlow resnet50 time: 42.3ms (= 8459.3ms / 200, input_shape=[2, 3, 224, 224])
PyTorch resnet50 time: 44.1ms (= 8824.2ms / 200, input_shape=[2, 3, 224, 224])
✔️ Relative speed: 1.04 (= 44.1ms / 42.3ms)

OneFlow resnet50 time: 37.5ms (= 7503.6ms / 200, input_shape=[1, 3, 224, 224])
PyTorch resnet50 time: 39.8ms (= 7967.3ms / 200, input_shape=[1, 3, 224, 224])
✔️ Relative speed: 1.06 (= 39.8ms / 37.5ms)

OneFlow swin dataloader time: 0.247s (= 49.358s / 200, num_workers=1)
PyTorch swin dataloader time: 0.152s (= 30.405s / 200, num_workers=1)
Relative speed: 0.616 (= 0.152s / 0.247s)

OneFlow swin dataloader time: 0.065s (= 12.983s / 200, num_workers=4)
PyTorch swin dataloader time: 0.043s (= 8.516s / 200, num_workers=4)
Relative speed: 0.656 (= 0.043s / 0.065s)

OneFlow swin dataloader time: 0.035s (= 6.981s / 200, num_workers=8)
PyTorch swin dataloader time: 0.023s (= 4.565s / 200, num_workers=8)
Relative speed: 0.654 (= 0.023s / 0.035s)

❌ OneFlow resnet50 time: 146.1ms (= 14609.6ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 169.9ms (= 16987.1ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.16 (= 169.9ms / 146.1ms)

OneFlow resnet50 time: 98.2ms (= 9817.2ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 112.1ms (= 11213.2ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.14 (= 112.1ms / 98.2ms)

OneFlow resnet50 time: 73.3ms (= 14661.3ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 87.2ms (= 17432.4ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.19 (= 87.2ms / 73.3ms)

OneFlow resnet50 time: 62.2ms (= 12449.5ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 74.6ms (= 14924.3ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.20 (= 74.6ms / 62.2ms)

OneFlow resnet50 time: 54.2ms (= 10837.9ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 74.3ms (= 14852.0ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.37 (= 74.3ms / 54.2ms)

@github-actions
Copy link
Contributor

CI failed when running job: cpu-module. PR label automerge has been removed

@BBuf BBuf added the automerge label May 21, 2022
@github-actions
Copy link
Contributor

Speed stats:
GPU Name: GeForce GTX 1080 

✔️ OneFlow resnet50 time: 128.9ms (= 12891.3ms / 100, input_shape=[16, 3, 224, 224])
PyTorch resnet50 time: 140.7ms (= 14065.8ms / 100, input_shape=[16, 3, 224, 224])
✔️ Relative speed: 1.09 (= 140.7ms / 128.9ms)

OneFlow resnet50 time: 75.5ms (= 7548.5ms / 100, input_shape=[8, 3, 224, 224])
PyTorch resnet50 time: 85.0ms (= 8504.2ms / 100, input_shape=[8, 3, 224, 224])
✔️ Relative speed: 1.13 (= 85.0ms / 75.5ms)

OneFlow resnet50 time: 52.5ms (= 10499.1ms / 200, input_shape=[4, 3, 224, 224])
PyTorch resnet50 time: 52.7ms (= 10546.5ms / 200, input_shape=[4, 3, 224, 224])
❌ Relative speed: 1.00 (= 52.7ms / 52.5ms)

OneFlow resnet50 time: 40.4ms (= 8070.2ms / 200, input_shape=[2, 3, 224, 224])
PyTorch resnet50 time: 44.3ms (= 8864.3ms / 200, input_shape=[2, 3, 224, 224])
✔️ Relative speed: 1.10 (= 44.3ms / 40.4ms)

OneFlow resnet50 time: 37.1ms (= 7428.2ms / 200, input_shape=[1, 3, 224, 224])
PyTorch resnet50 time: 38.0ms (= 7601.3ms / 200, input_shape=[1, 3, 224, 224])
✔️ Relative speed: 1.02 (= 38.0ms / 37.1ms)

OneFlow swin dataloader time: 0.396s (= 79.116s / 200, num_workers=1)
PyTorch swin dataloader time: 0.150s (= 29.973s / 200, num_workers=1)
Relative speed: 0.379 (= 0.150s / 0.396s)

OneFlow swin dataloader time: 0.062s (= 12.489s / 200, num_workers=4)
PyTorch swin dataloader time: 0.040s (= 7.954s / 200, num_workers=4)
Relative speed: 0.637 (= 0.040s / 0.062s)

OneFlow swin dataloader time: 0.036s (= 7.231s / 200, num_workers=8)
PyTorch swin dataloader time: 0.022s (= 4.397s / 200, num_workers=8)
Relative speed: 0.608 (= 0.022s / 0.036s)

✔️ OneFlow resnet50 time: 136.3ms (= 13625.5ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 159.8ms (= 15981.2ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.17 (= 159.8ms / 136.3ms)

OneFlow resnet50 time: 88.4ms (= 8835.9ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 101.1ms (= 10113.2ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.14 (= 101.1ms / 88.4ms)

OneFlow resnet50 time: 60.6ms (= 12110.9ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 79.0ms (= 15805.8ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.31 (= 79.0ms / 60.6ms)

OneFlow resnet50 time: 51.1ms (= 10215.3ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 69.1ms (= 13812.2ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.35 (= 69.1ms / 51.1ms)

OneFlow resnet50 time: 45.1ms (= 9010.0ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 67.2ms (= 13430.4ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.49 (= 67.2ms / 45.1ms)

@BBuf BBuf requested review from oneflow-ci-bot and removed request for oneflow-ci-bot May 21, 2022 04:38
@github-actions
Copy link
Contributor

Speed stats:
GPU Name: GeForce GTX 1080 

✔️ OneFlow resnet50 time: 128.9ms (= 12888.3ms / 100, input_shape=[16, 3, 224, 224])
PyTorch resnet50 time: 141.6ms (= 14157.6ms / 100, input_shape=[16, 3, 224, 224])
✔️ Relative speed: 1.10 (= 141.6ms / 128.9ms)

OneFlow resnet50 time: 75.9ms (= 7591.4ms / 100, input_shape=[8, 3, 224, 224])
PyTorch resnet50 time: 82.2ms (= 8216.4ms / 100, input_shape=[8, 3, 224, 224])
✔️ Relative speed: 1.08 (= 82.2ms / 75.9ms)

OneFlow resnet50 time: 51.5ms (= 10292.8ms / 200, input_shape=[4, 3, 224, 224])
PyTorch resnet50 time: 63.9ms (= 12790.0ms / 200, input_shape=[4, 3, 224, 224])
✔️ Relative speed: 1.24 (= 63.9ms / 51.5ms)

OneFlow resnet50 time: 41.5ms (= 8291.0ms / 200, input_shape=[2, 3, 224, 224])
PyTorch resnet50 time: 40.6ms (= 8110.4ms / 200, input_shape=[2, 3, 224, 224])
❌ Relative speed: 0.98 (= 40.6ms / 41.5ms)

OneFlow resnet50 time: 37.0ms (= 7396.3ms / 200, input_shape=[1, 3, 224, 224])
PyTorch resnet50 time: 37.5ms (= 7499.4ms / 200, input_shape=[1, 3, 224, 224])
✔️ Relative speed: 1.01 (= 37.5ms / 37.0ms)

OneFlow swin dataloader time: 0.243s (= 48.628s / 200, num_workers=1)
PyTorch swin dataloader time: 0.149s (= 29.794s / 200, num_workers=1)
Relative speed: 0.613 (= 0.149s / 0.243s)

OneFlow swin dataloader time: 0.064s (= 12.742s / 200, num_workers=4)
PyTorch swin dataloader time: 0.041s (= 8.286s / 200, num_workers=4)
Relative speed: 0.650 (= 0.041s / 0.064s)

OneFlow swin dataloader time: 0.036s (= 7.188s / 200, num_workers=8)
PyTorch swin dataloader time: 0.022s (= 4.318s / 200, num_workers=8)
Relative speed: 0.601 (= 0.022s / 0.036s)

❌ OneFlow resnet50 time: 137.8ms (= 13781.8ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 161.8ms (= 16179.1ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.17 (= 161.8ms / 137.8ms)

OneFlow resnet50 time: 86.9ms (= 8690.5ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 102.1ms (= 10208.2ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.17 (= 102.1ms / 86.9ms)

OneFlow resnet50 time: 62.5ms (= 12491.9ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 88.3ms (= 17659.1ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.41 (= 88.3ms / 62.5ms)

OneFlow resnet50 time: 51.9ms (= 10389.3ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 70.0ms (= 13999.9ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.35 (= 70.0ms / 51.9ms)

OneFlow resnet50 time: 46.3ms (= 9264.5ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 75.6ms (= 15120.3ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.63 (= 75.6ms / 46.3ms)

@github-actions
Copy link
Contributor

CI failed when running job: cpu-module. PR label automerge has been removed

@github-actions
Copy link
Contributor

Speed stats:
GPU Name: NVIDIA GeForce GTX 1080 

❌ OneFlow resnet50 time: 130.2ms (= 13023.1ms / 100, input_shape=[16, 3, 224, 224])
PyTorch resnet50 time: 144.0ms (= 14404.0ms / 100, input_shape=[16, 3, 224, 224])
✔️ Relative speed: 1.11 (= 144.0ms / 130.2ms)

OneFlow resnet50 time: 76.4ms (= 7636.7ms / 100, input_shape=[8, 3, 224, 224])
PyTorch resnet50 time: 84.8ms (= 8478.6ms / 100, input_shape=[8, 3, 224, 224])
✔️ Relative speed: 1.11 (= 84.8ms / 76.4ms)

OneFlow resnet50 time: 54.0ms (= 10805.7ms / 200, input_shape=[4, 3, 224, 224])
PyTorch resnet50 time: 56.1ms (= 11214.0ms / 200, input_shape=[4, 3, 224, 224])
✔️ Relative speed: 1.04 (= 56.1ms / 54.0ms)

OneFlow resnet50 time: 43.0ms (= 8594.0ms / 200, input_shape=[2, 3, 224, 224])
PyTorch resnet50 time: 45.6ms (= 9126.0ms / 200, input_shape=[2, 3, 224, 224])
✔️ Relative speed: 1.06 (= 45.6ms / 43.0ms)

OneFlow resnet50 time: 37.6ms (= 7529.0ms / 200, input_shape=[1, 3, 224, 224])
PyTorch resnet50 time: 40.7ms (= 8132.3ms / 200, input_shape=[1, 3, 224, 224])
✔️ Relative speed: 1.08 (= 40.7ms / 37.6ms)

OneFlow swin dataloader time: 0.379s (= 75.843s / 200, num_workers=1)
PyTorch swin dataloader time: 0.151s (= 30.246s / 200, num_workers=1)
Relative speed: 0.399 (= 0.151s / 0.379s)

OneFlow swin dataloader time: 0.065s (= 12.969s / 200, num_workers=4)
PyTorch swin dataloader time: 0.041s (= 8.118s / 200, num_workers=4)
Relative speed: 0.626 (= 0.041s / 0.065s)

OneFlow swin dataloader time: 0.037s (= 7.306s / 200, num_workers=8)
PyTorch swin dataloader time: 0.022s (= 4.435s / 200, num_workers=8)
Relative speed: 0.607 (= 0.022s / 0.037s)

❌ OneFlow resnet50 time: 145.6ms (= 14559.5ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 170.4ms (= 17042.2ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.17 (= 170.4ms / 145.6ms)

OneFlow resnet50 time: 98.5ms (= 9850.1ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 112.2ms (= 11221.8ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.14 (= 112.2ms / 98.5ms)

OneFlow resnet50 time: 73.4ms (= 14682.2ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 88.5ms (= 17708.6ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.21 (= 88.5ms / 73.4ms)

OneFlow resnet50 time: 61.8ms (= 12362.4ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 74.4ms (= 14882.6ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.20 (= 74.4ms / 61.8ms)

OneFlow resnet50 time: 57.5ms (= 11506.3ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 77.5ms (= 15497.9ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.35 (= 77.5ms / 57.5ms)

@BBuf BBuf merged commit 0afc09f into master May 21, 2022
@BBuf BBuf deleted the fix_upsample_shape_infer_bug branch May 21, 2022 15:25
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.

5 participants