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

Proper handling of "allow_np_array" attribute in optimizer #16494

Merged
merged 1 commit into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion python/mxnet/optimizer/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1942,7 +1942,7 @@ def __init__(self, optimizer):

def __call__(self, index, grad, weight):
"""Updates weight given gradient and index."""
allow_np = self.optimizer.allow_np_array
allow_np = self.optimizer.allow_np_array if hasattr(self.optimizer, "allow_np_array") else is_np_array()
if not isinstance(index, (list, tuple)):
indices = [index]
grads = [_as_classic(grad, allow_np)]
Expand Down
9 changes: 9 additions & 0 deletions tests/python/unittest/test_numpy_gluon.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ def hybrid_forward(self, F, pred, label):
trainer.step(1)


@with_seed()
@use_np
def test_optimizer_backward_compat():
optimizer = mx.optimizer.SGD()
delattr(optimizer, "allow_np_array")
updater = mx.optimizer.Updater(optimizer)
updater(0, np.ones((0, 0)), np.zeros((0, 0)))


@with_seed()
@use_np
def test_np_loss_ndarray():
Expand Down