[CI] Test federated learning plugin in the CI (#8325)
This commit is contained in:
committed by
GitHub
parent
97a5b088a5
commit
2faa744aba
@@ -5,24 +5,36 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <thrust/host_vector.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <ctime>
|
||||
|
||||
#include "./helpers.h"
|
||||
#include "../../../plugin/federated/federated_communicator.h"
|
||||
#include "../../../plugin/federated/federated_server.h"
|
||||
#include "../../../src/collective/device_communicator_adapter.cuh"
|
||||
|
||||
namespace {
|
||||
|
||||
std::string GetServerAddress() {
|
||||
int port = GenerateRandomPort(50000, 60000);
|
||||
std::string address = std::string("localhost:") + std::to_string(port);
|
||||
return address;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace xgboost {
|
||||
namespace collective {
|
||||
|
||||
std::string const kServerAddress{"localhost:56789"}; // NOLINT(cert-err58-cpp)
|
||||
|
||||
class FederatedAdapterTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
server_address_ = GetServerAddress();
|
||||
server_thread_.reset(new std::thread([this] {
|
||||
grpc::ServerBuilder builder;
|
||||
federated::FederatedService service{kWorldSize};
|
||||
builder.AddListeningPort(kServerAddress, grpc::InsecureServerCredentials());
|
||||
builder.AddListeningPort(server_address_, grpc::InsecureServerCredentials());
|
||||
builder.RegisterService(&service);
|
||||
server_ = builder.BuildAndStart();
|
||||
server_->Wait();
|
||||
@@ -35,6 +47,7 @@ class FederatedAdapterTest : public ::testing::Test {
|
||||
}
|
||||
|
||||
static int const kWorldSize{2};
|
||||
std::string server_address_;
|
||||
std::unique_ptr<std::thread> server_thread_;
|
||||
std::unique_ptr<grpc::Server> server_;
|
||||
};
|
||||
@@ -52,9 +65,10 @@ TEST(FederatedAdapterSimpleTest, ThrowOnInvalidCommunicator) {
|
||||
TEST_F(FederatedAdapterTest, DeviceAllReduceSum) {
|
||||
std::vector<std::thread> threads;
|
||||
for (auto rank = 0; rank < kWorldSize; rank++) {
|
||||
threads.emplace_back(std::thread([rank] {
|
||||
FederatedCommunicator comm{kWorldSize, rank, kServerAddress};
|
||||
DeviceCommunicatorAdapter adapter{rank, &comm};
|
||||
threads.emplace_back(std::thread([rank, server_address=server_address_] {
|
||||
FederatedCommunicator comm{kWorldSize, rank, server_address};
|
||||
// Assign device 0 to all workers, since we run gtest in a single-GPU machine
|
||||
DeviceCommunicatorAdapter adapter{0, &comm};
|
||||
int const count = 3;
|
||||
thrust::device_vector<double> buffer(count, 0);
|
||||
thrust::sequence(buffer.begin(), buffer.end());
|
||||
@@ -74,9 +88,10 @@ TEST_F(FederatedAdapterTest, DeviceAllReduceSum) {
|
||||
TEST_F(FederatedAdapterTest, DeviceAllGatherV) {
|
||||
std::vector<std::thread> threads;
|
||||
for (auto rank = 0; rank < kWorldSize; rank++) {
|
||||
threads.emplace_back(std::thread([rank] {
|
||||
FederatedCommunicator comm{kWorldSize, rank, kServerAddress};
|
||||
DeviceCommunicatorAdapter adapter{rank, &comm};
|
||||
threads.emplace_back(std::thread([rank, server_address=server_address_] {
|
||||
FederatedCommunicator comm{kWorldSize, rank, server_address};
|
||||
// Assign device 0 to all workers, since we run gtest in a single-GPU machine
|
||||
DeviceCommunicatorAdapter adapter{0, &comm};
|
||||
|
||||
int const count = rank + 2;
|
||||
thrust::device_vector<char> buffer(count, 0);
|
||||
|
||||
Reference in New Issue
Block a user