Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion .agents/skills/code-review/references/custom-code-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ ModelArgs(const std::string& path, int32_t num_layers = 12);
// Good
ModelOutput forward(torch::Tensor tokens, ...) override;

// Bad
// Bad – missing override
ModelOutput forward(torch::Tensor tokens, ...);

// Bad – redundant virtual on override
virtual ModelOutput forward(torch::Tensor tokens, ...) override;

// Bad – missing override (virtual-only in derived class)
virtual ModelOutput forward(torch::Tensor tokens, ...);
```

Expand Down
4 changes: 2 additions & 2 deletions xllm/core/distributed_runtime/comm_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,13 @@ class ClientStreamReceiver : public brpc::StreamInputHandler {
return 0;
}

virtual void on_idle_timeout(brpc::StreamId id) override {
void on_idle_timeout(brpc::StreamId id) override {
if (!promise_set_.exchange(true)) {
close_promise_.set_value();
}
}

virtual void on_closed(brpc::StreamId id) override {
void on_closed(brpc::StreamId id) override {
if (!promise_set_.exchange(true)) {
close_promise_.set_value();
}
Expand Down
38 changes: 19 additions & 19 deletions xllm/core/distributed_runtime/disagg_pd_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,25 @@ class DisaggPDService : public proto::DisaggPDService {
::google::protobuf::Closure* done) override;

// for decode recv multiple tokens from prefill
virtual void MultiGenerations(::google::protobuf::RpcController* controller,
const proto::DisaggGenerationsRequests* request,
proto::Status* response,
::google::protobuf::Closure* done) override;

virtual void SendPullSignal(::google::protobuf::RpcController* controller,
const proto::PullSignal* request,
proto::Status* response,
::google::protobuf::Closure* done) override;

virtual void LinkInstance(::google::protobuf::RpcController* controller,
const proto::InstanceClusterInfo* request,
proto::Status* response,
::google::protobuf::Closure* done) override;

virtual void UnlinkInstance(::google::protobuf::RpcController* controller,
const proto::InstanceClusterInfo* request,
proto::Status* response,
::google::protobuf::Closure* done) override;
void MultiGenerations(::google::protobuf::RpcController* controller,
const proto::DisaggGenerationsRequests* request,
proto::Status* response,
::google::protobuf::Closure* done) override;

void SendPullSignal(::google::protobuf::RpcController* controller,
const proto::PullSignal* request,
proto::Status* response,
::google::protobuf::Closure* done) override;

void LinkInstance(::google::protobuf::RpcController* controller,
const proto::InstanceClusterInfo* request,
proto::Status* response,
::google::protobuf::Closure* done) override;

void UnlinkInstance(::google::protobuf::RpcController* controller,
const proto::InstanceClusterInfo* request,
proto::Status* response,
::google::protobuf::Closure* done) override;

protected:
std::unique_ptr<DisaggPDServiceImpl> disagg_pd_service_impl_;
Expand Down
80 changes: 38 additions & 42 deletions xllm/core/distributed_runtime/remote_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,31 @@ class RemoteWorker : public WorkerClient {

bool wait_for_server_ready(const std::string& server_address);

virtual bool init_model(const std::string& model_weights_path,
int32_t random_seed,
MasterStatus master_status) override;
bool init_model(const std::string& model_weights_path,
int32_t random_seed,
MasterStatus master_status) override;

virtual std::tuple<int64_t, int64_t> estimate_kv_cache_capacity() override;
std::tuple<int64_t, int64_t> estimate_kv_cache_capacity() override;

virtual bool allocate_kv_cache(const KVCacheShape& kv_cache_shape) override;
bool allocate_kv_cache(const KVCacheShape& kv_cache_shape) override;

virtual void get_cache_info(uint64_t& cluster_id,
std::string& addr,
uint16_t& port) override;
void get_cache_info(uint64_t& cluster_id,
std::string& addr,
uint16_t& port) override;

virtual bool link_cluster(const std::vector<uint64_t>& cluster_ids,
const std::vector<std::string>& addrs,
const std::vector<uint16_t>& ports) override;
bool link_cluster(const std::vector<uint64_t>& cluster_ids,
const std::vector<std::string>& addrs,
const std::vector<uint16_t>& ports) override;

virtual bool unlink_cluster(const std::vector<uint64_t>& cluster_ids,
const std::vector<std::string>& addrs,
const std::vector<uint16_t>& ports) override;
bool unlink_cluster(const std::vector<uint64_t>& cluster_ids,
const std::vector<std::string>& addrs,
const std::vector<uint16_t>& ports) override;

// P2P link for weight transfer
virtual bool link_p2p(const std::string& remote_addr) override;
virtual bool unlink_p2p(const std::string& remote_addr) override;
bool link_p2p(const std::string& remote_addr) override;
bool unlink_p2p(const std::string& remote_addr) override;

virtual bool pull_kv_blocks(
bool pull_kv_blocks(
const uint64_t src_cluster_id,
const std::string& src_addr,
const std::vector<uint64_t>& src_blocks,
Expand All @@ -80,82 +80,78 @@ class RemoteWorker : public WorkerClient {
const std::vector<uint64_t>& dst_linear_state_ids = {}) override;

// prepare input request
virtual ForwardInput prepare_inputs(Batch& batch) override;
ForwardInput prepare_inputs(Batch& batch) override;

virtual std::optional<ForwardOutput> step(
const ForwardInput& inputs) override;
std::optional<ForwardOutput> step(const ForwardInput& inputs) override;

virtual folly::SemiFuture<bool> init_model_async(
folly::SemiFuture<bool> init_model_async(
const std::string& model_weights_path,
int32_t random_seed,
MasterStatus master_status) override;

virtual folly::SemiFuture<std::tuple<int64_t, int64_t>>
folly::SemiFuture<std::tuple<int64_t, int64_t>>
estimate_kv_cache_capacity_async() override;

virtual folly::SemiFuture<bool> allocate_kv_cache_async(
folly::SemiFuture<bool> allocate_kv_cache_async(
const KVCacheShape& kv_cache_shape) override;

virtual folly::SemiFuture<bool> allocate_kv_cache_with_transfer_async(
folly::SemiFuture<bool> allocate_kv_cache_with_transfer_async(
const KVCacheShape& kv_cache_shape) override;

virtual folly::SemiFuture<bool> pull_kv_blocks_async(
folly::SemiFuture<bool> pull_kv_blocks_async(
const uint64_t src_cluster_id,
const std::string& src_addr,
const std::vector<uint64_t>& src_blocks,
const std::vector<uint64_t>& dst_blocks,
const std::vector<uint64_t>& src_linear_state_ids = {},
const std::vector<uint64_t>& dst_linear_state_ids = {}) override;

virtual folly::SemiFuture<uint32_t> transfer_kv_blocks(
folly::SemiFuture<uint32_t> transfer_kv_blocks(
const std::vector<BlockTransferInfo>& block_transfer_info) override;

virtual void transfer_kv_blocks(
void transfer_kv_blocks(
const uint64_t batch_id,
const std::vector<BlockTransferInfo>& block_transfer_info) override;

virtual void prefetch_from_storage(
void prefetch_from_storage(
const std::vector<BlockTransferInfo>& block_transfer_info,
std::shared_ptr<std::atomic<int32_t>> flag,
std::shared_ptr<std::atomic<uint32_t>> success_cnt) override;

// Run the model and return the output.
virtual folly::SemiFuture<std::optional<ForwardOutput>> step_async(
folly::SemiFuture<std::optional<ForwardOutput>> step_async(
const ForwardInput& inputs) override;

virtual folly::SemiFuture<std::optional<RawForwardOutput>> step_remote_async(
folly::SemiFuture<std::optional<RawForwardOutput>> step_remote_async(
const ForwardInput& inputs) override;

virtual folly::SemiFuture<folly::Unit> process_group_test_async() override;
folly::SemiFuture<folly::Unit> process_group_test_async() override;

virtual const torch::Device& device() const override;
const torch::Device& device() const override;

folly::SemiFuture<std::optional<RawForwardOutput>>
get_last_step_result_async();

virtual int64_t get_active_activation_memory() override;
int64_t get_active_activation_memory() override;

virtual folly::SemiFuture<int64_t> get_active_activation_memory_async()
override;
folly::SemiFuture<int64_t> get_active_activation_memory_async() override;

// Check if the connection to worker is healthy
bool check_health();

// Get worker global rank
int32_t global_rank() const { return global_rank_; }

virtual folly::SemiFuture<bool> sleep_async(
MasterStatus master_status) override;
folly::SemiFuture<bool> sleep_async(MasterStatus master_status) override;

virtual folly::SemiFuture<bool> wakeup_async(
const WakeupOptions& options) override;
folly::SemiFuture<bool> wakeup_async(const WakeupOptions& options) override;

virtual folly::SemiFuture<bool> update_weights_async(
folly::SemiFuture<bool> update_weights_async(
const std::string& weights_path) override;

virtual folly::SemiFuture<bool> start_profile_async() override;
folly::SemiFuture<bool> start_profile_async() override;

virtual folly::SemiFuture<bool> stop_profile_async() override;
folly::SemiFuture<bool> stop_profile_async() override;

private:
DISALLOW_COPY_AND_ASSIGN(RemoteWorker);
Expand Down
45 changes: 22 additions & 23 deletions xllm/core/framework/block/block_manager_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,42 +58,41 @@ class BlockManagerPool : public KVCacheManager {

~BlockManagerPool() = default;

virtual bool allocate(Sequence* sequence) override;
virtual bool allocate(std::vector<Sequence*>& sequences) override;
virtual bool allocate(Sequence* sequence, size_t num_tokens) override;
virtual bool allocate(Sequence* sequence,
size_t num_tokens,
size_t needed_copy_in_blocks_num) override;
bool allocate(Sequence* sequence) override;
bool allocate(std::vector<Sequence*>& sequences) override;
bool allocate(Sequence* sequence, size_t num_tokens) override;
bool allocate(Sequence* sequence,
size_t num_tokens,
size_t needed_copy_in_blocks_num) override;

// Try to allocate blocks with num_tokens,
// return {} if not enough blocks
virtual std::vector<Block> allocate(size_t num_tokens,
int32_t& dp_rank) override;
std::vector<Block> allocate(size_t num_tokens, int32_t& dp_rank) override;

virtual bool try_allocate(Sequence* sequence) override;
bool try_allocate(Sequence* sequence) override;

virtual void deallocate(Request* request) override;
virtual void deallocate(std::vector<Sequence*>& sequences) override;
virtual void deallocate(Sequence* sequence) override;
void deallocate(Request* request) override;
void deallocate(std::vector<Sequence*>& sequences) override;
void deallocate(Sequence* sequence) override;

void deallocate_without_cache(Sequence* sequence);

virtual void allocate_shared(Sequence* sequence) override;
virtual void cache(Sequence* sequence) override;
virtual void cache(Sequence* sequence, size_t num_tokens) override;
void allocate_shared(Sequence* sequence) override;
void cache(Sequence* sequence) override;
void cache(Sequence* sequence, size_t num_tokens) override;

virtual std::vector<std::vector<BlockTransferInfo>>*
get_swap_block_transfer_infos() override;
std::vector<std::vector<BlockTransferInfo>>* get_swap_block_transfer_infos()
override;

virtual float get_gpu_cache_usage_perc() const;

virtual uint32_t num_blocks() const override;
virtual int32_t block_size() const override;
uint32_t num_blocks() const override;
int32_t block_size() const override;
void reset_prefix_cache() override;
virtual std::vector<size_t> num_blocks_in_prefix_cache() const override;
virtual std::vector<size_t> num_free_blocks() const override;
virtual std::vector<size_t> num_used_blocks() const override;
virtual double kv_cache_utilization() const override;
std::vector<size_t> num_blocks_in_prefix_cache() const override;
std::vector<size_t> num_free_blocks() const override;
std::vector<size_t> num_used_blocks() const override;
double kv_cache_utilization() const override;

// get the options for the block manager
const Options& options() const { return options_; }
Expand Down
34 changes: 17 additions & 17 deletions xllm/core/framework/kv_cache_transfer/llm_data_dist_transfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,38 @@ class LlmDataDistTransfer : public KVCacheTransfer {
const InstanceRole& instance_role,
const std::string& model_type = "",
bool enable_lighting_indexer = false);
virtual ~LlmDataDistTransfer() = default;
~LlmDataDistTransfer() override = default;

virtual void initialize(int32_t device_id) override;
void initialize(int32_t device_id) override;

virtual void finalize() override;
void finalize() override;

virtual void register_kv_cache(std::vector<xllm::KVCache>& kv_caches,
const KVCacheShape& kv_cache_shape,
const torch::ScalarType dtype) override;
void register_kv_cache(std::vector<xllm::KVCache>& kv_caches,
const KVCacheShape& kv_cache_shape,
const torch::ScalarType dtype) override;

virtual void free_kv_cache() override;
void free_kv_cache() override;

virtual void get_cache_info(uint64_t& cluster_id, std::string& addr) override;
void get_cache_info(uint64_t& cluster_id, std::string& addr) override;

virtual bool link_cluster(const uint64_t cluster_id,
const std::string& remote_addr,
const uint16_t port) override;
bool link_cluster(const uint64_t cluster_id,
const std::string& remote_addr,
const uint16_t port) override;

virtual bool unlink_cluster(const uint64_t& cluster_id,
const std::string& remote_addr,
const uint16_t port,
bool force_flag = true) override;
bool unlink_cluster(const uint64_t& cluster_id,
const std::string& remote_addr,
const uint16_t port,
bool force_flag = true) override;

virtual bool pull_kv_blocks(
bool pull_kv_blocks(
const uint64_t src_cluster_id,
const std::string& src_addr,
const std::vector<uint64_t>& src_blocks,
const std::vector<uint64_t>& dst_blocks,
const std::vector<uint64_t>& src_linear_state_ids,
const std::vector<uint64_t>& dst_linear_state_ids) override;

virtual bool push_kv_blocks(
bool push_kv_blocks(
std::unordered_map<std::string, KVCacheInfo>& merged_kv_infos,
std::shared_ptr<NPULayerSynchronizerImpl>& layer_synchronizer,
bool is_spec_draft,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,17 @@ class MooncakeTransferEngineService
public:
MooncakeTransferEngineService() = default;

virtual ~MooncakeTransferEngineService() = default;
~MooncakeTransferEngineService() override = default;

virtual void OpenSession(google::protobuf::RpcController* controller,
const proto::SessionInfo* request,
proto::Status* response,
google::protobuf::Closure* done) override;
void OpenSession(google::protobuf::RpcController* controller,
const proto::SessionInfo* request,
proto::Status* response,
google::protobuf::Closure* done) override;

virtual void CloseSession(google::protobuf::RpcController* controller,
const proto::SessionInfo* request,
proto::Status* response,
google::protobuf::Closure* done) override;
void CloseSession(google::protobuf::RpcController* controller,
const proto::SessionInfo* request,
proto::Status* response,
google::protobuf::Closure* done) override;
};

} // namespace xllm
7 changes: 3 additions & 4 deletions xllm/core/framework/model/causal_lm.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,12 @@ class CausalLMImpl : public CausalLM {
}
}

virtual void prepare_expert_weight(
int32_t layer_id,
const std::vector<int32_t>& expert_ids) override {
void prepare_expert_weight(int32_t layer_id,
const std::vector<int32_t>& expert_ids) override {
return model_->prepare_expert_weight(layer_id, expert_ids);
}

virtual void update_expert_weight(int32_t layer_id) {
void update_expert_weight(int32_t layer_id) override {
return model_->update_expert_weight(layer_id);
}

Expand Down
Loading
Loading