You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by jx...@apache.org on 2017/07/30 01:44:26 UTC

[incubator-mxnet] branch master updated: Quiet regression stacktrace pr (#7156)

This is an automated email from the ASF dual-hosted git repository.

jxie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/master by this push:
     new cac9c25  Quiet regression stacktrace pr (#7156)
cac9c25 is described below

commit cac9c25535c47c3fe076d84e5542004948ae281b
Author: Dick Carter <di...@comcast.net>
AuthorDate: Sat Jul 29 18:44:23 2017 -0700

    Quiet regression stacktrace pr (#7156)
    
    * Quieted the expected, but confusing, exception output from unittest/test_symbol.py:test_zero_prop2.
    
    * Quieted the expected, but confusing, exception output from some unittests.
    
    * Fixed pylint error.
    
    * Empty commit to retrigger testing.
    
    * Empty commit again to test CI failure repeatability.
---
 python/mxnet/test_utils.py                     | 21 +++++++++++++++++++++
 tests/python/unittest/test_autograd.py         | 17 ++++++++++-------
 tests/python/unittest/test_contrib_autograd.py | 17 ++++++++++-------
 tests/python/unittest/test_symbol.py           | 14 +++++++++-----
 4 files changed, 50 insertions(+), 19 deletions(-)

diff --git a/python/mxnet/test_utils.py b/python/mxnet/test_utils.py
index ae5abdd..83c773f 100644
--- a/python/mxnet/test_utils.py
+++ b/python/mxnet/test_utils.py
@@ -7,9 +7,11 @@ import struct
 import traceback
 import numbers
 import subprocess
+import sys
 import os
 import errno
 import logging
+from contextlib import contextmanager
 import numpy as np
 import numpy.testing as npt
 import mxnet as mx
@@ -1044,3 +1046,22 @@ def same_array(array1, array2):
         return False
     array1[:] -= 1
     return same(array1.asnumpy(), array2.asnumpy())
+
+@contextmanager
+def discard_stderr():
+    """
+    Discards error output of a routine if invoked as:
+
+    with discard_stderr():
+        ...
+    """
+
+    try:
+        stderr_fileno = sys.stderr.fileno()
+        old_stderr = os.dup(stderr_fileno)
+        bit_bucket = open(os.devnull, 'w')
+        os.dup2(bit_bucket.fileno(), stderr_fileno)
+        yield
+    finally:
+        os.dup2(old_stderr, stderr_fileno)
+        bit_bucket.close()
diff --git a/tests/python/unittest/test_autograd.py b/tests/python/unittest/test_autograd.py
index 3fa4a74..8dea04d 100644
--- a/tests/python/unittest/test_autograd.py
+++ b/tests/python/unittest/test_autograd.py
@@ -222,13 +222,16 @@ def test_retain_grad():
         y.backward(retain_graph=False)
     assert (dx.asnumpy() == 2).all()
 
-    try:
-        with record():
-            y = x + 1
-            y.backward()
-            y.backward()
-    except Exception:
-        return
+    # The following sequence should throw an exception. We discard the expected
+    # stderr stack trace output for this operation to keep the test logs clean.
+    with discard_stderr():
+        try:
+            with record():
+                y = x + 1
+                y.backward()
+                y.backward()
+        except Exception:
+            return
 
     raise AssertionError(
         "differentiating the same graph twice without retain_graph should fail")
diff --git a/tests/python/unittest/test_contrib_autograd.py b/tests/python/unittest/test_contrib_autograd.py
index 24b417a..e7b0ce3 100644
--- a/tests/python/unittest/test_contrib_autograd.py
+++ b/tests/python/unittest/test_contrib_autograd.py
@@ -150,13 +150,16 @@ def test_retain_grad():
         y.backward(retain_graph=False)
     assert (dx.asnumpy() == 2).all()
 
-    try:
-        with train_section():
-            y = x + 1
-            y.backward()
-            y.backward()
-    except Exception:
-        return
+    # The following sequence should throw an exception. We discard the expected
+    # stderr stack trace output for this operation to keep the test logs clean.
+    with discard_stderr():
+        try:
+            with train_section():
+                y = x + 1
+                y.backward()
+                y.backward()
+        except Exception:
+            return
 
     raise AssertionError(
         "differentiating the same graph twice without retain_graph should fail")
diff --git a/tests/python/unittest/test_symbol.py b/tests/python/unittest/test_symbol.py
index 093a8f3..ee9e9dc 100644
--- a/tests/python/unittest/test_symbol.py
+++ b/tests/python/unittest/test_symbol.py
@@ -4,6 +4,7 @@ import re
 import mxnet as mx
 import numpy as np
 from common import models
+from mxnet.test_utils import discard_stderr
 import pickle as pkl
 
 def test_symbol_basic():
@@ -216,11 +217,14 @@ def test_zero_prop2():
     exe.forward()
     exe.backward()
 
-    try:
-        y.simple_bind(ctx=mx.cpu(), x=(10, 10), idx=(10,),
-                      type_dict={'x': np.float32, 'idx': np.int32})
-    except:
-        return
+    # The following bind() should throw an exception. We discard the expected stderr
+    # output for this operation only in order to keep the test logs clean.
+    with discard_stderr():
+        try:
+            y.simple_bind(ctx=mx.cpu(), x=(10, 10), idx=(10,),
+                          type_dict={'x': np.float32, 'idx': np.int32})
+        except:
+            return
 
     assert False
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@mxnet.apache.org" <co...@mxnet.apache.org>'].