Skip to content

Commit 34e28ed

Browse files
Ilia Cherniavskiifacebook-github-bot
Ilia Cherniavskii
authored andcommittedJun 17, 2020
Fix flaky test (pytorch#40175)
Summary: Pull Request resolved: pytorch#40175 Check that there is an increasing memory usage in the test Test Plan: CI Differential Revision: D22098192 Pulled By: ilia-cher fbshipit-source-id: bbdbc71f66baf18514332a98d8927441c61ebc16
1 parent bc9e8af commit 34e28ed

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed
 

‎test/test_openmp.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import collections
22
import unittest
33

4-
import numpy as np
54
import torch
65
from torch.testing._internal.common_utils import (
76
TestCase, run_tests, TEST_WITH_ASAN)
@@ -43,15 +42,15 @@ def func(self, runs):
4342
return last_rss
4443

4544
def func_rss(self, runs):
46-
last_rss = self.func(runs)
47-
# Do a least-mean-squares fit of last_rss to a line
48-
poly = np.polynomial.Polynomial.fit(
49-
range(len(last_rss)), np.array(last_rss), 1)
50-
coefs = poly.convert().coef
51-
# The coefs are (b, m) for the line y = m * x + b that fits the data.
52-
# If m == 0 it will not be present. Assert it is missing or < 1000.
53-
self.assertTrue(len(coefs) < 2 or coefs[1] < 1000,
54-
msg='memory did not stabilize, {}'.format(str(list(last_rss))))
45+
last_rss = list(self.func(runs))
46+
# Check that the sequence is not strictly increasing
47+
is_increasing = True
48+
for idx in range(len(last_rss)):
49+
if idx == 0:
50+
continue
51+
is_increasing = is_increasing and (last_rss[idx] > last_rss[idx - 1])
52+
self.assertTrue(not is_increasing,
53+
msg='memory usage is increasing, {}'.format(str(last_rss)))
5554

5655
def test_one_thread(self):
5756
"""Make sure there is no memory leak with one thread: issue gh-32284

0 commit comments

Comments
 (0)
Please sign in to comment.