-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dynamo] byteir backend switch to torch==2.12 (#315)
- as title - fix fx cache fail - add debug backend --------- Signed-off-by: huangchenhui.yellow <huangchenhui.yellow@bytedance.com>
- Loading branch information
Showing
7 changed files
with
263 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
frontends/torch-frontend/torch-frontend/python/torch_frontend/byteir_backend/debug.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import functools | ||
import logging | ||
from typing import Optional, Any, Callable, Dict, List, Sequence, Tuple, Union | ||
|
||
import torch | ||
|
||
from .compiler import byteir_compiler | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def debug_backend(gm: torch.fx.GraphModule, | ||
example_inputs: List[torch.Tensor]): | ||
""" | ||
compare results between byteir compiled function and eager mode graph. | ||
""" | ||
_opt_gm = byteir_compiler(gm, example_inputs) | ||
|
||
def f(*inputs): | ||
opt_inputs = [] | ||
for inp in inputs: | ||
_opt_inp = torch.empty_strided(size=inp.size(), | ||
stride=inp.stride(), | ||
storage_offset=inp.storage_offset()) | ||
opt_inputs.append(_opt_inp.copy_(inp)) | ||
|
||
eager_inputs = inputs | ||
eager_res = gm(*eager_inputs) | ||
opt_res = _opt_gm(*opt_inputs) | ||
|
||
# compare results | ||
# TODO: check meta info as well as numercial. | ||
try: | ||
torch.testing.assert_close(eager_res, opt_res) | ||
except Exception as e: | ||
log.error(f"******* debug backend fail *******") | ||
raise e | ||
|
||
print(f"******* debug backend pass *******") | ||
return eager_res | ||
|
||
return f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.