|
|
|
@ -22,7 +22,7 @@ namespace paddle {
|
|
|
|
|
namespace operators {
|
|
|
|
|
namespace distributed {
|
|
|
|
|
|
|
|
|
|
TEST(ConcurrentSet, Update) {
|
|
|
|
|
TEST(ConcurrentSet, All) {
|
|
|
|
|
ConcurrentSet concurrent_set;
|
|
|
|
|
std::vector<int64_t> in1 = {1, 2, 3, 4};
|
|
|
|
|
std::vector<int64_t> in2 = {2, 3, 5, 6};
|
|
|
|
@ -51,6 +51,45 @@ TEST(ConcurrentSet, Update) {
|
|
|
|
|
EXPECT_EQ(ret.size(), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(AsyncSparseParamUpdateRecorder, All) {
|
|
|
|
|
std::unordered_map<std::string, std::string> grad_to_param;
|
|
|
|
|
grad_to_param["grad1"] = "param1";
|
|
|
|
|
grad_to_param["grad2"] = "param2";
|
|
|
|
|
|
|
|
|
|
int trainer_num = 10;
|
|
|
|
|
|
|
|
|
|
AsyncSparseParamUpdateRecorder recorder(trainer_num, grad_to_param);
|
|
|
|
|
std::vector<int64_t> in1 = {1, 2, 3, 4};
|
|
|
|
|
std::vector<int64_t> in2 = {2, 3, 5, 6};
|
|
|
|
|
|
|
|
|
|
std::unordered_set<int64_t> in;
|
|
|
|
|
std::copy(in1.begin(), in1.end(), std::inserter(in, in.begin()));
|
|
|
|
|
std::copy(in2.begin(), in2.end(), std::inserter(in, in.begin()));
|
|
|
|
|
|
|
|
|
|
recorder.Update("grad1", in1);
|
|
|
|
|
recorder.Update("grad1", in2);
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(recorder.HasParam("param1"));
|
|
|
|
|
EXPECT_TRUE(recorder.HasParam("param2"));
|
|
|
|
|
EXPECT_FALSE(recorder.HasParam("param3"));
|
|
|
|
|
|
|
|
|
|
std::vector<int64_t> ret;
|
|
|
|
|
EXPECT_ANY_THROW(recorder.GetAndClear("param1", trainer_num, &ret));
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < trainer_num; ++i) {
|
|
|
|
|
std::vector<int64_t> ret;
|
|
|
|
|
std::unordered_set<int64_t> out;
|
|
|
|
|
|
|
|
|
|
recorder.GetAndClear("param1", i, &ret);
|
|
|
|
|
std::copy(ret.begin(), ret.end(), std::inserter(out, out.begin()));
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(in, out);
|
|
|
|
|
|
|
|
|
|
recorder.GetAndClear("param1", i, &ret);
|
|
|
|
|
EXPECT_EQ(ret.size(), 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace distributed
|
|
|
|
|
} // namespace operators
|
|
|
|
|
} // namespace paddle
|
|
|
|
|