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

* improve unique_name, uniq id is related to prefix

* fix join
fix-typo
Qiao Longfei 7 years ago committed by GitHub
parent 8d1ad97b3d
commit a128eb7b73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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()

Loading…
Cancel
Save