Skip to content

Commit 8e8ad82

Browse files
committed
refactor: add USE_NPU macro to multiple layer implementations for platform support and add layer namespace.
1 parent 38a90ea commit 8e8ad82

Some content is hidden

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

54 files changed

+233
-156
lines changed

xllm/core/layers/attention_mask.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616
#include "attention_mask.h"
1717

1818
namespace xllm {
19+
namespace layer {
1920

2021
AttentionMask::AttentionMask(at::Device device,
2122
torch::Dtype dtype,
@@ -83,4 +84,5 @@ void AttentionMask::update_attn_cache(torch::Dtype dtype,
8384
}
8485
}
8586

87+
} // namespace layer
8688
} // namespace xllm

xllm/core/layers/attention_mask.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
#include <torch/torch.h>
1818

1919
namespace xllm {
20+
namespace layer {
2021

2122
class AttentionMask : public torch::nn::Module {
2223
public:
@@ -49,4 +50,5 @@ class AttentionMask : public torch::nn::Module {
4950
at::Tensor atten_mask_cache_;
5051
};
5152

53+
} // namespace layer
5254
} // namespace xllm

xllm/core/layers/base_layer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616
#include "base_layer.h"
1717

1818
namespace xllm {
19+
namespace layer {
1920

2021
BaseLayer::BaseLayer(const Context& context)
2122
: device_(context.get_tensor_options().device()),
@@ -142,4 +143,5 @@ void BaseLayer::set_weight(const StateDict& state_dict,
142143
}
143144
}
144145

146+
} // namespace layer
145147
} // namespace xllm

xllm/core/layers/base_layer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ limitations under the License.
3333
#include "framework/state_dict/state_dict.h"
3434

3535
namespace xllm {
36+
namespace layer {
3637

3738
enum class TransposeType : int {
3839
INVALID = -1,
@@ -139,4 +140,5 @@ class BaseLayer : public torch::nn::Module {
139140
int32_t dp_local_tp_rank_;
140141
};
141142

143+
} // namespace layer
142144
} // namespace xllm

xllm/core/layers/column_parallel_linear.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ limitations under the License.
1717

1818
#if defined(USE_NPU)
1919
#include "npu/npu_column_parallel_linear_impl.h"
20-
#include "pytorch/adapter/utils/utils.h"
2120
#endif
2221

2322
namespace xllm {
23+
namespace layer {
2424

25+
#if defined(USE_NPU)
2526
class ColumnParallelLinear
2627
: public torch::nn::ModuleHolder<NpuColumnParallelLinearImpl> {
2728
public:
@@ -31,5 +32,7 @@ class ColumnParallelLinear
3132
ColumnParallelLinear(const Context& context)
3233
: ModuleHolder(std::make_shared<NpuColumnParallelLinearImpl>(context)) {}
3334
};
35+
#endif
3436

37+
} // namespace layer
3538
} // namespace xllm

xllm/core/layers/deepseek_v2_decoder_layer.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ limitations under the License.
1717

1818
#if defined(USE_NPU)
1919
#include "npu/npu_deepseek_v2_decoder_layer_impl.h"
20-
#include "pytorch/adapter/utils/utils.h"
2120
#endif
2221

2322
namespace xllm {
23+
namespace layer {
2424

25+
#if defined(USE_NPU)
2526
class DeepseekV2DecoderLayer
2627
: public torch::nn::ModuleHolder<NpuDeepseekV2DecoderLayerImpl> {
2728
public:
@@ -36,5 +37,7 @@ class DeepseekV2DecoderLayer
3637
layer_id,
3738
sm_scale)) {}
3839
};
40+
#endif
3941

42+
} // namespace layer
4043
} // namespace xllm

xllm/core/layers/llama_decoder_layer.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ limitations under the License.
1717

1818
#if defined(USE_NPU)
1919
#include "npu/npu_llama_decoder_layer_impl.h"
20-
#include "pytorch/adapter/utils/utils.h"
2120
#endif
2221

2322
namespace xllm {
23+
namespace layer {
2424

25+
#if defined(USE_NPU)
2526
class LlamaDecoderLayer
2627
: public torch::nn::ModuleHolder<NpuLlamaDecoderLayerImpl> {
2728
public:
@@ -31,5 +32,7 @@ class LlamaDecoderLayer
3132
LlamaDecoderLayer(const Context& context)
3233
: ModuleHolder(std::make_shared<NpuLlamaDecoderLayerImpl>(context)) {}
3334
};
35+
#endif
3436

37+
} // namespace layer
3538
} // namespace xllm

xllm/core/layers/lm_head.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ limitations under the License.
1717

1818
#if defined(USE_NPU)
1919
#include "npu/npu_lm_head_impl.h"
20-
#include "pytorch/adapter/utils/utils.h"
2120
#endif
2221

2322
namespace xllm {
23+
namespace layer {
2424

25+
#if defined(USE_NPU)
2526
class LmHead : public torch::nn::ModuleHolder<NpuLmHeadImpl> {
2627
public:
2728
using torch::nn::ModuleHolder<NpuLmHeadImpl>::ModuleHolder;
@@ -30,5 +31,7 @@ class LmHead : public torch::nn::ModuleHolder<NpuLmHeadImpl> {
3031
LmHead(const Context& context)
3132
: ModuleHolder(std::make_shared<NpuLmHeadImpl>(context)) {}
3233
};
34+
#endif
3335

36+
} // namespace layer
3437
} // namespace xllm

xllm/core/layers/multi_head_attention.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616
#include "multi_head_attention.h"
1717

1818
namespace xllm {
19+
namespace layer {
1920

2021
MultiheadAttentionImpl::MultiheadAttentionImpl(const Context& context)
2122
: n_head_(context.get_model_args().n_heads()),
@@ -104,4 +105,5 @@ void MultiheadAttentionImpl::verify_loaded_weights(
104105
<< "out_proj.bias is not loaded for " << prefix + "out_proj.bias";
105106
}
106107

108+
} // namespace layer
107109
} // namespace xllm

xllm/core/layers/multi_head_attention.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ limitations under the License.
2121
#include "framework/state_dict/state_dict.h"
2222

2323
namespace xllm {
24+
namespace layer {
2425

2526
class MultiheadAttentionImpl : public torch::nn::Module {
2627
public:
@@ -54,4 +55,5 @@ class MultiheadAttentionImpl : public torch::nn::Module {
5455

5556
TORCH_MODULE(MultiheadAttention);
5657

58+
} // namespace layer
5759
} // namespace xllm

0 commit comments

Comments
 (0)