diff --git a/python/oneflow/ao/quantization.py b/python/oneflow/ao/quantization.py new file mode 100644 index 00000000000..15446e933bf --- /dev/null +++ b/python/oneflow/ao/quantization.py @@ -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." + ) diff --git a/python/oneflow/jit/__init__.py b/python/oneflow/jit/__init__.py index 87eb5c82ec9..66c15520965 100644 --- a/python/oneflow/jit/__init__.py +++ b/python/oneflow/jit/__init__.py @@ -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, @@ -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 diff --git a/python/oneflow/jit/annotations.py b/python/oneflow/jit/annotations.py index ea76ac2eb2f..b99c2b5c580 100644 --- a/python/oneflow/jit/annotations.py +++ b/python/oneflow/jit/annotations.py @@ -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 diff --git a/python/oneflow/library.py b/python/oneflow/library.py new file mode 100644 index 00000000000..349a1687ce5 --- /dev/null +++ b/python/oneflow/library.py @@ -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." +) diff --git a/python/oneflow/onnx/__init__.py b/python/oneflow/onnx/__init__.py new file mode 100644 index 00000000000..b25f3f40411 --- /dev/null +++ b/python/oneflow/onnx/__init__.py @@ -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." + ) diff --git a/python/oneflow/onnx/symbolic_helper.py b/python/oneflow/onnx/symbolic_helper.py new file mode 100644 index 00000000000..81bb0119915 --- /dev/null +++ b/python/oneflow/onnx/symbolic_helper.py @@ -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