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

Commit

Permalink
Fix Python 2 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
leezu committed Oct 24, 2019
1 parent 6f0ff56 commit ff7e995
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion python/mxnet/gluon/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,9 @@ def load_parameters(self, filename, ctx=None, allow_missing=False,

if not any('.' in i for i in loaded.keys()):
# legacy loading
del loaded
loaded = None
# We cannot `del loaded` as it is used in a generator expression
# below. `del loaded` would be a SyntaxError in Python 2.
self.collect_params().load(
filename, ctx, allow_missing, ignore_extra, self.prefix,
cast_dtype=cast_dtype, dtype_source=dtype_source)
Expand Down
8 changes: 4 additions & 4 deletions tests/python/unittest/test_gluon.py
Original file line number Diff line number Diff line change
Expand Up @@ -1512,25 +1512,25 @@ def forward(self, x):
net2.load_parameters('tmp.params')

@with_seed()
def test_save_load_with_shared_params():
def test_save_load_deduplicate_with_shared_params():
class B(mx.gluon.Block):
def __init__(self, params=None):
super().__init__(params=params)
super(B, self).__init__(params=params)

with self.name_scope():
self.weight = self.params.get('weight', shape=(10, 10))

class C(mx.gluon.Block):
def __init__(self, b1, b2):
super().__init__()
super(C, self).__init__()
self.b1 = b1
self.b2 = b2

b1 = B()
b2 = B(b1.collect_params())
c = C(b1, b2)
c.initialize()
c.save_parameters('tmp.params')
c.save_parameters('tmp.params', deduplicate=True)

params = mx.nd.load('tmp.params')
assert len(params) == 1 # Only a single copy of the shared parameter is saved
Expand Down

0 comments on commit ff7e995

Please sign in to comment.