Skip to content

Conversation

@SunGaofeng
Copy link
Contributor

for the codes in python/paddle/fluid/layers/ops.py, in several functions as following. It will lead to a mistake when run in python3 because locals_var.items() is of type dict_items, which can't be modified during iteration. But the code like "kwargs[name] = val" in the for loop will change locals() and lead to change in locals_var.items(). To solve this problem, just use locals_var = locals().copy() instead.

def hard_shrink(x, threshold=None):
locals_var = locals()
kwargs = dict()
for name, val in locals_var.items():
if val is not None:
kwargs[name] = val
return hard_shrink(**kwargs)

@SunGaofeng SunGaofeng merged commit 3559e5a into PaddlePaddle:develop Jun 10, 2019
@SunGaofeng SunGaofeng changed the title fix bug when iterate in locals_var.items() in python3, test=develop fix bug when iterate in locals_var.items() in python3 Jun 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants