pytorch
6557ea05 - Context manager for hiding source ranges (#53188)

Commit
3 years ago
Context manager for hiding source ranges (#53188) Summary: Fixes https://github.com/pytorch/pytorch/issues/52456 ## Background Provides a context manager `_hide_source_ranges()` that disables printing graph source ranges by default. It can be overridden on a per-graph basis if desired. Pull Request resolved: https://github.com/pytorch/pytorch/pull/53188 Test Plan: ``` python test/test_jit.py TestJit.test_hide_source_ranges_context_manager ``` ```python import torch torch.jit.script def foo(x): return torch.add(x, x) print(foo.graph) with torch.jit._hide_source_ranges(): print(foo.graph) # Override context manager print(foo.graph.str(print_source_ranges=True)) print(foo.graph) ``` ``` graph(%x.1 : Tensor): %3 : int = prim::Constant[value=1]() %4 : Tensor = aten::add(%x.1, %x.1, %3) # /Users/jbschlosser/misc/example.py:5:11 return (%4) graph(%x.1 : Tensor): %3 : int = prim::Constant[value=1]() %4 : Tensor = aten::add(%x.1, %x.1, %3) return (%4) graph(%x.1 : Tensor): %3 : int = prim::Constant[value=1]() %4 : Tensor = aten::add(%x.1, %x.1, %3) # /Users/jbschlosser/misc/example.py:5:11 return (%4) graph(%x.1 : Tensor): %3 : int = prim::Constant[value=1]() %4 : Tensor = aten::add(%x.1, %x.1, %3) # /Users/jbschlosser/misc/example.py:5:11 return (%4) ``` Reviewed By: walterddr, zhangguanheng66 Differential Revision: D26817070 Pulled By: jbschlosser fbshipit-source-id: e9d123452c616b0a9dda9e134ef6c2886f229d9b
Author
Parents
Loading