mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 00:21:07 +01:00
Context: https://github.com/pytorch/torchdynamo/issues/1588 This PR moves [TorchDynamo](https://github.com/pytorch/torchdynamo) and TorchInductor into PyTorch core. - `torchdynamo` becomes `torch._dynamo` - `torchinductor` becomes `torch._inductor` This PR was generated by running `copy_to_core.sh` in https://github.com/pytorch/torchdynamo/pull/1538 Pull Request resolved: https://github.com/pytorch/pytorch/pull/86461 Approved by: https://github.com/voznesenskym
86 lines
2.3 KiB
Python
86 lines
2.3 KiB
Python
import os
|
|
import textwrap
|
|
from functools import lru_cache
|
|
|
|
from . import config
|
|
|
|
if os.environ.get("TORCHINDUCTOR_WRITE_MISSING_OPS") == "1":
|
|
|
|
@lru_cache(None)
|
|
def _record_missing_op(target):
|
|
with open("/tmp/missing_ops.txt", "a") as fd:
|
|
fd.write(str(target) + "\n")
|
|
|
|
else:
|
|
|
|
def _record_missing_op(target):
|
|
pass
|
|
|
|
|
|
class OperatorIssue(RuntimeError):
|
|
@staticmethod
|
|
def operator_str(target, args, kwargs):
|
|
lines = [f"target: {target}"] + [
|
|
f"args[{i}]: {arg}" for i, arg in enumerate(args)
|
|
]
|
|
if kwargs:
|
|
lines.append(f"kwargs: {kwargs}")
|
|
return textwrap.indent("\n".join(lines), " ")
|
|
|
|
|
|
class MissingOperatorWithoutDecomp(OperatorIssue):
|
|
def __init__(self, target, args, kwargs):
|
|
_record_missing_op(target)
|
|
super().__init__(f"missing lowering\n{self.operator_str(target, args, kwargs)}")
|
|
|
|
|
|
class MissingOperatorWithDecomp(OperatorIssue):
|
|
def __init__(self, target, args, kwargs):
|
|
_record_missing_op(target)
|
|
super().__init__(
|
|
f"missing decomposition\n{self.operator_str(target, args, kwargs)}"
|
|
+ textwrap.dedent(
|
|
f"""
|
|
|
|
There is a decomposition available for {target} in
|
|
torch._decomp.get_decompositions(). Please add this operator to the
|
|
`decompositions` list in {config.inductor_import}.decompositions
|
|
"""
|
|
)
|
|
)
|
|
|
|
|
|
class LoweringException(OperatorIssue):
|
|
def __init__(self, exc, target, args, kwargs):
|
|
super().__init__(
|
|
f"{type(exc).__name__}: {exc}\n{self.operator_str(target, args, kwargs)}"
|
|
)
|
|
|
|
|
|
class InvalidCxxCompiler(RuntimeError):
|
|
def __init__(self):
|
|
from . import config
|
|
|
|
super().__init__(
|
|
f"No working C++ compiler found in {config.__name__}.cpp.cxx: {config.cpp.cxx}"
|
|
)
|
|
|
|
|
|
class CppCompileError(RuntimeError):
|
|
def __init__(self, cmd, output):
|
|
super().__init__(
|
|
textwrap.dedent(
|
|
"""
|
|
C++ compile error
|
|
|
|
Command:
|
|
{cmd}
|
|
|
|
Output:
|
|
{output}
|
|
"""
|
|
)
|
|
.strip()
|
|
.format(cmd=" ".join(cmd), output=output.decode("utf-8"))
|
|
)
|