mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Set enable_faithful_generator_behavior
flag to True (#142513)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/142513 Approved by: https://github.com/zou3519 ghstack dependencies: #141055, #144421, #144422, #144423, #144424, #144420, #145223
This commit is contained in:
committed by
PyTorch MergeBot
parent
580a305681
commit
6a9a02acbe
@ -2237,7 +2237,7 @@ class GraphModule(torch.nn.Module):
|
||||
eager = EagerAndRecordGraphs()
|
||||
out = torch.compile(backend=eager, fullgraph=False)(fn)(x)
|
||||
self.assertEqual(expected, out)
|
||||
self.assertEqual(len(eager.graphs), 1)
|
||||
self.assertEqual(len(eager.graphs), 0)
|
||||
|
||||
def test_graph_break_before_and_after___enter__(self):
|
||||
@contextlib.contextmanager
|
||||
@ -2263,7 +2263,7 @@ class GraphModule(torch.nn.Module):
|
||||
eager = EagerAndRecordGraphs()
|
||||
out = torch.compile(backend=eager, fullgraph=False)(fn)(x)
|
||||
self.assertEqual(expected, out)
|
||||
self.assertEqual(len(eager.graphs), 1)
|
||||
self.assertEqual(len(eager.graphs), 0)
|
||||
|
||||
def test_graph_break_before___enter___and_disable___exit__(self):
|
||||
@contextlib.contextmanager
|
||||
@ -2293,7 +2293,7 @@ class GraphModule(torch.nn.Module):
|
||||
eager = EagerAndRecordGraphs()
|
||||
out = torch.compile(backend=eager, fullgraph=False)(fn)(x)
|
||||
self.assertEqual(expected, out)
|
||||
self.assertEqual(len(eager.graphs), 1)
|
||||
self.assertEqual(len(eager.graphs), 0)
|
||||
|
||||
def test_disable___enter__(self):
|
||||
def h(x):
|
||||
@ -2574,7 +2574,7 @@ class GraphModule(torch.nn.Module):
|
||||
eager = EagerAndRecordGraphs()
|
||||
out = torch.compile(backend=eager, fullgraph=False)(fn)(x)
|
||||
self.assertEqual(expected, out)
|
||||
self.assertEqual(len(eager.graphs), 1)
|
||||
self.assertEqual(len(eager.graphs), 0)
|
||||
|
||||
def test_dynamo_disable_ctx(self):
|
||||
@contextlib.contextmanager
|
||||
@ -2624,7 +2624,7 @@ class GraphModule(torch.nn.Module):
|
||||
eager = EagerAndRecordGraphs()
|
||||
out = torch.compile(backend=eager, fullgraph=False, dynamic=False)(f)(x)
|
||||
self.assertEqual(expected, out)
|
||||
self.assertEqual(len(eager.graphs), 3)
|
||||
self.assertEqual(len(eager.graphs), 2)
|
||||
|
||||
@parametrize("name", ("suppress", "stdout", "stderr"))
|
||||
def test_contextlib_suppress(self, name):
|
||||
|
@ -9579,21 +9579,6 @@ def ___make_guard_fn():
|
||||
):
|
||||
compiled_fn(x)
|
||||
|
||||
# FIXME(XuehaiPan): do not inline infinite generator if it does not raise errors in eager mode
|
||||
def fn(x):
|
||||
def gen():
|
||||
while True:
|
||||
yield x
|
||||
|
||||
return list(zip(range(10), gen()))
|
||||
|
||||
x = torch.randn([0, 1, 2, 3, 4, 5])
|
||||
compiled_fn = torch.compile(fn, backend="eager", fullgraph=True)
|
||||
with self.assertRaisesRegex(
|
||||
torch._dynamo.exc.Unsupported, "infinite generator"
|
||||
):
|
||||
compiled_fn(x)
|
||||
|
||||
def test_itertools_islice(self):
|
||||
counters.clear()
|
||||
|
||||
|
@ -1418,9 +1418,9 @@ class ReproTests(torch._dynamo.test_case.TestCase):
|
||||
self.assertTrue(same(opt_model(a, b, c, d), correct))
|
||||
|
||||
if torch._dynamo.config.assume_static_by_default:
|
||||
self.assertExpectedInline(cnt.frame_count, """4""")
|
||||
self.assertExpectedInline(cnt.frame_count, """2""")
|
||||
else:
|
||||
self.assertExpectedInline(cnt.frame_count, """5""")
|
||||
self.assertExpectedInline(cnt.frame_count, """3""")
|
||||
|
||||
def test_hf_model_output(self):
|
||||
ex = ModelOutput(a=torch.randn(10), b=torch.randn(10), c=torch.randn(10))
|
||||
|
@ -419,7 +419,7 @@ enable_trace_contextlib = True
|
||||
|
||||
# Enable tracing generator functions lazily. If False, Dynamo will exhaust
|
||||
# generators upon first execution. And if True, the generator will be accessed lazily
|
||||
enable_faithful_generator_behavior = False
|
||||
enable_faithful_generator_behavior = True
|
||||
|
||||
# Inline inbuilt nn modules
|
||||
inline_inbuilt_nn_modules = Config( # type: ignore[var-annotated]
|
||||
|
Reference in New Issue
Block a user