pytorch/torch/onnx/errors.py
Justin Chu d3ef5c3fa3 [ONNX] Clean up __init__ in torch.onnx (#78446)
- Move definitions in `__init__` to internal classes and expose them by importing to init (prevent circular dependencies): https://github.com/pytorch/pytorch/wiki/torch.onnx-Namespacing
  - Context classes and enums are moved to `_exporter_states.py`
  - Exceptions are moved to `errors.py`
- Define `__all__` for torch.onnx. https://github.com/pytorch/pytorch/wiki/Public-API-definition-and-documentation
- Moved `utils.__IN_ONNX_EXPORT` to `GLOBALS.in_onnx_export`
- Deprecated `torch.onnx._export`

Precedes #78231

Using this as an aid for finding public functions:

```python
list(filter(lambda x: not x.startswith("_"), torch.onnx.utils.__dict__.keys()))
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/78446
Approved by: https://github.com/BowenBao
2022-06-14 04:35:06 +00:00

45 lines
1.5 KiB
Python

"""ONNX exporter exceptions."""
from typing import Optional
from torch.onnx import _constants
__all__ = ["OnnxExporterError", "CheckerError", "UnsupportedOperatorError"]
class OnnxExporterError(RuntimeError):
"""Errors raised by the ONNX exporter."""
pass
class CheckerError(OnnxExporterError):
r"""Raised when ONNX checker detects an invalid model."""
pass
class UnsupportedOperatorError(OnnxExporterError):
"""Raised when an operator is unsupported by the exporter."""
def __init__(
self, domain: str, op_name: str, version: int, supported_version: Optional[int]
):
if domain in {"", "aten", "prim", "quantized"}:
msg = f"Exporting the operator '{domain}::{op_name}' to ONNX opset version {version} is not supported. "
if supported_version is not None:
msg += (
f"Support for this operator was added in version {supported_version}, "
"try exporting with this version."
)
else:
msg += "Please feel free to request support or submit a pull request on PyTorch GitHub: "
msg += _constants.PYTORCH_GITHUB_ISSUES_URL
else:
msg = (
f"ONNX export failed on an operator with unrecognized namespace '{domain}::{op_name}'. "
"If you are trying to export a custom operator, make sure you registered "
"it with the right domain and version."
)
super().__init__(msg)