Skip to content

Commit 2efcf9d

Browse files
williamwen42pytorchmergebot
authored andcommitted
[dynamo] Fix graph break registry loading in fbcode (pytorch#161550)
Summary: Add `torch/_dynamo/graph_break_registry.json` as an internal dependency. Minor related fixes. Test Plan: Test on OSS. Rollback Plan: Differential Revision: D81078973 Pull Request resolved: pytorch#161550 Approved by: https://github.com/Lucaskabela, https://github.com/anijain2305
1 parent 443452c commit 2efcf9d

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

test/dynamo/test_error_messages.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __exit__(self, exc_type, exc_value, traceback):
4747
pass
4848

4949

50-
class GraphBreakMessagesTest(LoggingTestCase):
50+
class ErrorMessagesTest(LoggingTestCase):
5151
def test_dynamic_shape_operator(self):
5252
def fn():
5353
return torch.nonzero(torch.rand([10, 10]))
@@ -783,12 +783,12 @@ def post_munge(s):
783783
lambda: torch.compile(fn, backend="eager", fullgraph=True)(),
784784
"""\
785785
Reconstruction failure
786-
Explanation: Dynamo has no bytecode reconstruction implemented for sourceless variable UserMethodVariable(<function GraphBreakMessagesTest.test_reconstruction_failure.<locals>.Foo.meth at 0xmem_addr>, UserDefinedObjectVariable(Foo)).
786+
Explanation: Dynamo has no bytecode reconstruction implemented for sourceless variable UserMethodVariable(<function ErrorMessagesTest.test_reconstruction_failure.<locals>.Foo.meth at 0xmem_addr>, UserDefinedObjectVariable(Foo)).
787787
Hint: If Dynamo is attempting to trace a return statement and your code is attempting to return a variable that Dynamo cannot reconstruct, then remove it from the return statement.
788788
Hint: This graph break may have been caused by an earlier graph break. Resolving the earlier graph break may resolve this one.
789789
Hint: Report an issue to PyTorch if you need reconstrtuction support. Note that objects that don't have reconstruction rules may be fundamentally unreconstructable.
790790
791-
Developer debug context: UserMethodVariable(<function GraphBreakMessagesTest.test_reconstruction_failure.<locals>.Foo.meth at 0xmem_addr>, UserDefinedObjectVariable(Foo))
791+
Developer debug context: UserMethodVariable(<function ErrorMessagesTest.test_reconstruction_failure.<locals>.Foo.meth at 0xmem_addr>, UserDefinedObjectVariable(Foo))
792792
793793
For more details about this graph break, please visit: https://meta-pytorch.github.io/compile-graph-break-site/gb/gb0092.html
794794
@@ -839,12 +839,12 @@ def post_munge(s):
839839
post_munge(munge_exc(records[1].exc_info[1], suppress_suffix=True, skip=0)),
840840
"""\
841841
Reconstruction failure
842-
Explanation: Dynamo has no bytecode reconstruction implemented for sourceless variable UserMethodVariable(<function GraphBreakMessagesTest.test_reconstruction_failure_gb.<locals>.Foo.meth at 0xmem_addr>, UserDefinedObjectVariable(Foo)).
842+
Explanation: Dynamo has no bytecode reconstruction implemented for sourceless variable UserMethodVariable(<function ErrorMessagesTest.test_reconstruction_failure_gb.<locals>.Foo.meth at 0xmem_addr>, UserDefinedObjectVariable(Foo)).
843843
Hint: If Dynamo is attempting to trace a return statement and your code is attempting to return a variable that Dynamo cannot reconstruct, then remove it from the return statement.
844844
Hint: This graph break may have been caused by an earlier graph break. Resolving the earlier graph break may resolve this one.
845845
Hint: Report an issue to PyTorch if you need reconstrtuction support. Note that objects that don't have reconstruction rules may be fundamentally unreconstructable.
846846
847-
Developer debug context: UserMethodVariable(<function GraphBreakMessagesTest.test_reconstruction_failure_gb.<locals>.Foo.meth at 0xmem_addr>, UserDefinedObjectVariable(Foo))
847+
Developer debug context: UserMethodVariable(<function ErrorMessagesTest.test_reconstruction_failure_gb.<locals>.Foo.meth at 0xmem_addr>, UserDefinedObjectVariable(Foo))
848848
849849
For more details about this graph break, please visit: https://meta-pytorch.github.io/compile-graph-break-site/gb/gb0092.html
850850
@@ -1298,10 +1298,10 @@ def post_munge(s):
12981298
lambda: outer(f, torch.randn(3)),
12991299
"""\
13001300
Skip calling `torch.compiler.disable()`d function
1301-
Explanation: Skip calling function `<function GraphBreakMessagesTest.test_disable_message.<locals>.f at 0xmem_addr>` since it was wrapped with `torch.compiler.disable` (reason: None)
1301+
Explanation: Skip calling function `<function ErrorMessagesTest.test_disable_message.<locals>.f at 0xmem_addr>` since it was wrapped with `torch.compiler.disable` (reason: None)
13021302
Hint: Remove the `torch.compiler.disable` call
13031303
1304-
Developer debug context: <function GraphBreakMessagesTest.test_disable_message.<locals>.f at 0xmem_addr>
1304+
Developer debug context: <function ErrorMessagesTest.test_disable_message.<locals>.f at 0xmem_addr>
13051305
13061306
For more details about this graph break, please visit: https://meta-pytorch.github.io/compile-graph-break-site/gb/gb0098.html
13071307
@@ -1320,10 +1320,10 @@ def g(x):
13201320
lambda: outer(g, torch.randn(3)),
13211321
"""\
13221322
Skip calling `torch.compiler.disable()`d function
1323-
Explanation: Skip calling function `<function GraphBreakMessagesTest.test_disable_message.<locals>.g at 0xmem_addr>` since it was wrapped with `torch.compiler.disable` (reason: test message)
1323+
Explanation: Skip calling function `<function ErrorMessagesTest.test_disable_message.<locals>.g at 0xmem_addr>` since it was wrapped with `torch.compiler.disable` (reason: test message)
13241324
Hint: Remove the `torch.compiler.disable` call
13251325
1326-
Developer debug context: <function GraphBreakMessagesTest.test_disable_message.<locals>.g at 0xmem_addr>
1326+
Developer debug context: <function ErrorMessagesTest.test_disable_message.<locals>.g at 0xmem_addr>
13271327
13281328
For more details about this graph break, please visit: https://meta-pytorch.github.io/compile-graph-break-site/gb/gb0098.html
13291329

torch/_dynamo/exc.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from typing import Any, NoReturn, Optional, TYPE_CHECKING
4040

4141
import torch._guards
42+
from torch._utils_internal import get_file_path_2
4243

4344
from . import config
4445
from .utils import counters
@@ -512,18 +513,29 @@ def format_graph_break_message(
512513

513514

514515
@lru_cache(maxsize=1)
515-
def _load_graph_break_registry() -> dict[str, Any]:
516+
def _load_gb_type_to_gb_id_map() -> dict[str, Any]:
516517
"""
517-
Loads the graph break registry from JSON file with caching.
518+
Loads the gb_type to gb_id map from the graph break registry from JSON file with caching.
519+
520+
Includes historical gb_type (mapping behavior of duplicate gb_types with different gb_ids is undefined).
518521
"""
519522
try:
520523
script_dir = Path(__file__).resolve().parent
521-
registry_path = script_dir / "graph_break_registry.json"
522-
with registry_path.open() as f:
523-
return json.load(f)
524-
except (FileNotFoundError, json.JSONDecodeError) as e:
524+
registry_path = get_file_path_2(
525+
"", str(script_dir), "graph_break_registry.json"
526+
)
527+
with open(registry_path) as f:
528+
registry = json.load(f)
529+
except Exception as e:
525530
log.error("Error accessing the registry file: %s", e)
526-
return {}
531+
registry = {}
532+
533+
mapping = {}
534+
for k, v in registry.items():
535+
for entry in v:
536+
mapping[entry["Gb_type"]] = k
537+
538+
return mapping
527539

528540

529541
def get_gbid_documentation_link(gb_type: str) -> Optional[str]:
@@ -540,11 +552,12 @@ def get_gbid_documentation_link(gb_type: str) -> Optional[str]:
540552
"https://meta-pytorch.github.io/compile-graph-break-site/gb/" # @lint-ignore
541553
)
542554

543-
registry = _load_graph_break_registry()
555+
gb_type_to_gb_id_map = _load_gb_type_to_gb_id_map()
544556

545-
for k, v in registry.items():
546-
if v and v[0].get("Gb_type") == gb_type:
547-
return f"{GRAPH_BREAK_SITE_URL}gb{k.lstrip('GB')}.html"
557+
if gb_type in gb_type_to_gb_id_map:
558+
return (
559+
f"{GRAPH_BREAK_SITE_URL}gb{gb_type_to_gb_id_map[gb_type].lstrip('GB')}.html"
560+
)
548561

549562
return None
550563

0 commit comments

Comments
 (0)