ref(upstream): 搬运 xllm ilu kernel+layer 完整源码 — 2089行 14个API声明
来源: Deep-Spark/xllm core/kernels/ilu/ + core/layers/ilu/
ixformer.h: 14个ixformer::infer API完整声明
kernel wrappers: activation(32) attention(162) fused_moe(99) group_gemm(39)
matmul(73) norm(50) rope(31) + headers
layer dispatch: fused_moe.cpp(797行) attention.cpp(189行) + headers
覆盖状态 (ix_moe_bridge.cpp vs ixformer.h 14个API):
已覆盖 13/14: silu_and_mul, rms_norm, residual_rms_norm, ixformer_linear,
ixformer_linear_ex, topk_softmax, moe_compute_token_index, moe_expand_input,
moe_w16a16_group_gemm, moe_output_reduce_sum, xllm_paged_attention,
xllm_reshape_and_cache, xllm_rotary_embedding
缺失 1/14: ixinfer_flash_attn_unpad_with_block_tables
dlopen 调用链验证:
12个 prebuilt .so → 9个 qwen3_5.py + 2个 paged_attn.py + 1个 block_major_kv_cache.py
辅助模块: bi100_env, bi100_profile, gdn_prefix, block_major_kv_cache 全部到位
This commit is contained in:
28
upstream_ref/xllm_latest/core/kernels/ilu/CMakeLists.txt
Normal file
28
upstream_ref/xllm_latest/core/kernels/ilu/CMakeLists.txt
Normal file
@@ -0,0 +1,28 @@
|
||||
include(cc_library)
|
||||
set(CMAKE_CUDA_ARCHITECTURES ivcore11)
|
||||
file(GLOB_RECURSE ILU_HEADER_FILES
|
||||
"${CMAKE_CURRENT_LIST_DIR}/*.h"
|
||||
)
|
||||
|
||||
file(GLOB_RECURSE ILU_SOURCE_FILES
|
||||
"${CMAKE_CURRENT_LIST_DIR}/*.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/*.cu"
|
||||
)
|
||||
|
||||
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
|
||||
|
||||
cc_library(
|
||||
NAME
|
||||
ilu_kernels
|
||||
HDRS
|
||||
${ILU_HEADER_FILES}
|
||||
SRCS
|
||||
${ILU_SOURCE_FILES}
|
||||
DEPS
|
||||
torch
|
||||
:util
|
||||
ixformer_kernels
|
||||
ixformer
|
||||
${Python3_LIBRARIES}
|
||||
cuinfer
|
||||
)
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2025-2026 The xLLM Authors.
|
||||
/* Copyright 2025 The xLLM Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
/* Copyright 2025-2026 The xLLM Authors.
|
||||
/* Copyright 2025 The xLLM Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2025-2026 The xLLM Authors.
|
||||
/* Copyright 2025 The xLLM Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2025-2026 The xLLM Authors.
|
||||
/* Copyright 2026 The xLLM Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2025-2026 The xLLM Authors.
|
||||
/* Copyright 2025 The xLLM Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2025-2026 The xLLM Authors.
|
||||
/* Copyright 2025 The xLLM Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2025-2026 The xLLM Authors.
|
||||
/* Copyright 2025 The xLLM Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2025-2026 The xLLM Authors.
|
||||
/* Copyright 2025 The xLLM Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2025-2026 The xLLM Authors.
|
||||
/* Copyright 2025 The xLLM Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2025-2026 The xLLM Authors.
|
||||
/* Copyright 2025 The xLLM Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
14
upstream_ref/xllm_latest/core/layers/ilu/CMakeLists.txt
Executable file
14
upstream_ref/xllm_latest/core/layers/ilu/CMakeLists.txt
Executable file
@@ -0,0 +1,14 @@
|
||||
include(cc_library)
|
||||
|
||||
cc_library(
|
||||
NAME
|
||||
ilu_layers
|
||||
HDRS
|
||||
attention.h
|
||||
fused_moe.h
|
||||
SRCS
|
||||
attention.cpp
|
||||
fused_moe.cpp
|
||||
DEPS
|
||||
:common_layers
|
||||
)
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2025-2026 The xLLM Authors.
|
||||
/* Copyright 2025 The xLLM Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2025-2026 The xLLM Authors.
|
||||
/* Copyright 2025 The xLLM Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2025-2026 The xLLM Authors.
|
||||
/* Copyright 2026 The xLLM Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -20,9 +20,6 @@ limitations under the License.
|
||||
#include <iomanip>
|
||||
|
||||
#include "common/global_flags.h"
|
||||
#include "core/framework/config/eplb_config.h"
|
||||
#include "core/framework/config/scheduler_config.h"
|
||||
#include "core/framework/config/speculative_config.h"
|
||||
#include "framework/parallel_state/parallel_state.h"
|
||||
#include "kernels/ops_api.h"
|
||||
#include "layers/common/dp_utils.h"
|
||||
@@ -89,9 +86,7 @@ FusedMoEImpl::FusedMoEImpl(const ModelArgs& model_args,
|
||||
}
|
||||
|
||||
// Deep EP initialization check
|
||||
enable_deep_ep_ =
|
||||
::xllm::EPLBConfig::get_instance().expert_parallel_degree() == 2 &&
|
||||
ep_size > 1;
|
||||
enable_deep_ep_ = FLAGS_expert_parallel_degree == 2 && ep_size > 1;
|
||||
if (enable_deep_ep_) {
|
||||
// for now, we only implement the deep ep for decode stage.
|
||||
// so we will assume the max_token_num is limited to max_batch_size * (1+K)
|
||||
@@ -108,20 +103,16 @@ FusedMoEImpl::FusedMoEImpl(const ModelArgs& model_args,
|
||||
torch::ScalarType combine_dtype = options_.dtype().toScalarType();
|
||||
int64_t combine_token_size = hidden_size_ * get_dtype_size(combine_dtype);
|
||||
// Ensure calculation base is at least ep_size
|
||||
int64_t effective_seqs = std::max(
|
||||
(int64_t)::xllm::SchedulerConfig::get_instance().max_seqs_per_batch(),
|
||||
(int64_t)ep_size);
|
||||
// NOTE: ::xllm::SchedulerConfig::get_instance().max_seqs_per_batch()
|
||||
// represents the maximum total batch size, regardless of the dp size. To
|
||||
// ensure robust scheduling and account for the worst-case scenario, we must
|
||||
// guarantee that each rank is capable of handling the maximum possible
|
||||
// number of tokens. Therefore, we define max_num_tokens_per_rank as the
|
||||
// full maximum value, without dividing by either the rank count or the dp
|
||||
// size.
|
||||
int64_t effective_seqs =
|
||||
std::max((int64_t)FLAGS_max_seqs_per_batch, (int64_t)ep_size);
|
||||
// NOTE: FLAGS_max_seqs_per_batch represents the maximum total batch size,
|
||||
// regardless of the dp size. To ensure robust scheduling and account
|
||||
// for the worst-case scenario, we must guarantee that each rank is capable
|
||||
// of handling the maximum possible number of tokens. Therefore, we define
|
||||
// max_num_tokens_per_rank as the full maximum value, without dividing by
|
||||
// either the rank count or the dp size.
|
||||
int64_t max_num_tokens_per_rank =
|
||||
(1 +
|
||||
::xllm::SpeculativeConfig::get_instance().num_speculative_tokens()) *
|
||||
effective_seqs * topk_;
|
||||
(1 + FLAGS_num_speculative_tokens) * effective_seqs * topk_;
|
||||
|
||||
// make sure that all layers share the same deep ep instance
|
||||
// so that the memory footprint is minimized
|
||||
@@ -723,8 +714,8 @@ torch::Tensor FusedMoEImpl::forward(const torch::Tensor& hidden_states,
|
||||
const ModelInputParams& input_params) {
|
||||
// we only support all2all communication for decode stage for now
|
||||
bool enable_all2all_communication =
|
||||
enable_deep_ep_ && std::all_of(input_params.parallel.dp_is_decode.begin(),
|
||||
input_params.parallel.dp_is_decode.end(),
|
||||
enable_deep_ep_ && std::all_of(input_params.dp_is_decode.begin(),
|
||||
input_params.dp_is_decode.end(),
|
||||
[](int32_t val) { return val == 1; });
|
||||
|
||||
bool is_dp_ep_parallel =
|
||||
@@ -739,7 +730,7 @@ torch::Tensor FusedMoEImpl::forward(const torch::Tensor& hidden_states,
|
||||
if (need_gather_and_slice) {
|
||||
input = parallel_state::gather(input,
|
||||
parallel_args_.dp_local_process_group_,
|
||||
input_params.parallel.dp_global_token_nums);
|
||||
input_params.dp_global_token_nums);
|
||||
}
|
||||
// MoE Gate
|
||||
auto router_logits = gate_(input);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2025-2026 The xLLM Authors.
|
||||
/* Copyright 2025 The xLLM Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
Reference in New Issue
Block a user