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

Skip to content

Commit 8ac82a1

Browse files
StrongerXipytorchmergebot
authored andcommitted
[dynamo] Add test to ensure we don't print fx graph upon data dependent graph break (#153416)
This adds a regression test for #149831, also as part of getting it cherry-picked into 2.7.1. Pull Request resolved: #153416 Approved by: https://github.com/atalman
1 parent 9df9d9d commit 8ac82a1

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
@@ -7153,6 +7154,31 @@ def fn(x):
71537154
x = torch.randn(4)
71547155
self.assertEqual(fn(x), opt_fn(x))
71557156

7157+
def test_data_dependent_error_log_no_print(self):
7158+
# This is a regression test case for
7159+
# https://github.com/pytorch/pytorch/pull/149831
7160+
from io import StringIO
7161+
7162+
capturedOutput = StringIO()
7163+
sys.stderr = capturedOutput
7164+
7165+
@torch.compile(fullgraph=True)
7166+
def func(a):
7167+
if a.sum() > 0:
7168+
return a + 1
7169+
return a + 2
7170+
7171+
a = torch.rand(10, 10)
7172+
try:
7173+
func(a)
7174+
except Exception:
7175+
pass
7176+
sys.stderr = sys.__stderr__
7177+
7178+
# Make sure we don't _print_ out the graph module.
7179+
output = capturedOutput.getvalue()
7180+
self.assertNotIn("class GraphModule", output)
7181+
71567182

71577183
instantiate_parametrized_tests(ReproTests)
71587184

0 commit comments

Comments
 (0)
0