def test_spares_proximal_ada_grad_compile(): """ test sparse proximal_ada_grad compile """ indices = Tensor(np.array([0, 1]).astype(np.int32)) label = Tensor(np.zeros([2, 1, 2]).astype(np.float32)) net = NetWithSparseGatherV2() net.set_train() optimizer = ProximalAdagrad(net.trainable_params(), weight_decay=0.9, loss_scale=1024.0) optimizer.target = 'CPU' train_network = TrainOneStepCell(net, optimizer) _executor.compile(train_network, indices, label)
def test_proximal_target(): """ test_proximal_target """ net = NetWithSparseGatherV2() net.set_train() optimizer = ProximalAdagrad(net.trainable_params(), weight_decay=0.9, loss_scale=1024.0) if optimizer.target not in ('CPU', 'Ascend'): raise ValueError("The value must be 'CPU' or 'Ascend', but got value {}".format(optimizer.target))
def test_proximal_ada_grad(): """ test_proximal_ada_grad """ inputs = Tensor(np.ones([1, 64]).astype(np.float32)) label = Tensor(np.zeros([1, 10]).astype(np.float32)) net = Net() net.set_train() loss = nn.SoftmaxCrossEntropyWithLogits() optimizer = ProximalAdagrad(net.trainable_params()) net_with_loss = WithLossCell(net, loss) train_network = TrainOneStepCell(net_with_loss, optimizer) _executor.compile(train_network, inputs, label)