8000 [dynamo] Add test to ensure we don't print fx graph upon data depende… · pytorch/pytorch@f94bdd2 · GitHub
[go: up one dir, main page]

Skip to content

Commit f94bdd2

Browse files
committed
[dynamo] Add test to ensure we don't print fx graph upon data dependent graph break
This adds a regression test for #149831, also as part of getting it cherry-picked into 2.7.1. [ghstack-poisoned]
1 parent 0e59b59 commit f94bdd2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/dynamo/test_repros.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import itertools
1616
import os
1717
import random
18+
import sys
1819
import types
1920
import typing
2021
import unittest
@@ -7091,6 +7092,31 @@ def fn(x):
70917092
x = torch.randn(4)
70927093
self.assertEqual(fn(x), opt_fn(x))
70937094

7095+
def test_data_dependent_error_log_no_print(self):
7096+
# This is a regression test case for
7097+
# https://github.com/pytorch/pytorch/pull/149831
7098+
from io import StringIO
7099+
7100+
capturedOutput = StringIO()
7101+
sys.stderr = capturedOutput
7102+
7103+ @torch.compile(fullgraph=True)
7104+
def func(a):
7105+
if a.sum() > 0:
7106+
return a + 1
7107+
return a + 2
7108+
7109+
a = torch.rand(10, 10)
7110+
try:
7111+
func(a)
7112+
except Exception:
7113+
pass
7114+
sys.stderr = sys.__stderr__
7115+
7116+
# Make sure we don't _print_ out the graph module.
7117+
output = capturedOutput.getvalue()
7118+
self.assertNotIn("class GraphModule", output)
7119+
70947120

70957121
instantiate_parametrized_tests(ReproTests)
70967122

0 commit comments

Comments
 (0)
0