diff --git a/paddle/pybind/pybind.cc b/paddle/pybind/pybind.cc index 4baff895daa1f26fe3f344372f2686fbcbb82098..2a0075356ed1e0f0b3501ac681c5e3a1bf37e2ca 100644 --- a/paddle/pybind/pybind.cc +++ b/paddle/pybind/pybind.cc @@ -15,6 +15,7 @@ limitations under the License. */ #include "paddle/pybind/protobuf.h" #include // for call_once +#include #include "gflags/gflags.h" #include "paddle/framework/backward.h" #include "paddle/framework/executor.h" @@ -42,9 +43,9 @@ limitations under the License. */ namespace paddle { namespace pybind { -static size_t UniqueIntegerGenerator() { - static std::atomic generator; - return generator.fetch_add(1); +static size_t UniqueIntegerGenerator(const std::string &prefix) { + static std::unordered_map> generators; + return generators[prefix].fetch_add(1); } std::once_flag gflags_init_flag; diff --git a/python/paddle/v2/framework/framework.py b/python/paddle/v2/framework/framework.py index 43101c9ddad76b7c1c322130dc0362a5c8ea4336..f8d2f67410a6c06a1642180d2d62c881ec6bda3d 100644 --- a/python/paddle/v2/framework/framework.py +++ b/python/paddle/v2/framework/framework.py @@ -119,8 +119,9 @@ class Variable(object): @staticmethod def _unique_var_name_(): - uid = core.unique_integer() # unique during whole process. - return "_generated_var_%d" % uid + prefix = "_generated_var" + uid = core.unique_integer(prefix) # unique during whole process. + return "_".join([prefix, str(uid)]) @staticmethod def _convert_np_dtype_to_dtype_(np_dtype): diff --git a/python/paddle/v2/framework/layer_helper.py b/python/paddle/v2/framework/layer_helper.py index 1f72c9bc7b0ceda1dd954703fcc10c77a3e5ed25..d96dbe172c22617182e7ebf4aab175c6142352b7 100644 --- a/python/paddle/v2/framework/layer_helper.py +++ b/python/paddle/v2/framework/layer_helper.py @@ -8,7 +8,7 @@ from paddle.v2.framework.framework import Variable, g_program, \ def unique_name(prefix): - uid = core.unique_integer() # unique during whole process. + uid = core.unique_integer(prefix) # unique during whole process. return "_".join([prefix, str(uid)]) diff --git a/python/paddle/v2/framework/tests/test_image_classification_layer.py b/python/paddle/v2/framework/tests/test_image_classification_layer.py index 7411689b615aeaa900fecb8c5ae00cf92203289c..b4eda13552e60f009ec910e3d21e9d77107133a1 100644 --- a/python/paddle/v2/framework/tests/test_image_classification_layer.py +++ b/python/paddle/v2/framework/tests/test_image_classification_layer.py @@ -37,7 +37,7 @@ class TestLayer(unittest.TestCase): layers.batch_norm( input=images, program=program, init_program=init_program) - #print str(program) + # print str(program) def test_dropout_layer(self): program = Program() @@ -53,7 +53,7 @@ class TestLayer(unittest.TestCase): program=program, init_program=init_program) - #print str(program) + # print str(program) def test_img_conv_group(self): program = Program()