未验证 提交 a128eb7b 编写于 作者: Q Qiao Longfei 提交者: GitHub

improve unique_name, uniq id is related to prefix (#5223)

* improve unique_name, uniq id is related to prefix

* fix join
上级 8d1ad97b
......@@ -15,6 +15,7 @@ limitations under the License. */
#include "paddle/pybind/protobuf.h"
#include <mutex> // for call_once
#include <unordered_map>
#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<size_t> generator;
return generator.fetch_add(1);
static size_t UniqueIntegerGenerator(const std::string &prefix) {
static std::unordered_map<std::string, std::atomic<size_t>> generators;
return generators[prefix].fetch_add(1);
}
std::once_flag gflags_init_flag;
......
......@@ -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):
......
......@@ -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)])
......
......@@ -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()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册