normal state running ok
This commit is contained in:
@@ -5,12 +5,12 @@ export LDFLAGS= -pthread -lm -lrt
|
||||
export CFLAGS = -Wall -O3 -msse2 -Wno-unknown-pragmas -fPIC -I../src
|
||||
|
||||
# specify tensor path
|
||||
BIN = test_allreduce test_recover test_model_recover speed_test
|
||||
BIN = test_allreduce test_recover test_model_recover speed_test test_local_recover
|
||||
# objectives that makes up rabit library
|
||||
RABIT_OBJ = allreduce_base.o allreduce_robust.o engine.o
|
||||
MPIOBJ = engine_mpi.o
|
||||
|
||||
OBJ = $(RABIT_OBJ) test_allreduce.o test_recover.o test_model_recover.o speed_test.o
|
||||
OBJ = $(RABIT_OBJ) test_allreduce.o test_recover.o test_model_recover.o speed_test.o test_local_recover.o
|
||||
MPIBIN = test_allreduce.mpi speed_test.mpi
|
||||
.PHONY: clean all
|
||||
|
||||
@@ -24,6 +24,7 @@ test_allreduce.o: test_allreduce.cpp ../src/*.h
|
||||
speed_test.o: speed_test.cpp ../src/*.h
|
||||
test_recover.o: test_recover.cpp ../src/*.h
|
||||
test_model_recover.o: test_model_recover.cpp ../src/*.h
|
||||
test_local_recover.o: test_local_recover.cpp ../src/*.h
|
||||
|
||||
# we can link against MPI version to get use MPI
|
||||
test_allreduce: test_allreduce.o $(RABIT_OBJ)
|
||||
@@ -32,6 +33,7 @@ speed_test: speed_test.o $(RABIT_OBJ)
|
||||
speed_test.mpi: speed_test.o $(MPIOBJ)
|
||||
test_recover: test_recover.o $(RABIT_OBJ)
|
||||
test_model_recover: test_model_recover.o $(RABIT_OBJ)
|
||||
test_local_recover: test_local_recover.o $(RABIT_OBJ)
|
||||
|
||||
$(BIN) :
|
||||
$(CXX) $(CFLAGS) -o $@ $(filter %.cpp %.o %.c %.cc, $^) $(LDFLAGS)
|
||||
|
||||
@@ -6,8 +6,8 @@ then
|
||||
exit -1
|
||||
fi
|
||||
nrep=0
|
||||
echo ./$@ job_id=$OMPI_COMM_WORLD_RANK
|
||||
until ./$@ job_id=$OMPI_COMM_WORLD_RANK repeat=$nrep; do
|
||||
echo ./$@ task_id=$OMPI_COMM_WORLD_RANK
|
||||
until ./$@ task_id=$OMPI_COMM_WORLD_RANK repeat=$nrep; do
|
||||
sleep 1
|
||||
nrep=$((nrep+1))
|
||||
echo ./$@ job_id=$OMPI_COMM_WORLD_RANK repeat=$nrep
|
||||
|
||||
154
test/test_local_recover.cpp
Normal file
154
test/test_local_recover.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
// this is a test case to test whether rabit can recover model when
|
||||
// facing an exception
|
||||
#include <rabit.h>
|
||||
#include <utils.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
#include <mock.h>
|
||||
|
||||
using namespace rabit;
|
||||
|
||||
struct MockException {
|
||||
};
|
||||
|
||||
// dummy model
|
||||
class Model : public rabit::utils::ISerializable {
|
||||
public:
|
||||
// iterations
|
||||
std::vector<float> data;
|
||||
// load from stream
|
||||
virtual void Load(rabit::utils::IStream &fi) {
|
||||
fi.Read(&data);
|
||||
}
|
||||
/*! \brief save the model to the stream */
|
||||
virtual void Save(rabit::utils::IStream &fo) const {
|
||||
fo.Write(data);
|
||||
}
|
||||
virtual void InitModel(size_t n, float v) {
|
||||
data.resize(n, v);
|
||||
}
|
||||
};
|
||||
|
||||
inline void TestMax(test::Mock &mock, Model *model, Model *local, int ntrial, int iter) {
|
||||
int rank = rabit::GetRank();
|
||||
int nproc = rabit::GetWorldSize();
|
||||
const int z = iter + 111;
|
||||
|
||||
std::vector<float> ndata(model->data.size());
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
ndata[i] = (i * (rank+1)) % z + local->data[i];
|
||||
}
|
||||
mock.Allreduce<op::Max>(&ndata[0], ndata.size());
|
||||
if (ntrial == iter && rank == 3) {
|
||||
//exit(-1);
|
||||
}
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
float rmax = (i * 1) % z + model->data[i];
|
||||
for (int r = 0; r < nproc; ++r) {
|
||||
rmax = std::max(rmax, (float)((i * (r+1)) % z) + model->data[i] + r);
|
||||
}
|
||||
utils::Check(rmax == ndata[i], "[%d] TestMax check failure", rank);
|
||||
}
|
||||
model->data = ndata;
|
||||
local->data = ndata;
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
local->data[i] = ndata[i] + rank;
|
||||
}
|
||||
}
|
||||
|
||||
inline void TestSum(test::Mock &mock, Model *model, Model *local, int ntrial, int iter) {
|
||||
int rank = rabit::GetRank();
|
||||
int nproc = rabit::GetWorldSize();
|
||||
const int z = 131 + iter;
|
||||
|
||||
std::vector<float> ndata(model->data.size());
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
ndata[i] = (i * (rank+1)) % z + local->data[i];
|
||||
}
|
||||
mock.Allreduce<op::Sum>(&ndata[0], ndata.size());
|
||||
|
||||
if (ntrial == iter && rank == 0) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
float rsum = 0.0f;
|
||||
for (int r = 0; r < nproc; ++r) {
|
||||
rsum += (float)((i * (r+1)) % z) + model->data[i] + r;
|
||||
}
|
||||
utils::Check(fabsf(rsum - ndata[i]) < 1e-5 ,
|
||||
"[%d] TestSum check failure, local=%g, allreduce=%g", rank, rsum, ndata[i]);
|
||||
}
|
||||
model->data = ndata;
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
local->data[i] = ndata[i] + rank;
|
||||
}
|
||||
}
|
||||
|
||||
inline void TestBcast(test::Mock &mock, size_t n, int root, int ntrial) {
|
||||
int rank = rabit::GetRank();
|
||||
std::string s; s.resize(n);
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
s[i] = char(i % 126 + 1);
|
||||
}
|
||||
std::string res;
|
||||
if (root == rank) {
|
||||
res = s;
|
||||
mock.Broadcast(&res, root);
|
||||
} else {
|
||||
mock.Broadcast(&res, root);
|
||||
}
|
||||
utils::Check(res == s, "[%d] TestBcast fail", rank);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 3) {
|
||||
printf("Usage: <ndata> <config>\n");
|
||||
return 0;
|
||||
}
|
||||
int n = atoi(argv[1]);
|
||||
rabit::Init(argc, argv);
|
||||
int rank = rabit::GetRank();
|
||||
int nproc = rabit::GetWorldSize();
|
||||
std::string name = rabit::GetProcessorName();
|
||||
test::Mock mock(rank, argv[2], argv[3]);
|
||||
Model model, local;
|
||||
srand(0);
|
||||
int ntrial = 0;
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
int n;
|
||||
if (sscanf(argv[i], "repeat=%d", &n) == 1) ntrial = n;
|
||||
}
|
||||
while (true) {
|
||||
try {
|
||||
int iter = rabit::LoadCheckPoint(&model, &local);
|
||||
if (iter == 0) {
|
||||
model.InitModel(n, 1.0f);
|
||||
local.InitModel(n, 1.0f + rank);
|
||||
utils::LogPrintf("[%d] reload-trail=%d, init iter=%d\n", rank, ntrial, iter);
|
||||
} else {
|
||||
utils::LogPrintf("[%d] reload-trail=%d, init iter=%d\n", rank, ntrial, iter);
|
||||
}
|
||||
for (int r = iter; r < 3; ++r) {
|
||||
TestMax(mock, &model, &local, ntrial, r);
|
||||
utils::LogPrintf("[%d] !!!TestMax pass, iter=%d\n", rank, r);
|
||||
int step = std::max(nproc / 3, 1);
|
||||
for (int i = 0; i < nproc; i += step) {
|
||||
TestBcast(mock, n, i, ntrial);
|
||||
}
|
||||
utils::LogPrintf("[%d] !!!TestBcast pass, iter=%d\n", rank, r);
|
||||
TestSum(mock, &model, &local, ntrial, r);
|
||||
utils::LogPrintf("[%d] !!!TestSum pass, iter=%d\n", rank, r);
|
||||
rabit::CheckPoint(&model, &local);
|
||||
utils::LogPrintf("[%d] !!!CheckPont pass, iter=%d\n", rank, r);
|
||||
}
|
||||
break;
|
||||
} catch (MockException &e) {
|
||||
rabit::engine::GetEngine()->InitAfterException();
|
||||
++ntrial;
|
||||
}
|
||||
}
|
||||
rabit::Finalize();
|
||||
return 0;
|
||||
}
|
||||
@@ -132,7 +132,7 @@ int main(int argc, char *argv[]) {
|
||||
utils::LogPrintf("[%d] !!!TestBcast pass, iter=%d\n", rank, r);
|
||||
TestSum(mock, &model, ntrial, r);
|
||||
utils::LogPrintf("[%d] !!!TestSum pass, iter=%d\n", rank, r);
|
||||
rabit::CheckPoint(model);
|
||||
rabit::CheckPoint(&model);
|
||||
utils::LogPrintf("[%d] !!!CheckPont pass, iter=%d\n", rank, r);
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user