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 tensor method docstr bug #7841

Merged
merged 16 commits into from
Mar 26, 2022
Merged

fix tensor method docstr bug #7841

merged 16 commits into from
Mar 26, 2022

Conversation

BBuf
Copy link
Contributor

@BBuf BBuf commented Mar 19, 2022

修复了一部分Tensor方法没有docstr的bug。

  • sqrt
  • square
  • addmm
  • cosh
  • diagonal
  • log
  • ndim
  • rsqrt

剩下的:

  • stride
  • clone
  • data
  • detach
  • dtype
  • shape

是通过pybind11直接导出的,直接设置docstr会触发错误,后面需要和迟哥讨论一下再解决。

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/zhangxiaoyu/oneflow/python/oneflow/__init__.py", line 401, in <module>
    import oneflow.framework.docstr as docstr
  File "/home/zhangxiaoyu/oneflow/python/oneflow/framework/docstr/__init__.py", line 30, in <module>
    from .tensor import *
  File "/home/zhangxiaoyu/oneflow/python/oneflow/framework/docstr/tensor.py", line 1563, in <module>
    add_docstr(
  File "/home/zhangxiaoyu/oneflow/python/oneflow/framework/docstr/utils.py", line 32, in add_docstr
    return oneflow._oneflow_internal.add_doc(fun, docstr)
oneflow._oneflow_internal.exception.RuntimeException: 
  File "/home/zhangxiaoyu/oneflow/oneflow/api/python/framework/doc.cpp", line 56, in AddFunctionDoc
    RuntimeError: function is instancemethod, not a valid function.
>>> exit()

最后:norm这个算子的docstr比较复杂,设计到pytorch的新老接口替换的问题,也需要再讨论一下。

这个pr可以先合并,以下是本次补充的docstr的截图。

image

image

image

image

image

image

image

@BBuf BBuf requested review from oneflow-ci-bot and removed request for oneflow-ci-bot March 20, 2022 02:12
@github-actions
Copy link
Contributor

CI failed when running job: cuda-module-distributed-rank-1. PR label automerge has been removed

@BBuf BBuf requested review from oneflow-ci-bot and removed request for oneflow-ci-bot March 20, 2022 12:49
@BBuf BBuf added the automerge label Mar 20, 2022
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot March 20, 2022 15:47
@github-actions
Copy link
Contributor

CI failed when running job: cuda-module-distributed-rank-0. PR label automerge has been removed

@BBuf BBuf requested review from oneflow-ci-bot and removed request for oneflow-ci-bot March 20, 2022 22:31
@BBuf BBuf requested review from oneflow-ci-bot and removed request for oneflow-ci-bot March 22, 2022 15:43
@BBuf BBuf added the automerge label Mar 22, 2022
@BBuf BBuf requested review from oneflow-ci-bot and removed request for oneflow-ci-bot March 23, 2022 01:26
@doombeaker
Copy link
Contributor

我发现,我用 add_docstr 是可以直接对 dtype 等内容添加文档的?

>>> import oneflow
>>> from oneflow.framework.docstr.utils import add_docstr
>>> print(oneflow.Tensor.dtype.__doc__)

>>> add_docstr(oneflow.Tensor.dtype, "it's ok")
<property object at 0x7f3d85bcb6b0>
>>> print(oneflow.Tensor.dtype.__doc__)
it's ok

oneflow 版本:

(oneflow-dev-gcc7-v2) yaochi@oneflow-23:~/build_exp$ python -m oneflow --doctor
path: ['/home/yaochi/oneflow/python/oneflow']
version: 0.8.0+cu112.git.1875c6e2b3
git_commit: 1875c6e2b3
cmake_build_type: Release
rdma: False
mlir: False

有点奇怪,要不要核对下是不是oneflow版本的问题?因为我有点记忆,后江修过类似的问题。我本来以为是还没考虑全情况,不过我这边测又没问题……

@BBuf BBuf requested review from oneflow-ci-bot and removed request for oneflow-ci-bot March 24, 2022 09:30
@github-actions
Copy link
Contributor

CI failed when running job: cuda-module-distributed-rank-0. PR label automerge has been removed

@BBuf BBuf requested review from oneflow-ci-bot and removed request for oneflow-ci-bot March 26, 2022 02:23
@BBuf BBuf added the automerge label Mar 26, 2022
@github-actions
Copy link
Contributor

Speed stats:
GPU Name: GeForce GTX 1080 

✔️ OneFlow resnet50 time: 128.4ms (= 12835.7ms / 100, input_shape=[16, 3, 224, 224])
PyTorch resnet50 time: 141.0ms (= 14101.6ms / 100, input_shape=[16, 3, 224, 224])
✔️ Relative speed: 1.10 (= 141.0ms / 128.4ms)

✔️ OneFlow resnet50 time: 77.3ms (= 7726.3ms / 100, input_shape=[8, 3, 224, 224])
PyTorch resnet50 time: 84.4ms (= 8443.4ms / 100, input_shape=[8, 3, 224, 224])
✔️ Relative speed: 1.09 (= 84.4ms / 77.3ms)

OneFlow resnet50 time: 52.2ms (= 10433.4ms / 200, input_shape=[4, 3, 224, 224])
PyTorch resnet50 time: 58.1ms (= 11610.3ms / 200, input_shape=[4, 3, 224, 224])
✔️ Relative speed: 1.11 (= 58.1ms / 52.2ms)

OneFlow resnet50 time: 42.7ms (= 8536.4ms / 200, input_shape=[2, 3, 224, 224])
PyTorch resnet50 time: 49.1ms (= 9816.3ms / 200, input_shape=[2, 3, 224, 224])
✔️ Relative speed: 1.15 (= 49.1ms / 42.7ms)

OneFlow resnet50 time: 38.3ms (= 7661.7ms / 200, input_shape=[1, 3, 224, 224])
PyTorch resnet50 time: 38.5ms (= 7691.3ms / 200, input_shape=[1, 3, 224, 224])
✔️ Relative speed: 1.00 (= 38.5ms / 38.3ms)

OneFlow swin dataloader time: 0.254s (= 50.788s / 200, num_workers=1)
PyTorch swin dataloader time: 0.260s (= 51.949s / 200, num_workers=1)
✔️ Relative speed: 1.023 (= 0.260s / 0.254s)

OneFlow swin dataloader time: 0.065s (= 12.961s / 200, num_workers=4)
PyTorch swin dataloader time: 0.070s (= 13.969s / 200, num_workers=4)
✔️ Relative speed: 1.078 (= 0.070s / 0.065s)

OneFlow swin dataloader time: 0.037s (= 7.436s / 200, num_workers=8)
PyTorch swin dataloader time: 0.038s (= 7.609s / 200, num_workers=8)
✔️ Relative speed: 1.023 (= 0.038s / 0.037s)

✔️ OneFlow resnet50 time: 135.9ms (= 13585.9ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 155.8ms (= 15576.7ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.15 (= 155.8ms / 135.9ms)

OneFlow resnet50 time: 87.1ms (= 8710.0ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 108.0ms (= 10801.9ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.24 (= 108.0ms / 87.1ms)

OneFlow resnet50 time: 61.0ms (= 12192.4ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 76.0ms (= 15192.1ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.25 (= 76.0ms / 61.0ms)

OneFlow resnet50 time: 52.9ms (= 10589.2ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 67.9ms (= 13588.0ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.28 (= 67.9ms / 52.9ms)

OneFlow resnet50 time: 50.2ms (= 10043.8ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 71.7ms (= 14337.0ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.43 (= 71.7ms / 50.2ms)

@mergify mergify bot merged commit efe66bb into master Mar 26, 2022
@mergify mergify bot deleted the fix_tensor_method_docstr branch March 26, 2022 08:35
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.

4 participants