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

add dummy interfaces for import timm #10395

Merged
merged 3 commits into from
Jan 4, 2024

Conversation

marigoold
Copy link
Contributor

@marigoold marigoold commented Jan 4, 2024

python3 -c "import timm" 输出如下,然后成功返回

/data/home/wangyi/workspace/oneflow-public/python/oneflow/jit/__init__.py:19: UserWarning: The oneflow.jit interface is just to align the torch.jit interface and has no practical significance.
  warnings.warn(
/data/home/wangyi/workspace/oneflow-public/python/oneflow/jit/__init__.py:134: UserWarning: The oneflow.jit.Final interface is just to align the torch.jit.Final interface and has no practical significance.
  warnings.warn(
/data/home/wangyi/workspace/oneflow-public/python/oneflow/jit/__init__.py:31: UserWarning: The oneflow.jit.script interface is just to align the torch.jit.script interface and has no practical significance.
  warnings.warn(
/home/wangyi/miniconda3/envs/py10/lib/python3.10/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: 'load_library is not implemented'If you don't plan on using image functionality from `torchvision.io`, you can ignore this warning. Otherwise, there might be something wrong with your environment. Did you have `libjpeg` or `libpng` installed before building `torchvision` from source?
  warn(
/data/home/wangyi/workspace/oneflow-public/python/oneflow/jit/__init__.py:49: UserWarning: The oneflow.jit.unused interface is just to align the torch.jit.unused interface and has no practical significance.
  warnings.warn(
/data/home/wangyi/workspace/oneflow-public/python/oneflow/onnx/symbolic_helper.py:21: UserWarning: The oneflow.onnx.parse_args interface is just to align the torch.onnx.parse_args interface and has no practical significance.
  warnings.warn(
/data/home/wangyi/workspace/oneflow-public/python/oneflow/jit/__init__.py:57: UserWarning: The oneflow.jit._script_if_tracing interface is just to align the torch.jit._script_if_tracing interface and has no practical significance.
  warnings.warn(
/data/home/wangyi/workspace/oneflow-public/python/oneflow/onnx/__init__.py:26: UserWarning: The oneflow.onnx.register_custom_op_symbolic interface is just to align the torch.onnx.register_custom_op_symbolic interface and has no practical significance.
  warnings.warn(
/data/home/wangyi/workspace/oneflow-public/python/oneflow/jit/__init__.py:65: UserWarning: The oneflow.jit._overload_method interface is just to align the torch.jit._overload_method interface and has no practical significance.
  warnings.warn(
/data/home/wangyi/workspace/oneflow-public/python/oneflow/jit/__init__.py:134: UserWarning: The oneflow.jit.Final interface is just to align the torch.jit.Final interface and has no practical significance.
  warnings.warn(
/data/home/wangyi/workspace/oneflow-public/python/oneflow/jit/__init__.py:31: UserWarning: The oneflow.jit.script interface is just to align the torch.jit.script interface and has no practical significance.
  warnings.warn(
/data/home/wangyi/workspace/oneflow-public/python/oneflow/jit/__init__.py:38: UserWarning: The oneflow.jit.ignore interface is just to align the torch.jit.ignore interface and has no practical significance.
  warnings.warn(
/data/home/wangyi/workspace/oneflow-public/python/oneflow/jit/__init__.py:140: UserWarning: The oneflow.jit.interface interface is just to align the torch.jit.interface interface and has no practical significance.
  warnings.warn(

@marigoold marigoold enabled auto-merge (squash) January 4, 2024 06:11
@marigoold marigoold requested review from oneflow-ci-bot and removed request for oneflow-ci-bot January 4, 2024 06:16
Copy link
Contributor

@levi131 levi131 left a comment

Choose a reason for hiding this comment

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

LGTM

@daquexian
Copy link
Contributor

开 lazy mock 还需要这些空接口吗?

@marigoold
Copy link
Contributor Author

marigoold commented Jan 4, 2024

开 lazy mock 还需要这些空接口吗?

有些是装饰器函数,比如

     13 @parse_args("v", "v", "f")
---> 14 def symbolic_multi_label_nms(g, boxes, scores, iou_threshold):
     15     boxes = opset11.unsqueeze(g, boxes, 0)
     16     scores = opset11.unsqueeze(g, opset11.unsqueeze(g, scores, 0), 0)

有些是 __init__.py 里面就会调用的,比如

  File "/home/wangyi/miniconda3/envs/py10/lib/python3.10/site-packages/torchvision/ops/__init__.py", line 30, in <module>
_register_custom_op()

有些是类型声明的,比如 return_indices: torch.jit.Final[bool]

Copy link
Contributor

github-actions bot commented Jan 4, 2024

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

@github-actions github-actions bot removed the automerge label Jan 4, 2024
@daquexian
Copy link
Contributor

开 lazy mock 还需要这些空接口吗?

有些是装饰器函数,比如

     13 @parse_args("v", "v", "f")
---> 14 def symbolic_multi_label_nms(g, boxes, scores, iou_threshold):
     15     boxes = opset11.unsqueeze(g, boxes, 0)
     16     scores = opset11.unsqueeze(g, opset11.unsqueeze(g, scores, 0), 0)

有些是 __init__.py 里面就会调用的,比如

  File "/home/wangyi/miniconda3/envs/py10/lib/python3.10/site-packages/torchvision/ops/__init__.py", line 30, in <module>
_register_custom_op()

有些是类型声明的,比如 return_indices: torch.jit.Final[bool]

开了 lazy mock 之后这些接口即使不存在应该也都不会报错?

lazy mock 是 这里 的 lazy=True 参数

Copy link
Contributor

github-actions bot commented Jan 4, 2024

Code got formatted by CI. Please request CI again if you still want to have this PR merged. If the PR is from a forked repo, please download the patch files from the GitHub Actions web page and apply them locally.

@marigoold marigoold requested review from oneflow-ci-bot and removed request for oneflow-ci-bot January 4, 2024 06:49
@marigoold
Copy link
Contributor Author

开 lazy mock 还需要这些空接口吗?

有些是装饰器函数,比如

     13 @parse_args("v", "v", "f")
---> 14 def symbolic_multi_label_nms(g, boxes, scores, iou_threshold):
     15     boxes = opset11.unsqueeze(g, boxes, 0)
     16     scores = opset11.unsqueeze(g, opset11.unsqueeze(g, scores, 0), 0)

有些是 __init__.py 里面就会调用的,比如

  File "/home/wangyi/miniconda3/envs/py10/lib/python3.10/site-packages/torchvision/ops/__init__.py", line 30, in <module>
_register_custom_op()

有些是类型声明的,比如 return_indices: torch.jit.Final[bool]

开了 lazy mock 之后这些接口即使不存在应该也都不会报错?

lazy mock 是 这里 的 lazy=True 参数

我试了下还真是 😅 用户当时使用的时候是没开 lazy,会直接报错

@daquexian
Copy link
Contributor

我试了下还真是 😅 用户当时使用的时候是没开 lazy,会直接报错

可以把 lazy 设成默认的,或者更新下文档推荐用户使用 lazy(现在文档里说 lazy 是为了调试方便,这个看法过时了)

Copy link
Contributor

github-actions bot commented Jan 4, 2024

Copy link
Contributor

github-actions bot commented Jan 4, 2024

Speed stats:
GPU Name: NVIDIA GeForce RTX 3080 Ti 

❌ OneFlow resnet50 time: 43.2ms (= 4324.2ms / 100, input_shape=[16, 3, 224, 224])
PyTorch resnet50 time: 57.3ms (= 5729.2ms / 100, input_shape=[16, 3, 224, 224])
✔️ Relative speed: 1.32 (= 57.3ms / 43.2ms)

OneFlow resnet50 time: 26.2ms (= 2624.8ms / 100, input_shape=[8, 3, 224, 224])
PyTorch resnet50 time: 38.5ms (= 3848.5ms / 100, input_shape=[8, 3, 224, 224])
✔️ Relative speed: 1.47 (= 38.5ms / 26.2ms)

OneFlow resnet50 time: 18.7ms (= 3739.0ms / 200, input_shape=[4, 3, 224, 224])
PyTorch resnet50 time: 36.7ms (= 7334.9ms / 200, input_shape=[4, 3, 224, 224])
✔️ Relative speed: 1.96 (= 36.7ms / 18.7ms)

OneFlow resnet50 time: 17.9ms (= 3574.0ms / 200, input_shape=[2, 3, 224, 224])
PyTorch resnet50 time: 30.7ms (= 6149.3ms / 200, input_shape=[2, 3, 224, 224])
✔️ Relative speed: 1.72 (= 30.7ms / 17.9ms)

OneFlow resnet50 time: 17.1ms (= 3420.7ms / 200, input_shape=[1, 3, 224, 224])
PyTorch resnet50 time: 28.6ms (= 5729.6ms / 200, input_shape=[1, 3, 224, 224])
✔️ Relative speed: 1.67 (= 28.6ms / 17.1ms)

OneFlow swin dataloader time: 0.200s (= 40.095s / 200, num_workers=1)
PyTorch swin dataloader time: 0.129s (= 25.811s / 200, num_workers=1)
Relative speed: 0.644 (= 0.129s / 0.200s)

OneFlow swin dataloader time: 0.056s (= 11.296s / 200, num_workers=4)
PyTorch swin dataloader time: 0.032s (= 6.428s / 200, num_workers=4)
Relative speed: 0.569 (= 0.032s / 0.056s)

OneFlow swin dataloader time: 0.030s (= 6.055s / 200, num_workers=8)
PyTorch swin dataloader time: 0.017s (= 3.398s / 200, num_workers=8)
Relative speed: 0.561 (= 0.017s / 0.030s)

❌ OneFlow resnet50 time: 49.0ms (= 4899.3ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 65.9ms (= 6586.1ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.34 (= 65.9ms / 49.0ms)

OneFlow resnet50 time: 36.4ms (= 3640.3ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 44.4ms (= 4444.9ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.22 (= 44.4ms / 36.4ms)

OneFlow resnet50 time: 28.0ms (= 5599.0ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 39.6ms (= 7926.5ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.42 (= 39.6ms / 28.0ms)

OneFlow resnet50 time: 25.3ms (= 5063.4ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 38.4ms (= 7673.7ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.52 (= 38.4ms / 25.3ms)

OneFlow resnet50 time: 23.8ms (= 4766.1ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 36.0ms (= 7192.2ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.51 (= 36.0ms / 23.8ms)

@marigoold marigoold merged commit 891c710 into master Jan 4, 2024
20 checks passed
@marigoold marigoold deleted the dev_wy_add_dummy_interface_for_timm_mock branch January 4, 2024 10:15
marigoold added a commit that referenced this pull request Jan 11, 2024
#10395 这个 PR 里多此一举给
jit/\_\_init__.py 加了一个 warning,导致 import oneflow 的时候就会显示这个 warning,这里去掉
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.

6 participants