diff --git a/python/paddle/tests/test_model.py b/python/paddle/tests/test_model.py index 0ced69c0f2ea9620918c3cd0e3b970a1226a3863..bc9652ee18919e2c3cde85cafa8861d4a3f9f479 100644 --- a/python/paddle/tests/test_model.py +++ b/python/paddle/tests/test_model.py @@ -718,6 +718,20 @@ class TestModelFunction(unittest.TestCase): model.save(save_dir, training=False) shutil.rmtree(save_dir) + def test_accumulate(self, ): + dim = 20 + data = np.random.random(size=(4, dim)).astype(np.float32) + label = np.random.randint(0, 10, size=(4, 1)).astype(np.int64) + net = MyModel() + optim = fluid.optimizer.SGD(learning_rate=0.001, + parameter_list=net.parameters()) + inputs = [InputSpec([None, dim], 'float32', 'x')] + labels = [InputSpec([None, 1], 'int64', 'label')] + model = Model(net, inputs, labels) + model.prepare(optim, loss=CrossEntropyLoss(reduction="sum")) + loss1, = model.train_batch([data], [label], update=True) + loss2, = model.train_batch([data], [label], update=False) + class TestModelWithLRScheduler(unittest.TestCase): def test_fit_by_step(self):