You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/04/19 04:46:14 UTC

[GitHub] [incubator-mxnet] szha opened a new issue #18101: test_sparse_fm.py::test_factorization_machine_module

szha opened a new issue #18101: test_sparse_fm.py::test_factorization_machine_module
URL: https://github.com/apache/incubator-mxnet/issues/18101
 
 
   ## Description
   http://jenkins.mxnet-ci.amazon-ml.com/blue/organizations/jenkins/mxnet-validation%2Fwindows-cpu/detail/PR-18025/32/pipeline
   
   ```
   ================================== FAILURES ===================================
   ______________________ test_factorization_machine_module ______________________
   
   verbose = False
   
       def test_factorization_machine_module(verbose=False):
           """ Test factorization machine model with sparse operators """
           def check_factorization_machine_module(optimizer=None, num_epochs=None):
               print("check_factorization_machine_module( {} )".format(optimizer))
       
               def fm(factor_size, feature_dim, init):
                   x = mx.symbol.Variable("data", stype='csr')
                   v = mx.symbol.Variable("v", shape=(feature_dim, factor_size),
                                          init=init, stype='row_sparse')
       
                   w1_weight = mx.symbol.var('w1_weight', shape=(feature_dim, 1),
                                             init=init, stype='row_sparse')
                   w1_bias = mx.symbol.var('w1_bias', shape=(1))
                   w1 = mx.symbol.broadcast_add(mx.symbol.dot(x, w1_weight), w1_bias)
       
                   v_s = mx.symbol._internal._square_sum(data=v, axis=1, keepdims=True)
                   x_s = mx.symbol.square(data=x)
                   bd_sum = mx.sym.dot(x_s, v_s)
       
                   w2 = mx.symbol.dot(x, v)
                   w2_squared = 0.5 * mx.symbol.square(data=w2)
       
                   w_all = mx.symbol.Concat(w1, w2_squared, dim=1)
                   sum1 = mx.symbol.sum(data=w_all, axis=1, keepdims=True)
                   sum2 = 0.5 * mx.symbol.negative(bd_sum)
                   model = mx.sym.elemwise_add(sum1, sum2)
       
                   y = mx.symbol.Variable("label")
                   model = mx.symbol.LinearRegressionOutput(data=model, label=y)
                   return model
       
               # model
               init = mx.initializer.Normal(sigma=0.01)
               factor_size = 4
               feature_dim = 10000
               model = fm(factor_size, feature_dim, init)
       
               # data iter
               num_batches = 5
               batch_size = 64
               num_samples = batch_size * num_batches
               # generate some random csr data
               csr_nd = rand_ndarray((num_samples, feature_dim), 'csr', 0.1)
               label = mx.nd.ones((num_samples,1))
               # the alternative is to use LibSVMIter
               train_iter = mx.io.NDArrayIter(data=csr_nd,
                                              label={'label':label},
                                              batch_size=batch_size,
                                              last_batch_handle='discard')
               # create module
               mod = mx.mod.Module(symbol=model, data_names=['data'], label_names=['label'])
               # allocate memory by given the input data and lable shapes
               mod.bind(data_shapes=train_iter.provide_data, label_shapes=train_iter.provide_label)
               # initialize parameters by uniform random numbers
               mod.init_params(initializer=init)
               if optimizer == 'sgd':
                   # use Sparse SGD with learning rate 0.1 to train
                   sgd = mx.optimizer.SGD(momentum=0.1, clip_gradient=5.0, learning_rate=0.01,
                                          rescale_grad=1.0/batch_size)
                   mod.init_optimizer(optimizer=sgd)
                   if num_epochs is None:
                       num_epochs = 10
                   expected_accuracy = 0.02
               elif optimizer == 'adam':
                   # use Sparse Adam to train
                   adam = mx.optimizer.Adam(clip_gradient=5.0, learning_rate=0.0005,
                                            rescale_grad=1.0/batch_size)
                   mod.init_optimizer(optimizer=adam)
                   if num_epochs is None:
                       num_epochs = 10
                   expected_accuracy = 0.05
               elif optimizer == 'adagrad':
                   # use Sparse AdaGrad with learning rate 0.1 to train
                   adagrad = mx.optimizer.AdaGrad(clip_gradient=5.0, learning_rate=0.01,
                                                  rescale_grad=1.0/batch_size)
                   mod.init_optimizer(optimizer=adagrad)
                   if num_epochs is None:
                       num_epochs = 20
                   expected_accuracy = 0.09
               else:
                   raise AssertionError("Unsupported optimizer type '" + optimizer + "' specified")
               # use accuracy as the metric
               metric = mx.metric.create('MSE')
               # train 'num_epochs' epoch
               for epoch in range(num_epochs):
                   train_iter.reset()
                   metric.reset()
                   for batch in train_iter:
                       mod.forward(batch, is_train=True)       # compute predictions
                       mod.update_metric(metric, batch.label)  # accumulate prediction accuracy
                       mod.backward()                          # compute gradients
                       mod.update()                            # update parameters
                   print('Epoch %d, Training %s' % (epoch, metric.get()))
               if num_epochs > 1:
                   assert(metric.get()[1] < expected_accuracy)
       
           if verbose is True:
               print("============ SGD ==========================")
               start = time.clock()
           check_factorization_machine_module('sgd')
           if verbose is True:
               print("Duration: {}".format(time.clock() - start))
               print("============ ADAM ==========================")
               start = time.clock()
           check_factorization_machine_module('adam')
           if verbose is True:
               print("Duration: {}".format(time.clock() - start))
               print("============ ADAGRAD ==========================")
               start = time.clock()
   >       check_factorization_machine_module('adagrad')
   
   tests\python\train\test_sparse_fm.py:132: 
   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
   
   optimizer = 'adagrad', num_epochs = 20
   
       def check_factorization_machine_module(optimizer=None, num_epochs=None):
           print("check_factorization_machine_module( {} )".format(optimizer))
       
           def fm(factor_size, feature_dim, init):
               x = mx.symbol.Variable("data", stype='csr')
               v = mx.symbol.Variable("v", shape=(feature_dim, factor_size),
                                      init=init, stype='row_sparse')
       
               w1_weight = mx.symbol.var('w1_weight', shape=(feature_dim, 1),
                                         init=init, stype='row_sparse')
               w1_bias = mx.symbol.var('w1_bias', shape=(1))
               w1 = mx.symbol.broadcast_add(mx.symbol.dot(x, w1_weight), w1_bias)
       
               v_s = mx.symbol._internal._square_sum(data=v, axis=1, keepdims=True)
               x_s = mx.symbol.square(data=x)
               bd_sum = mx.sym.dot(x_s, v_s)
       
               w2 = mx.symbol.dot(x, v)
               w2_squared = 0.5 * mx.symbol.square(data=w2)
       
               w_all = mx.symbol.Concat(w1, w2_squared, dim=1)
               sum1 = mx.symbol.sum(data=w_all, axis=1, keepdims=True)
               sum2 = 0.5 * mx.symbol.negative(bd_sum)
               model = mx.sym.elemwise_add(sum1, sum2)
       
               y = mx.symbol.Variable("label")
               model = mx.symbol.LinearRegressionOutput(data=model, label=y)
               return model
       
           # model
           init = mx.initializer.Normal(sigma=0.01)
           factor_size = 4
           feature_dim = 10000
           model = fm(factor_size, feature_dim, init)
       
           # data iter
           num_batches = 5
           batch_size = 64
           num_samples = batch_size * num_batches
           # generate some random csr data
           csr_nd = rand_ndarray((num_samples, feature_dim), 'csr', 0.1)
           label = mx.nd.ones((num_samples,1))
           # the alternative is to use LibSVMIter
           train_iter = mx.io.NDArrayIter(data=csr_nd,
                                          label={'label':label},
                                          batch_size=batch_size,
                                          last_batch_handle='discard')
           # create module
           mod = mx.mod.Module(symbol=model, data_names=['data'], label_names=['label'])
           # allocate memory by given the input data and lable shapes
           mod.bind(data_shapes=train_iter.provide_data, label_shapes=train_iter.provide_label)
           # initialize parameters by uniform random numbers
           mod.init_params(initializer=init)
           if optimizer == 'sgd':
               # use Sparse SGD with learning rate 0.1 to train
               sgd = mx.optimizer.SGD(momentum=0.1, clip_gradient=5.0, learning_rate=0.01,
                                      rescale_grad=1.0/batch_size)
               mod.init_optimizer(optimizer=sgd)
               if num_epochs is None:
                   num_epochs = 10
               expected_accuracy = 0.02
           elif optimizer == 'adam':
               # use Sparse Adam to train
               adam = mx.optimizer.Adam(clip_gradient=5.0, learning_rate=0.0005,
                                        rescale_grad=1.0/batch_size)
               mod.init_optimizer(optimizer=adam)
               if num_epochs is None:
                   num_epochs = 10
               expected_accuracy = 0.05
           elif optimizer == 'adagrad':
               # use Sparse AdaGrad with learning rate 0.1 to train
               adagrad = mx.optimizer.AdaGrad(clip_gradient=5.0, learning_rate=0.01,
                                              rescale_grad=1.0/batch_size)
               mod.init_optimizer(optimizer=adagrad)
               if num_epochs is None:
                   num_epochs = 20
               expected_accuracy = 0.09
           else:
               raise AssertionError("Unsupported optimizer type '" + optimizer + "' specified")
           # use accuracy as the metric
           metric = mx.metric.create('MSE')
           # train 'num_epochs' epoch
           for epoch in range(num_epochs):
               train_iter.reset()
               metric.reset()
               for batch in train_iter:
                   mod.forward(batch, is_train=True)       # compute predictions
                   mod.update_metric(metric, batch.label)  # accumulate prediction accuracy
                   mod.backward()                          # compute gradients
                   mod.update()                            # update parameters
               print('Epoch %d, Training %s' % (epoch, metric.get()))
           if num_epochs > 1:
   >           assert(metric.get()[1] < expected_accuracy)
   E           assert 0.09908652901649476 < 0.09
   
   tests\python\train\test_sparse_fm.py:117: AssertionError
   ---------------------------- Captured stderr setup ----------------------------
   DEBUG:root:np/mx/python random seeds are set to 947737299, use MXNET_TEST_SEED=947737299 to reproduce.
   np/mx/python random seeds are set to 947737299, use MXNET_TEST_SEED=947737299 to reproduce.
   np/mx/python random seeds are set to 947737299, use MXNET_TEST_SEED=947737299 to reproduce.
   np/mx/python random seeds are set to 947737299, use MXNET_TEST_SEED=947737299 to reproduce.
   np/mx/python random seeds are set to 947737299, use MXNET_TEST_SEED=947737299 to reproduce.
   ----------------------------- Captured log setup ------------------------------
   DEBUG    root:conftest.py:187 np/mx/python random seeds are set to 947737299, use MXNET_TEST_SEED=947737299 to reproduce.
   ---------------------------- Captured stdout call -----------------------------
   check_factorization_machine_module( sgd )
   Epoch 0, Training ('mse', 0.38593093752861024)
   Epoch 1, Training ('mse', 0.03555763177573681)
   Epoch 2, Training ('mse', 0.02565006911754608)
   Epoch 3, Training ('mse', 0.02250824309885502)
   Epoch 4, Training ('mse', 0.01979263238608837)
   Epoch 5, Training ('mse', 0.017411202564835547)
   Epoch 6, Training ('mse', 0.015326767414808273)
   Epoch 7, Training ('mse', 0.013501375541090965)
   Epoch 8, Training ('mse', 0.011901451274752617)
   Epoch 9, Training ('mse', 0.010497985407710075)
   check_factorization_machine_module( adam )
   Epoch 0, Training ('mse', 0.3476409211754799)
   Epoch 1, Training ('mse', 0.0968520075082779)
   Epoch 2, Training ('mse', 0.05835656188428402)
   Epoch 3, Training ('mse', 0.044359903410077096)
   Epoch 4, Training ('mse', 0.01865335088223219)
   Epoch 5, Training ('mse', 0.009723421186208725)
   Epoch 6, Training ('mse', 0.0045152821112424135)
   Epoch 7, Training ('mse', 0.004055538633838296)
   Epoch 8, Training ('mse', 0.0023699487326666714)
   Epoch 9, Training ('mse', 0.0014662319677881896)
   check_factorization_machine_module( adagrad )
   Epoch 0, Training ('mse', 102.1065269947052)
   Epoch 1, Training ('mse', 22.654237747192383)
   Epoch 2, Training ('mse', 12.700697994232177)
   Epoch 3, Training ('mse', 5.140128922462464)
   Epoch 4, Training ('mse', 3.1698575735092165)
   Epoch 5, Training ('mse', 2.1391861915588377)
   Epoch 6, Training ('mse', 1.5156056463718415)
   Epoch 7, Training ('mse', 1.1175895392894746)
   Epoch 8, Training ('mse', 0.8494489401578903)
   Epoch 9, Training ('mse', 0.6609541833400726)
   Epoch 10, Training ('mse', 0.5238838002085686)
   Epoch 11, Training ('mse', 0.42143079414963724)
   Epoch 12, Training ('mse', 0.3430994592607021)
   Epoch 13, Training ('mse', 0.2820735163986683)
   Epoch 14, Training ('mse', 0.23377536311745645)
   Epoch 15, Training ('mse', 0.19504224695265293)
   Epoch 16, Training ('mse', 0.16363248713314532)
   Epoch 17, Training ('mse', 0.137921386025846)
   Epoch 18, Training ('mse', 0.11670769434422254)
   Epoch 19, Training ('mse', 0.09908652901649476)
   -------------------------- Captured stderr teardown ---------------------------
   INFO:root:np/mx/python random seeds are set to 947737299, use MXNET_TEST_SEED=947737299 to reproduce.
   np/mx/python random seeds are set to 947737299, use MXNET_TEST_SEED=947737299 to reproduce.
   np/mx/python random seeds are set to 947737299, use MXNET_TEST_SEED=947737299 to reproduce.
   np/mx/python random seeds are set to 947737299, use MXNET_TEST_SEED=947737299 to reproduce.
   np/mx/python random seeds are set to 947737299, use MXNET_TEST_SEED=947737299 to reproduce.
   ---------------------------- Captured log teardown ----------------------------
   INFO     root:conftest.py:198 np/mx/python random seeds are set to 947737299, use MXNET_TEST_SEED=947737299 to reproduce.
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] szha commented on issue #18101: test_sparse_fm.py::test_factorization_machine_module

Posted by GitBox <gi...@apache.org>.
szha commented on issue #18101:
URL: https://github.com/apache/incubator-mxnet/issues/18101#issuecomment-620853694


   another occurrence: http://jenkins.mxnet-ci.amazon-ml.com/blue/rest/organizations/jenkins/pipelines/mxnet-validation/pipelines/centos-cpu/branches/PR-18146/runs/24/nodes/146/steps/265/log/?start=0
   
   added 5 retries


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org