Skip to content
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

Add paddle custom flags support #56256

Merged
merged 53 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
d2e13bf
update
huangjiyi Aug 13, 2023
6759057
repalce gflags header
huangjiyi Aug 13, 2023
38bdc32
replace DEFINE_<type> with PD_DEFINE_<type>
huangjiyi Aug 13, 2023
690e5e6
fix bug
huangjiyi Aug 13, 2023
5322138
fix bug
huangjiyi Aug 13, 2023
b87c48f
fix bug
huangjiyi Aug 14, 2023
ce6dd36
update cmake
huangjiyi Aug 14, 2023
6189e5c
add :: before some paddle namespace
huangjiyi Aug 14, 2023
441f93c
fix link error
huangjiyi Aug 15, 2023
b2cbec3
fix CI-Py3
huangjiyi Aug 15, 2023
5056552
allow commandline parse
huangjiyi Aug 16, 2023
6e51cb0
fix SetFlagsFromEnv
huangjiyi Aug 16, 2023
21f4ac4
Merge branch 'develop' into paddle_flags
huangjiyi Aug 16, 2023
27f25fe
fix bug
huangjiyi Aug 16, 2023
511b8c6
fix bug
huangjiyi Aug 16, 2023
e099242
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
huangjiyi Aug 16, 2023
ae9d3ca
fix CI-CINN
huangjiyi Aug 16, 2023
0504034
fix CI-Coverage-build
huangjiyi Aug 16, 2023
1404cd6
fix CI-Windows-build
huangjiyi Aug 16, 2023
c0b331b
fix CI-Inference
huangjiyi Aug 16, 2023
6682cdd
fix bug
huangjiyi Aug 16, 2023
a791251
fix bug
huangjiyi Aug 16, 2023
e5d814d
fix CI-CINN
huangjiyi Aug 16, 2023
f4f2c69
fix inference api test
huangjiyi Aug 17, 2023
e4588a1
fix infer_ut test
huangjiyi Aug 17, 2023
4d6e2b7
revert infer_ut gflags usage
huangjiyi Aug 17, 2023
7936b8d
update
huangjiyi Aug 17, 2023
b662dae
fix inference
huangjiyi Aug 17, 2023
d5792de
remove flags export macro
huangjiyi Aug 18, 2023
4982051
revert inference demo_ci gflags usage
huangjiyi Aug 19, 2023
b3a08b1
update
huangjiyi Aug 19, 2023
a608765
update
huangjiyi Aug 20, 2023
2774d0c
update
huangjiyi Aug 20, 2023
2a107ff
update
huangjiyi Aug 20, 2023
6ce358b
update
huangjiyi Aug 20, 2023
9ec8a7f
update
huangjiyi Aug 20, 2023
7bd8872
update
huangjiyi Aug 20, 2023
0a1d585
update
huangjiyi Aug 20, 2023
757ac98
fix bug when turn on WITH_GFLAGS
huangjiyi Aug 20, 2023
c839a8d
turn on WITH_GFLAGS
huangjiyi Aug 20, 2023
d3122a7
fix bug when turn on WITH_GFLAGS
huangjiyi Aug 20, 2023
31cd016
fix bug when turn on WITH_GFLAGS
huangjiyi Aug 20, 2023
4182d18
update
huangjiyi Aug 20, 2023
f9e5af6
Merge branch 'flags_with_gflags' of https://github.com/huangjiyi/Padd…
huangjiyi Aug 20, 2023
d3890a4
update and add unittest
huangjiyi Aug 21, 2023
5fd6d35
add unittest
huangjiyi Aug 21, 2023
eb71219
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
huangjiyi Aug 22, 2023
d1c3e13
fix conflict
huangjiyi Aug 22, 2023
8583c11
rerun ci
huangjiyi Aug 22, 2023
c81c5ef
update
huangjiyi Aug 23, 2023
6875a7a
resolve conflict
huangjiyi Aug 25, 2023
2770b7d
Merge branch 'develop' into paddle_flags
huangjiyi Aug 25, 2023
0fcc8e7
resolve conflict
huangjiyi Aug 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ option(WITH_BRPC_RDMA "Use brpc rdma as the rpc protocal" OFF)
option(ON_INFER "Turn on inference optimization and inference-lib generation"
ON)
option(WITH_CPP_DIST "Install PaddlePaddle C++ distribution" OFF)
option(WITH_GFLAGS "Compile PaddlePaddle with gflags support" OFF)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议把这个打开ON再重新跑一次CI,看有没有问题

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经提了测试 PR 了:

################################ Internal Configurations #######################################
option(WITH_NV_JETSON "Compile PaddlePaddle with NV JETSON" OFF)
option(WITH_PROFILER "Compile PaddlePaddle with GPU profiler and gperftools"
Expand Down
10 changes: 10 additions & 0 deletions cmake/cinn.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ if(WITH_MKL)
endif()
endif()

if(NOT WITH_GFLAGS)
target_link_libraries(cinnapi gflags)
add_dependencies(cinnapi gflags)
endif()

if(WITH_GPU)
target_link_libraries(
cinnapi
Expand Down Expand Up @@ -237,6 +242,11 @@ function(gen_cinncore LINKTYPE)
endif()
endif()

if(NOT WITH_GFLAGS)
target_link_libraries(${CINNCORE_TARGET} gflags)
add_dependencies(${CINNCORE_TARGET} gflags)
endif()

if(WITH_GPU)
target_link_libraries(
${CINNCORE_TARGET}
Expand Down
4 changes: 4 additions & 0 deletions cmake/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ if(WITH_DISTRIBUTE)
add_definitions(-DPADDLE_WITH_DISTRIBUTE)
endif()

if(WITH_GFLAGS)
add_definitions(-DPADDLE_WITH_GFLAGS)
endif()

if(WITH_PSCORE)
add_definitions(-DPADDLE_WITH_PSCORE)
endif()
Expand Down
13 changes: 13 additions & 0 deletions cmake/external/brpc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,16 @@ add_dependencies(brpc extern_brpc)
add_definitions(-DBRPC_WITH_GLOG)

list(APPEND external_project_dependencies brpc)

set(EXTERNAL_BRPC_DEPS
brpc
protobuf
ssl
crypto
leveldb
glog
snappy)

if(NOT WITH_GFLAGS)
set(EXTERNAL_BRPC_DEPS ${EXTERNAL_BRPC_DEPS} gflags)
endif()
11 changes: 11 additions & 0 deletions cmake/external/gflags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,14 @@ if(WIN32)
set_property(GLOBAL PROPERTY OS_DEPENDENCY_MODULES shlwapi.lib)
endif()
endif()

# We have implemented a custom flags tool paddle_flags to replace gflags.
# User can also choose to use gflags by setting WITH_GFLAGS=ON. But when
# using paddle_flags, gflags is also needed for other third party libraries
# including glog and brpc. So we can not remove gflags completely.
set(flags_dep)
if(WITH_GFLAGS)
list(APPEND flags_dep gflags)
else()
list(APPEND flags_dep paddle_flags)
endif()
11 changes: 11 additions & 0 deletions cmake/inference_lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,22 @@ copy(
inference_lib_dist
SRCS ${PADDLE_SOURCE_DIR}/paddle/utils/flat_hash_map.h
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/utils/)
copy(
inference_lib_dist
SRCS ${PADDLE_SOURCE_DIR}/paddle/utils/flags.h
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/utils/)
copy(
inference_lib_dist
SRCS ${PADDLE_SOURCE_DIR}/paddle/extension.h
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/)

if(NOT WITH_GFLAGS)
copy(
inference_lib_dist
SRCS ${PADDLE_SOURCE_DIR}/paddle/utils/flags_native.h
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/paddle/utils/)
endif()

# the include path of phi needs to be changed to adapt to inference api path
add_custom_command(
TARGET inference_lib_dist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "paddle/phi/common/place.h"
#include "paddle/phi/core/distributed/check/static_check.h"

DECLARE_bool(xccl_blocking_wait);
PD_DECLARE_bool(xccl_blocking_wait);

constexpr int64_t kWaitBlockTImeout = 10;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "paddle/phi/core/distributed/comm_context_manager.h"

PHI_DECLARE_bool(nccl_blocking_wait);
DECLARE_bool(use_stream_safe_cuda_allocator);
PD_DECLARE_bool(use_stream_safe_cuda_allocator);

// set this flag to `true` and recompile to enable dynamic checks
constexpr bool FLAGS_enable_nccl_dynamic_check = false;
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/distributed/collective/reducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "paddle/phi/backends/device_manager.h"
#include "paddle/phi/core/flags.h"

DECLARE_bool(use_stream_safe_cuda_allocator);
PD_DECLARE_bool(use_stream_safe_cuda_allocator);
PHI_DECLARE_string(allocator_strategy);

namespace paddle {
Expand Down
11 changes: 1 addition & 10 deletions paddle/fluid/distributed/fleet_executor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,7 @@ proto_library(interceptor_message_proto SRCS interceptor_message.proto)
if(WITH_ARM_BRPC)
set(BRPC_DEPS arm_brpc snappy phi glog)
elseif(WITH_DISTRIBUTE AND NOT WITH_PSLIB)
set(BRPC_DEPS
brpc
ssl
crypto
protobuf
zlib
leveldb
snappy
phi
glog)
set(BRPC_DEPS ${EXTERNAL_BRPC_DEPS} zlib phi)
else()
set(BRPC_DEPS "")
endif()
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/distributed/fleet_executor/carrier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <algorithm>
#include <vector>

#include "gflags/gflags.h"
#include "paddle/fluid/distributed/fleet_executor/global.h"
#include "paddle/fluid/distributed/fleet_executor/interceptor.h"
#include "paddle/fluid/distributed/fleet_executor/message_bus.h"
Expand All @@ -29,6 +28,7 @@
#include "paddle/fluid/framework/variable.h"
#include "paddle/fluid/framework/variable_helper.h"
#include "paddle/fluid/platform/flags.h"
#include "paddle/utils/flags.h"
PADDLE_DEFINE_EXPORTED_bool(
fleet_executor_with_standalone,
false,
Expand Down
27 changes: 2 additions & 25 deletions paddle/fluid/distributed/ps/service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,11 @@ set_source_files_properties(${BRPC_SRCS})

if(WITH_HETERPS)

set(BRPC_DEPS
brpc
ssl
crypto
protobuf
phi
glog
zlib
leveldb
snappy
glog
device_context
rocksdb)
set(BRPC_DEPS ${EXTERNAL_BRPC_DEPS} phi zlib device_context rocksdb)

else()

set(BRPC_DEPS
brpc
ssl
crypto
protobuf
phi
glog
zlib
leveldb
snappy
glog
device_context)
set(BRPC_DEPS ${EXTERNAL_BRPC_DEPS} phi zlib device_context)

endif()

Expand Down
79 changes: 41 additions & 38 deletions paddle/fluid/distributed/ps/service/brpc_ps_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,49 +34,53 @@ class Variable;
namespace paddle {
namespace distributed {

DEFINE_int32(pserver_push_dense_merge_limit,
12,
"limit max push_dense local merge requests");
PD_DEFINE_int32(pserver_push_dense_merge_limit,
12,
"limit max push_dense local merge requests");

DEFINE_int32(pserver_push_sparse_merge_limit,
12,
"limit max push_sparse local merge requests");
PD_DEFINE_int32(pserver_push_sparse_merge_limit,
12,
"limit max push_sparse local merge requests");

DEFINE_int32(pserver_pull_dense_limit,
12,
"limit max push_sparse local merge requests");
PD_DEFINE_int32(pserver_pull_dense_limit,
12,
"limit max push_sparse local merge requests");

DEFINE_int32(pserver_async_push_dense_interval_ms,
10,
"async push_dense to server interval");
PD_DEFINE_int32(pserver_async_push_dense_interval_ms,
10,
"async push_dense to server interval");

DEFINE_int32(pserver_async_push_sparse_interval_ms,
10,
"async push_sparse to server interval");
PD_DEFINE_int32(pserver_async_push_sparse_interval_ms,
10,
"async push_sparse to server interval");

DEFINE_bool(pserver_scale_gradient_by_merge,
false,
"scale dense gradient when merged");
PD_DEFINE_bool(pserver_scale_gradient_by_merge,
false,
"scale dense gradient when merged");

DEFINE_int32(pserver_communicate_compress_type,
0,
"none:0 snappy:1 gzip:2 zlib:3 lz4:4");
PD_DEFINE_int32(pserver_communicate_compress_type,
0,
"none:0 snappy:1 gzip:2 zlib:3 lz4:4");

DEFINE_int32(pserver_max_async_call_num,
13,
"max task num in async_call_server");
PD_DEFINE_int32(pserver_max_async_call_num,
13,
"max task num in async_call_server");

DEFINE_int32(pserver_timeout_ms, 500000, "pserver request server timeout_ms");
PD_DEFINE_int32(pserver_timeout_ms,
500000,
"pserver request server timeout_ms");

DEFINE_int32(pserver_connect_timeout_ms,
10000,
"pserver connect server timeout_ms");
PD_DEFINE_int32(pserver_connect_timeout_ms,
10000,
"pserver connect server timeout_ms");

DEFINE_int32(pserver_sparse_merge_thread, 1, "pserver sparse merge thread num");
PD_DEFINE_int32(pserver_sparse_merge_thread,
1,
"pserver sparse merge thread num");

DEFINE_int32(pserver_sparse_table_shard_num,
1000,
"sparse table shard for save & load");
PD_DEFINE_int32(pserver_sparse_table_shard_num,
1000,
"sparse table shard for save & load");

inline size_t get_sparse_shard(uint32_t shard_num,
uint32_t server_num,
Expand Down Expand Up @@ -140,7 +144,7 @@ int32_t BrpcPsClient::StartFlClientService(const std::string &self_endpoint) {

if (_fl_server.Start(self_endpoint.c_str(), &options) != 0) {
VLOG(0) << "fl-ps > StartFlClientService failed. Try again.";
auto ip_port = paddle::string::Split(self_endpoint, ':');
auto ip_port = ::paddle::string::Split(self_endpoint, ':');
std::string ip = ip_port[0];
int port = std::stoi(ip_port[1]);
std::string int_ip_port = GetIntTypeEndpoint(ip, port);
Expand Down Expand Up @@ -202,8 +206,7 @@ int32_t BrpcPsClient::InitializeFlWorker(const std::string &self_endpoint) {
options.protocol = "baidu_std";
options.timeout_ms = FLAGS_pserver_timeout_ms;
options.connection_type = "pooled";
options.connect_timeout_ms =
paddle::distributed::FLAGS_pserver_connect_timeout_ms;
options.connect_timeout_ms = FLAGS_pserver_connect_timeout_ms;
options.max_retry = 3;
// 获取 coordinator 列表,并连接
std::string coordinator_ip_port;
Expand Down Expand Up @@ -336,11 +339,11 @@ int32_t BrpcPsClient::Initialize() {
auto table_id = worker_param.downpour_table_param(i).table_id();
if (type == PS_DENSE_TABLE) {
_push_dense_task_queue_map[table_id] =
paddle::framework::MakeChannel<DenseAsyncTask *>();
::paddle::framework::MakeChannel<DenseAsyncTask *>();
}
if (type == PS_SPARSE_TABLE) {
_push_sparse_task_queue_map[table_id] =
paddle::framework::MakeChannel<SparseAsyncTask *>();
::paddle::framework::MakeChannel<SparseAsyncTask *>();
_push_sparse_merge_count_map[table_id] = 0;
}
}
Expand Down Expand Up @@ -446,7 +449,7 @@ std::future<int32_t> BrpcPsClient::PrintTableStat(uint32_t table_id) {
int ret = 0;
uint64_t feasign_size = 0;
uint64_t mf_size = 0;
paddle::framework::BinaryArchive ar;
::paddle::framework::BinaryArchive ar;
auto *closure = reinterpret_cast<DownpourBrpcClosure *>(done);
for (size_t i = 0; i < request_call_num; ++i) {
if (closure->check_response(i, PS_PRINT_TABLE_STAT) != 0) {
Expand Down
24 changes: 12 additions & 12 deletions paddle/fluid/distributed/ps/service/brpc_ps_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class RpcController;
} // namespace protobuf
} // namespace google

DEFINE_int32(pserver_timeout_ms_s2s,
10000,
"pserver request server timeout_ms");
DEFINE_int32(pserver_connect_timeout_ms_s2s,
10000,
"pserver connect server timeout_ms");
DEFINE_string(pserver_connection_type_s2s,
"pooled",
"pserver connection_type[pooled:single]");
PD_DEFINE_int32(pserver_timeout_ms_s2s,
10000,
"pserver request server timeout_ms");
PD_DEFINE_int32(pserver_connect_timeout_ms_s2s,
10000,
"pserver connect server timeout_ms");
PD_DEFINE_string(pserver_connection_type_s2s,
"pooled",
"pserver connection_type[pooled:single]");

namespace paddle {
namespace distributed {
Expand Down Expand Up @@ -169,7 +169,7 @@ int32_t BrpcPsServer::ReceiveFromPServer(int msg_type,
LOG(WARNING) << "SERVER>>RESPONSE>>msg = 0 Finish S2S Response";
return 0;
}
paddle::framework::BinaryArchive ar;
::paddle::framework::BinaryArchive ar;
ar.SetReadBuffer(const_cast<char *>(msg.c_str()), msg.length(), nullptr);
if (ar.Cursor() == ar.Finish()) {
LOG(WARNING) << "SERVER>>RESPONSE ar = 0>> Finish S2S Response";
Expand Down Expand Up @@ -598,7 +598,7 @@ int32_t BrpcPsService::PrintTableStat(Table *table,
brpc::Controller *cntl) {
CHECK_TABLE_EXIST(table, request, response)
std::pair<int64_t, int64_t> ret = table->PrintTableStat();
paddle::framework::BinaryArchive ar;
::paddle::framework::BinaryArchive ar;
ar << ret.first << ret.second;
std::string table_info(ar.Buffer(), ar.Length());
response.set_data(table_info);
Expand Down Expand Up @@ -723,7 +723,7 @@ int32_t BrpcPsService::CacheShuffle(Table *table,
table->Flush();
double cache_threshold = std::stod(request.params(2));
LOG(INFO) << "cache threshold for cache shuffle: " << cache_threshold;
// auto shuffled_ins = paddle::ps::make_channel<std::pair<uint64_t,
// auto shuffled_ins = ::paddle::ps::make_channel<std::pair<uint64_t,
// std::string>>();
// shuffled_ins->set_block_size(80000);
_server->StartS2S();
Expand Down
Loading