Skip to content

Commit 1a91e7f

Browse files
committed
feat(pp): add Pipeline Parallel support with WorkerKey/RankInfo refactor
Squashed: 39e0391 feat: add PP support with centralized data plane and WorkerKey abstraction c16d747 fix: improve transfer manager and engine robustness for PP 94fa15c refactor: separate per-rank state into RankInfo and unify dp_client_id (#165)
1 parent 2c5fd53 commit 1a91e7f

46 files changed

Lines changed: 2203 additions & 1530 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CMakeLists.txt‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,20 @@ target_include_directories(xxhash PUBLIC
6767
install(FILES ${XXHASH_HEADERS} DESTINATION include)
6868

6969
# ==================== prometheus-cpp Library ====================
70-
# Option to enable/disable monitoring (env FLEXKV_ENABLE_METRICS=0 or -DFLEXKV_ENABLE_MONITORING=OFF)
71-
set(_FLEXKV_MONITORING_DEFAULT ON)
70+
# Step 1: Auto-detect default from directory existence
71+
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/third_party/prometheus-cpp")
72+
set(_FLEXKV_MONITORING_DEFAULT ON)
73+
else()
74+
set(_FLEXKV_MONITORING_DEFAULT OFF)
75+
message(STATUS "third_party/prometheus-cpp not found, Prometheus monitoring defaults to OFF")
76+
endif()
77+
78+
# Step 2: Environment variable override (FLEXKV_ENABLE_METRICS=1/0)
7279
if(DEFINED ENV{FLEXKV_ENABLE_METRICS})
73-
if("$ENV{FLEXKV_ENABLE_METRICS}" STREQUAL "0" OR "$ENV{FLEXKV_ENABLE_METRICS}" STREQUAL "OFF"
80+
if("$ENV{FLEXKV_ENABLE_METRICS}" STREQUAL "1" OR "$ENV{FLEXKV_ENABLE_METRICS}" STREQUAL "ON"
81+
OR "$ENV{FLEXKV_ENABLE_METRICS}" STREQUAL "YES" OR "$ENV{FLEXKV_ENABLE_METRICS}" STREQUAL "TRUE")
82+
set(_FLEXKV_MONITORING_DEFAULT ON)
83+
elseif("$ENV{FLEXKV_ENABLE_METRICS}" STREQUAL "0" OR "$ENV{FLEXKV_ENABLE_METRICS}" STREQUAL "OFF"
7484
OR "$ENV{FLEXKV_ENABLE_METRICS}" STREQUAL "NO" OR "$ENV{FLEXKV_ENABLE_METRICS}" STREQUAL "FALSE")
7585
set(_FLEXKV_MONITORING_DEFAULT OFF)
7686
endif()

‎benchmarks/benchmark_dist_kvcache.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
from flexkv.server.client import KVTPClient
5454
from flexkv.common.storage import KVCacheLayout, KVCacheLayoutType
5555
from flexkv.common.config import (
56-
ModelConfig, CacheConfig, UserConfig,
56+
ModelConfig, CacheConfig, UserConfig, RankInfo,
5757
update_default_config_from_user_config, parse_path_list,
5858
GLOBAL_CONFIG_FROM_ENV,
5959
)
@@ -152,7 +152,8 @@ def load_dist_config(config_path: str):
152152
# Store mooncake_config_path in cache_config so it survives spawn subprocesses via pickle
153153
cache_config.mooncake_config_path = mooncake_config_path
154154

155-
update_default_config_from_user_config(model_config, cache_config, user_config)
155+
rank_info = RankInfo(model_config=model_config)
156+
update_default_config_from_user_config(rank_info, cache_config, user_config)
156157

157158
# Handle server_client_mode from config
158159
if config.get("server_client_mode", False):

‎benchmarks/benchmark_workers.py‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,10 @@ def bench_worker(args):
377377

378378
transfer_op = TransferOp(
379379
transfer_type=transfer_type,
380-
layer_id=0,
381-
layer_granularity=num_layers_to_transfer,
382380
src_block_ids=block_ids,
383381
dst_block_ids=block_ids,
384382
graph_id=0,
385-
dp_id=0,
383+
dp_client_id=0,
386384
successors=[],
387385
predecessors=[],
388386
)
@@ -397,12 +395,10 @@ def bench_worker(args):
397395

398396
reverse_transfer_op = TransferOp(
399397
transfer_type=reverse_type,
400-
layer_id=0,
401-
layer_granularity=num_layers_to_transfer,
402398
src_block_ids=reverse_block_ids,
403399
dst_block_ids=reverse_block_ids,
404400
graph_id=1,
405-
dp_id=0,
401+
dp_client_id=0,
406402
successors=[],
407403
predecessors=[],
408404
)

‎benchmarks/dist_benchmark/benchmark_dist_direct.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
from flexkv.server.client import KVTPClient
6666
from flexkv.common.storage import KVCacheLayout, KVCacheLayoutType
6767
from flexkv.common.config import (
68-
ModelConfig, CacheConfig, UserConfig,
68+
ModelConfig, CacheConfig, UserConfig, RankInfo,
6969
update_default_config_from_user_config, parse_path_list,
7070
GLOBAL_CONFIG_FROM_ENV,
7171
)
@@ -163,7 +163,7 @@ def load_dist_direct_config(config_path: str):
163163
# Store mooncake_config_path in cache_config so it survives spawn subprocesses via pickle
164164
cache_config.mooncake_config_path = mooncake_config_path
165165

166-
update_default_config_from_user_config(model_config, cache_config, user_config)
166+
update_default_config_from_user_config(RankInfo(model_config=model_config), cache_config, user_config)
167167

168168
# IMPORTANT: Ensure server_client_mode is NOT set for direct mode
169169
# Even if config says server_client_mode: true, we override it here

‎benchmarks/dist_benchmark/benchmark_dist_kvcache.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
from flexkv.server.client import KVTPClient
5454
from flexkv.common.storage import KVCacheLayout, KVCacheLayoutType
5555
from flexkv.common.config import (
56-
ModelConfig, CacheConfig, UserConfig,
56+
ModelConfig, CacheConfig, UserConfig, RankInfo,
5757
update_default_config_from_user_config, parse_path_list,
5858
GLOBAL_CONFIG_FROM_ENV,
5959
)
@@ -152,7 +152,7 @@ def load_dist_config(config_path: str):
152152
# Store mooncake_config_path in cache_config so it survives spawn subprocesses via pickle
153153
cache_config.mooncake_config_path = mooncake_config_path
154154

155-
update_default_config_from_user_config(model_config, cache_config, user_config)
155+
update_default_config_from_user_config(RankInfo(model_config=model_config), cache_config, user_config)
156156

157157
# Handle server_client_mode from config
158158
if config.get("server_client_mode", False):

‎benchmarks/dist_benchmark/utils.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def load_config(config_path: str) -> Tuple[ModelConfig, CacheConfig]:
122122
user_config.ssd_cache_dir = parse_path_list(config["ssd_cache_dir"])
123123
if "enable_gds" in config:
124124
user_config.enable_gds = config["enable_gds"]
125-
update_default_config_from_user_config(model_config, cache_config, user_config)
125+
update_default_config_from_user_config(RankInfo(model_config=model_config), cache_config, user_config)
126126
return model_config, cache_config
127127

128128
if __name__ == "__main__":

‎benchmarks/utils.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def load_config(config_path: str) -> Tuple[ModelConfig, CacheConfig]:
122122
user_config.ssd_cache_dir = parse_path_list(config["ssd_cache_dir"])
123123
if "enable_gds" in config:
124124
user_config.enable_gds = config["enable_gds"]
125-
update_default_config_from_user_config(model_config, cache_config, user_config)
125+
update_default_config_from_user_config(RankInfo(model_config=model_config), cache_config, user_config)
126126
return model_config, cache_config
127127

128128
if __name__ == "__main__":

‎build.sh‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ fi
6666
echo "=== Building in ${BUILD_TYPE} mode ==="
6767

6868
# Install submodules
69-
git submodule update --init --recursive
69+
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
70+
git submodule update --init --recursive
71+
else
72+
echo "WARNING: Not a git repository, skipping submodule update. If submodules are missing, please clone the repo instead of copying."
73+
fi
7074

7175
mkdir -p build
7276
cd build

‎csrc/bindings.cpp‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,14 @@ PYBIND11_MODULE(c_ext, m) {
419419
py::class_<flexkv::LayerwiseTransferGroup>(m, "LayerwiseTransferGroup")
420420
.def(py::init<int, const std::vector<std::vector<torch::Tensor>> &,
421421
torch::Tensor &, std::map<int, std::vector<std::string>> &,
422-
int, int, torch::Tensor &, torch::Tensor &, torch::Tensor &,
422+
int, torch::Tensor &, torch::Tensor &, torch::Tensor &,
423423
torch::Tensor &, int, int, torch::Tensor &, int,
424424
const std::vector<std::vector<torch::Tensor>> &,
425425
torch::Tensor, torch::Tensor, torch::Tensor,
426426
torch::Tensor, torch::Tensor,
427427
std::map<int, std::vector<std::string>>>(),
428428
py::arg("num_gpus"), py::arg("gpu_blocks"), py::arg("cpu_blocks"),
429-
py::arg("ssd_files"), py::arg("dp_group_id"), py::arg("num_layers"),
429+
py::arg("ssd_files"), py::arg("num_layers"),
430430
py::arg("gpu_kv_strides_tensor"),
431431
py::arg("gpu_block_strides_tensor"),
432432
py::arg("gpu_layer_strides_tensor"),
@@ -510,13 +510,13 @@ PYBIND11_MODULE(c_ext, m) {
510510
py::init<std::map<int, std::vector<std::string>> &, int, int, int>());
511511

512512
py::class_<flexkv::TPTransferThreadGroup>(m, "TPTransferThreadGroup")
513-
.def(py::init<int, const std::vector<int64_t> &, int, int64_t, int, int,
513+
.def(py::init<int, const std::vector<int64_t> &, int, int64_t, int,
514514
const std::vector<int64_t> &, const std::vector<int64_t> &,
515515
const std::vector<int64_t> &, const std::vector<int64_t> &,
516516
const std::vector<int64_t> &>(),
517517
py::arg("num_gpus"), py::arg("gpu_block_ptrs_flat"),
518518
py::arg("num_tensors_per_gpu"), py::arg("cpu_blocks_ptr"),
519-
py::arg("dp_group_id"), py::arg("num_layers"),
519+
py::arg("num_layers"),
520520
py::arg("gpu_kv_strides_in_bytes"),
521521
py::arg("gpu_block_strides_in_bytes"),
522522
py::arg("gpu_layer_strides_in_bytes"),
@@ -529,19 +529,19 @@ PYBIND11_MODULE(c_ext, m) {
529529
py::arg("cpu_block_stride_in_bytes"),
530530
py::arg("cpu_tp_stride_in_bytes"), py::arg("transfer_num_cta"),
531531
py::arg("is_host_to_device"), py::arg("use_ce_transfer"),
532-
py::arg("layer_id"), py::arg("layer_granularity"), py::arg("is_mla"),
533-
py::arg("is_nsa_cp") = false);
532+
py::arg("layer_id"), py::arg("layer_granularity"), py::arg("is_mla")
533+
);
534534

535535
#ifdef FLEXKV_ENABLE_GDS
536536
py::class_<flexkv::TPGDSTransferThreadGroup>(m, "TPGDSTransferThreadGroup")
537537
.def(py::init<int, const std::vector<int64_t> &, int,
538-
std::map<int, std::vector<std::string>> &, int, int,
538+
std::map<int, std::vector<std::string>> &, int,
539539
const std::vector<int64_t> &, const std::vector<int64_t> &,
540540
const std::vector<int64_t> &, const std::vector<int64_t> &,
541541
const std::vector<int64_t> &>(),
542542
py::arg("num_gpus"), py::arg("gpu_block_ptrs_flat"),
543543
py::arg("num_tensors_per_gpu"), py::arg("ssd_files"),
544-
py::arg("dp_group_id"), py::arg("num_layers"),
544+
py::arg("num_layers"),
545545
py::arg("gpu_kv_strides_in_bytes"),
546546
py::arg("gpu_block_strides_in_bytes"),
547547
py::arg("gpu_layer_strides_in_bytes"),

‎csrc/gds/tp_gds_transfer_thread_group.cpp‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ TPGDSTransferThreadGroup::TPGDSTransferThreadGroup(
99
const std::vector<int64_t> &gpu_block_ptrs_flat,
1010
int num_tensors_per_gpu,
1111
std::map<int, std::vector<std::string>> &ssd_files,
12-
int dp_group_id,
1312
int num_layers,
1413
const std::vector<int64_t> &gpu_kv_strides_in_bytes,
1514
const std::vector<int64_t> &gpu_block_strides_in_bytes,
@@ -19,7 +18,6 @@ TPGDSTransferThreadGroup::TPGDSTransferThreadGroup(
1918

2019
num_gpus_ = num_gpus;
2120
num_tensors_per_gpu_ = num_tensors_per_gpu;
22-
dp_group_id_ = dp_group_id;
2321

2422
// per-GPU layout parameters
2523
gpu_kv_strides_in_bytes_ = new int64_t[num_gpus];

0 commit comments

Comments
 (0)