8000 Make test_create_graph_and_full_backward_hook_cycle more robust to ra… · pytorch/pytorch@3eb04ae · GitHub
[go: up one dir, main page]

Skip to content

Commit 3eb04ae

Browse files
committed
Make test_create_graph_and_full_backward_hook_cycle more robust to random warnings
ghstack-source-id: 32e30eb Pull Request resolved: #153407
1 parent f5001d3 commit 3eb04ae

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

test/test_autograd.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9333,12 +9333,11 @@ def forward(self, x):
93339333
tmp.grad_fn.metadata["a"] = test
93349334

93359335
with set_warn_always_context(True):
9336-
with warnings.catch_warnings(record=True) as w:
9336+
with warnings.catch_warnings(record=True) as ws:
93379337
tmp.exp().sum().backward(create_graph=True)
9338-
self.assertTrue(len(w) == 1)
9339-
self.assertTrue(
9340-
"Using backward() with create_graph=True" in str(w[0].message)
9341-
)
9338+
filtered_ws = [
9339+
w for w in ws if "Using backward() with create_graph=True" in str(w.message)]
9340+
self.assertTrue(len(filtered_ws) == 1)
93429341

93439342
# Remove the backward + create_graph=True cycle
93449343
a.grad = None

0 commit comments

Comments
 (0)
0