Commit d3ab9c6
Fix: Dynamo log always emits ANSI color codes into torch_compile_debug/torchdynamo/debug.log due to colored=True in lazy_format_graph_code (#167823)
Summary:
Added ANSI escape sequence handling and a custom logging formatter.
Please refer to pytorch/pytorch#167812 for detailed background explanation.
This PR adds a format for log_file_handler in dynamo logger to filter ANSI codes.
Before this change, log in debug.log:
```
def forward(self, L_x_: "�[31mi64�[0m�[34m[]�[0m�[2m�[34m[]�[0m�[2m�[32mcpu�[0m"):
l_x_ = L_x_
�[2m# File: /Users/bytedance/Downloads/Repo/pytorch/mydebug1.py:11 in forward, code: a = torch.ones(2, x.item())�[0m
item: "Sym(s20 + 5)" = l_x_.item(); �[2ml_x_ = None�[0m
a: "�[31mf32�[0m�[34m[2, s20 + 5]�[0m�[2m�[34m[Max(1, s20 + 5), 1]�[0m�[2m�[32mcpu�[0m" = torch.ones(�[34m2�[0m, item)
�[2m# File: /Users/bytedance/Downloads/Repo/pytorch/mydebug1.py:12 in forward, code: b = torch.ones(3, y.item() + 5)�[0m
b: "�[31mf32�[0m�[34m[3, s20 + 5]�[0m�[2m�[34m[Max(1, s20 + 5), 1]�[0m�[2m�[32mcpu�[0m" = torch.ones(�[34m3�[0m, item); �[2mitem = None�[0m
�[2m# File: /Users/bytedance/Downloads/Repo/pytorch/mydebug1.py:13 in forward, code: res = torch.cat([a, b], dim=0)�[0m
res: "�[31mf32�[0m�[34m[5, s20 + 5]�[0m�[2m�[34m[Max(1, s20 + 5), 1]�[0m�[2m�[32mcpu�[0m" = torch.cat([a, b], dim = �[34m0�[0m); �[2ma = b = None�[0m
�[2m# File: /Users/bytedance/Downloads/Repo/pytorch/mydebug1.py:14 in forward, code: return res.sum()�[0m
sum_1: "�[31mf32�[0m�[34m[]�[0m�[2m�[34m[]�[0m�[2m�[32mcpu�[0m" = res.sum(); �[2mres = None�[0m
return (sum_1,)
```
After this change, log in debug.log:
```
def forward(self, L_x_: "i64[][]cpu"):
l_x_ = L_x_
# File: /Users/bytedance/Downloads/Repo/pytorch/mydebug1.py:11 in forward, code: a = torch.ones(2, x.item())
item: "Sym(s20 + 5)" = l_x_.item(); l_x_ = None
a: "f32[2, s20 + 5][Max(1, s20 + 5), 1]cpu" = torch.ones(2, item)
# File: /Users/bytedance/Downloads/Repo/pytorch/mydebug1.py:12 in forward, code: b = torch.ones(3, y.item() + 5)
b: "f32[3, s20 + 5][Max(1, s20 + 5), 1]cpu" = torch.ones(3, item); item = None
# File: /Users/bytedance/Downloads/Repo/pytorch/mydebug1.py:13 in forward, code: res = torch.cat([a, b], dim=0)
res: "f32[5, s20 + 5][Max(1, s20 + 5), 1]cpu" = torch.cat([a, b], dim = 0); a = b = None
# File: /Users/bytedance/Downloads/Repo/pytorch/mydebug1.py:14 in forward, code: return res.sum()
sum_1: "f32[][]cpu" = res.sum(); res = None
return (sum_1,)
```
X-link: pytorch/pytorch#167823
Approved by: https://github.com/angelayi
Reviewed By: yangw-dev
Differential Revision: D87297668
fbshipit-source-id: 1d2b6d08cc2a068954107515b564bf7f1c9f6e421 parent 2b7a1a4 commit d3ab9c6
1 file changed
+22
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
903 | 903 | | |
904 | 904 | | |
905 | 905 | | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
906 | 927 | | |
907 | 928 | | |
908 | 929 | | |
909 | 930 | | |
910 | 931 | | |
| 932 | + | |
911 | 933 | | |
912 | 934 | | |
913 | 935 | | |
| |||
0 commit comments