Skip to content

Commit

Permalink
add dummy interfaces for import timm (#10395)
Browse files Browse the repository at this point in the history
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(
```
  • Loading branch information
marigoold authored Jan 4, 2024
1 parent 18538f6 commit 891c710
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 1 deletion.
29 changes: 29 additions & 0 deletions python/oneflow/ao/quantization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Copyright 2020 The OneFlow Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""


class DeQuantStub:
def __init__(self, *args, **kwargs):
raise NotImplementedError(
"The oneflow.ao.DeQuantStub interface is just to align the torch.ao.DeQuantStub interface and has no practical significance."
)


class QuantStub:
def __init__(self, *args, **kwargs):
raise NotImplementedError(
"The oneflow.ao.QuantStub interface is just to align the torch.ao.QuantStub interface and has no practical significance."
)
70 changes: 70 additions & 0 deletions python/oneflow/jit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
import warnings
from typing import Any, Dict, List, Set, Tuple, Union, Callable

warnings.warn(
"The oneflow.jit interface is just to align the torch.jit interface and has no practical significance."
)


def script(
obj,
Expand Down Expand Up @@ -71,3 +75,69 @@ def is_scripting():

def is_tracing():
return False


class _Final:
"""Mixin to prohibit subclassing"""

__slots__ = ("__weakref__",)

def __init_subclass__(self, *args, **kwds):
if "_root" not in kwds:
raise TypeError("Cannot subclass special typing classes")


class _SpecialForm(_Final, _root=True):
__slots__ = ("_name", "__doc__", "_getitem")

def __init__(self, getitem):
self._getitem = getitem
self._name = getitem.__name__
self.__doc__ = getitem.__doc__

def __getattr__(self, item):
if item in {"__name__", "__qualname__"}:
return self._name

raise AttributeError(item)

def __mro_entries__(self, bases):
raise TypeError(f"Cannot subclass {self!r}")

def __repr__(self):
return "typing." + self._name

def __reduce__(self):
return self._name

def __call__(self, *args, **kwds):
raise TypeError(f"Cannot instantiate {self!r}")

def __or__(self, other):
return Union[self, other]

def __ror__(self, other):
return Union[other, self]

def __instancecheck__(self, obj):
raise TypeError(f"{self} cannot be used with isinstance()")

def __subclasscheck__(self, cls):
raise TypeError(f"{self} cannot be used with issubclass()")

def __getitem__(self, parameters):
return self._getitem(self, parameters)


@_SpecialForm
def Final(*args, **kwargs):
warnings.warn(
"The oneflow.jit.Final interface is just to align the torch.jit.Final interface and has no practical significance."
)


def interface(fn):
warnings.warn(
"The oneflow.jit.interface interface is just to align the torch.jit.interface interface and has no practical significance."
)
return fn
2 changes: 1 addition & 1 deletion python/oneflow/jit/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
from typing import Tuple
from typing import Tuple, List

BroadcastingList2 = Tuple
20 changes: 20 additions & 0 deletions python/oneflow/library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Copyright 2020 The OneFlow Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import warnings

warnings.warn(
"The oneflow.library interface is just to align the torch.library interface and has no practical significance."
)
28 changes: 28 additions & 0 deletions python/oneflow/onnx/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Copyright 2020 The OneFlow Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import warnings


def symbolic_opset11():
warnings.warn(
"The oneflow.onnx.symbolic_opset11 interface is just to align the torch.onnx.symbolic_opset11 interface and has no practical significance."
)


def register_custom_op_symbolic(*args, **kwargs):
warnings.warn(
"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."
)
28 changes: 28 additions & 0 deletions python/oneflow/onnx/symbolic_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Copyright 2020 The OneFlow Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import warnings


def parse_args(*args, **kwargs):
warnings.warn(
"The oneflow.onnx.parse_args interface is just to align the torch.onnx.parse_args interface and has no practical significance."
)

def func(fn):
return fn

return func

0 comments on commit 891c710

Please sign in to comment.