Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

CI test randomness 3 #9791

Merged
merged 12 commits into from
Feb 18, 2018
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions python/mxnet/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
from .ndarray import array
from .symbol import Symbol

_rng = np.random.RandomState(1234)


def default_context():
"""Get default context for regression test."""
Expand Down Expand Up @@ -844,7 +842,7 @@ def random_projection(shape):
"""
# random_projection should not have elements too small,
# otherwise too much precision is lost in numerical gradient
plain = _rng.rand(*shape) + 0.1
plain = np.random.rand(*shape) + 0.1
return plain

location = _parse_location(sym=sym, location=location, ctx=ctx, dtype=dtype)
Expand Down Expand Up @@ -876,8 +874,9 @@ def random_projection(shape):
location = dict(list(location.items()) +
[("__random_proj", mx.nd.array(random_projection(out_shape[0]),
ctx=ctx, dtype=dtype))])
args_grad_npy = dict([(k, _rng.normal(0, 0.01, size=location[k].shape)) for k in grad_nodes]
+ [("__random_proj", _rng.normal(0, 0.01, size=out_shape[0]))])
args_grad_npy = dict([(k, np.random.normal(0, 0.01, size=location[k].shape))
for k in grad_nodes]
+ [("__random_proj", np.random.normal(0, 0.01, size=out_shape[0]))])

args_grad = {k: mx.nd.array(v, ctx=ctx, dtype=dtype) for k, v in args_grad_npy.items()}
if grad_stype_dict is not None:
Expand Down Expand Up @@ -1068,7 +1067,7 @@ def check_symbolic_backward(sym, location, out_grads, expected, rtol=1e-5, atol=
if isinstance(expected, (list, tuple)):
expected = {k:v for k, v in zip(sym.list_arguments(), expected)}

args_grad_npy = {k:_rng.normal(size=v.shape) for k, v in expected.items()}
args_grad_npy = {k:np.random.normal(size=v.shape) for k, v in expected.items()}
args_grad_data = {}
for k, v in args_grad_npy.items():
nd = mx.nd.array(v, ctx=ctx, dtype=dtype)
Expand Down Expand Up @@ -1162,7 +1161,7 @@ def check_speed(sym, location=None, ctx=None, N=20, grad_req=None, typ="whole",
grad_req = 'write'
if location is None:
exe = sym.simple_bind(grad_req=grad_req, ctx=ctx, **kwargs)
location = {k: _rng.normal(size=arr.shape, scale=1.0) for k, arr in
location = {k: np.random.normal(size=arr.shape, scale=1.0) for k, arr in
exe.arg_dict.items()}
else:
assert isinstance(location, dict), "Expect dict, get \"location\"=%s" %str(location)
Expand Down
5 changes: 5 additions & 0 deletions tests/python/gpu/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
# specific language governing permissions and limitations
# under the License.

import sys
import os
import numpy as np
import mxnet as mx
from mxnet.test_utils import *
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
sys.path.insert(0, os.path.join(curr_path, '../unittest'))
from common import setup_module, with_seed
from mxnet.gluon import utils

def _get_model():
Expand Down Expand Up @@ -51,6 +55,7 @@ def _get_data(shape):
path='data/inception-v3-dump.npz',
sha1_hash=hash_inception_v3)

@with_seed()
def test_consistency(dump=False):
shape = (299, 299)
_get_model()
Expand Down
8 changes: 8 additions & 0 deletions tests/python/gpu/test_gluon_model_zoo_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
from mxnet.gluon.model_zoo.vision import get_model
from mxnet.test_utils import assert_almost_equal
import sys
import os
import unittest
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
sys.path.insert(0, os.path.join(curr_path, '../unittest'))
from common import setup_module, with_seed

def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
Expand All @@ -34,6 +38,7 @@ def download_data():
'http://data.mxnet.io/data/val-5k-256.rec', VAL_DATA)

@unittest.skip("test fails intermittently. temporarily disabled.")
@with_seed()
def test_inference():
all_models = ['resnet50_v1', 'vgg19_bn', 'alexnet', #'inceptionv3',
'densenet201', 'squeezenet1.0', 'mobilenet0.25']
Expand Down Expand Up @@ -91,6 +96,9 @@ def get_nn_model(name):
else:
return get_model(name)

# Hardcoding bad seed that caused a failure on the Py2 MKLDNN-GPU CI runner
# to check for failure repeatability
@with_seed(1521019752)
def test_training():
# We use network models without dropout for testing.
# TODO(zhengda) mobilenet can't pass this test even without MKLDNN.
Expand Down
6 changes: 6 additions & 0 deletions tests/python/gpu/test_kvstore_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@
# under the License.

# pylint: skip-file
import sys
import os
import mxnet as mx
import numpy as np
import unittest
from mxnet.test_utils import assert_almost_equal, default_context
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
sys.path.insert(0, os.path.join(curr_path, '../unittest'))
from common import setup_module, with_seed

shape = (4, 4)
keys = [5, 7, 11]
Expand All @@ -36,6 +41,7 @@ def init_kv_with_str(stype='default', kv_type='local'):
return kv


@with_seed()
def test_rsp_push_pull():
def check_rsp_push_pull(kv_type, is_push_cpu=True):
kv = init_kv_with_str('row_sparse', kv_type)
Expand Down
Loading