Skip to content
Draft
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
6 changes: 3 additions & 3 deletions docs/src/content/docs/en/dev_guide/code_arch.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ immediate callees before exploring platform-specific implementations.
| 1 | [`xllm/xllm.cpp`](https://github.com/xLLM-AI/xllm/blob/main/xllm/xllm.cpp): `main()`, `run()` | How are configuration, the master, and the HTTP service connected? |
| 2 | [`chat_service_impl.cpp`](https://github.com/xLLM-AI/xllm/blob/main/xllm/api_service/chat_service_impl.cpp): `ChatServiceImpl::process_async_impl()` | How do chat messages become an internal request with an output callback? |
| 3 | [`llm_master.cpp`](https://github.com/xLLM-AI/xllm/blob/main/xllm/core/distributed_runtime/llm_master.cpp): `LLMMaster::handle_request()`, `run()` | How does a request enter the scheduler, and what drives the scheduling loop? |
| 4 | [`continuous_scheduler.cpp`](https://github.com/xLLM-AI/xllm/blob/main/xllm/core/scheduler/continuous_scheduler.cpp): `ContinuousSchedulerBase::step()` | How is one batch scheduled, executed, and processed? |
| 4 | [`continuous_scheduler.cpp`](https://github.com/xLLM-AI/xllm/blob/main/xllm/core/scheduler/continuous_scheduler.cpp): `ContinuousScheduler::step()` | How is one batch scheduled, executed, and processed? |
| 5 | [`llm_engine.cpp`](https://github.com/xLLM-AI/xllm/blob/main/xllm/core/distributed_runtime/llm_engine.cpp): `LLMEngine::step()` | How does a batch reach the workers, and how are their results collected? |
| 6 | [`llm_worker_impl.cpp`](https://github.com/xLLM-AI/xllm/blob/main/xllm/core/runtime/llm_worker_impl.cpp): `LLMWorkerImpl::step_internal()` | Where do model execution, logits, and token sampling happen? |

Expand Down Expand Up @@ -380,7 +380,7 @@ POST /v1/chat/completions
-> HTTP route / APIService / ChatServiceImpl
-> LLMMaster / LLMRequestFactory
messages -> chat template -> prompt -> token IDs -> Request
-> ContinuousSchedulerBase / SchedulerPolicy
-> ContinuousScheduler / SchedulerPolicy
choose sequences and token budgets -> BatchGroup
-> LLMEngine
build inputs -> dispatch to worker ranks
Expand All @@ -406,7 +406,7 @@ POST /v1/chat/completions
applies the chat template, tokenizes and validates the prompt, and creates
request/sequence state. The master then calls `scheduler_->add_request()`.

3. **Choose work for the next step.** `ContinuousSchedulerBase` manages the
3. **Choose work for the next step.** `ContinuousScheduler` manages the
request queues and execution loop.
[`scheduler_policy.cpp`](https://github.com/xLLM-AI/xllm/blob/main/xllm/core/scheduler/scheduler_policy.cpp)
contains the batch-assembly policies: `PrefillFirstPolicy`,
Expand Down
6 changes: 3 additions & 3 deletions docs/src/content/docs/zh/dev_guide/code_arch.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ title: "代码架构与请求流程"
| 1 | [`xllm/xllm.cpp`](https://github.com/xLLM-AI/xllm/blob/main/xllm/xllm.cpp):`main()`、`run()` | 配置、master 和 HTTP 服务如何连接起来? |
| 2 | [`chat_service_impl.cpp`](https://github.com/xLLM-AI/xllm/blob/main/xllm/api_service/chat_service_impl.cpp):`ChatServiceImpl::process_async_impl()` | 聊天消息如何转换为内部请求,并绑定输出回调? |
| 3 | [`llm_master.cpp`](https://github.com/xLLM-AI/xllm/blob/main/xllm/core/distributed_runtime/llm_master.cpp):`LLMMaster::handle_request()`、`run()` | 请求如何进入调度器?谁在驱动调度循环? |
| 4 | [`continuous_scheduler.cpp`](https://github.com/xLLM-AI/xllm/blob/main/xllm/core/scheduler/continuous_scheduler.cpp):`ContinuousSchedulerBase::step()` | 一轮批次如何被调度、执行并处理结果? |
| 4 | [`continuous_scheduler.cpp`](https://github.com/xLLM-AI/xllm/blob/main/xllm/core/scheduler/continuous_scheduler.cpp):`ContinuousScheduler::step()` | 一轮批次如何被调度、执行并处理结果? |
| 5 | [`llm_engine.cpp`](https://github.com/xLLM-AI/xllm/blob/main/xllm/core/distributed_runtime/llm_engine.cpp):`LLMEngine::step()` | 批次如何发送到各个 worker,执行结果如何汇总? |
| 6 | [`llm_worker_impl.cpp`](https://github.com/xLLM-AI/xllm/blob/main/xllm/core/runtime/llm_worker_impl.cpp):`LLMWorkerImpl::step_internal()` | 模型执行、logits 计算和 token 采样发生在哪里? |

Expand Down Expand Up @@ -322,7 +322,7 @@ POST /v1/chat/completions
-> HTTP route / APIService / ChatServiceImpl
-> LLMMaster / LLMRequestFactory
messages -> chat template -> prompt -> token IDs -> Request
-> ContinuousSchedulerBase / SchedulerPolicy
-> ContinuousScheduler / SchedulerPolicy
choose sequences and token budgets -> BatchGroup
-> LLMEngine
build inputs -> dispatch to worker ranks
Expand All @@ -345,7 +345,7 @@ POST /v1/chat/completions
应用聊天模板,对提示词分词并校验,创建请求和序列状态。随后 master 调用
`scheduler_->add_request()` 将请求加入调度器。

3. **选择下一轮执行的工作。** `ContinuousSchedulerBase` 管理请求队列和执行循环。
3. **选择下一轮执行的工作。** `ContinuousScheduler` 管理请求队列和执行循环。
[`scheduler_policy.cpp`](https://github.com/xLLM-AI/xllm/blob/main/xllm/core/scheduler/scheduler_policy.cpp)
中的 `PrefillFirstPolicy`、`DecodeFirstPolicy` 和 `UnifiedPolicy` 负责组批,
考虑 token/序列预算与缓存容量。想了解哪些请求会一起执行,应继续阅读策略文件;
Expand Down
11 changes: 7 additions & 4 deletions tests/core/framework/parallel_state/mlu_cp_capability_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ TEST(MluCpCapabilityTest, AcceptsOrthogonalDeepseekV4TargetAndSuffix) {
/*engine_type=*/EngineType::LLM,
/*model_type=*/"deepseek_v4")
.has_value());
EXPECT_FALSE(validate_context_parallel_config(options,
/*engine_type=*/EngineType::SSM,
Options suffix_decode_options = options;
suffix_decode_options.num_speculative_tokens(/*value=*/2);
EXPECT_FALSE(validate_context_parallel_config(suffix_decode_options,
/*engine_type=*/EngineType::LLM,
/*model_type=*/"deepseek_v4")
.has_value());
}
Expand Down Expand Up @@ -105,9 +107,10 @@ TEST(MluCpCapabilityTest, RejectsUnsupportedTopologyAndAcceptsMtp) {
.has_value());

Options mtp_options = make_cp_options(kWorldSize);
mtp_options.speculative_algorithm("MTP");
mtp_options.speculative_algorithm(/*value=*/"MTP")
.num_speculative_tokens(/*value=*/2);
EXPECT_FALSE(validate_context_parallel_config(mtp_options,
/*engine_type=*/EngineType::SSM,
/*engine_type=*/EngineType::LLM,
/*model_type=*/"glm_moe_dsa")
.has_value());

Expand Down
52 changes: 28 additions & 24 deletions tests/core/framework/parallel_state/npu_cp_capability_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,27 +235,23 @@ TEST(NpuCpCapabilityTest, PythonCpPreservesQwenAndRestrictsGlm) {
.ep_size(16)
.instance_role(InstanceRole::PREFILL)
.enable_graph(false)
.speculative_algorithm("MTP");
.speculative_algorithm(/*value=*/"MTP")
.num_speculative_tokens(/*value=*/2);
EXPECT_FALSE(validate_context_parallel_config(options,
/*engine_type=*/EngineType::LLM,
/*model_type=*/"qwen3")
.has_value());
EXPECT_FALSE(validate_context_parallel_config(options,
/*engine_type=*/EngineType::SSM,
/*model_type=*/"qwen3")
.has_value());
EXPECT_FALSE(validate_context_parallel_config(options,
/*engine_type=*/EngineType::SSM,
/*engine_type=*/EngineType::LLM,
/*model_type=*/"glm_moe_dsa")
.has_value());

options.speculative_algorithm("DSpark");
EXPECT_NE(validate_context_parallel_config(options,
/*engine_type=*/EngineType::SSM,
/*model_type=*/"glm_moe_dsa")
.value_or("")
.find("aux-hidden-capture"),
std::string::npos);
options.speculative_algorithm(/*value=*/"DSpark")
.draft_model_path(/*value=*/"/tmp/draft");
EXPECT_TRUE(validate_context_parallel_config(options,
/*engine_type=*/EngineType::LLM,
/*model_type=*/"glm_moe_dsa")
.has_value());

options.cp_size(1).instance_role(InstanceRole::DECODE).enable_disagg_pd(true);
EXPECT_FALSE(validate_context_parallel_config(options,
Expand Down Expand Up @@ -361,12 +357,19 @@ TEST(NpuCpCapabilityTest, PythonGlm5NextCapabilityGate) {
/*model_type=*/"glm5_next")
.has_value());

EXPECT_NE(
validate_context_parallel_config(
options, /*engine_type=*/EngineType::SSM, /*model_type=*/"glm5_next")
.value_or(/*default_value=*/"")
.find(/*str=*/"target-side speculative verification"),
std::string::npos);
options.speculative_algorithm(/*value=*/"MTP")
.num_speculative_tokens(/*value=*/2)
.draft_model_path(/*value=*/"/tmp/draft");
EXPECT_EQ(
validate_context_parallel_config(options,
/*engine_type=*/EngineType::LLM,
/*model_type=*/"glm5_next"),
std::optional<std::string>{
/*value=*/
"Python GLM-5 Next CP does not support target-side speculative "
"verification; run speculation on a cp_size=1 Decode instance"});

options.num_speculative_tokens(/*value=*/0).draft_model_path(std::nullopt);

execution_config.python_graph_backend("inductor");
EXPECT_NE(
Expand Down Expand Up @@ -498,11 +501,12 @@ TEST(NpuCpCapabilityTest, PythonGlmMtpSupportsCpWithDecodeAclGraph) {
.cp_size(2)
.dp_size(1)
.ep_size(1)
.instance_role(InstanceRole::DEFAULT)
.enable_graph(true)
.speculative_algorithm("MTP");
.instance_role(/*value=*/InstanceRole::DEFAULT)
.enable_graph(/*value=*/true)
.speculative_algorithm(/*value=*/"MTP")
.num_speculative_tokens(/*value=*/2);
EXPECT_FALSE(validate_context_parallel_config(options,
/*engine_type=*/EngineType::SSM,
/*engine_type=*/EngineType::LLM,
/*model_type=*/"glm_moe_dsa")
.has_value());

Expand All @@ -511,7 +515,7 @@ TEST(NpuCpCapabilityTest, PythonGlmMtpSupportsCpWithDecodeAclGraph) {
options.instance_role(InstanceRole::PREFILL).enable_disagg_pd(true);
parallel_config.kv_split_size(0);
EXPECT_FALSE(validate_context_parallel_config(options,
/*engine_type=*/EngineType::SSM,
/*engine_type=*/EngineType::LLM,
/*model_type=*/"glm_moe_dsa")
.has_value());
}
Expand Down
Loading
Loading