Skip to content

Commit

Permalink
[NPU]fix uts (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
USTCKAY authored Jul 12, 2023
1 parent 81382db commit a17035e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
14 changes: 7 additions & 7 deletions backends/npu/tests/unittests/test_momentum_op_npu.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ def _test_momentum_dygraph_common(self, regularization):
out = linear(inp)
loss = paddle.mean(out)
# This can be any optimizer supported by dygraph.
momentum = paddle.fluid.contrib.optimizer.Momentum(
momentum = paddle.optimizer.Momentum(
learning_rate=0.01,
momentum=0.9,
parameter_list=linear.parameters(),
regularization=regularization,
parameters=linear.parameters(),
weight_decay=regularization,
)
momentum.minimize(loss)

Expand All @@ -261,7 +261,7 @@ def test_momentum_static(self):
cost = paddle.nn.functional.square_error_cost(input=y_predict, label=y)
avg_cost = paddle.mean(cost)

momentum_optimizer = paddle.fluid.contrib.optimizer.Momentum(
momentum_optimizer = paddle.optimizer.Momentum(
learning_rate=0.1, momentum=0.9
)
momentum_optimizer.minimize(avg_cost)
Expand Down Expand Up @@ -311,11 +311,11 @@ def __test_vs(self, place=paddle.CustomPlace("npu", 0)):
weight_attr=paddle.nn.initializer.Constant(value=2.0),
bias_attr=paddle.nn.initializer.Constant(value=2.0),
)
momentum_new = paddle.fluid.contrib.optimizer.Momentum(
momentum_new = paddle.optimizer.Momentum(
learning_rate=0.01,
momentum=0.9,
parameter_list=linear_new.parameters(),
regularization=paddle.regularizer.L2Decay(coeff=0.1),
parameters=linear_new.parameters(),
weight_decay=paddle.regularizer.L2Decay(coeff=0.1),
)
self.__update_params(momentum=momentum_new, linear=linear_new)

Expand Down
5 changes: 2 additions & 3 deletions backends/npu/tests/unittests/test_rmsprop_op_npu.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import numpy as np
import paddle
import paddle.fluid as fluid

paddle.enable_static()
SEED = 2021
Expand Down Expand Up @@ -49,7 +48,7 @@ def _test(self, run_npu=True):

cost = paddle.nn.functional.cross_entropy(input=prediction, label=label)
loss = paddle.mean(cost)
rmsprop = fluid.optimizer.RMSProp(learning_rate=0.01)
rmsprop = paddle.optimizer.RMSProp(learning_rate=0.01)
rmsprop.minimize(loss)

if run_npu:
Expand Down Expand Up @@ -110,7 +109,7 @@ def _test(self, run_npu=True):

cost = paddle.nn.functional.cross_entropy(input=prediction, label=label)
loss = paddle.mean(cost)
rmsprop = fluid.optimizer.RMSProp(learning_rate=0.01, centered=True)
rmsprop = paddle.optimizer.RMSProp(learning_rate=0.01, centered=True)
rmsprop.minimize(loss)

if run_npu:
Expand Down

0 comments on commit a17035e

Please sign in to comment.