Skip to content

Commit 6087921

Browse files
masnesralpytorchmergebot
authored andcommitted
[inductor][codecache] Print bytes in codecache debug output (#164898)
Summary: We have an internal request to help understand why the hash of `post_grad_custom_post_pass` is changing between attempts. We don't get useful info from the debug output, because we just print "<bytes>". Instead, attempt to print at least _some_ of the value in case it contains readable characters. Test Plan: Registered a dummy post_grad_custom_pass and printed codecache debug output `TORCH_LOGS=+torch._inductor.codecache python ~/foo.py` Yields something like: ``` V1007 16:41:19.024000 3546009 /data/users/slarsen/pytorch-3.10_4/torch/_inductor/codecache.py:989] [0/0] [law2ujt2wzjb5tyiu6jh64r2lxpvl62yvxcsmdouhg3qyelhhdv] post_grad_custom_post_pass: HelloWorld!����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������... ``` Differential Revision: [D84108770](https://our.internmc.facebook.com/intern/diff/D84108770) Pull Request resolved: #164898 Approved by: https://github.com/oulgen
1 parent 086dec3 commit 6087921

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

torch/_inductor/codecache.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,8 @@ def get_str(obj: Any) -> str:
657657
if isinstance(obj, torch.Tensor):
658658
return str(extract_tensor_metadata_for_cache_key(obj))
659659
elif isinstance(obj, bytes):
660-
return "<bytes>"
660+
val = obj.decode("utf-8", errors="replace")
661+
return val if len(val) <= 1024 else val[:1024] + "..."
661662
elif type(obj) in self.dispatch_table:
662663
# Run the reducer on the object
663664
return str(self.dispatch_table[type(obj)](obj)[1])

0 commit comments

Comments
 (0)