-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement secure horizontal scheme for federated learning #10231
Merged
trivialfis
merged 84 commits into
dmlc:vertical-federated-learning
from
ZiyueXu77:SecureHorizontal
Jun 18, 2024
Merged
Changes from all commits
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
8570ba5
Add additional data split mode to cover the secure vertical pipeline
ZiyueXu77 2d00db6
Add IsSecure info and update corresponding functions
ZiyueXu77 ab17f5a
Modify evaluate_splits to block non-label owners to perform hist comp…
ZiyueXu77 fb1787c
Continue using Allgather for best split sync for secure vertical, equ…
ZiyueXu77 7a2a2b8
Modify histogram sync scheme for secure vertical case, can identify g…
ZiyueXu77 3ca3142
Sync cut informaiton across clients, full pipeline works for testing …
ZiyueXu77 22dd522
Code cleanup, phase 1 of alternative vertical pipeline finished
ZiyueXu77 52e8951
Code clean
ZiyueXu77 e9eef15
change kColS to kColSecure to avoid confusion with kCols
ZiyueXu77 91c8a2f
Replace allreduce with allgather, functional but inefficient version
ZiyueXu77 8340c26
Update AllGather behavior from individual pair to bulk by adopting ne…
ZiyueXu77 42a9df1
comment out the record printing
ZiyueXu77 41e5abb
fix pointer bug for histsync with allgather
ZiyueXu77 ea5dc98
Merge branch 'dmlc:master' into SecureBoostP2
ZiyueXu77 5d542f8
Merge branch 'dmlc:master' into SecureBoostP2
ZiyueXu77 d91be10
identify the HE adding locations
ZiyueXu77 dd60317
revise and simplify template code
ZiyueXu77 8da824c
revise and simplify template code
ZiyueXu77 fb9f4fa
prepare aggregator for gh broadcast
ZiyueXu77 e77f8c6
prepare histogram for histindex and row index for allgather
ZiyueXu77 7ef48c8
Merge branch 'vertical-federated-learning' into SecureBoostP2
ZiyueXu77 8405791
fix conflicts
ZiyueXu77 db7d518
fix conflicts
ZiyueXu77 dd6adde
fix format
ZiyueXu77 9567e67
fix allgather logic and update unit test
ZiyueXu77 53800f2
fix linting
ZiyueXu77 b7e70f1
fix linting and other unit test issues
ZiyueXu77 49e8fd6
fix linting and other unit test issues
ZiyueXu77 da0f7a6
integration with interface initial attempt
ZiyueXu77 406cda3
integration with interface initial attempt
ZiyueXu77 f6c63aa
integration with interface initial attempt
ZiyueXu77 f223df7
functional integration with interface
ZiyueXu77 d881d84
remove debugging prints
ZiyueXu77 2997cf7
remove processor from another PR
ZiyueXu77 3a1f9ac
Update the processor functions according to new processor implementation
ZiyueXu77 1107604
Move processor interface init from learner to communicator
ZiyueXu77 30b7ed5
Move processor interface init from learner to communicator functional
ZiyueXu77 a3ddf7d
switch to allgatherV for encrypted message with varying lenghts
ZiyueXu77 3123b51
consolidate with processor interface PR
ZiyueXu77 73225a0
remove prints and fix format
ZiyueXu77 e85b1fb
fix linting over reference pass
ZiyueXu77 57750b4
fix undefined symbol issue
ZiyueXu77 fa2665a
fix processor test
ZiyueXu77 87d2fdb
secure vertical relies on processor, move the unit test
ZiyueXu77 9941293
type correction
ZiyueXu77 dd4f440
type correction
ZiyueXu77 5b2dfe6
extra linting from last change
ZiyueXu77 80d3b89
Added Windows support
nvidianz 184b67f
Merge pull request #4 from nvidianz/processor-windows-support
ZiyueXu77 3382707
fix for cstdint types
ZiyueXu77 2a8f19a
fix for cstdint types
ZiyueXu77 9ff2935
Added support for horizontal secure XGBoost
nvidianz 38e9d3d
Merge pull request #5 from nvidianz/processor-horizontal-support
ZiyueXu77 38c176c
update with mock plugin
ZiyueXu77 a5ce92e
secure horizontal fully functional with mock plugin
ZiyueXu77 5e824ac
linting fix
ZiyueXu77 81db216
linting fix
ZiyueXu77 15c211a
linting fix
ZiyueXu77 f7341cd
fix type
ZiyueXu77 a579205
Merge branch 'vertical-federated-learning' into SecureHorizontal
ZiyueXu77 35d8c15
change loader and proc params input pattern to align with std map
ZiyueXu77 3d31905
update with secure vertical incorporation
ZiyueXu77 7f86787
Merge branch 'vertical-federated-learning' into SecureHorizontal
ZiyueXu77 bdcb6e2
Update mock_processor to enable nvflare usage
ZiyueXu77 a8205d3
[backport] Fix compiling with the latest CTX. (#10263)
trivialfis ae77f2d
Merge remote-tracking branch 'ZiyueXu77/SecureHorizontal' into Secure…
trivialfis cc13605
fix secure horizontal inference
ZiyueXu77 d7a6da6
initialized aggr context only once
ZiyueXu77 032b14d
Added support for multiple plugins in a single lib
nvidianz ea9b298
Merge pull request #7 from nvidianz/support-multi-processors
ZiyueXu77 7f3472e
remove redundant condition
ZiyueXu77 5569e78
Added support for boolean in proc_params
nvidianz 71e578c
Merge pull request #10 from nvidianz/support-bool-params-2nd-try
ZiyueXu77 454f69d
free buffer
ZiyueXu77 e2f77e2
Merge branch 'vertical-federated-learning' into SecureHorizontal
trivialfis 6e4a3fb
Merge branch 'vertical-federated-learning' into SecureHorizontal
trivialfis 61c8f47
CUDA.
trivialfis 05be1e8
Fix clean build.
trivialfis e0795cf
Fix include.
trivialfis fd4f331
tidy.
trivialfis 074c63b
lint.
trivialfis 2a8fd72
nolint.
trivialfis ac02279
disable.
trivialfis 1ef69ea
disable sanitizer.
trivialfis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/*! | ||
* Copyright 2022 XGBoost contributors | ||
*/ | ||
#include <map> | ||
#include "communicator.h" | ||
|
||
#include "comm.h" | ||
|
@@ -9,14 +10,41 @@ | |
#include "rabit_communicator.h" | ||
|
||
#if defined(XGBOOST_USE_FEDERATED) | ||
#include "../../plugin/federated/federated_communicator.h" | ||
#include "../../plugin/federated/federated_communicator.h" | ||
#endif | ||
|
||
#include "../processing/processor.h" | ||
processing::Processor *processor_instance; | ||
|
||
namespace xgboost::collective { | ||
thread_local std::unique_ptr<Communicator> Communicator::communicator_{new NoOpCommunicator()}; | ||
thread_local CommunicatorType Communicator::type_{}; | ||
thread_local std::string Communicator::nccl_path_{}; | ||
|
||
std::map<std::string, std::string> JsonToMap(xgboost::Json const& config, std::string key) { | ||
auto json_map = xgboost::OptionalArg<xgboost::Object>(config, key, xgboost::JsonObject::Map{}); | ||
std::map<std::string, std::string> params{}; | ||
for (auto entry : json_map) { | ||
std::string text; | ||
xgboost::Value* value = &(entry.second.GetValue()); | ||
if (value->Type() == xgboost::Value::ValueKind::kString) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
text = reinterpret_cast<xgboost::String *>(value)->GetString(); | ||
} else if (value->Type() == xgboost::Value::ValueKind::kInteger) { | ||
auto num = reinterpret_cast<xgboost::Integer *>(value)->GetInteger(); | ||
text = std::to_string(num); | ||
} else if (value->Type() == xgboost::Value::ValueKind::kNumber) { | ||
auto num = reinterpret_cast<xgboost::Number *>(value)->GetNumber(); | ||
text = std::to_string(num); | ||
} else if (value->Type() == xgboost::Value::ValueKind::kBoolean) { | ||
text = reinterpret_cast<xgboost::Boolean *>(value)->GetBoolean() ? "true" : "false"; | ||
} else { | ||
text = "Unsupported type"; | ||
} | ||
params[entry.first] = text; | ||
} | ||
return params; | ||
} | ||
|
||
void Communicator::Init(Json const& config) { | ||
auto nccl = OptionalArg<String>(config, "dmlc_nccl_path", std::string{DefaultNcclName()}); | ||
nccl_path_ = nccl; | ||
|
@@ -38,26 +66,46 @@ void Communicator::Init(Json const& config) { | |
} | ||
case CommunicatorType::kFederated: { | ||
#if defined(XGBOOST_USE_FEDERATED) | ||
communicator_.reset(FederatedCommunicator::Create(config)); | ||
communicator_.reset(FederatedCommunicator::Create(config)); | ||
// Get processor configs | ||
std::string plugin_name{}; | ||
std::string loader_params_key{}; | ||
std::string loader_params_map{}; | ||
std::string proc_params_key{}; | ||
std::string proc_params_map{}; | ||
plugin_name = OptionalArg<String>(config, "plugin_name", plugin_name); | ||
// Initialize processor if plugin_name is provided | ||
if (!plugin_name.empty()) { | ||
std::map<std::string, std::string> loader_params = JsonToMap(config, "loader_params"); | ||
std::map<std::string, std::string> proc_params = JsonToMap(config, "proc_params"); | ||
processing::ProcessorLoader loader(loader_params); | ||
processor_instance = loader.Load(plugin_name); | ||
processor_instance->Initialize(collective::GetRank() == 0, proc_params); | ||
} | ||
#else | ||
LOG(FATAL) << "XGBoost is not compiled with Federated Learning support."; | ||
LOG(FATAL) << "XGBoost is not compiled with Federated Learning support."; | ||
#endif | ||
break; | ||
} | ||
case CommunicatorType::kInMemory: | ||
case CommunicatorType::kInMemoryNccl: { | ||
communicator_.reset(InMemoryCommunicator::Create(config)); | ||
break; | ||
} | ||
case CommunicatorType::kUnknown: | ||
LOG(FATAL) << "Unknown communicator type."; | ||
break; | ||
} | ||
|
||
case CommunicatorType::kInMemory: | ||
case CommunicatorType::kInMemoryNccl: { | ||
communicator_.reset(InMemoryCommunicator::Create(config)); | ||
break; | ||
} | ||
case CommunicatorType::kUnknown: | ||
LOG(FATAL) << "Unknown communicator type."; | ||
} | ||
} | ||
|
||
#ifndef XGBOOST_USE_CUDA | ||
void Communicator::Finalize() { | ||
communicator_->Shutdown(); | ||
communicator_.reset(new NoOpCommunicator()); | ||
if (processor_instance != nullptr) { | ||
processor_instance->Shutdown(); | ||
processor_instance = nullptr; | ||
} | ||
} | ||
#endif | ||
} // namespace xgboost::collective |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I ask why the vertical federated learning section is being modified for horizontal learning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one adds additional horizontal functions to the vertical_P2 PR, so it in fact includes everything that PR has, since that PR has not been merged, this one shows all the vertical modifications,
"Modifictions added beyond #10124"